From 0503c59bdfb78f0226610ddbdc6ac6e8d32c4c72 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 19 Jun 2005 02:39:43 +0000 Subject: [PATCH] various load balancing tweaks --- includes/DefaultSettings.php | 3 +++ includes/LoadBalancer.php | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4911d3e193..6b9751ddd6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -416,6 +416,9 @@ $wgMasterWaitTimeout = 10; /** File to log MySQL errors to */ $wgDBerrorLog = false; +/** When to give an error message */ +$wgDBClusterTimeout = 10; + /** * wgDBminWordLen : * MySQL 3.x : used to discard words that MySQL will not return any results for diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 5ed207cb26..a60d28476b 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -148,7 +148,7 @@ class LoadBalancer { function getReaderIndex() { - global $wgMaxLag, $wgReadOnly; + global $wgMaxLag, $wgReadOnly, $wgDBClusterTimeout; $fname = 'LoadBalancer::getReaderIndex'; wfProfileIn( $fname ); @@ -206,10 +206,18 @@ class LoadBalancer { $totalElapsed += $sleepTime; usleep( $sleepTime ); } - } while ( count( $loads ) && !$done && $totalElapsed / 1e6 < $this->mWaitTimeout ); + } while ( count( $loads ) && !$done && $totalElapsed / 1e6 < $wgDBClusterTimeout ); if ( $i !== false && $this->isOpen( $i ) ) { - $this->mReadIndex = $i; + # Wait for the session master pos for a short time + if ( $this->mWaitForFile ) { + if ( !$this->doWait( $i ) ) { + $this->mServers[$i]['slave pos'] = $this->mConnections[$i]->getSlavePos(); + } + } + if ( $i != false ) { + $this->mReadIndex = $i; + } } else { $i = false; } @@ -238,7 +246,6 @@ class LoadBalancer { * Otherwise sets a variable telling it to wait if such a connection is opened */ function waitFor( $file, $pos ) { - /* $fname = 'LoadBalancer::waitFor'; wfProfileIn( $fname ); @@ -259,15 +266,12 @@ class LoadBalancer { } } wfProfileOut( $fname ); - */ } /** * Wait for a given slave to catch up to the master pos stored in $this */ function doWait( $index ) { - return true; - /* global $wgMemc; $retVal = false; @@ -303,7 +307,7 @@ class LoadBalancer { wfDebug( "Done\n" ); } } - return $retVal;*/ + return $retVal; } /** @@ -358,13 +362,6 @@ class LoadBalancer { if ( !$this->isOpen( $i ) ) { $this->mConnections[$i] = $this->reallyOpenConnection( $this->mServers[$i] ); - - if ( $this->isOpen( $i ) && $i != 0 && $this->mWaitForFile ) { - if ( !$this->doWait( $i ) ) { - $this->mServers[$i]['slave pos'] = $this->mConnections[$i]->getSlavePos(); - $success = false; - } - } } if ( !$this->isOpen( $i ) ) { wfDebug( "Failed to connect to database $i at {$this->mServers[$i]['host']}\n" ); -- 2.20.1