Reduce lag waiting time in CategoryMembershipUpdateJob critical section
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 21 Nov 2017 02:09:52 +0000 (18:09 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 21 Nov 2017 04:08:43 +0000 (04:08 +0000)
Bug: T180793
Change-Id: Icfe8dd16f4194c5d4f88d7547f732acae8b1cfe2

includes/jobqueue/jobs/CategoryMembershipChangeJob.php

index 55c1367..cc81a96 100644 (file)
@@ -59,6 +59,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 );
@@ -67,8 +74,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;