aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/filebackend/FileBackend.php2
-rw-r--r--includes/filebackend/lockmanager/DBLockManager.php8
-rw-r--r--includes/filebackend/lockmanager/LockManager.php10
-rw-r--r--includes/filebackend/lockmanager/LockManagerGroup.php43
4 files changed, 40 insertions, 23 deletions
diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php
index 8c0ce884494c..0e61d0c4b3bd 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -101,7 +101,7 @@ abstract class FileBackend {
: wfWikiID(); // e.g. "my_wiki-en_"
$this->lockManager = ( $config['lockManager'] instanceof LockManager )
? $config['lockManager']
- : LockManagerGroup::singleton()->get( $config['lockManager'] );
+ : LockManagerGroup::singleton( $this->wikiId )->get( $config['lockManager'] );
$this->fileJournal = isset( $config['fileJournal'] )
? ( ( $config['fileJournal'] instanceof FileJournal )
? $config['fileJournal']
diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php
index 8196d5b8f4a4..7b365c1b15f0 100644
--- a/includes/filebackend/lockmanager/DBLockManager.php
+++ b/includes/filebackend/lockmanager/DBLockManager.php
@@ -22,7 +22,8 @@
*/
/**
- * Version of LockManager based on using DB table locks.
+ * Version of LockManager based on using DB table row locks.
+ *
* This is meant for multi-wiki systems that may share files.
* All locks are blocking, so it might be useful to set a small
* lock-wait timeout via server config to curtail deadlocks.
@@ -67,6 +68,7 @@ class DBLockManager extends QuorumLockManager {
* each having an odd-numbered list of DB names (peers) as values.
* Any DB named 'localDBMaster' will automatically use the DB master
* settings for this wiki (without the need for a dbServers entry).
+ * Only use 'localDBMaster' if the domain is a valid wiki ID.
* - lockExpiry : Lock timeout (seconds) for dropped connections. [optional]
* This tells the DB server how long to wait before assuming
* connection failure and releasing all the locks for a session.
@@ -197,8 +199,8 @@ class DBLockManager extends QuorumLockManager {
if ( !isset( $this->conns[$lockDb] ) ) {
$db = null;
if ( $lockDb === 'localDBMaster' ) {
- $lb = wfGetLBFactory()->getMainLB( $this->wiki );
- $db = $lb->getConnection( DB_MASTER, array(), $this->wiki );
+ $lb = wfGetLBFactory()->getMainLB( $this->domain );
+ $db = $lb->getConnection( DB_MASTER, array(), $this->domain );
} elseif ( isset( $this->dbServers[$lockDb] ) ) {
$config = $this->dbServers[$lockDb];
$db = DatabaseBase::factory( $config['type'], $config );
diff --git a/includes/filebackend/lockmanager/LockManager.php b/includes/filebackend/lockmanager/LockManager.php
index 119006a38502..f988ff417216 100644
--- a/includes/filebackend/lockmanager/LockManager.php
+++ b/includes/filebackend/lockmanager/LockManager.php
@@ -53,7 +53,7 @@ abstract class LockManager {
/** @var Array Map of (resource path => lock type => count) */
protected $locksHeld = array();
- protected $wiki; // string; wiki ID
+ protected $domain; // string; domain (usually wiki ID)
/* Lock types; stronger locks have higher values */
const LOCK_SH = 1; // shared lock (for reads)
@@ -64,12 +64,12 @@ abstract class LockManager {
* Construct a new instance from configuration
*
* $config paramaters include:
- * - wiki : Wiki ID string that all resources are relative to [optional]
+ * - domain : Domain (usually wiki ID) that all resources are relative to [optional]
*
* @param $config Array
*/
public function __construct( array $config ) {
- $this->wiki = isset( $config['wiki'] ) ? $config['wiki'] : wfWikiID();
+ $this->domain = isset( $config['domain'] ) ? $config['domain'] : wfWikiID();
}
/**
@@ -102,14 +102,14 @@ abstract class LockManager {
/**
* Get the base 36 SHA-1 of a string, padded to 31 digits.
- * Before hashing, the path will be prefixed with the wiki ID.
+ * Before hashing, the path will be prefixed with the domain ID.
* This should be used interally for lock key or file names.
*
* @param $path string
* @return string
*/
final protected function sha1Base36Absolute( $path ) {
- return wfBaseConvert( sha1( "{$this->wiki}:{$path}" ), 16, 36, 31 );
+ return wfBaseConvert( sha1( "{$this->domain}:{$path}" ), 16, 36, 31 );
}
/**
diff --git a/includes/filebackend/lockmanager/LockManagerGroup.php b/includes/filebackend/lockmanager/LockManagerGroup.php
index 267d391e4008..f0d581837e43 100644
--- a/includes/filebackend/lockmanager/LockManagerGroup.php
+++ b/includes/filebackend/lockmanager/LockManagerGroup.php
@@ -29,32 +29,32 @@
* @since 1.19
*/
class LockManagerGroup {
- /** @var Array (wiki => LockManager) */
+ /** @var Array (domain => LockManager) */
protected static $instances = array();
- protected $wiki; // string; wiki ID
+ protected $domain; // string; domain (usually wiki ID)
- /** @var Array of (name => ('class' =>, 'config' =>, 'instance' =>)) */
+ /** @var Array of (name => ('class' => ..., 'config' => ..., 'instance' => ...)) */
protected $managers = array();
/**
- * @param $wiki string Wiki ID
+ * @param $domain string Domain (usually wiki ID)
*/
- protected function __construct( $wiki ) {
- $this->wiki = $wiki;
+ protected function __construct( $domain ) {
+ $this->domain = $domain;
}
/**
- * @param $wiki string Wiki ID
+ * @param $domain string Domain (usually wiki ID)
* @return LockManagerGroup
*/
- public static function singleton( $wiki = false ) {
- $wiki = ( $wiki === false ) ? wfWikiID() : $wiki;
- if ( !isset( self::$instances[$wiki] ) ) {
- self::$instances[$wiki] = new self( $wiki );
- self::$instances[$wiki]->initFromGlobals();
+ public static function singleton( $domain = false ) {
+ $domain = ( $domain === false ) ? wfWikiID() : $domain;
+ if ( !isset( self::$instances[$domain] ) ) {
+ self::$instances[$domain] = new self( $domain );
+ self::$instances[$domain]->initFromGlobals();
}
- return self::$instances[$wiki];
+ return self::$instances[$domain];
}
/**
@@ -86,7 +86,7 @@ class LockManagerGroup {
*/
protected function register( array $configs ) {
foreach ( $configs as $config ) {
- $config['wiki'] = $this->wiki;
+ $config['domain'] = $this->domain;
if ( !isset( $config['name'] ) ) {
throw new MWException( "Cannot register a lock manager with no name." );
}
@@ -125,6 +125,21 @@ class LockManagerGroup {
}
/**
+ * Get the config array for a lock manager object with a given name
+ *
+ * @param $name string
+ * @return Array
+ * @throws MWException
+ */
+ public function config( $name ) {
+ if ( !isset( $this->managers[$name] ) ) {
+ throw new MWException( "No lock manager defined with the name `$name`." );
+ }
+ $class = $this->managers[$name]['class'];
+ return array( 'class' => $class ) + $this->managers[$name]['config'];
+ }
+
+ /**
* Get the default lock manager configured for the site.
* Returns NullLockManager if no lock manager could be found.
*