Fix logged method in LoadBalancer
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 5e08094..f36d98e 100644 (file)
@@ -938,10 +938,6 @@ class LoadBalancer implements ILoadBalancer {
                        $server = $this->servers[$i];
                        $server['serverIndex'] = $i;
                        $server['autoCommitOnly'] = $autoCommit;
-                       if ( $this->localDomain->getDatabase() !== null ) {
-                               // Use the local domain table prefix if the local domain is specified
-                               $server['tablePrefix'] = $this->localDomain->getTablePrefix();
-                       }
                        $conn = $this->reallyOpenConnection( $server, $this->localDomain );
                        $host = $this->getServerName( $i );
                        if ( $conn->isOpen() ) {
@@ -1037,7 +1033,6 @@ class LoadBalancer implements ILoadBalancer {
                                $this->errorConnection = $conn;
                                $conn = false;
                        } else {
-                               $conn->tablePrefix( $prefix ); // as specified
                                // Note that if $domain is an empty string, getDomainID() might not match it
                                $this->conns[$connInUseKey][$i][$conn->getDomainID()] = $conn;
                                $this->connLogger->debug( __METHOD__ . ": opened new connection for $i/$domain" );
@@ -1081,20 +1076,20 @@ class LoadBalancer implements ILoadBalancer {
         * Returns a Database object whether or not the connection was successful.
         *
         * @param array $server
-        * @param DatabaseDomain $domainOverride Use an unspecified domain to not select any database
+        * @param DatabaseDomain $domain Domain the connection is for, possibly unspecified
         * @return Database
         * @throws DBAccessError
         * @throws InvalidArgumentException
         */
-       protected function reallyOpenConnection( array $server, DatabaseDomain $domainOverride ) {
+       protected function reallyOpenConnection( array $server, DatabaseDomain $domain ) {
                if ( $this->disabled ) {
                        throw new DBAccessError();
                }
 
-               // Handle $domainOverride being a specified or an unspecified domain
-               if ( $domainOverride->getDatabase() === null ) {
-                       // Normally, an RDBMS requires a DB name specified on connection and the $server
-                       // configuration array is assumed to already specify an appropriate DB name.
+               if ( $domain->getDatabase() === null ) {
+                       // The database domain does not specify a DB name and some database systems require a
+                       // valid DB specified on connection. The $server configuration array contains a default
+                       // DB name to use for connections in such cases.
                        if ( $server['type'] === 'mysql' ) {
                                // For MySQL, DATABASE and SCHEMA are synonyms, connections need not specify a DB,
                                // and the DB name in $server might not exist due to legacy reasons (the default
@@ -1102,10 +1097,16 @@ class LoadBalancer implements ILoadBalancer {
                                $server['dbname'] = null;
                        }
                } else {
-                       $server['dbname'] = $domainOverride->getDatabase();
-                       $server['schema'] = $domainOverride->getSchema();
+                       $server['dbname'] = $domain->getDatabase();
+               }
+
+               if ( $domain->getSchema() !== null ) {
+                       $server['schema'] = $domain->getSchema();
                }
 
+               // It is always possible to connect with any prefix, even the empty string
+               $server['tablePrefix'] = $domain->getTablePrefix();
+
                // Let the handle know what the cluster master is (e.g. "db1052")
                $masterName = $this->getServerName( $this->getWriterIndex() );
                $server['clusterMasterHost'] = $masterName;
@@ -1255,10 +1256,11 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function closeAll() {
-               $this->forEachOpenConnection( function ( IDatabase $conn ) {
+               $fname = __METHOD__;
+               $this->forEachOpenConnection( function ( IDatabase $conn ) use ( $fname ) {
                        $host = $conn->getServer();
                        $this->connLogger->debug(
-                               __METHOD__ . ": closing connection to database '$host'." );
+                               $fname . ": closing connection to database '$host'." );
                        $conn->close();
                } );
 
@@ -1446,6 +1448,7 @@ class LoadBalancer implements ILoadBalancer {
                } );
 
                $e = null; // first exception
+               $fname = __METHOD__;
                // Loop until callbacks stop adding callbacks on other connections
                do {
                        // Run any pending callbacks for each connection...
@@ -1463,13 +1466,13 @@ class LoadBalancer implements ILoadBalancer {
                                }
                        );
                        // Clear out any active transactions left over from callbacks...
-                       $this->forEachOpenMasterConnection( function ( Database $conn ) use ( &$e ) {
+                       $this->forEachOpenMasterConnection( function ( Database $conn ) use ( &$e, $fname ) {
                                if ( $conn->writesPending() ) {
                                        // A callback from another handle wrote to this one and DBO_TRX is set
-                                       $this->queryLogger->warning( __METHOD__ . ": found writes pending." );
+                                       $this->queryLogger->warning( $fname . ": found writes pending." );
                                        $fnames = implode( ', ', $conn->pendingWriteAndCallbackCallers() );
                                        $this->queryLogger->warning(
-                                               __METHOD__ . ": found writes pending ($fnames).",
+                                               $fname . ": found writes pending ($fnames).",
                                                [
                                                        'db_server' => $conn->getServer(),
                                                        'db_name' => $conn->getDBname()
@@ -1478,10 +1481,10 @@ class LoadBalancer implements ILoadBalancer {
                                } elseif ( $conn->trxLevel() ) {
                                        // A callback from another handle read from this one and DBO_TRX is set,
                                        // which can easily happen if there is only one DB (no replicas)
-                                       $this->queryLogger->debug( __METHOD__ . ": found empty transaction." );
+                                       $this->queryLogger->debug( $fname . ": found empty transaction." );
                                }
                                try {
-                                       $conn->commit( __METHOD__, $conn::FLUSHING_ALL_PEERS );
+                                       $conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
                                } catch ( Exception $ex ) {
                                        $e = $e ?: $ex;
                                }
@@ -1928,14 +1931,14 @@ class LoadBalancer implements ILoadBalancer {
                                "Foreign domain connections are still in use ($domains)." );
                }
 
-               $oldDomain = $this->localDomain->getId();
                $this->setLocalDomain( new DatabaseDomain(
                        $this->localDomain->getDatabase(),
                        $this->localDomain->getSchema(),
                        $prefix
                ) );
 
-               $this->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix, $oldDomain ) {
+               // Update the prefix for all local connections...
+               $this->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) {
                        if ( !$db->getLBInfo( 'foreign' ) ) {
                                $db->tablePrefix( $prefix );
                        }