From: Aaron Schulz Date: Tue, 30 Jan 2018 03:09:07 +0000 (-0800) Subject: rdbms: set the schema in the LBFactory local domain X-Git-Tag: 1.31.0-rc.0~727^2 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=d444b2c0b40087a87fb74914be89041b09d8593b;p=lhc%2Fweb%2Fwiklou.git rdbms: set the schema in the LBFactory local domain Also, enforce that new DB connection use the domain schema as is the case with the DB name and table prefix. The code worked previously since the local domain did not override the schema in the server configuration arrays, so it happened not to clobber the domain schema. Lastly, fix unit test fatal in LBFactorySingle::forEachLB() when called during LBFactorySingle::_destruct(). Change-Id: Ia9ddef0f21591d0c8b15f2947cd61569e3fec7a0 --- diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index aa1918d51f..560733200f 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -46,7 +46,7 @@ abstract class MWLBFactory { $lbConf += [ 'localDomain' => new DatabaseDomain( $mainConfig->get( 'DBname' ), - null, + $mainConfig->get( 'DBmwschema' ), $mainConfig->get( 'DBprefix' ) ), 'profiler' => Profiler::instance(), diff --git a/includes/libs/rdbms/lbfactory/LBFactorySingle.php b/includes/libs/rdbms/lbfactory/LBFactorySingle.php index cd998c3e7b..587ab23c02 100644 --- a/includes/libs/rdbms/lbfactory/LBFactorySingle.php +++ b/includes/libs/rdbms/lbfactory/LBFactorySingle.php @@ -102,6 +102,8 @@ class LBFactorySingle extends LBFactory { * @param array $params */ public function forEachLB( $callback, array $params = [] ) { - call_user_func_array( $callback, array_merge( [ $this->lb ], $params ) ); + if ( isset( $this->lb ) ) { // may not be set during _destruct() + call_user_func_array( $callback, array_merge( [ $this->lb ], $params ) ); + } } } diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index ee3c86f1ee..864e6f0a3c 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -825,7 +825,7 @@ class LoadBalancer implements ILoadBalancer { // Use the local domain table prefix if the local domain is specified $server['tablePrefix'] = $this->localDomain->getTablePrefix(); } - $conn = $this->reallyOpenConnection( $server, $this->localDomain->getDatabase() ); + $conn = $this->reallyOpenConnection( $server, $this->localDomain ); $host = $this->getServerName( $i ); if ( $conn->isOpen() ) { $this->connLogger->debug( "Connected to database $i at '$host'." ); @@ -926,7 +926,7 @@ class LoadBalancer implements ILoadBalancer { $server['foreignPoolRefCount'] = 0; $server['foreign'] = true; $server['autoCommitOnly'] = $autoCommit; - $conn = $this->reallyOpenConnection( $server, $dbName ); + $conn = $this->reallyOpenConnection( $server, $domainInstance ); if ( !$conn->isOpen() ) { $this->connLogger->warning( __METHOD__ . ": connection error for $i/$domain" ); $this->errorConnection = $conn; @@ -969,18 +969,19 @@ class LoadBalancer implements ILoadBalancer { * Returns a Database object whether or not the connection was successful. * * @param array $server - * @param string|null $dbNameOverride Use "" to not select any database + * @param DatabaseDomain $domainOverride Use an unspecified domain to not select any database * @return Database * @throws DBAccessError * @throws InvalidArgumentException */ - protected function reallyOpenConnection( array $server, $dbNameOverride ) { + protected function reallyOpenConnection( array $server, DatabaseDomain $domainOverride ) { if ( $this->disabled ) { throw new DBAccessError(); } - if ( $dbNameOverride !== null ) { - $server['dbname'] = $dbNameOverride; + if ( $domainOverride->getDatabase() !== null ) { + $server['dbname'] = $domainOverride->getDatabase(); + $server['schema'] = $domainOverride->getSchema(); } // Let the handle know what the cluster master is (e.g. "db1052") @@ -1698,7 +1699,7 @@ class LoadBalancer implements ILoadBalancer { $oldDomain = $this->localDomain->getId(); $this->setLocalDomain( new DatabaseDomain( $this->localDomain->getDatabase(), - null, + $this->localDomain->getSchema(), $prefix ) ); diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php index c73756330a..89472e7a66 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancerSingle.php @@ -72,7 +72,7 @@ class LoadBalancerSingle extends LoadBalancer { return new static( [ 'connection' => $db ] + $params ); } - protected function reallyOpenConnection( array $server, $dbNameOverride ) { + protected function reallyOpenConnection( array $server, DatabaseDomain $domainOverride ) { return $this->db; } }