From 37022e2e89d8b55d69644ed9e7b78ac3254bf2ed Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 15 Aug 2019 21:07:36 +0300 Subject: [PATCH] LockManagerGroup tweaks One small change that was supposed to be in 5a6c18a0863 but didn't make it into the patch version that got merged, and removal of some long-dead code. phan objected to the use of new $class without being explicitly reassured that $class is, in fact, a string. I don't know why. Change-Id: Ifa00c59ab4464109414f21db37e3a6db21decdf3 --- includes/DefaultSettings.php | 4 ---- .../lockmanager/LockManagerGroup.php | 17 +---------------- .../lockmanager/LockManagerGroupFactory.php | 6 +++--- .../LockManagerGroupIntegrationTest.php | 2 +- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7e13fc25c9..6c5c3d2c4c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -788,10 +788,6 @@ $wgFileBackends = []; * See LockManager::__construct() for more details. * Additional parameters are specific to the lock manager class used. * These settings should be global to all wikis. - * - * When using DBLockManager, the 'dbsByBucket' map can reference 'localDBMaster' as - * a peer database in each bucket. This will result in an extra connection to the domain - * that the LockManager services, which must also be a valid wiki ID. */ $wgLockManagers = []; diff --git a/includes/filebackend/lockmanager/LockManagerGroup.php b/includes/filebackend/lockmanager/LockManagerGroup.php index 7da3753c9b..9b43164a31 100644 --- a/includes/filebackend/lockmanager/LockManagerGroup.php +++ b/includes/filebackend/lockmanager/LockManagerGroup.php @@ -104,25 +104,10 @@ class LockManagerGroup { // Lazy-load the actual lock manager instance if ( !isset( $this->managers[$name]['instance'] ) ) { $class = $this->managers[$name]['class']; + '@phan-var string $class'; $config = $this->managers[$name]['config']; - if ( $class === DBLockManager::class ) { - $lb = $this->lbFactory->getMainLB( $config['domain'] ); - $config['dbServers']['localDBMaster'] = $lb->getLazyConnectionRef( - DB_MASTER, - [], - $config['domain'], - $lb::CONN_TRX_AUTOCOMMIT - ); - $config['srvCache'] = ObjectCache::getLocalServerInstance( 'hash' ); - } $config['logger'] = LoggerFactory::getInstance( 'LockManager' ); - // XXX Looks like phan is right, we are trying to instantiate an abstract class and it - // throws. Did this ever work? Presumably we need to detect the right subclass? Or - // should we just get rid of this? It looks like it never worked since it was first - // introduced by 0cf832a3394 in 2016, so if no one's complained until now, clearly it - // can't be very useful? - // @phan-suppress-next-line PhanTypeInstantiateAbstract $this->managers[$name]['instance'] = new $class( $config ); } diff --git a/includes/filebackend/lockmanager/LockManagerGroupFactory.php b/includes/filebackend/lockmanager/LockManagerGroupFactory.php index 54bbc3d17c..9c8d4bb716 100644 --- a/includes/filebackend/lockmanager/LockManagerGroupFactory.php +++ b/includes/filebackend/lockmanager/LockManagerGroupFactory.php @@ -35,12 +35,12 @@ class LockManagerGroupFactory { } /** - * @param string|bool $domain Domain (usually wiki ID). false for the default (normally the - * current wiki's domain). + * @param string|null|false $domain Domain (usually wiki ID). false for the default (normally + * the current wiki's domain). * @return LockManagerGroup */ public function getLockManagerGroup( $domain = false ) : LockManagerGroup { - if ( $domain === false ) { + if ( $domain === false || $domain === null ) { $domain = $this->defaultDomain; } diff --git a/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php b/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php index 0615e9510d..45ad180bb2 100644 --- a/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php +++ b/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php @@ -41,7 +41,7 @@ class LockManagerGroupIntegrationTest extends MediaWikiIntegrationTestCase { LockManagerGroup::destroySingletons(); $this->assertSame( - null, + WikiMap::getCurrentWikiDbDomain()->getId(), LockManagerGroup::singleton( null )->config( 'a' )['domain'] ); } -- 2.20.1