Put the code for waiting for slave lag the new-and-improved way (using master positio...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 19 Apr 2011 14:52:11 +0000 (14:52 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 19 Apr 2011 14:52:11 +0000 (14:52 +0000)
includes/GlobalFunctions.php
maintenance/runBatchedQuery.php

index 4ba0c7c..a416258 100644 (file)
@@ -3177,6 +3177,22 @@ function wfWaitForSlaves( $maxLag, $wiki = false ) {
        }
 }
 
+/**
+ * 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() {
+       $lb = wfGetLB();
+       // bug 27975 - Don't try to wait for slaves if there are none
+       // Prevents permission error when getting master position
+       if ( $lb->getServerCount() > 1 ) {
+               $dbw = $lb->getConnection( DB_MASTER );
+               $pos = $dbw->getMasterPos();
+               $lb->waitForAll( $pos );
+       }
+}
+
 /**
  * Used to be used for outputting text in the installer/updater
  * @deprecated Warnings in 1.19, removal in 1.20
index dd3680c..e641db8 100644 (file)
@@ -29,7 +29,6 @@ class BatchedQueryRunner extends Maintenance {
                parent::__construct();
                $this->mDescription = "Run a query repeatedly until it affects 0 rows, and wait for slaves in between.\n" .
                                "NOTE: You need to set a LIMIT clause yourself.";
-               $this->addOption( 'wait', "Wait for replication lag to go down to this value. Default: 5", false, true );
        }
 
        public function execute() {
@@ -46,7 +45,7 @@ class BatchedQueryRunner extends Maintenance {
                        $dbw->query( $query, __METHOD__ );
                        $affected = $dbw->affectedRows();
                        $this->output( "$affected rows\n" );
-                       wfWaitForSlaves( $wait );
+                       wfWaitForSlaves_masterPos();
                } while ( $affected > 0 );
        }