X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilebackend%2Flockmanager%2FDBLockManager.php;h=c9aad43a489ebcc801896cbe304c756fcdbdad2a;hb=77fc516630b0089826c69ac5176936f13c467e1c;hp=f4410cad6c0189ae52a9e862baf8b16c92bc589f;hpb=d42754e47722436ef52218f21a8e544a05ee9ad7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php index f4410cad6c..c9aad43a48 100644 --- a/includes/filebackend/lockmanager/DBLockManager.php +++ b/includes/filebackend/lockmanager/DBLockManager.php @@ -26,9 +26,8 @@ * * This is meant for multi-wiki systems that may share files. * - * All lock requests for a resource, identified by a hash string, will map - * to one bucket. Each bucket maps to one or several peer DBs, each on their - * own server, all having the filelocks.sql tables (with row-level locking). + * All lock requests for a resource, identified by a hash string, will map to one bucket. + * Each bucket maps to one or several peer DBs, each on their own server. * A majority of peer DBs must agree for a lock to be acquired. * * Caching is used to avoid hitting servers that are down. @@ -37,7 +36,7 @@ * @since 1.19 */ abstract class DBLockManager extends QuorumLockManager { - /** @var array Map of DB names to server config */ + /** @var array[] Map of DB names to server config */ protected $dbServers; // (DB name => server config array) /** @var BagOStuff */ protected $statusCache; @@ -46,7 +45,7 @@ abstract class DBLockManager extends QuorumLockManager { protected $safeDelay; // integer number of seconds protected $session = 0; // random integer - /** @var array Map Database connections (DB name => Database) */ + /** @var IDatabase[] Map Database connections (DB name => Database) */ protected $conns = []; /** @@ -113,6 +112,8 @@ abstract class DBLockManager extends QuorumLockManager { return $status; } + abstract protected function doGetLocksOnServer( $lockSrv, array $paths, $type ); + protected function freeLocksOnServer( $lockSrv, array $pathsByType ) { return Status::newGood(); } @@ -148,8 +149,7 @@ abstract class DBLockManager extends QuorumLockManager { if ( !isset( $this->conns[$lockDb] ) ) { $db = null; if ( $lockDb === 'localDBMaster' ) { - $lb = wfGetLBFactory()->getMainLB( $this->domain ); - $db = $lb->getConnection( DB_MASTER, [], $this->domain ); + $db = $this->getLocalLB()->getConnection( DB_MASTER, [], $this->domain ); } elseif ( isset( $this->dbServers[$lockDb] ) ) { $config = $this->dbServers[$lockDb]; $db = DatabaseBase::factory( $config['type'], $config ); @@ -176,6 +176,13 @@ abstract class DBLockManager extends QuorumLockManager { return $this->conns[$lockDb]; } + /** + * @return LoadBalancer + */ + protected function getLocalLB() { + return wfGetLBFactory()->getMainLB( $this->domain ); + } + /** * Do additional initialization for new lock DB connection * @@ -235,6 +242,8 @@ abstract class DBLockManager extends QuorumLockManager { /** * MySQL version of DBLockManager that supports shared locks. + * + * All lock servers must have the innodb table defined in locking/filelocks.sql. * All locks are non-blocking, which avoids deadlocks. * * @ingroup LockManager @@ -247,10 +256,11 @@ class MySqlLockManager extends DBLockManager { self::LOCK_EX => self::LOCK_EX ]; - /** - * @param string $lockDb - * @param IDatabase $db - */ + protected function getLocalLB() { + // Use a separate connection so releaseAllLocks() doesn't rollback the main trx + return wfGetLBFactory()->newMainLB( $this->domain ); + } + protected function initConnection( $lockDb, IDatabase $db ) { # Let this transaction see lock rows from other transactions $db->query( "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" );