r32845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32844‎ | r32845 | r32846 >
Date:10:08, 6 April 2008
Author:tstarling
Status:old
Tags:
Comment:
fixed a couple of places where the default DB could be used inappropriately
Modified paths:
  • /trunk/phase3/includes/LoadBalancer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LoadBalancer.php
@@ -86,9 +86,9 @@
8787 return $i;
8888 }
8989
90 - function getRandomNonLagged( $loads ) {
 90+ function getRandomNonLagged( $loads, $wiki = false ) {
9191 # Unset excessively lagged servers
92 - $lags = $this->getLagTimes();
 92+ $lags = $this->getLagTimes( $wiki );
9393 foreach ( $lags as $i => $lag ) {
9494 if ( $i != 0 && isset( $this->mServers[$i]['max lag'] ) ) {
9595 if ( $lag === false ) {
@@ -185,7 +185,7 @@
186186 if ( $wgReadOnly || $this->mAllowLagged || $laggedSlaveMode ) {
187187 $i = $this->pickRandom( $currentLoads );
188188 } else {
189 - $i = $this->getRandomNonLagged( $currentLoads );
 189+ $i = $this->getRandomNonLagged( $currentLoads, $wiki );
190190 if ( $i === false && count( $currentLoads ) != 0 ) {
191191 # All slaves lagged. Switch to read-only mode
192192 $wgReadOnly = wfMsgNoDBForContent( 'readonly_lag' );
@@ -595,7 +595,7 @@
596596 $class = 'Database' . ucfirst( $type );
597597
598598 # Create object
599 - wfDebug( "Connecting to $host...\n" );
 599+ wfDebug( "Connecting to $host $dbname...\n" );
600600 $db = new $class( $host, $user, $password, $dbname, 1, $flags );
601601 if ( $db->isOpen() ) {
602602 wfDebug( "Connected\n" );
@@ -690,14 +690,18 @@
691691 # master (however unlikely that may be), then we can fetch the position from the slave.
692692 $masterConn = $this->getAnyOpenConnection( 0 );
693693 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+ }
697701 } else {
698 - $pos = $masterConn->getMasterPos();
699702 wfDebug( "Master pos fetched from master\n" );
 703+ return $masterConn->getMasterPos();
700704 }
701 - return $pos;
 705+ return false;
702706 }
703707
704708 /**
@@ -801,8 +805,9 @@
802806 }
803807
804808 /**
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.
807812 */
808813 function getMaxLag() {
809814 $maxLag = -1;
@@ -828,7 +833,7 @@
829834 * Get lag time for each server
830835 * Results are cached for a short time in memcached, and indefinitely in the process cache
831836 */
832 - function getLagTimes() {
 837+ function getLagTimes( $wiki = false ) {
833838 wfProfileIn( __METHOD__ );
834839
835840 if ( !isset( $this->mLagTimes ) ) {
@@ -861,7 +866,7 @@
862867 $times[$i] = 0;
863868 } elseif ( false !== ( $conn = $this->getAnyOpenConnection( $i ) ) ) {
864869 $times[$i] = $conn->getLag();
865 - } elseif ( false !== ( $conn = $this->openConnection( $i ) ) ) {
 870+ } elseif ( false !== ( $conn = $this->openConnection( $i, $wiki ) ) ) {
866871 $times[$i] = $conn->getLag();
867872 }
868873 }

Status & tagging log