From: Aaron Schulz Date: Fri, 1 Feb 2013 18:29:10 +0000 (-0800) Subject: [LockManager] Generallized wiki field to a domain field. X-Git-Tag: 1.31.0-rc.0~20829 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=a4f27a198ffbcf93fce5371cd905cdd704f22c5c;p=lhc%2Fweb%2Fwiklou.git [LockManager] Generallized wiki field to a domain field. * In some cases (like certain qualified file backends), a domain may be desired that is not simple a wiki ID. * Also added a LockManangerGroup::config() function to export the configuration of a lock manager. Change-Id: I5a75c55be3cc9017ed8a717d6d30e466fd00340f --- diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php index 8c0ce88449..0e61d0c4b3 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 8196d5b8f4..7b365c1b15 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 119006a385..f988ff4172 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 267d391e40..f0d581837e 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." ); } @@ -124,6 +124,21 @@ class LockManagerGroup { 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.