Merge "Make addedwatchtext less verbose"
[lhc/web/wiklou.git] / includes / db / LoadBalancer.php
index 99c9a14..52dca08 100644 (file)
@@ -60,8 +60,6 @@ class LoadBalancer {
        private $mLastError = 'Unknown error';
        /** @var integer Total connections opened */
        private $connsOpened = 0;
-       /** @var ProcessCacheLRU */
-       private $mProcCache;
 
        /** @var integer Warn when this many connection are held */
        const CONN_HELD_WARN_THRESHOLD = 10;
@@ -113,8 +111,6 @@ class LoadBalancer {
                                }
                        }
                }
-
-               $this->mProcCache = new ProcessCacheLRU( 30 );
        }
 
        /**
@@ -538,7 +534,6 @@ class LoadBalancer {
                # Now we have an explicit index into the servers array
                $conn = $this->openConnection( $i, $wiki );
                if ( !$conn ) {
-
                        return $this->reportConnectionError();
                }
 
@@ -651,10 +646,7 @@ class LoadBalancer {
        public function openConnection( $i, $wiki = false ) {
                if ( $wiki !== false ) {
                        $conn = $this->openForeignConnection( $i, $wiki );
-
-                       return $conn;
-               }
-               if ( isset( $this->mConns['local'][$i][0] ) ) {
+               } elseif ( isset( $this->mConns['local'][$i][0] ) ) {
                        $conn = $this->mConns['local'][$i][0];
                } else {
                        $server = $this->mServers[$i];
@@ -671,6 +663,15 @@ class LoadBalancer {
                        }
                }
 
+               if ( $conn && !$conn->isOpen() ) {
+                       // Connection was made but later unrecoverably lost for some reason.
+                       // Do not return a handle that will just throw exceptions on use,
+                       // but let the calling code (e.g. getReaderIndex) try another server.
+                       // See DatabaseMyslBase::ping() for how this can happen.
+                       $this->mErrorConnection = $conn;
+                       $conn = false;
+               }
+
                return $conn;
        }
 
@@ -1235,16 +1236,8 @@ class LoadBalancer {
                        return array( 0 => 0 ); // no replication = no lag
                }
 
-               if ( $this->mProcCache->has( 'slave_lag', 'times', 1 ) ) {
-                       return $this->mProcCache->get( 'slave_lag', 'times' );
-               }
-
                # Send the request to the load monitor
-               $times = $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
-
-               $this->mProcCache->set( 'slave_lag', 'times', $times );
-
-               return $times;
+               return $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
        }
 
        /**
@@ -1271,8 +1264,10 @@ class LoadBalancer {
 
        /**
         * Clear the cache for slag lag delay times
+        *
+        * This is only used for testing
         */
        public function clearLagTimeCache() {
-               $this->mProcCache->clear( 'slave_lag' );
+               $this->getLoadMonitor()->clearCaches();
        }
 }