From: Aaron Schulz Date: Wed, 22 Oct 2014 17:56:36 +0000 (-0700) Subject: Optimized wfWaitForSlaves() to get the master positions for all LBs first X-Git-Tag: 1.31.0-rc.0~13518 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=dadaf48a39454d7d9e5a418da2c7ecb330a3fa35;p=lhc%2Fweb%2Fwiklou.git Optimized wfWaitForSlaves() to get the master positions for all LBs first Change-Id: I4a4aa6a3f68ace85dcbfb73e982a16c62e21e6ed --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4eea662420..11388e8607 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3807,8 +3807,11 @@ function wfWaitForSlaves( $lbs[] = wfGetLB( $wiki ); } - $ok = true; - foreach ( $lbs as $lb ) { + // Get all the master positions of applicable DBs right now. + // This can be faster since waiting on one cluster reduces the + // time needed to wait on the next clusters. + $masterPositions = array_fill( 0, count( $lbs ), false ); + foreach ( $lbs as $i => $lb ) { // bug 27975 - Don't try to wait for slaves if there are none // Prevents permission error when getting master position if ( $lb->getServerCount() > 1 ) { @@ -3819,12 +3822,16 @@ function wfWaitForSlaves( if ( $ifWritesSince && $dbw->lastDoneWrites() < $ifWritesSince ) { continue; // no writes since the last wait } - $pos = $dbw->getMasterPos(); + $masterPositions[$i] = $dbw->getMasterPos(); + } + } + + $ok = true; + foreach ( $lbs as $i => $lb ) { + if ( $masterPositions[$i] ) { // The DBMS may not support getMasterPos() or the whole // load balancer might be fake (e.g. $wgAllDBsAreLocalhost). - if ( $pos !== false ) { - $ok = $lb->waitForAll( $pos, $timeout ) && $ok; - } + $ok = $lb->waitForAll( $masterPositions[$i], $timeout ) && $ok; } }