From dadaf48a39454d7d9e5a418da2c7ecb330a3fa35 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 22 Oct 2014 10:56:36 -0700 Subject: [PATCH] Optimized wfWaitForSlaves() to get the master positions for all LBs first Change-Id: I4a4aa6a3f68ace85dcbfb73e982a16c62e21e6ed --- includes/GlobalFunctions.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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; } } -- 2.20.1