From af3fd687dbf8eff68f5b5da05f4ecc42beb78f9c Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 5 Jan 2010 23:39:16 +0000 Subject: [PATCH] Add $maxlag parameter to LoadBalancer::getMaxLag() so it'll actually select the right DB when opening new connections. Looks like an ugly temp fix to me but I have no idea how to do it properly offhand. --- includes/GlobalFunctions.php | 2 +- includes/db/LoadBalancer.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4d1f1f5de0..9664e32921 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3146,7 +3146,7 @@ function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) { function wfWaitForSlaves( $maxLag, $wiki = false ) { if( $maxLag ) { $lb = wfGetLB( $wiki ); - list( $host, $lag ) = $lb->getMaxLag(); + list( $host, $lag ) = $lb->getMaxLag( $wiki ); while( $lag > $maxLag ) { $name = @gethostbyaddr( $host ); if( $name !== false ) { diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 68d142cba8..cbf824bf30 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -878,14 +878,18 @@ class LoadBalancer { * Get the hostname and lag time of the most-lagged slave. * This is useful for maintenance scripts that need to throttle their updates. * May attempt to open connections to slaves on the default DB. + * @param $wiki string Wiki ID, or false for the default database */ - function getMaxLag() { + function getMaxLag( $wiki = false ) { $maxLag = -1; $host = ''; foreach ( $this->mServers as $i => $conn ) { - $conn = $this->getAnyOpenConnection( $i ); + $conn = false; + if ( $wiki === false ) { + $conn = $this->getAnyOpenConnection( $i ); + } if ( !$conn ) { - $conn = $this->openConnection( $i ); + $conn = $this->openConnection( $i, $wiki ); } if ( !$conn ) { continue; -- 2.20.1