From: Tim Starling Date: Tue, 22 Jun 2004 08:54:26 +0000 (+0000) Subject: Load balancer bug fixes X-Git-Tag: 1.5.0alpha1~2793 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=2ba9d12c88582c7c8aa57e0aef477219e50b7926;p=lhc%2Fweb%2Fwiklou.git Load balancer bug fixes --- diff --git a/includes/DatabaseFunctions.php b/includes/DatabaseFunctions.php index f416176996..0169b9ff5e 100644 --- a/includes/DatabaseFunctions.php +++ b/includes/DatabaseFunctions.php @@ -26,6 +26,7 @@ if ($wgDBtype=="mysql") { # If errors are explicitly ignored, returns success function wfQuery( $sql, $db, $fname = "" ) { + global $wgOut; if ( !is_numeric( $db ) ) { # Someone has tried to call this the old way $wgOut->fatalError( wfMsgNoDB( "wrong_wfQuery_params", $db, $sql ) ); diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 1ff454a21a..94f4f55cff 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -72,7 +72,8 @@ class LoadBalancer { foreach ( $weights as $w ) { $sum += $w; } - $rand = mt_rand() / RAND_MAX * $sum; + $max = mt_getrandmax(); + $rand = mt_rand(0, $max) / $max * $sum; $sum = 0; foreach ( $weights as $i => $w ) { @@ -96,8 +97,10 @@ class LoadBalancer { # don't work $loads = $this->mLoads; do { - $i = pickRandom( $loads ); + $i = $this->pickRandom( $loads ); if ( $i !== false ) { + wfDebug( "Using reader #$i: {$this->mServers[$i]}\n" ); + $conn =& $this->getConnection( $i ); if ( !$conn->isOpen() ) { unset( $loads[$i] );