rdbms: turn LoadBalancer waitTimeout default into a class constant
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index ee3c86f..a3361cd 100644 (file)
@@ -122,6 +122,8 @@ class LoadBalancer implements ILoadBalancer {
 
        /** @var int Default 'maxLag' when unspecified */
        const MAX_LAG_DEFAULT = 10;
+       /** @var int Default 'waitTimeout' when unspecified */
+       const MAX_WAIT_DEFAULT = 10;
        /** @var int Seconds to cache master server read-only status */
        const TTL_CACHE_READONLY = 5;
 
@@ -151,7 +153,9 @@ class LoadBalancer implements ILoadBalancer {
                        : DatabaseDomain::newUnspecified();
                $this->setLocalDomain( $localDomain );
 
-               $this->mWaitTimeout = isset( $params['waitTimeout'] ) ? $params['waitTimeout'] : 10;
+               $this->mWaitTimeout = isset( $params['waitTimeout'] )
+                       ? $params['waitTimeout']
+                       : self::MAX_WAIT_DEFAULT;
 
                $this->mReadIndex = -1;
                $this->mConns = [
@@ -825,7 +829,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 +930,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 +973,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 +1703,7 @@ class LoadBalancer implements ILoadBalancer {
                $oldDomain = $this->localDomain->getId();
                $this->setLocalDomain( new DatabaseDomain(
                        $this->localDomain->getDatabase(),
-                       null,
+                       $this->localDomain->getSchema(),
                        $prefix
                ) );