Fixed fatal when using fake load balancers.
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Apr 2013 17:29:09 +0000 (10:29 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Apr 2013 17:29:13 +0000 (10:29 -0700)
The error was:
Catchable fatal error: Argument 1 passed to DatabaseMysql::masterPosWait()
must implement interface DBMasterPos, boolean given, called in
/var/www/DevWiki/core/includes/db/LoadBalancer.php on line 419

Change-Id: I230585930c1424b0868f9aa290167c66bc6848bd

includes/GlobalFunctions.php
includes/db/LoadBalancer.php

index 1a4b985..bda7fec 100644 (file)
@@ -3615,7 +3615,11 @@ function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
        if ( $lb->getServerCount() > 1 ) {
                $dbw = $lb->getConnection( DB_MASTER, array(), $wiki );
                $pos = $dbw->getMasterPos();
-               $lb->waitForAll( $pos );
+               // The DBMS may not support getMasterPos() or the whole
+               // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
+               if ( $pos !== false ) {
+                       $lb->waitForAll( $pos );
+               }
        }
 }
 
index 187870f..57d48f4 100644 (file)
@@ -348,7 +348,7 @@ class LoadBalancer {
         * Set the master wait position
         * If a DB_SLAVE connection has been opened already, waits
         * Otherwise sets a variable telling it to wait if such a connection is opened
-        * @param $pos int
+        * @param $pos DBMasterPos
         */
        public function waitFor( $pos ) {
                wfProfileIn( __METHOD__ );
@@ -366,7 +366,7 @@ class LoadBalancer {
 
        /**
         * Set the master wait position and wait for ALL slaves to catch up to it
-        * @param $pos int
+        * @param $pos DBMasterPos
         */
        public function waitForAll( $pos ) {
                wfProfileIn( __METHOD__ );
@@ -399,7 +399,7 @@ class LoadBalancer {
         * @param $open bool
         * @return bool
         */
-       function doWait( $index, $open = false ) {
+       protected function doWait( $index, $open = false ) {
                # Find a connection to wait on
                $conn = $this->getAnyOpenConnection( $index );
                if ( !$conn ) {