Index: trunk/phase3/includes/LoadBalancer.php |
— | — | @@ -86,9 +86,9 @@ |
87 | 87 | return $i; |
88 | 88 | } |
89 | 89 | |
90 | | - function getRandomNonLagged( $loads ) { |
| 90 | + function getRandomNonLagged( $loads, $wiki = false ) { |
91 | 91 | # Unset excessively lagged servers |
92 | | - $lags = $this->getLagTimes(); |
| 92 | + $lags = $this->getLagTimes( $wiki ); |
93 | 93 | foreach ( $lags as $i => $lag ) { |
94 | 94 | if ( $i != 0 && isset( $this->mServers[$i]['max lag'] ) ) { |
95 | 95 | if ( $lag === false ) { |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | if ( $wgReadOnly || $this->mAllowLagged || $laggedSlaveMode ) { |
187 | 187 | $i = $this->pickRandom( $currentLoads ); |
188 | 188 | } else { |
189 | | - $i = $this->getRandomNonLagged( $currentLoads ); |
| 189 | + $i = $this->getRandomNonLagged( $currentLoads, $wiki ); |
190 | 190 | if ( $i === false && count( $currentLoads ) != 0 ) { |
191 | 191 | # All slaves lagged. Switch to read-only mode |
192 | 192 | $wgReadOnly = wfMsgNoDBForContent( 'readonly_lag' ); |
— | — | @@ -595,7 +595,7 @@ |
596 | 596 | $class = 'Database' . ucfirst( $type ); |
597 | 597 | |
598 | 598 | # Create object |
599 | | - wfDebug( "Connecting to $host...\n" ); |
| 599 | + wfDebug( "Connecting to $host $dbname...\n" ); |
600 | 600 | $db = new $class( $host, $user, $password, $dbname, 1, $flags ); |
601 | 601 | if ( $db->isOpen() ) { |
602 | 602 | wfDebug( "Connected\n" ); |
— | — | @@ -690,14 +690,18 @@ |
691 | 691 | # master (however unlikely that may be), then we can fetch the position from the slave. |
692 | 692 | $masterConn = $this->getAnyOpenConnection( 0 ); |
693 | 693 | if ( !$masterConn ) { |
694 | | - $conn = $this->getConnection( DB_SLAVE ); |
695 | | - $pos = $conn->getSlavePos(); |
696 | | - wfDebug( "Master pos fetched from slave\n" ); |
| 694 | + for ( $i = 1; $i < count( $this->mServers ); $i++ ) { |
| 695 | + $conn = $this->getAnyOpenConnection( $i ); |
| 696 | + if ( $conn ) { |
| 697 | + wfDebug( "Master pos fetched from slave\n" ); |
| 698 | + return $conn->getSlavePos(); |
| 699 | + } |
| 700 | + } |
697 | 701 | } else { |
698 | | - $pos = $masterConn->getMasterPos(); |
699 | 702 | wfDebug( "Master pos fetched from master\n" ); |
| 703 | + return $masterConn->getMasterPos(); |
700 | 704 | } |
701 | | - return $pos; |
| 705 | + return false; |
702 | 706 | } |
703 | 707 | |
704 | 708 | /** |
— | — | @@ -801,8 +805,9 @@ |
802 | 806 | } |
803 | 807 | |
804 | 808 | /** |
805 | | - * Get the hostname and lag time of the most-lagged slave |
806 | | - * This is useful for maintenance scripts that need to throttle their updates |
| 809 | + * Get the hostname and lag time of the most-lagged slave. |
| 810 | + * This is useful for maintenance scripts that need to throttle their updates. |
| 811 | + * May attempt to open connections to slaves on the default DB. |
807 | 812 | */ |
808 | 813 | function getMaxLag() { |
809 | 814 | $maxLag = -1; |
— | — | @@ -828,7 +833,7 @@ |
829 | 834 | * Get lag time for each server |
830 | 835 | * Results are cached for a short time in memcached, and indefinitely in the process cache |
831 | 836 | */ |
832 | | - function getLagTimes() { |
| 837 | + function getLagTimes( $wiki = false ) { |
833 | 838 | wfProfileIn( __METHOD__ ); |
834 | 839 | |
835 | 840 | if ( !isset( $this->mLagTimes ) ) { |
— | — | @@ -861,7 +866,7 @@ |
862 | 867 | $times[$i] = 0; |
863 | 868 | } elseif ( false !== ( $conn = $this->getAnyOpenConnection( $i ) ) ) { |
864 | 869 | $times[$i] = $conn->getLag(); |
865 | | - } elseif ( false !== ( $conn = $this->openConnection( $i ) ) ) { |
| 870 | + } elseif ( false !== ( $conn = $this->openConnection( $i, $wiki ) ) ) { |
866 | 871 | $times[$i] = $conn->getLag(); |
867 | 872 | } |
868 | 873 | } |