Merge r86398 into the old wfWaitForSlaves. Update core calls.
authorPlatonides <platonides@users.mediawiki.org>
Wed, 20 Apr 2011 00:12:06 +0000 (00:12 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Wed, 20 Apr 2011 00:12:06 +0000 (00:12 +0000)
maintenance/waitForSlave.php still calls the old prototype.
Most instances were replaced with
sed -i 's/wfWaitForSlaves( [0-9]* );/wfWaitForSlaves();/' ./maintenance/initEditCount.php ./maintenance/updateRestrictions.php ./maintenance/updateSpecialPages.php ./maintenance/importDump.php ./maintenance/moveBatch.php ./maintenance/storage/resolveStubs.php ./maintenance/storage/trackBlobs.php ./maintenance/storage/fixBug20757.php ./maintenance/storage/moveToExternal.php ./maintenance/storage/compressOld.inc ./maintenance/populateSha1.php ./maintenance/deleteDefaultMessages.php ./maintenance/migrateUserGroup.php ./maintenance/importImages.php ./maintenance/runJobs.php ./maintenance/archives/upgradeLogging.php ./maintenance/deleteBatch.php ./maintenance/populateLogSearch.php ./maintenance/populateLogUsertext.php ./maintenance/gearman/gearmanWorker.php ./maintenance/populateRevisionLength.php ./maintenance/refreshLinks.php ./maintenance/deleteSelfExternals.php ./maintenance/upgrade1_5.php ./maintenance/rebuildFileCache.php ./includes/job/RefreshLinksJob.php ./includes/installer/MysqlUpdater.php ./maintenance/convertUserOptions.php ./maintenance/populateParentId.php ./maintenance/runBatchedQuery.php ./maintenance/upgrade1_5.php ./maintenance/waitForSlave.php ./maintenance/populateCategory.php ./maintenance/importImages.php

32 files changed:
includes/GlobalFunctions.php
includes/installer/MysqlUpdater.php
includes/job/RefreshLinksJob.php
maintenance/archives/upgradeLogging.php
maintenance/convertUserOptions.php
maintenance/deleteBatch.php
maintenance/deleteDefaultMessages.php
maintenance/deleteSelfExternals.php
maintenance/gearman/gearmanWorker.php
maintenance/importDump.php
maintenance/importImages.php
maintenance/initEditCount.php
maintenance/migrateUserGroup.php
maintenance/moveBatch.php
maintenance/populateCategory.php
maintenance/populateLogSearch.php
maintenance/populateLogUsertext.php
maintenance/populateParentId.php
maintenance/populateRevisionLength.php
maintenance/populateSha1.php
maintenance/rebuildFileCache.php
maintenance/refreshLinks.php
maintenance/runBatchedQuery.php
maintenance/runJobs.php
maintenance/storage/compressOld.inc
maintenance/storage/fixBug20757.php
maintenance/storage/moveToExternal.php
maintenance/storage/resolveStubs.php
maintenance/storage/trackBlobs.php
maintenance/updateRestrictions.php
maintenance/updateSpecialPages.php
maintenance/upgrade1_5.php

index a416258..15cfb7a 100644 (file)
@@ -3146,43 +3146,17 @@ function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
 }
 
 /**
- * Sleep until the worst slave's replication lag is less than or equal to
- * $maxLag, in seconds.  Use this when updating very large numbers of rows, as
+ * Modern version of wfWaitForSlaves(). Instead of looking at replication lag
+ * and waiting for it to go down, this waits for the slaves to catch up to the
+ * master position. Use this when updating very large numbers of rows, as
  * in maintenance scripts, to avoid causing too much lag.  Of course, this is
  * a no-op if there are no slaves.
- *
- * Every time the function has to wait for a slave, it will print a message to
- * that effect (and then sleep for a little while), so it's probably not best
- * to use this outside maintenance scripts in its present form.
- *
- * @param $maxLag Integer
+ * 
+ * @param $maxLag Integer (deprecated)
  * @param $wiki mixed Wiki identifier accepted by wfGetLB
  * @return null
  */
-function wfWaitForSlaves( $maxLag, $wiki = false ) {
-       if( $maxLag ) {
-               $lb = wfGetLB( $wiki );
-               list( $host, $lag ) = $lb->getMaxLag( $wiki );
-               while( $lag > $maxLag ) {
-                       wfSuppressWarnings();
-                       $name = gethostbyaddr( $host );
-                       wfRestoreWarnings();
-                       if( $name !== false ) {
-                               $host = $name;
-                       }
-                       print "Waiting for $host (lagged $lag seconds)...\n";
-                       sleep( $maxLag );
-                       list( $host, $lag ) = $lb->getMaxLag();
-               }
-       }
-}
-
-/**
- * Modern version of wfWaitForSlaves(). Instead of looking at replication lag
- * and waiting for it to go down, this waits for the slaves to catch up to the
- * master position. This is much better for lag control than wfWaitForSlaves()
- */
-function wfWaitForSlaves_masterPos() {
+function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
        $lb = wfGetLB();
        // bug 27975 - Don't try to wait for slaves if there are none
        // Prevents permission error when getting master position
index fc41194..f9f212d 100644 (file)
@@ -652,7 +652,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        foreach ( $res as $row ) {
                                $count = ( $count + 1 ) % 100;
                                if ( $count == 0 ) {
-                                       wfWaitForSlaves( 10 );
+                                       wfWaitForSlaves();
                                }
                                $this->db->insert( 'templatelinks',
                                        array(
index cc91fa8..910f0c5 100644 (file)
@@ -119,7 +119,7 @@ class RefreshLinksJob2 extends Job {
                        $update = new LinksUpdate( $title, $parserOutput, false );
                        $update->doUpdate();
                        wfProfileOut( __METHOD__.'-update' );
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                wfProfileOut( __METHOD__ );
 
index d920639..1765bd9 100644 (file)
@@ -164,7 +164,7 @@ EOT;
                        $this->dbw->insert( $dstTable, $batch, __METHOD__ );
                        $numRowsCopied += count( $batch );
 
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                echo "Copied $numRowsCopied rows\n";
        }
index 278d40f..f46f710 100644 (file)
@@ -46,7 +46,7 @@ class ConvertUserOptions extends Maintenance {
                        $id = $this->convertOptionBatch( $res, $dbw );
                        $dbw->commit();
 
-                       wfWaitForSlaves( 1 );
+                       wfWaitForSlaves();
 
                        if ( $id )
                                $this->output( "--Converted to ID $id\n" );
index c8bb480..f5f850a 100644 (file)
@@ -104,7 +104,7 @@ class DeleteBatch extends Maintenance {
                        if ( $interval ) {
                                sleep( $interval );
                        }
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
 }
        }
 }
index fc482ac..e518509 100644 (file)
@@ -64,7 +64,7 @@ class DeleteDefaultMessages extends Maintenance {
 
                foreach ( $res as $row ) {
                        if ( function_exists( 'wfWaitForSlaves' ) ) {
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                        }
                        $dbw->ping();
                        $title = Title::makeTitle( $row->page_namespace, $row->page_title );
index db23e92..4e9f54f 100644 (file)
@@ -39,7 +39,7 @@ class DeleteSelfExternals extends Maintenance {
                $this->output( "Deleting self externals from $wgServer\n" );
                $db = wfGetDB( DB_MASTER );
                while ( 1 ) {
-                       wfWaitForSlaves( 2 );
+                       wfWaitForSlaves();
                        $db->commit();
                        $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE el_to"
                                . $db->buildLike( $wgServer . '/', $db->anyString() ), $this->mBatchSize );
index aea126a..3ea1008 100644 (file)
@@ -36,7 +36,7 @@ function wfGearmanMonitor( $idle, $lastJob ) {
        $interval = 5;
        $now = time();
        if ( $now - $lastSleep >= $interval ) {
-               wfWaitForSlaves( $interval );
+               wfWaitForSlaves();
                $lastSleep = $now;
        }
        return false;
index 71cfbc0..5397959 100644 (file)
@@ -154,7 +154,7 @@ class BackupReader {
                                $this->progress( "$this->revCount ($revrate revs/sec)" );
                        }
                }
-               wfWaitForSlaves( 5 );
+               wfWaitForSlaves();
                // XXX: Don't let deferred jobs array get absurdly large (bug 24375)
                wfDoUpdates( 'commit' );
        }
index cc713db..47dc3cc 100644 (file)
@@ -249,8 +249,8 @@ if ( count( $args ) > 0 ) {
                                                $article = new Article( $title );
                                                echo "\nWaiting for slaves...\n";
                                                // Wait for slaves.
-                                               sleep( 2.0 );
-                                               wfWaitForSlaves( 1.0 );
+                                               sleep( 2.0 ); # Why this sleep?
+                                               wfWaitForSlaves();
 
                                                echo( "\nSetting image restrictions ... " );
                                                if ( $article->updateRestrictions( $restrictions ) )
index e421e29..0f13645 100644 (file)
@@ -93,7 +93,7 @@ in the load balancer, usually indicating a replication environment.' );
                                        $delta,
                                        $rate ) );
 
-                               wfWaitForSlaves( 10 );
+                               wfWaitForSlaves();
                        }
                } else {
                        // Subselect should work on modern MySQLs etc
index c416320..771ed94 100644 (file)
@@ -60,7 +60,7 @@ class MigrateUserGroup extends Maintenance {
                        $dbw->commit();
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                $this->output( "Done! $count user(s) in group '$oldGroup' are now in '$newGroup' instead.\n" );
        }
index c749533..9b9f910 100644 (file)
@@ -101,7 +101,7 @@ class MoveBatch extends Maintenance {
                        if ( $interval ) {
                                sleep( $interval );
                        }
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
        }
 }
index ce0765c..13b77fa 100644 (file)
@@ -119,7 +119,7 @@ TEXT;
                        ++$i;
                        if ( !( $i % self::REPORTING_INTERVAL ) ) {
                                $this->output( "$name\n" );
-                               wfWaitForSlaves( $maxlag );
+                               wfWaitForSlaves();
                        }
                        usleep( $throttle * 1000 );
                }
index ce2d95c..894c9ee 100644 (file)
@@ -130,7 +130,7 @@ class PopulateLogSearch extends Maintenance {
                        }
                        $blockStart += self::LOG_SEARCH_BATCH_SIZE;
                        $blockEnd += self::LOG_SEARCH_BATCH_SIZE;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                if ( $db->insert(
                                'updatelog',
index bb3927c..af912ad 100644 (file)
@@ -59,7 +59,7 @@ class PopulateLogUsertext extends Maintenance {
                        $db->commit();
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                if ( $db->insert(
                                'updatelog',
index 387f5a5..7cbc267 100644 (file)
@@ -98,7 +98,7 @@ class PopulateParentId extends Maintenance {
                        }
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                $logged = $db->insert( 'updatelog',
                        array( 'ul_key' => 'populate rev_parent_id' ),
index 0af51dc..7ed306e 100644 (file)
@@ -78,7 +78,7 @@ class PopulateRevisionLength extends Maintenance {
                        }
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                $logged = $db->insert( 'updatelog',
                        array( 'ul_key' => 'populate rev_len' ),
index 1714c0d..165a6cf 100644 (file)
@@ -68,7 +68,7 @@ class PopulateSha1 extends Maintenance {
                foreach ( $res as $row ) {
                        if ( $i % 100 == 0 ) {
                                $this->output( sprintf( "Done %d of %d, %5.3f%%  \r", $i, $numRows, $i / $numRows * 100 ) );
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                        }
                        $file = wfLocalFile( $row->img_name );
                        if ( !$file ) {
index 5028cbe..4bf6462 100644 (file)
@@ -109,7 +109,7 @@ class RebuildFileCache extends Maintenance {
                        }
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                $this->output( "Done!\n" );
 
index 420f555..8fe4d3c 100644 (file)
@@ -107,7 +107,7 @@ class RefreshLinks extends Maintenance {
                        foreach ( $res as $row ) {
                                if ( !( ++$i % $reportingInterval ) ) {
                                        $this->output( "$i\n" );
-                                       wfWaitForSlaves( $maxLag );
+                                       wfWaitForSlaves();
                                }
                                $this->fixRedirect( $row->page_id );
                        }
@@ -127,7 +127,7 @@ class RefreshLinks extends Maintenance {
                        foreach ( $res as $row ) {
                                if ( !( ++$i % $reportingInterval ) ) {
                                        $this->output( "$i\n" );
-                                       wfWaitForSlaves( $maxLag );
+                                       wfWaitForSlaves();
                                }
                                if ( $redirectsOnly ) {
                                        $this->fixRedirect( $row->page_id );
@@ -148,7 +148,7 @@ class RefreshLinks extends Maintenance {
 
                                if ( !( $id % $reportingInterval ) ) {
                                        $this->output( "$id\n" );
-                                       wfWaitForSlaves( $maxLag );
+                                       wfWaitForSlaves();
                                }
                                $this->fixRedirect( $id );
                        }
@@ -161,7 +161,7 @@ class RefreshLinks extends Maintenance {
 
                                        if ( !( $id % $reportingInterval ) ) {
                                                $this->output( "$id\n" );
-                                               wfWaitForSlaves( $maxLag );
+                                               wfWaitForSlaves();
                                        }
                                        self::fixLinksFromArticle( $id );
                                }
@@ -237,7 +237,7 @@ class RefreshLinks extends Maintenance {
         * @author Merlijn van Deen <valhallasw@arctus.nl>
         */
        private function deleteLinksFromNonexistent( $maxLag = 0, $batchSize = 100 ) {
-               wfWaitForSlaves( $maxLag );
+               wfWaitForSlaves();
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -273,7 +273,7 @@ class RefreshLinks extends Maintenance {
                                $counter++;
                                $list[] = $row->$field;
                                if ( ( $counter % $batchSize ) == 0 ) {
-                                       wfWaitForSlaves( 5 );
+                                       wfWaitForSlaves();
                                        $dbw->delete( $table, array( $field => $list ), __METHOD__ );
 
                                        $this->output( $counter . ".." );
index e641db8..8d1b53e 100644 (file)
@@ -45,7 +45,7 @@ class BatchedQueryRunner extends Maintenance {
                        $dbw->query( $query, __METHOD__ );
                        $affected = $dbw->affectedRows();
                        $this->output( "$affected rows\n" );
-                       wfWaitForSlaves_masterPos();
+                       wfWaitForSlaves();
                } while ( $affected > 0 );
        }
 
index 69c006b..0edf7ac 100644 (file)
@@ -72,7 +72,7 @@ class RunJobs extends Maintenance {
                                if ( !$job )
                                        break;
 
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                                $t = microtime( true );
                                $offset = $job->id;
                                $status = $job->run();
index 187e976..02e85cb 100644 (file)
@@ -155,7 +155,7 @@ function compressWithConcat( $startId, $maxChunkSize, $beginDate,
        #$conds[] = 'page_id=rev_page AND rev_id != page_latest';
 
        for ( $pageId = $startId; $pageId <= $maxPageId; $pageId++ ) {
-               wfWaitForSlaves( 5 );
+               wfWaitForSlaves();
 
                # Wake up
                $dbr->ping();
@@ -309,7 +309,7 @@ function compressWithConcat( $startId, $maxChunkSize, $beginDate,
                        print "/";
                        $dbw->commit();
                        $i += $thisChunkSize;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                print "\n";
        }
index d04a24f..b6def2d 100644 (file)
@@ -260,7 +260,7 @@ class FixBug20757 extends Maintenance {
                static $iteration = 0;
                ++$iteration;
                if ( ++$iteration > 50 == 0 ) {
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                        $iteration = 0;
                }
        }
index 5ce225c..64f3ada 100644 (file)
@@ -66,7 +66,7 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) {
 
                if ( !( $block % REPORTING_INTERVAL ) ) {
                        print "oldid=$blockStart, moved=$numMoved\n";
-                       wfWaitForSlaves( 2 );
+                       wfWaitForSlaves();
                }
 
                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
index fad4590..08d0ee0 100644 (file)
@@ -45,7 +45,7 @@ function resolveStubs() {
        $numBlocks = intval( $maxID / $blockSize ) + 1;
 
        for ( $b = 0; $b < $numBlocks; $b++ ) {
-               wfWaitForSlaves( 2 );
+               wfWaitForSlaves();
 
                printf( "%5.2f%%\n", $b / $numBlocks * 100 );
                $start = intval( $maxID / $numBlocks ) * $b + 1;
index 53377b9..b5f8004 100644 (file)
@@ -206,7 +206,7 @@ class TrackBlobs {
                        if ( $batchesDone >= $this->reportingInterval ) {
                                $batchesDone = 0;
                                echo "$startId / $endId\n";
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                        }
                }
                echo "Found $rowsInserted revisions\n";
@@ -290,7 +290,7 @@ class TrackBlobs {
                        if ( $batchesDone >= $this->reportingInterval ) {
                                $batchesDone = 0;
                                echo "$startId / $endId\n";
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                        }
                }
                echo "Found $rowsInserted orphan text rows\n";
index c815f4b..f1d6139 100644 (file)
@@ -96,7 +96,7 @@ class UpdateRestrictions extends Maintenance {
                        }
                        $blockStart += $this->mBatchSize - 1;
                        $blockEnd += $this->mBatchSize - 1;
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
                $this->output( "...removing dead rows from page_restrictions\n" );
                // Kill any broken rows from previous imports
index 46d0fcc..dff201c 100644 (file)
@@ -58,7 +58,7 @@ class UpdateSpecialPages extends Maintenance {
                        }
                        $this->output( sprintf( "completed in %.2fs\n", $seconds ) );
                        # Wait for the slave to catch up
-                       wfWaitForSlaves( 5 );
+                       wfWaitForSlaves();
                }
 
                // This is needed to initialise $wgQueryPages
@@ -130,7 +130,7 @@ class UpdateSpecialPages extends Maintenance {
                                                $dbw->commit();
                                        }
                                        # Wait for the slave to catch up
-                                       wfWaitForSlaves( 5 );
+                                       wfWaitForSlaves();
                                } else {
                                        $this->output( "cheap, skipped\n" );
                                }
index 22fab70..709d0b2 100644 (file)
@@ -101,7 +101,6 @@ class FiveUpgrade extends Maintenance {
 
                $this->cleanupSwaps = array();
                $this->emailAuth = false; # don't preauthenticate emails
-               $this->maxLag    = 10; # if slaves are lagged more than 10 secs, wait
                $this->step      = $this->getOption( 'step', null );
        }
 
@@ -316,7 +315,7 @@ class FiveUpgrade extends Maintenance {
         */
        function insertChunk( &$chunk ) {
                // Give slaves a chance to catch up
-               wfWaitForSlaves( $this->maxLag );
+               wfWaitForSlaves();
                $this->dbw->insert( $this->chunkTable, $chunk, $this->chunkFunction, $this->chunkOptions );
        }