Load balancer bug fixes
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 22 Jun 2004 08:54:26 +0000 (08:54 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 22 Jun 2004 08:54:26 +0000 (08:54 +0000)
includes/DatabaseFunctions.php
includes/LoadBalancer.php

index f416176..0169b9f 100644 (file)
@@ -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 ) );
index 1ff454a..94f4f55 100644 (file)
@@ -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] );