From cdaa91bd276828d60f94ad2b482e02ee4d07da05 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 19 Apr 2011 14:52:11 +0000 Subject: [PATCH] Put the code for waiting for slave lag the new-and-improved way (using master position) in wfWaitForSlaves_masterPos(). I guess I should deprecate or re-do wfWaitForSlaves() and update callers, but I'm lazy --- includes/GlobalFunctions.php | 16 ++++++++++++++++ maintenance/runBatchedQuery.php | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4ba0c7c891..a41625829d 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 diff --git a/maintenance/runBatchedQuery.php b/maintenance/runBatchedQuery.php index dd3680c983..e641db8c2e 100644 --- a/maintenance/runBatchedQuery.php +++ b/maintenance/runBatchedQuery.php @@ -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 ); } -- 2.20.1