mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-51245 sqlsrv: Diagnose missing READ_COMMITTED_SNAPSHOT mode
Without it, transactions are executed in standard READ_COMMITED mode, without snapshoting/row versioning, leading to update conflicts under high concurrency.
This commit is contained in:
parent
a9daab4927
commit
48657a6713
@ -117,6 +117,37 @@ class sqlsrv_native_moodle_database extends moodle_database {
|
||||
return get_string('nativesqlsrvhelp', 'install');
|
||||
}
|
||||
|
||||
/**
|
||||
* Diagnose database and tables, this function is used
|
||||
* to verify database and driver settings, db engine types, etc.
|
||||
*
|
||||
* @return string null means everything ok, string means problem found.
|
||||
*/
|
||||
public function diagnose() {
|
||||
// Verify the database is running with READ_COMMITTED_SNAPSHOT enabled.
|
||||
// (that's required to get snapshots/row versioning on READ_COMMITED mode).
|
||||
$correctrcsmode = false;
|
||||
$sql = "SELECT is_read_committed_snapshot_on
|
||||
FROM sys.databases
|
||||
WHERE name = '{$this->dbname}'";
|
||||
$this->query_start($sql, null, SQL_QUERY_AUX);
|
||||
$result = sqlsrv_query($this->sqlsrv, $sql);
|
||||
$this->query_end($result);
|
||||
if ($result) {
|
||||
if ($row = sqlsrv_fetch_array($result)) {
|
||||
$correctrcsmode = (bool)reset($row);
|
||||
}
|
||||
}
|
||||
$this->free_result($result);
|
||||
|
||||
if (!$correctrcsmode) {
|
||||
return get_string('mssqlrcsmodemissing', 'error');
|
||||
}
|
||||
|
||||
// Arrived here, all right.
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to db
|
||||
* Must be called before most other methods. (you can call methods that return connection configuration parameters)
|
||||
|
Loading…
x
Reference in New Issue
Block a user