MDL-74681 lib/dml: moodle_read_slave_trait: written table timestamping
Moved written table timestamping from query_start() to query_end(): We are adjusting table last written times at the end of transaction. That does not apply to immediate database writes that are not performed within transaction. This change is to set last written time after the query has finished for such writes, rather than before it started. That way long write operations cannot spill over the latency parameter.
This commit is contained in:
@@ -41,6 +41,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
select_db_handle as read_slave_select_db_handle;
|
||||
can_use_readonly as read_slave_can_use_readonly;
|
||||
query_start as read_slave_query_start;
|
||||
query_end as read_slave_query_end;
|
||||
}
|
||||
|
||||
/** @var array $dbhcursor keep track of open cursors */
|
||||
@@ -184,12 +185,20 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
}
|
||||
|
||||
ob_start();
|
||||
if (empty($this->dboptions['dbpersist'])) {
|
||||
$this->pgsql = pg_connect($connection, PGSQL_CONNECT_FORCE_NEW);
|
||||
} else {
|
||||
$this->pgsql = pg_pconnect($connection, PGSQL_CONNECT_FORCE_NEW);
|
||||
// It seems that pg_connect() handles some errors differently.
|
||||
// For example, name resolution error will raise an exception, and non-existing
|
||||
// database or wrong credentials will just return false.
|
||||
// We need to cater for both.
|
||||
try {
|
||||
if (empty($this->dboptions['dbpersist'])) {
|
||||
$this->pgsql = pg_connect($connection, PGSQL_CONNECT_FORCE_NEW);
|
||||
} else {
|
||||
$this->pgsql = pg_pconnect($connection, PGSQL_CONNECT_FORCE_NEW);
|
||||
}
|
||||
$dberr = ob_get_contents();
|
||||
} catch (\Exception $e) {
|
||||
$dberr = $e->getMessage();
|
||||
}
|
||||
$dberr = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$status = $this->pgsql ? pg_connection_status($this->pgsql) : false;
|
||||
@@ -326,7 +335,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
// reset original debug level
|
||||
error_reporting($this->last_error_reporting);
|
||||
try {
|
||||
parent::query_end($result);
|
||||
$this->read_slave_query_end($result);
|
||||
if ($this->savepointpresent and $this->last_type != SQL_QUERY_AUX and $this->last_type != SQL_QUERY_SELECT) {
|
||||
$res = @pg_query($this->pgsql, "RELEASE SAVEPOINT moodle_pg_savepoint; SAVEPOINT moodle_pg_savepoint");
|
||||
if ($res) {
|
||||
|
||||
Reference in New Issue
Block a user