From 57ba462e4bc38bb6a75bdb7eef5cb7d27df59729 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Sep 2016 19:17:22 -0700 Subject: [PATCH] Move LBFactoryMulti to /libs/rdbms Also rename $wiki => $domain and lastWiki => lastDomain. Change-Id: I2a30f42721715c56f5cddf9f07c10e8de70addd1 --- autoload.php | 2 +- includes/libs/rdbms/lbfactory/LBFactory.php | 8 +-- .../rdbms/lbfactory}/LBFactoryMulti.php | 71 +++++++++---------- 3 files changed, 39 insertions(+), 42 deletions(-) rename includes/{db/loadbalancer => libs/rdbms/lbfactory}/LBFactoryMulti.php (86%) diff --git a/autoload.php b/autoload.php index 52c929a56f..4a72799c46 100644 --- a/autoload.php +++ b/autoload.php @@ -659,7 +659,7 @@ $wgAutoloadLocalClasses = [ 'KuConverter' => __DIR__ . '/languages/classes/LanguageKu.php', 'LBFactory' => __DIR__ . '/includes/libs/rdbms/lbfactory/LBFactory.php', 'LBFactoryMW' => __DIR__ . '/includes/db/loadbalancer/LBFactoryMW.php', - 'LBFactoryMulti' => __DIR__ . '/includes/db/loadbalancer/LBFactoryMulti.php', + 'LBFactoryMulti' => __DIR__ . '/includes/libs/rdbms/lbfactory/LBFactoryMulti.php', 'LBFactorySimple' => __DIR__ . '/includes/libs/rdbms/lbfactory/LBFactorySimple.php', 'LBFactorySingle' => __DIR__ . '/includes/db/loadbalancer/LBFactorySingle.php', 'LCStore' => __DIR__ . '/includes/cache/localisation/LCStore.php', diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index 00474fe0bc..40ba458826 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -141,7 +141,7 @@ abstract class LBFactory { * Create a new load balancer object. The resulting object will be untracked, * not chronology-protected, and the caller is responsible for cleaning it up. * - * @param bool|string $domain Wiki ID, or false for the current wiki + * @param bool|string $domain Domain ID, or false for the current domain * @return ILoadBalancer */ abstract public function newMainLB( $domain = false ); @@ -149,7 +149,7 @@ abstract class LBFactory { /** * Get a cached (tracked) load balancer object. * - * @param bool|string $domain Wiki ID, or false for the current wiki + * @param bool|string $domain Domain ID, or false for the current domain * @return ILoadBalancer */ abstract public function getMainLB( $domain = false ); @@ -160,7 +160,7 @@ abstract class LBFactory { * cleaning it up. * * @param string $cluster External storage cluster, or false for core - * @param bool|string $domain Wiki ID, or false for the current wiki + * @param bool|string $domain Domain ID, or false for the current domain * @return ILoadBalancer */ abstract protected function newExternalLB( $cluster, $domain = false ); @@ -169,7 +169,7 @@ abstract class LBFactory { * Get a cached (tracked) load balancer for external storage * * @param string $cluster External storage cluster, or false for core - * @param bool|string $domain Wiki ID, or false for the current wiki + * @param bool|string $domain Domain ID, or false for the current domain * @return ILoadBalancer */ abstract public function getExternalLB( $cluster, $domain = false ); diff --git a/includes/db/loadbalancer/LBFactoryMulti.php b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php similarity index 86% rename from includes/db/loadbalancer/LBFactoryMulti.php rename to includes/libs/rdbms/lbfactory/LBFactoryMulti.php index 1f7f528ab1..0f1493a82b 100644 --- a/includes/db/loadbalancer/LBFactoryMulti.php +++ b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php @@ -1,6 +1,6 @@ lowest): @@ -83,7 +83,7 @@ * * @ingroup Database */ -class LBFactoryMulti extends LBFactoryMW { +class LBFactoryMulti extends LBFactory { /** @var array A map of database names to section names */ private $sectionsByDB; @@ -94,9 +94,8 @@ class LBFactoryMulti extends LBFactoryMW { private $sectionLoads; /** - * @var array A server info associative array as documented for - * $wgDBservers. The host, hostName and load entries will be - * overridden + * @var array[] Server info associative array + * @note The host, hostName and load entries will be overridden */ private $serverTemplate; @@ -157,7 +156,7 @@ class LBFactoryMulti extends LBFactoryMW { private $loadMonitorClass; /** @var string */ - private $lastWiki; + private $lastDomain; /** @var string */ private $lastSection; @@ -178,7 +177,7 @@ class LBFactoryMulti extends LBFactoryMW { foreach ( $required as $key ) { if ( !isset( $conf[$key] ) ) { - throw new InvalidArgumentException( __CLASS__ . ": $key is required in configuration" ); + throw new InvalidArgumentException( __CLASS__ . ": $key is required." ); } $this->$key = $conf[$key]; } @@ -191,32 +190,32 @@ class LBFactoryMulti extends LBFactoryMW { } /** - * @param bool|string $wiki + * @param bool|string $domain * @return string */ - private function getSectionForWiki( $wiki = false ) { - if ( $this->lastWiki === $wiki ) { + private function getSectionForDomain( $domain = false ) { + if ( $this->lastDomain === $domain ) { return $this->lastSection; } - list( $dbName, ) = $this->getDBNameAndPrefix( $wiki ); + list( $dbName, ) = $this->getDBNameAndPrefix( $domain ); if ( isset( $this->sectionsByDB[$dbName] ) ) { $section = $this->sectionsByDB[$dbName]; } else { $section = 'DEFAULT'; } $this->lastSection = $section; - $this->lastWiki = $wiki; + $this->lastDomain = $domain; return $section; } /** - * @param bool|string $wiki + * @param bool|string $domain * @return LoadBalancer */ - public function newMainLB( $wiki = false ) { - list( $dbName, ) = $this->getDBNameAndPrefix( $wiki ); - $section = $this->getSectionForWiki( $wiki ); + public function newMainLB( $domain = false ) { + list( $dbName, ) = $this->getDBNameAndPrefix( $domain ); + $section = $this->getSectionForDomain( $domain ); if ( isset( $this->groupLoadsByDB[$dbName] ) ) { $groupLoads = $this->groupLoadsByDB[$dbName]; } else { @@ -224,7 +223,8 @@ class LBFactoryMulti extends LBFactoryMW { } if ( isset( $this->groupLoadsBySection[$section] ) ) { - $groupLoads = array_merge_recursive( $groupLoads, $this->groupLoadsBySection[$section] ); + $groupLoads = array_merge_recursive( + $groupLoads, $this->groupLoadsBySection[$section] ); } $readOnlyReason = $this->readOnlyReason; @@ -247,13 +247,13 @@ class LBFactoryMulti extends LBFactoryMW { } /** - * @param bool|string $wiki + * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain * @return LoadBalancer */ - public function getMainLB( $wiki = false ) { - $section = $this->getSectionForWiki( $wiki ); + public function getMainLB( $domain = false ) { + $section = $this->getSectionForDomain( $domain ); if ( !isset( $this->mainLBs[$section] ) ) { - $lb = $this->newMainLB( $wiki ); + $lb = $this->newMainLB( $domain ); $this->getChronologyProtector()->initLB( $lb ); $this->mainLBs[$section] = $lb; } @@ -263,11 +263,11 @@ class LBFactoryMulti extends LBFactoryMW { /** * @param string $cluster - * @param bool|string $wiki + * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain * @throws InvalidArgumentException * @return LoadBalancer */ - protected function newExternalLB( $cluster, $wiki = false ) { + protected function newExternalLB( $cluster, $domain = false ) { if ( !isset( $this->externalLoads[$cluster] ) ) { throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" ); } @@ -289,12 +289,12 @@ class LBFactoryMulti extends LBFactoryMW { /** * @param string $cluster External storage cluster, or false for core - * @param bool|string $wiki Wiki ID, or false for the current wiki + * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain * @return LoadBalancer */ - public function getExternalLB( $cluster, $wiki = false ) { + public function getExternalLB( $cluster, $domain = false ) { if ( !isset( $this->extLBs[$cluster] ) ) { - $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki ); + $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $domain ); $this->getChronologyProtector()->initLB( $this->extLBs[$cluster] ); } @@ -390,18 +390,15 @@ class LBFactoryMulti extends LBFactoryMW { } /** - * Get the database name and prefix based on the wiki ID - * @param bool|string $wiki - * @return array + * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain + * @return array [database name, table prefix] */ - private function getDBNameAndPrefix( $wiki = false ) { - if ( $wiki === false ) { - global $wgDBname, $wgDBprefix; + private function getDBNameAndPrefix( $domain = false ) { + $domain = ( $domain === false ) + ? $this->localDomain + : DatabaseDomain::newFromId( $domain ); - return [ $wgDBname, $wgDBprefix ]; - } else { - return wfSplitWikiID( $wiki ); - } + return [ $domain->getDatabase(), $domain->getTablePrefix() ]; } /** -- 2.20.1