Cleanups to DatabaseMysqlBase
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactory.php
index 107a7e2..49fac6a 100644 (file)
@@ -50,7 +50,7 @@ abstract class LBFactory {
        protected $wanCache;
 
        /** @var string Local domain */
-       protected $domain;
+       protected $localDomain;
        /** @var string Local hostname of the app server */
        protected $hostname;
        /** @var mixed */
@@ -79,7 +79,7 @@ abstract class LBFactory {
         * @param array $conf
         */
        public function __construct( array $conf ) {
-               $this->domain = isset( $conf['domain'] ) ? $conf['domain'] : '';
+               $this->localDomain = isset( $conf['localDomain'] ) ? $conf['localDomain'] : '';
 
                if ( isset( $conf['readOnlyReason'] ) && is_string( $conf['readOnlyReason'] ) ) {
                        $this->readOnlyReason = $conf['readOnlyReason'];
@@ -445,8 +445,7 @@ abstract class LBFactory {
                $failed = [];
                foreach ( $lbs as $i => $lb ) {
                        if ( $masterPositions[$i] ) {
-                               // The DBMS may not support getMasterPos() or the whole
-                               // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
+                               // The DBMS may not support getMasterPos()
                                if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) {
                                        $failed[] = $lb->getServerName( $lb->getWriterIndex() );
                                }
@@ -608,7 +607,7 @@ abstract class LBFactory {
         */
        final protected function baseLoadBalancerParams() {
                return [
-                       'localDomain' => $this->domain,
+                       'localDomain' => $this->localDomain,
                        'readOnlyReason' => $this->readOnlyReason,
                        'srvCache' => $this->srvCache,
                        'wanCache' => $this->wanCache,
@@ -633,15 +632,18 @@ abstract class LBFactory {
        }
 
        /**
-        * Define a new local domain (for testing)
+        * Set a new table prefix for the existing local domain ID for testing
         *
-        * Caller should make sure no local connection are open to the old local domain
-        *
-        * @param string $domain
+        * @param string $prefix
         * @since 1.28
         */
-       public function setDomainPrefix( $domain ) {
-               $this->domain = $domain;
+       public function setDomainPrefix( $prefix ) {
+               list( $dbName, ) = explode( '-', $this->localDomain, 2 );
+               $this->localDomain = "{$dbName}-{$prefix}";
+
+               $this->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
+                       $lb->setDomainPrefix( $prefix );
+               } );
        }
 
        /**