: 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']
*/
/**
- * 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.
* 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.
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 );
/** @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)
* 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();
}
/**
/**
* 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 );
}
/**
* @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];
}
/**
*/
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." );
}
return $this->managers[$name]['instance'];
}
+ /**
+ * 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.