Merge "Rename SquidUpdate => CdnCacheUpdate"
[lhc/web/wiklou.git] / includes / db / loadbalancer / LoadBalancer.php
index 65ee9c7..19b2d1c 100644 (file)
@@ -208,8 +208,6 @@ class LoadBalancer {
                        return false;
                }
 
-               # wfDebugLog( 'connect', var_export( $loads, true ) );
-
                # Return a random representative of the remainder
                return ArrayUtils::pickRandom( $loads );
        }
@@ -247,7 +245,7 @@ class LoadBalancer {
                                $nonErrorLoads = $this->mGroupLoads[$group];
                        } else {
                                # No loads for this group, return false and the caller can use some other group
-                               wfDebug( __METHOD__ . ": no loads for group $group\n" );
+                               wfDebugLog( 'connect', __METHOD__ . ": no loads for group $group\n" );
 
                                return false;
                        }
@@ -347,7 +345,8 @@ class LoadBalancer {
                                }
                        }
                        $serverName = $this->getServerName( $i );
-                       wfDebug( __METHOD__ . ": using server $serverName for group '$group'\n" );
+                       wfDebugLog( 'connect', __METHOD__ .
+                               ": using server $serverName for group '$group'\n" );
                }
 
                return $i;
@@ -455,7 +454,8 @@ class LoadBalancer {
                /** @var DBMasterPos $knownReachedPos */
                $knownReachedPos = $this->srvCache->get( $key );
                if ( $knownReachedPos && $knownReachedPos->hasReached( $this->mWaitForPos ) ) {
-                       wfDebugLog( 'replication', __METHOD__ . ": Slave $server known to be caught up.\n" );
+                       wfDebugLog( 'replication', __METHOD__ .
+                               ": slave $server known to be caught up (pos >= $knownReachedPos).\n" );
                        return true;
                }
 
@@ -469,7 +469,7 @@ class LoadBalancer {
                        } else {
                                $conn = $this->openConnection( $index, '' );
                                if ( !$conn ) {
-                                       wfDebugLog( 'replication', __METHOD__ . ": failed to open connection to $server\n" );
+                                       wfDebugLog( 'replication', __METHOD__ . ": failed to connect to $server\n" );
 
                                        return false;
                                }
@@ -594,7 +594,6 @@ class LoadBalancer {
                $refCount = $conn->getLBInfo( 'foreignPoolRefCount' );
                if ( $serverIndex === null || $refCount === null ) {
                        wfDebug( __METHOD__ . ": this connection was not opened as a foreign connection\n" );
-
                        /**
                         * This can happen in code like:
                         *   foreach ( $dbs as $db ) {
@@ -605,7 +604,6 @@ class LoadBalancer {
                         * When a connection to the local DB is opened in this way, reuseConnection()
                         * should be ignored
                         */
-
                        return;
                }
 
@@ -687,10 +685,10 @@ class LoadBalancer {
                        $conn = $this->reallyOpenConnection( $server, false );
                        $serverName = $this->getServerName( $i );
                        if ( $conn->isOpen() ) {
-                               wfDebug( "Connected to database $i at $serverName\n" );
+                               wfDebugLog( 'connect', "Connected to database $i at $serverName\n" );
                                $this->mConns['local'][$i][0] = $conn;
                        } else {
-                               wfDebug( "Failed to connect to database $i at $serverName\n" );
+                               wfDebugLog( 'connect', "Failed to connect to database $i at $serverName\n" );
                                $this->mErrorConnection = $conn;
                                $conn = false;
                        }
@@ -965,14 +963,10 @@ class LoadBalancer {
                        for ( $i = 1; $i < $serverCount; $i++ ) {
                                $conn = $this->getAnyOpenConnection( $i );
                                if ( $conn ) {
-                                       wfDebug( "Master pos fetched from slave\n" );
-
                                        return $conn->getSlavePos();
                                }
                        }
                } else {
-                       wfDebug( "Master pos fetched from master\n" );
-
                        return $masterConn->getMasterPos();
                }
 
@@ -1173,7 +1167,8 @@ class LoadBalancer {
                if ( !$this->laggedSlaveMode && $this->getServerCount() > 1 ) {
                        try {
                                // See if laggedSlaveMode gets set
-                               $this->getConnection( DB_SLAVE, false, $wiki );
+                               $conn = $this->getConnection( DB_SLAVE, false, $wiki );
+                               $this->reuseConnection( $conn );
                        } catch ( DBConnectionError $e ) {
                                // Avoid expensive re-connect attempts and failures
                                $this->slavesDownMode = true;