X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueueDB.php;h=84b2a0b2dd61efe70753afe0840cd3287277d735;hb=287bb1a064c48c8222a824452f1226e64816ffeb;hp=f6b4d53db143e1d4cc8203c3af5c6ce62db35777;hpb=950cf6016c10953213e5f985dfc18a32d8673197;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index f6b4d53db1..84b2a0b2dd 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -20,6 +20,8 @@ * @file * @author Aaron Schulz */ +use MediaWiki\MediaWikiServices; +use Wikimedia\ScopedCallback; /** * Class to handle job queues stored in the DB @@ -67,7 +69,7 @@ class JobQueueDB extends JobQueue { * @return bool */ protected function doIsEmpty() { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); try { $found = $dbr->selectField( // unclaimed job 'job', '1', [ 'job_cmd' => $this->type, 'job_token' => '' ], __METHOD__ @@ -92,7 +94,7 @@ class JobQueueDB extends JobQueue { } try { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); $size = (int)$dbr->selectField( 'job', 'COUNT(*)', [ 'job_cmd' => $this->type, 'job_token' => '' ], __METHOD__ @@ -121,7 +123,7 @@ class JobQueueDB extends JobQueue { return $count; } - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); try { $count = (int)$dbr->selectField( 'job', 'COUNT(*)', [ 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ], @@ -152,7 +154,7 @@ class JobQueueDB extends JobQueue { return $count; } - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); try { $count = (int)$dbr->selectField( 'job', 'COUNT(*)', [ @@ -185,7 +187,8 @@ class JobQueueDB extends JobQueue { $dbw->onTransactionIdle( function () use ( $dbw, $jobs, $flags, $method ) { $this->doBatchPushInternal( $dbw, $jobs, $flags, $method ); - } + }, + __METHOD__ ); } @@ -493,15 +496,18 @@ class JobQueueDB extends JobQueue { // jobs to become no-ops without any actual jobs that made them redundant. $dbw = $this->getMasterDB(); $cache = $this->dupCache; - $dbw->onTransactionIdle( function () use ( $cache, $params, $key, $dbw ) { - $timestamp = $cache->get( $key ); // current last timestamp of this job - if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) { - return true; // a newer version of this root job was enqueued - } + $dbw->onTransactionIdle( + function () use ( $cache, $params, $key, $dbw ) { + $timestamp = $cache->get( $key ); // current last timestamp of this job + if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) { + return true; // a newer version of this root job was enqueued + } - // Update the timestamp of the last root job started at the location... - return $cache->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL ); - } ); + // Update the timestamp of the last root job started at the location... + return $cache->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL ); + }, + __METHOD__ + ); return true; } @@ -526,7 +532,8 @@ class JobQueueDB extends JobQueue { * @return void */ protected function doWaitForBackups() { - wfWaitForSlaves( false, $this->wiki, $this->cluster ?: false ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory->waitForReplication( [ 'wiki' => $this->wiki, 'cluster' => $this->cluster ] ); } /** @@ -559,7 +566,7 @@ class JobQueueDB extends JobQueue { * @return Iterator */ protected function getJobIterator( array $conds ) { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); try { return new MappedIterator( $dbr->select( 'job', self::selectFields(), $conds ), @@ -587,7 +594,7 @@ class JobQueueDB extends JobQueue { } protected function doGetSiblingQueuesWithJobs( array $types ) { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); // @note: this does not check whether the jobs are claimed or not. // This is useful so JobQueueGroup::pop() also sees queues that only // have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue @@ -604,7 +611,7 @@ class JobQueueDB extends JobQueue { } protected function doGetSiblingQueueSizes( array $types ) { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); $res = $dbr->select( 'job', [ 'job_cmd', 'COUNT(*) AS count' ], [ 'job_cmd' => $types ], __METHOD__, [ 'GROUP BY' => 'job_cmd' ] ); @@ -730,7 +737,7 @@ class JobQueueDB extends JobQueue { * @throws JobQueueConnectionError * @return DBConnRef */ - protected function getSlaveDB() { + protected function getReplicaDB() { try { return $this->getDB( DB_REPLICA ); } catch ( DBConnectionError $e ) { @@ -755,9 +762,10 @@ class JobQueueDB extends JobQueue { * @return DBConnRef */ protected function getDB( $index ) { + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $lb = ( $this->cluster !== false ) - ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki ) - : wfGetLB( $this->wiki ); + ? $lbFactory->getExternalLB( $this->cluster, $this->wiki ) + : $lbFactory->getMainLB( $this->wiki ); return $lb->getConnectionRef( $index, [], $this->wiki ); }