From 2ba9d12c88582c7c8aa57e0aef477219e50b7926 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 22 Jun 2004 08:54:26 +0000 Subject: [PATCH] Load balancer bug fixes --- includes/DatabaseFunctions.php | 1 + includes/LoadBalancer.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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] ); -- 2.20.1