From 3a15ecebea7c560e01f81b7145f2cc32bb167c5f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 20 Jan 2016 09:23:46 -0800 Subject: [PATCH] Migrate callers to waitForReplication() Change-Id: I7b2b13b9315891561d2d8cc04a12ecad2dc73d70 --- includes/installer/DatabaseUpdater.php | 2 +- includes/installer/MysqlUpdater.php | 2 +- includes/jobqueue/JobRunner.php | 7 ++++++- includes/jobqueue/jobs/CategoryMembershipChangeJob.php | 4 ++-- includes/jobqueue/jobs/HTMLCacheUpdateJob.php | 2 +- includes/jobqueue/jobs/RecentChangesUpdateJob.php | 8 +++++--- includes/objectcache/SqlBagOStuff.php | 7 ++++++- includes/utils/BatchRowWriter.php | 2 +- 8 files changed, 23 insertions(+), 11 deletions(-) diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 904fde83dc..61c3002fa8 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -456,7 +456,7 @@ abstract class DatabaseUpdater { flush(); if ( $ret !== false ) { $updatesDone[] = $origParams; - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication(); } else { $updatesSkipped[] = array( $func, $params, $origParams ); } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 4813beabe5..10fed319f1 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -836,7 +836,7 @@ class MysqlUpdater extends DatabaseUpdater { foreach ( $res as $row ) { $count = ( $count + 1 ) % 100; if ( $count == 0 ) { - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication( array( 'wiki' => wfWikiID() ) ); } $this->db->insert( 'templatelinks', array( diff --git a/includes/jobqueue/JobRunner.php b/includes/jobqueue/JobRunner.php index 4ab9f5ad2e..39193187cf 100644 --- a/includes/jobqueue/JobRunner.php +++ b/includes/jobqueue/JobRunner.php @@ -208,7 +208,12 @@ class JobRunner implements LoggerAwareInterface { // other wikis in the farm (on different masters) get a chance. $timePassed = microtime( true ) - $lastCheckTime; if ( $timePassed >= self::LAG_CHECK_PERIOD || $timePassed < 0 ) { - if ( !wfWaitForSlaves( $lastCheckTime, false, '*', self::MAX_ALLOWED_LAG ) ) { + try { + wfGetLBFactory()->waitForReplication( array( + 'ifWritesSince' => $lastCheckTime, + 'timeout' => self::MAX_ALLOWED_LAG + ) ); + } catch ( DBReplicationWaitError $e ) { $response['reached'] = 'slave-lag-limit'; break; } diff --git a/includes/jobqueue/jobs/CategoryMembershipChangeJob.php b/includes/jobqueue/jobs/CategoryMembershipChangeJob.php index c9e20a9bea..98c87a5ace 100644 --- a/includes/jobqueue/jobs/CategoryMembershipChangeJob.php +++ b/includes/jobqueue/jobs/CategoryMembershipChangeJob.php @@ -169,7 +169,7 @@ class CategoryMembershipChangeJob extends Job { $catMembChange->triggerCategoryAddedNotification( $categoryTitle ); if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) { $dbw->commit( __METHOD__, 'flush' ); - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication(); } } @@ -178,7 +178,7 @@ class CategoryMembershipChangeJob extends Job { $catMembChange->triggerCategoryRemovedNotification( $categoryTitle ); if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) { $dbw->commit( __METHOD__, 'flush' ); - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication(); } } } diff --git a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php index df0a66e409..0d48cb3858 100644 --- a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php +++ b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php @@ -120,7 +120,7 @@ class HTMLCacheUpdateJob extends Job { // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already. foreach ( array_chunk( $pageIds, $wgUpdateRowsPerQuery ) as $batch ) { $dbw->commit( __METHOD__, 'flush' ); - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication(); $dbw->update( 'page', array( 'page_touched' => $dbw->timestamp( $touchTimestamp ) ), diff --git a/includes/jobqueue/jobs/RecentChangesUpdateJob.php b/includes/jobqueue/jobs/RecentChangesUpdateJob.php index d6fa26b81f..0685299026 100644 --- a/includes/jobqueue/jobs/RecentChangesUpdateJob.php +++ b/includes/jobqueue/jobs/RecentChangesUpdateJob.php @@ -98,7 +98,9 @@ class RecentChangesUpdateJob extends Job { if ( count( $rcIds ) === $batchSize ) { // There might be more, so try waiting for slaves - if ( !wfWaitForSlaves( null, false, false, /* $timeout = */ 3 ) ) { + try { + wfGetLBFactory()->waitForReplication( array( 'timeout' => 3 ) ); + } catch ( DBReplicationWaitError $e ) { // Another job will continue anyway break; } @@ -125,7 +127,7 @@ class RecentChangesUpdateJob extends Job { $lockKey = wfWikiID() . '-activeusers'; if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) { - return false; // exclusive update (avoids duplicate entries) + return; // exclusive update (avoids duplicate entries) } $nowUnix = time(); @@ -203,7 +205,7 @@ class RecentChangesUpdateJob extends Job { } foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) { $dbw->insert( 'querycachetwo', $rowBatch, __METHOD__ ); - wfWaitForSlaves(); + wfGetLBFactory()->waitForReplication(); } } diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 57765190e9..0e3c9ebbf9 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -735,7 +735,12 @@ class SqlBagOStuff extends BagOStuff { protected function waitForSlaves() { if ( !$this->serverInfos ) { // Main LB is used; wait for any slaves to catch up - return wfWaitForSlaves( null, false, false, $this->syncTimeout ); + try { + wfGetLBFactory()->waitForReplication( array( 'wiki' => wfWikiID() ) ); + return true; + } catch ( DBReplicationWaitError $e ) { + return false; + } } else { // Custom DB server list; probably doesn't use replication return true; diff --git a/includes/utils/BatchRowWriter.php b/includes/utils/BatchRowWriter.php index 13cab5bd2b..ffb7053b38 100644 --- a/includes/utils/BatchRowWriter.php +++ b/includes/utils/BatchRowWriter.php @@ -66,6 +66,6 @@ class BatchRowWriter { } $this->db->commit(); - wfWaitForSlaves( false, false, $this->clusterName ); + wfGetLBFactory()->waitForReplication(); } } -- 2.20.1