Fix LoadBalancer::getMasterPos() callers to handle a non-object being returned
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 12 Jan 2018 23:18:14 +0000 (15:18 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 12 Jan 2018 23:18:14 +0000 (15:18 -0800)
Change-Id: I3356057f27a051835734329afa339ea76842a389

includes/libs/rdbms/ChronologyProtector.php
includes/libs/rdbms/lbfactory/LBFactory.php
includes/objectcache/SqlBagOStuff.php

index 152ff74..4fcd885 100644 (file)
@@ -147,8 +147,10 @@ class ChronologyProtector implements LoggerAwareInterface {
                $masterName = $lb->getServerName( $lb->getWriterIndex() );
                if ( $lb->getServerCount() > 1 ) {
                        $pos = $lb->getMasterPos();
-                       $this->logger->info( __METHOD__ . ": LB for '$masterName' has pos $pos\n" );
-                       $this->shutdownPositions[$masterName] = $pos;
+                       if ( $pos ) {
+                               $this->logger->info( __METHOD__ . ": LB for '$masterName' has pos $pos\n" );
+                               $this->shutdownPositions[$masterName] = $pos;
+                       }
                } else {
                        $this->logger->info( __METHOD__ . ": DB '$masterName' touched\n" );
                }
index 187527e..2324553 100644 (file)
@@ -358,7 +358,7 @@ abstract class LBFactory implements ILBFactory {
                $failed = [];
                foreach ( $lbs as $i => $lb ) {
                        if ( $masterPositions[$i] ) {
-                               // The DBMS may not support getMasterPos()
+                               // The RDBMS may not support getMasterPos()
                                if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) {
                                        $failed[] = $lb->getServerName( $lb->getWriterIndex() );
                                }
index c286055..6691f73 100644 (file)
@@ -808,6 +808,9 @@ class SqlBagOStuff extends BagOStuff {
 
                // Main LB is used; wait for any replica DBs to catch up
                $masterPos = $lb->getMasterPos();
+               if ( !$masterPos ) {
+                       return true; // not applicable
+               }
 
                $loop = new WaitConditionLoop(
                        function () use ( $lb, $masterPos ) {