Merge "rdbms: make LoadBalancer::doWait() cast $timeout to an integer"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 16 Apr 2018 01:01:21 +0000 (01:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 16 Apr 2018 01:01:21 +0000 (01:01 +0000)
1  2 
includes/libs/rdbms/loadbalancer/LoadBalancer.php

@@@ -575,6 -575,7 +575,6 @@@ class LoadBalancer implements ILoadBala
                        if ( !empty( $connsByServer[$i] ) ) {
                                /** @var IDatabase[] $serverConns */
                                $serverConns = $connsByServer[$i];
 -
                                return reset( $serverConns );
                        }
                }
         * @return bool
         */
        protected function doWait( $index, $open = false, $timeout = null ) {
-               $timeout = max( 1, $timeout ?: $this->waitTimeout );
+               $timeout = max( 1, intval( $timeout ?: $this->waitTimeout ) );
  
                // Check if we already know that the DB has reached this point
                $server = $this->getServerName( $index );
                        $domain = false; // local connection requested
                }
  
 -              if ( ( $flags & self::CONN_TRX_AUTO ) === self::CONN_TRX_AUTO ) {
 +              if ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) === self::CONN_TRX_AUTOCOMMIT ) {
                        // Assuming all servers are of the same type (or similar), which is overwhelmingly
                        // the case, use the master server information to get the attributes. The information
                        // for $i cannot be used since it might be DB_REPLICA, which might require connection
                                // rows (e.g. FOR UPDATE) or (b) make small commits during a larger transactions
                                // to reduce lock contention. None of these apply for sqlite and using separate
                                // connections just causes self-deadlocks.
 -                              $flags &= ~self::CONN_TRX_AUTO;
 -                              $this->connLogger->info( __METHOD__ . ': ignoring CONN_TRX_AUTO to avoid deadlocks.' );
 +                              $flags &= ~self::CONN_TRX_AUTOCOMMIT;
 +                              $this->connLogger->info( __METHOD__ .
 +                                      ': ignoring CONN_TRX_AUTOCOMMIT to avoid deadlocks.' );
                        }
                }
  
  
                if ( $i == self::DB_MASTER ) {
                        $i = $this->getWriterIndex();
 -              } else {
 +              } elseif ( $i == self::DB_REPLICA ) {
                        # Try to find an available server in any the query groups (in order)
                        foreach ( $groups as $group ) {
                                $groupIndex = $this->getReaderIndex( $group, $domain );
                // main set of DB connections but rather its own pool since:
                // a) those are usually set to implicitly use transaction rounds via DBO_TRX
                // b) those must support the use of explicit transaction rounds via beginMasterChanges()
 -              $autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
 +              $autoCommit = ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT );
  
                if ( $domain !== false ) {
                        // Connection is to a foreign domain
                $domainInstance = DatabaseDomain::newFromId( $domain );
                $dbName = $domainInstance->getDatabase();
                $prefix = $domainInstance->getTablePrefix();
 -              $autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
 +              $autoCommit = ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT );
  
                if ( $autoCommit ) {
                        $connFreeKey = self::KEY_FOREIGN_FREE_NOROUND;
        }
  
        public function closeConnection( IDatabase $conn ) {
 -              $serverIndex = $conn->getLBInfo( 'serverIndex' ); // second index level of mConns
 +              $serverIndex = $conn->getLBInfo( 'serverIndex' );
                foreach ( $this->conns as $type => $connsByServer ) {
                        if ( !isset( $connsByServer[$serverIndex] ) ) {
                                continue;