Migrate some wfWikiId() callers to getLocalDomainID()
[lhc/web/wiklou.git] / includes / jobqueue / JobRunner.php
index a85613a..39b5b3b 100644 (file)
@@ -29,7 +29,6 @@ use Psr\Log\LoggerInterface;
 use Wikimedia\ScopedCallback;
 use Wikimedia\Rdbms\LBFactory;
 use Wikimedia\Rdbms\DBError;
-use Wikimedia\Rdbms\DBReplicationWaitError;
 
 /**
  * Job queue runner utility methods
@@ -69,7 +68,7 @@ class JobRunner implements LoggerAwareInterface {
        }
 
        /**
-        * @param LoggerInterface $logger
+        * @param LoggerInterface|null $logger
         */
        public function __construct( LoggerInterface $logger = null ) {
                if ( $logger === null ) {
@@ -132,7 +131,7 @@ class JobRunner implements LoggerAwareInterface {
                }
                // Bail out if there is too much DB lag.
                // This check should not block as we want to try other wiki queues.
-               list( , $maxLag ) = $lbFactory->getMainLB( wfWikiID() )->getMaxLag();
+               list( , $maxLag ) = $lbFactory->getMainLB()->getMaxLag();
                if ( $maxLag >= self::MAX_ALLOWED_LAG ) {
                        $response['reached'] = 'replica-lag-limit';
                        return $response;
@@ -225,21 +224,16 @@ 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 ) {
-                                       try {
-                                               $lbFactory->waitForReplication( [
-                                                       'ifWritesSince' => $lastCheckTime,
-                                                       'timeout' => self::MAX_ALLOWED_LAG
-                                               ] );
-                                       } catch ( DBReplicationWaitError $e ) {
+                                       $success = $lbFactory->waitForReplication( [
+                                               'ifWritesSince' => $lastCheckTime,
+                                               'timeout' => self::MAX_ALLOWED_LAG,
+                                       ] );
+                                       if ( !$success ) {
                                                $response['reached'] = 'replica-lag-limit';
                                                break;
                                        }
                                        $lastCheckTime = microtime( true );
                                }
-                               // Don't let any queue replica DBs/backups fall behind
-                               if ( $jobsPopped > 0 && ( $jobsPopped % 100 ) == 0 ) {
-                                       $group->waitForBackups();
-                               }
 
                                // Bail if near-OOM instead of in a job
                                if ( !$this->checkMemoryOK() ) {
@@ -542,7 +536,7 @@ class JobRunner implements LoggerAwareInterface {
                $syncThreshold = $this->config->get( 'JobSerialCommitThreshold' );
 
                $time = false;
-               $lb = $lbFactory->getMainLB( wfWikiID() );
+               $lb = $lbFactory->getMainLB();
                if ( $syncThreshold !== false && $lb->getServerCount() > 1 ) {
                        // Generally, there is one master connection to the local DB
                        $dbwSerial = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
@@ -582,12 +576,12 @@ class JobRunner implements LoggerAwareInterface {
                $this->debugCallback( $msg );
 
                // Wait for an exclusive lock to commit
-               if ( !$dbwSerial->lock( 'jobrunner-serial-commit', __METHOD__, 30 ) ) {
+               if ( !$dbwSerial->lock( 'jobrunner-serial-commit', $fnameTrxOwner, 30 ) ) {
                        // This will trigger a rollback in the main loop
                        throw new DBError( $dbwSerial, "Timed out waiting on commit queue." );
                }
-               $unlocker = new ScopedCallback( function () use ( $dbwSerial ) {
-                       $dbwSerial->unlock( 'jobrunner-serial-commit', __METHOD__ );
+               $unlocker = new ScopedCallback( function () use ( $dbwSerial, $fnameTrxOwner ) {
+                       $dbwSerial->unlock( 'jobrunner-serial-commit', $fnameTrxOwner );
                } );
 
                // Wait for the replica DBs to catch up