Tim Starling has submitted this change and it was merged.
Change subject: Revert "Refactored use of $wgMemc in JobQueueDB to use a field."
......................................................................
Revert "Refactored use of $wgMemc in JobQueueDB to use a field."
This reverts commit 7293699561f8751c66d55697e63b13a18653ac6b
Unit tests fail.
Change-Id: Iac8025844b37c584e451a4120e54898ae4f2524e
---
M includes/job/JobQueueDB.php
1 file changed, 38 insertions(+), 24 deletions(-)
Approvals:
Tim Starling: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/includes/job/JobQueueDB.php b/includes/job/JobQueueDB.php
index 6ab11dc..a7a459f 100644
--- a/includes/job/JobQueueDB.php
+++ b/includes/job/JobQueueDB.php
@@ -35,9 +35,6 @@
const MAX_JOB_RANDOM = 2147483647; // integer; 2^31 - 1, used for
job_random
const MAX_OFFSET = 255; // integer; maximum number of rows to skip
- /** @var BagOStuff */
- protected $cache;
-
protected $cluster = false; // string; name of an external DB cluster
/**
@@ -51,7 +48,6 @@
protected function __construct( array $params ) {
parent::__construct( $params );
$this->cluster = isset( $params['cluster'] ) ?
$params['cluster'] : false;
- $this->cache = wfGetMainCache();
}
protected function supportedOrders() {
@@ -67,9 +63,11 @@
* @return bool
*/
protected function doIsEmpty() {
+ global $wgMemc;
+
$key = $this->getCacheKey( 'empty' );
- $isEmpty = $this->cache->get( $key );
+ $isEmpty = $wgMemc->get( $key );
if ( $isEmpty === 'true' ) {
return true;
} elseif ( $isEmpty === 'false' ) {
@@ -80,7 +78,7 @@
$found = $dbr->selectField( // unclaimed job
'job', '1', array( 'job_cmd' => $this->type,
'job_token' => '' ), __METHOD__
);
- $this->cache->add( $key, $found ? 'false' : 'true',
self::CACHE_TTL_LONG );
+ $wgMemc->add( $key, $found ? 'false' : 'true',
self::CACHE_TTL_LONG );
return !$found;
}
@@ -90,9 +88,11 @@
* @return integer
*/
protected function doGetSize() {
+ global $wgMemc;
+
$key = $this->getCacheKey( 'size' );
- $size = $this->cache->get( $key );
+ $size = $wgMemc->get( $key );
if ( is_int( $size ) ) {
return $size;
}
@@ -102,7 +102,7 @@
array( 'job_cmd' => $this->type, 'job_token' => '' ),
__METHOD__
);
- $this->cache->set( $key, $size, self::CACHE_TTL_SHORT );
+ $wgMemc->set( $key, $size, self::CACHE_TTL_SHORT );
return $size;
}
@@ -112,13 +112,15 @@
* @return integer
*/
protected function doGetAcquiredCount() {
+ global $wgMemc;
+
if ( $this->claimTTL <= 0 ) {
return 0; // no acknowledgements
}
$key = $this->getCacheKey( 'acquiredcount' );
- $count = $this->cache->get( $key );
+ $count = $wgMemc->get( $key );
if ( is_int( $count ) ) {
return $count;
}
@@ -128,7 +130,7 @@
array( 'job_cmd' => $this->type, "job_token !=
{$dbr->addQuotes( '' )}" ),
__METHOD__
);
- $this->cache->set( $key, $count, self::CACHE_TTL_SHORT );
+ $wgMemc->set( $key, $count, self::CACHE_TTL_SHORT );
return $count;
}
@@ -158,11 +160,12 @@
$key = $this->getCacheKey( 'empty' );
$atomic = ( $flags & self::QoS_Atomic );
- $cache = $this->cache;
$dbw->onTransactionIdle(
- function() use ( $dbw, $cache, $rowSet,
$rowList, $atomic, $key, $scope
+ function() use ( $dbw, $rowSet, $rowList,
$atomic, $key, $scope
) {
+ global $wgMemc;
+
if ( $atomic ) {
$dbw->begin( __METHOD__ ); // wrap all
the job additions in one transaction
}
@@ -201,7 +204,7 @@
$dbw->commit( __METHOD__ );
}
- $cache->set( $key, 'false',
JobQueueDB::CACHE_TTL_LONG );
+ $wgMemc->set( $key, 'false',
JobQueueDB::CACHE_TTL_LONG );
} );
}
@@ -213,7 +216,9 @@
* @return Job|bool
*/
protected function doPop() {
- if ( $this->cache->get( $this->getCacheKey( 'empty' ) ) ===
'true' ) {
+ global $wgMemc;
+
+ if ( $wgMemc->get( $this->getCacheKey( 'empty' ) ) === 'true' )
{
return false; // queue is empty
}
@@ -233,7 +238,7 @@
}
// Check if we found a row to reserve...
if ( !$row ) {
- $this->cache->set( $this->getCacheKey( 'empty'
), 'true', self::CACHE_TTL_LONG );
+ $wgMemc->set( $this->getCacheKey( 'empty' ),
'true', self::CACHE_TTL_LONG );
break; // nothing to do
}
wfIncrStats( 'job-pop' );
@@ -267,9 +272,11 @@
* @return Row|false
*/
protected function claimRandom( $uuid, $rand, $gte ) {
+ global $wgMemc;
+
list( $dbw, $scope ) = $this->getMasterDB();
// Check cache to see if the queue has <= OFFSET items
- $tinyQueue = $this->cache->get( $this->getCacheKey( 'small' ) );
+ $tinyQueue = $wgMemc->get( $this->getCacheKey( 'small' ) );
$row = false; // the row acquired
$invertedDirection = false; // whether one job_random direction
was already scanned
@@ -310,7 +317,7 @@
);
if ( !$row ) {
$tinyQueue = true; // we know the queue
must have <= MAX_OFFSET rows
- $this->cache->set( $this->getCacheKey(
'small' ), 1, 30 );
+ $wgMemc->set( $this->getCacheKey(
'small' ), 1, 30 );
continue; // use job_random
}
}
@@ -403,6 +410,8 @@
* @return integer Number of jobs recycled/deleted
*/
public function recycleAndDeleteStaleJobs() {
+ global $wgMemc;
+
$now = time();
list( $dbw, $scope ) = $this->getMasterDB();
$count = 0; // affected rows
@@ -440,7 +449,7 @@
);
$count += $dbw->affectedRows();
wfIncrStats( 'job-recycle',
$dbw->affectedRows() );
- $this->cache->set( $this->getCacheKey( 'empty'
), 'false', self::CACHE_TTL_LONG );
+ $wgMemc->set( $this->getCacheKey( 'empty' ),
'false', self::CACHE_TTL_LONG );
}
}
@@ -509,15 +518,16 @@
// maintained. Having only the de-duplication registration
succeed would cause
// jobs to become no-ops without any actual jobs that made them
redundant.
list( $dbw, $scope ) = $this->getMasterDB();
- $cache = $this->cache;
- $dbw->onTransactionIdle( function() use ( $cache, $params,
$key, $scope ) {
- $timestamp = $cache->get( $key ); // current last
timestamp of this job
+ $dbw->onTransactionIdle( function() use ( $params, $key, $scope
) {
+ global $wgMemc;
+
+ $timestamp = $wgMemc->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 );
+ return $wgMemc->set( $key, $params['rootJobTimestamp'],
JobQueueDB::ROOTJOB_TTL );
} );
return true;
@@ -530,6 +540,8 @@
* @return bool
*/
protected function isRootJobOldDuplicate( Job $job ) {
+ global $wgMemc;
+
$params = $job->getParams();
if ( !isset( $params['rootJobSignature'] ) ) {
return false; // job has no de-deplication info
@@ -539,7 +551,7 @@
}
// Get the last time this root job was enqueued
- $timestamp = $this->cache->get( $this->getRootJobCacheKey(
$params['rootJobSignature'] ) );
+ $timestamp = $wgMemc->get( $this->getRootJobCacheKey(
$params['rootJobSignature'] ) );
// Check if a new root job was started at the location after
this one's...
return ( $timestamp && $timestamp > $params['rootJobTimestamp']
);
@@ -569,8 +581,10 @@
* @return void
*/
protected function doFlushCaches() {
+ global $wgMemc;
+
foreach ( array( 'empty', 'size', 'acquiredcount' ) as $type ) {
- $this->cache->delete( $this->getCacheKey( $type ) );
+ $wgMemc->delete( $this->getCacheKey( $type ) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/54329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iac8025844b37c584e451a4120e54898ae4f2524e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Tim Starling <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits