MDL-14992 pg session locking (8.2 and later only), refactoring and db session not default yet in new installs

This commit is contained in:
skodak
2009-01-17 14:31:29 +00:00
parent a644e212df
commit 5e9dd01778
4 changed files with 58 additions and 28 deletions
+40
View File
@@ -1047,6 +1047,46 @@ class pgsql_native_moodle_database extends moodle_database {
return $positivematch ? '~*' : '!~*';
}
/// session locking
public function session_lock_supported() {
return $this->is_min_version('8.2.0');
}
public function get_session_lock($rowid) {
// TODO: there is a potential locking problem for database running
// multiple instances of moodle, we could try to use pg_advisory_lock(int, int),
// luckily there is not a big chance that they would collide
if (!$this->session_lock_supported()) {
return;
}
parent::get_session_lock($rowid);
$sql = "SELECT pg_advisory_lock($rowid)";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
$this->query_end($result);
if ($result) {
pg_free_result($result);
}
}
public function release_session_lock($rowid) {
if (!$this->session_lock_supported()) {
return;
}
parent::release_session_lock($rowid);
$sql = "SELECT pg_advisory_unlock($rowid)";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
$this->query_end($result);
if ($result) {
pg_free_result($result);
}
}
/// transactions
/**
* on DBs that support it, switch to transaction mode and begin a transaction