Merge "Reduce lag waiting time in CategoryMembershipUpdateJob critical section"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 21 Nov 2017 19:13:34 +0000 (19:13 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 21 Nov 2017 19:13:34 +0000 (19:13 +0000)
includes/jobqueue/jobs/CategoryMembershipChangeJob.php

index 4251a25..16640be 100644 (file)
@@ -61,6 +61,13 @@ class CategoryMembershipChangeJob extends Job {
                        return false; // deleted?
                }
 
+               // Cut down on the time spent in safeWaitForMasterPos() in the critical section
+               $dbr = $lb->getConnection( DB_REPLICA, [ 'recentchanges' ] );
+               if ( !$lb->safeWaitForMasterPos( $dbr ) ) {
+                       $this->setLastError( "Timed out while pre-waiting for replica DB to catch up" );
+                       return false;
+               }
+
                // Use a named lock so that jobs for this page see each others' changes
                $lockKey = "CategoryMembershipUpdates:{$page->getId()}";
                $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
@@ -69,8 +76,7 @@ class CategoryMembershipChangeJob extends Job {
                        return false;
                }
 
-               $dbr = $lb->getConnection( DB_REPLICA, [ 'recentchanges' ] );
-               // Wait till the replica DB is caught up so that jobs for this page see each others' changes
+               // Wait till replica DB is caught up so that jobs for this page see each others' changes
                if ( !$lb->safeWaitForMasterPos( $dbr ) ) {
                        $this->setLastError( "Timed out while waiting for replica DB to catch up" );
                        return false;