MDL-19711 dml: Enable use of readonly slave database handles

Implemented with moodle_read_slave_trait

Functionality is triggered by supplying config dboption['readonly'].
See config-dist.php for more info on supported dboptions.

pgsql and mysqli drivers are using this feature. Also added support for
connection timeout for these two drivers.
This commit is contained in:
Srdjan 2020-05-07 14:14:29 +10:00
parent d85118369d
commit 46cfde3d95
19 changed files with 2422 additions and 28 deletions

View file

@ -108,13 +108,13 @@ abstract class moodle_database {
/** @var float Last time in seconds with millisecond precision. */
protected $last_time;
/** @var bool Flag indicating logging of query in progress. This helps prevent infinite loops. */
private $loggingquery = false;
protected $loggingquery = false;
/** @var bool True if the db is used for db sessions. */
protected $used_for_db_sessions = false;
/** @var array Array containing open transactions. */
private $transactions = array();
protected $transactions = array();
/** @var bool Flag used to force rollback of all current transactions. */
private $force_rollback = false;
@ -2717,6 +2717,22 @@ abstract class moodle_database {
return $this->reads;
}
/**
* Returns whether we want to connect to slave database for read queries.
* @return bool Want read only connection
*/
public function want_read_slave(): bool {
return false;
}
/**
* Returns the number of reads before first write done by this database.
* @return int Number of reads.
*/
public function perf_get_reads_slave(): int {
return 0;
}
/**
* Returns the number of writes done by this database.
* @return int Number of writes.