Migrate callers to waitForReplication()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 20 Jan 2016 17:23:46 +0000 (09:23 -0800)
committerTim Starling <tstarling@wikimedia.org>
Thu, 28 Jan 2016 03:00:08 +0000 (03:00 +0000)
Change-Id: I7b2b13b9315891561d2d8cc04a12ecad2dc73d70

includes/installer/DatabaseUpdater.php
includes/installer/MysqlUpdater.php
includes/jobqueue/JobRunner.php
includes/jobqueue/jobs/CategoryMembershipChangeJob.php
includes/jobqueue/jobs/HTMLCacheUpdateJob.php
includes/jobqueue/jobs/RecentChangesUpdateJob.php
includes/objectcache/SqlBagOStuff.php
includes/utils/BatchRowWriter.php

index 904fde8..61c3002 100644 (file)
@@ -456,7 +456,7 @@ abstract class DatabaseUpdater {
                        flush();
                        if ( $ret !== false ) {
                                $updatesDone[] = $origParams;
-                               wfWaitForSlaves();
+                               wfGetLBFactory()->waitForReplication();
                        } else {
                                $updatesSkipped[] = array( $func, $params, $origParams );
                        }
index 4813bea..10fed31 100644 (file)
@@ -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(
index 4ab9f5a..3919318 100644 (file)
@@ -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;
                                        }
index c9e20a9..98c87a5 100644 (file)
@@ -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();
                        }
                }
        }
index df0a66e..0d48cb3 100644 (file)
@@ -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 ) ),
index d6fa26b..0685299 100644 (file)
@@ -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();
                                }
                        }
 
index 5776519..0e3c9eb 100644 (file)
@@ -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;
index 13cab5b..ffb7053 100644 (file)
@@ -66,6 +66,6 @@ class BatchRowWriter {
                }
 
                $this->db->commit();
-               wfWaitForSlaves( false, false, $this->clusterName );
+               wfGetLBFactory()->waitForReplication();
        }
 }