MediaWiki  master
JobQueueRedis Class Reference

Class to handle job queues stored in Redis. More...

Inheritance diagram for JobQueueRedis:
Collaboration diagram for JobQueueRedis:

Public Member Functions

 __construct (array $params)
 
 getAllAbandonedJobs ()
 
 getAllAcquiredJobs ()
 
 getAllDelayedJobs ()
 
 getAllQueuedJobs ()
 
 getCoalesceLocationInternal ()
 
 getJobFromUidInternal ( $uid, $conn)
 This function should not be called outside JobQueueRedis. More...
 
 getServerQueuesWithJobs ()
 
- Public Member Functions inherited from JobQueue
 ack (RunnableJob $job)
 Acknowledge that a job was completed. More...
 
 batchPush (array $jobs, $flags=0)
 Push a batch of jobs into the queue. More...
 
 deduplicateRootJob (IJobSpecification $job)
 Register the "root job" of a given job into the queue for de-duplication. More...
 
 delayedJobsEnabled ()
 
 delete ()
 Deleted all unclaimed and delayed jobs from the queue. More...
 
 flushCaches ()
 Clear any process and persistent caches. More...
 
 getAbandonedCount ()
 Get the number of acquired jobs that can no longer be attempted. More...
 
 getAcquiredCount ()
 Get the number of acquired jobs (these are temporarily out of the queue). More...
 
 getAllAbandonedJobs ()
 Get an iterator to traverse over all abandoned jobs in this queue. More...
 
 getAllAcquiredJobs ()
 Get an iterator to traverse over all claimed jobs in this queue. More...
 
 getAllDelayedJobs ()
 Get an iterator to traverse over all delayed jobs in this queue. More...
 
 getAllQueuedJobs ()
 Get an iterator to traverse over all available jobs in this queue. More...
 
 getCoalesceLocationInternal ()
 Do not use this function outside of JobQueue/JobQueueGroup. More...
 
 getDelayedCount ()
 Get the number of delayed jobs (these are temporarily out of the queue). More...
 
 getDomain ()
 
 getOrder ()
 
 getReadOnlyReason ()
 
 getSiblingQueueSizes (array $types)
 Check the size of each of the given queues. More...
 
 getSiblingQueuesWithJobs (array $types)
 Check whether each of the given queues are empty. More...
 
 getSize ()
 Get the number of available (unacquired, non-delayed) jobs in the queue. More...
 
 getType ()
 
 getWiki ()
 
 isEmpty ()
 Quickly check if the queue has no available (unacquired, non-delayed) jobs. More...
 
 pop ()
 Pop a job off of the queue. More...
 
 push ( $jobs, $flags=0)
 Push one or more jobs into the queue. More...
 
 waitForBackups ()
 Wait for any replica DBs or backup servers to catch up. More...
 

Public Attributes

const MAX_PUSH_SIZE = 25
 
- Public Attributes inherited from JobQueue
const QOS_ATOMIC = 1
 
const ROOTJOB_TTL = 2419200
 

Protected Member Functions

 doAck (RunnableJob $job)
 
 doBatchPush (array $jobs, $flags)
 
 doDeduplicateRootJob (IJobSpecification $job)
 
 doDelete ()
 
 doGetAbandonedCount ()
 
 doGetAcquiredCount ()
 
 doGetDelayedCount ()
 
 doGetSiblingQueueSizes (array $types)
 
 doGetSiblingQueuesWithJobs (array $types)
 
 doGetSize ()
 
 doIsEmpty ()
 
 doIsRootJobOldDuplicate (IJobSpecification $job)
 
 doPop ()
 
 getConnection ()
 Get a connection to the server that handles all sub-queues for this queue. More...
 
 getJobFromFields (array $fields)
 
 getJobIterator (RedisConnRef $conn, array $uids)
 
 getNewJobFields (IJobSpecification $job)
 
 handleErrorAndMakeException (RedisConnRef $conn, $e)
 
 optimalOrder ()
 
 popAndAcquireBlob (RedisConnRef $conn)
 
 pushBlobs (RedisConnRef $conn, array $items)
 
 serialize (array $fields)
 
 supportedOrders ()
 
 supportsDelayedJobs ()
 
 unserialize ( $blob)
 
- Protected Member Functions inherited from JobQueue
 __construct (array $params)
 
 assertNotReadOnly ()
 
 doAck (RunnableJob $job)
 
 doBatchPush (array $jobs, $flags)
 
 doDeduplicateRootJob (IJobSpecification $job)
 
 doDelete ()
 
 doFlushCaches ()
 
 doGetAbandonedCount ()
 
 doGetAcquiredCount ()
 
 doGetDelayedCount ()
 
 doGetSiblingQueueSizes (array $types)
 
 doGetSiblingQueuesWithJobs (array $types)
 
 doGetSize ()
 
 doIsEmpty ()
 
 doIsRootJobOldDuplicate (IJobSpecification $job)
 
 doPop ()
 
 doWaitForBackups ()
 
 factoryJob ( $command, $params)
 
 getRootJobCacheKey ( $signature)
 
 incrStats ( $key, $type, $delta=1)
 Call wfIncrStats() for the queue overall and for the queue type. More...
 
 isRootJobOldDuplicate (IJobSpecification $job)
 Check if the "root" job of a given job has been superseded by a newer one. More...
 
 optimalOrder ()
 Get the default queue order to use if configuration does not specify one. More...
 
 supportedOrders ()
 Get the allowed queue orders for configuration validation. More...
 
 supportsDelayedJobs ()
 Find out if delayed jobs are supported for configuration validation. More...
 

Protected Attributes

string $compression
 Compression method to use. More...
 
LoggerInterface $logger
 
RedisConnectionPool $redisPool
 
string $server
 Server address. More...
 
- Protected Attributes inherited from JobQueue
int $claimTTL
 Time to live in seconds. More...
 
string $domain
 DB domain ID. More...
 
int $maxTries
 Maximum number of times to try a job. More...
 
string $order
 Job priority for pop() More...
 
string bool $readOnlyReason
 Read only rationale (or false if r/w) More...
 
StatsdDataFactoryInterface $stats
 
string $type
 Job type. More...
 
WANObjectCache $wanCache
 

Private Member Functions

 decodeQueueName ( $name)
 
 encodeQueueName ()
 
 getGlobalKey ( $name)
 
 getQueueKey ( $prop, $type=null)
 

Additional Inherited Members

- Static Public Member Functions inherited from JobQueue
static factory (array $params)
 Get a job queue object of the specified type. More...
 

Detailed Description

Class to handle job queues stored in Redis.

This is a faster and less resource-intensive job queue than JobQueueDB. All data for a queue using this class is placed into one redis server. The mediawiki/services/jobrunner background service must be set up and running.

There are eight main redis keys (per queue) used to track jobs:

  • l-unclaimed : A list of job IDs used for ready unclaimed jobs
  • z-claimed : A sorted set of (job ID, UNIX timestamp as score) used for job retries
  • z-abandoned : A sorted set of (job ID, UNIX timestamp as score) used for broken jobs
  • z-delayed : A sorted set of (job ID, UNIX timestamp as score) used for delayed jobs
  • h-idBySha1 : A hash of (SHA1 => job ID) for unclaimed jobs used for de-duplication
  • h-sha1ById : A hash of (job ID => SHA1) for unclaimed jobs used for de-duplication
  • h-attempts : A hash of (job ID => attempt count) used for job claiming/retries
  • h-data : A hash of (job ID => serialized blobs) for job storage A job ID can be in only one of z-delayed, l-unclaimed, z-claimed, and z-abandoned. If an ID appears in any of those lists, it should have a h-data entry for its ID. If a job has a SHA1 de-duplication value and its ID is in l-unclaimed or z-delayed, then there should be no other such jobs with that SHA1. Every h-idBySha1 entry has an h-sha1ById entry and every h-sha1ById must refer to an ID that is l-unclaimed. If a job has its ID in z-claimed or z-abandoned, then it must also have an h-attempts entry for its ID.

The following keys are used to track queue states:

  • s-queuesWithJobs : A set of all queues with non-abandoned jobs

The background service takes care of undelaying, recycling, and pruning jobs as well as removing s-queuesWithJobs entries as queues empty.

Additionally, "rootjob:* keys track "root jobs" used for additional de-duplication. Aside from root job keys, all keys have no expiry, and are only removed when jobs are run. All the keys are prefixed with the relevant wiki ID information.

This class requires Redis 2.6 as it makes use Lua scripts for fast atomic operations. Additionally, it should be noted that redis has different persistence modes, such as rdb snapshots, journaling, and no persistence. Appropriate configuration should be made on the servers based on what queues are using it and what tolerance they have.

Since
1.22

Definition at line 68 of file JobQueueRedis.php.

Constructor & Destructor Documentation

◆ __construct()

JobQueueRedis::__construct ( array  $params)
Parameters
array$paramsPossible keys:
  • redisConfig : An array of parameters to RedisConnectionPool::__construct(). Note that the serializer option is ignored as "none" is always used.
  • redisServer : A hostname/port combination or the absolute path of a UNIX socket. If a hostname is specified but no port, the standard port number 6379 will be used. Required.
  • compression : The type of compression to use; one of (none,gzip).
  • daemonized : Set to true if the redisJobRunnerService runs in the background. This will disable job recycling/undelaying from the MediaWiki side to avoid redundance and out-of-sync configuration.
Exceptions
InvalidArgumentException

Definition at line 94 of file JobQueueRedis.php.

References server, and RedisConnectionPool\singleton().

Member Function Documentation

◆ decodeQueueName()

JobQueueRedis::decodeQueueName (   $name)
private
Parameters
string$nameJSON
Returns
array (type, wiki)

Definition at line 792 of file JobQueueRedis.php.

References $name.

Referenced by getServerQueuesWithJobs().

◆ doAck()

JobQueueRedis::doAck ( RunnableJob  $job)
protected
See also
JobQueue::doAck()
Parameters
RunnableJob$job
Returns
RunnableJob|bool
Exceptions
UnexpectedValueException
JobQueueError

Definition at line 389 of file JobQueueRedis.php.

References $e, $res, are, as, data, getConnection(), RunnableJob\getMetadata(), getQueueKey(), handleErrorAndMakeException(), JobQueue\incrStats(), null, of, that, then, type, and wfDebugLog().

◆ doBatchPush()

JobQueueRedis::doBatchPush ( array  $jobs,
  $flags 
)
protected
See also
JobQueue::doBatchPush()
Parameters
IJobSpecification[]$jobs
int$flags
Returns
void
Exceptions
JobQueueError

Definition at line 196 of file JobQueueRedis.php.

References $e, $job, as, getConnection(), getNewJobFields(), handleErrorAndMakeException(), JobQueue\incrStats(), pushBlobs(), type, and wfDebugLog().

◆ doDeduplicateRootJob()

JobQueueRedis::doDeduplicateRootJob ( IJobSpecification  $job)
protected

◆ doDelete()

JobQueueRedis::doDelete ( )
protected

◆ doGetAbandonedCount()

JobQueueRedis::doGetAbandonedCount ( )
protected
See also
JobQueue::doGetAbandonedCount()
Returns
int
Exceptions
JobQueueError

Definition at line 180 of file JobQueueRedis.php.

References $e, getConnection(), getQueueKey(), and handleErrorAndMakeException().

◆ doGetAcquiredCount()

JobQueueRedis::doGetAcquiredCount ( )
protected
See also
JobQueue::doGetAcquiredCount()
Returns
int
Exceptions
JobQueueError

Definition at line 148 of file JobQueueRedis.php.

References $e, getConnection(), getQueueKey(), and handleErrorAndMakeException().

◆ doGetDelayedCount()

JobQueueRedis::doGetDelayedCount ( )
protected
See also
JobQueue::doGetDelayedCount()
Returns
int
Exceptions
JobQueueError

Definition at line 166 of file JobQueueRedis.php.

References $e, getConnection(), getQueueKey(), and handleErrorAndMakeException().

◆ doGetSiblingQueueSizes()

JobQueueRedis::doGetSiblingQueueSizes ( array  $types)
protected

◆ doGetSiblingQueuesWithJobs()

JobQueueRedis::doGetSiblingQueuesWithJobs ( array  $types)
protected

Definition at line 600 of file JobQueueRedis.php.

References doGetSiblingQueueSizes().

◆ doGetSize()

JobQueueRedis::doGetSize ( )
protected
See also
JobQueue::doGetSize()
Returns
int
Exceptions
JobQueueError

Definition at line 134 of file JobQueueRedis.php.

References $e, getConnection(), getQueueKey(), and handleErrorAndMakeException().

Referenced by doIsEmpty().

◆ doIsEmpty()

JobQueueRedis::doIsEmpty ( )
protected
See also
JobQueue::doIsEmpty()
Returns
bool
Exceptions
JobQueueError

Definition at line 125 of file JobQueueRedis.php.

References doGetSize().

◆ doIsRootJobOldDuplicate()

◆ doPop()

JobQueueRedis::doPop ( )
protected

◆ encodeQueueName()

JobQueueRedis::encodeQueueName ( )
private
Returns
string JSON

Definition at line 784 of file JobQueueRedis.php.

References type.

Referenced by doDelete(), and pushBlobs().

◆ getAllAbandonedJobs()

JobQueueRedis::getAllAbandonedJobs ( )
See also
JobQueue::getAllAbandonedJobs()
Returns
Iterator
Exceptions
JobQueueError

Definition at line 568 of file JobQueueRedis.php.

References $e, getConnection(), getJobIterator(), getQueueKey(), and handleErrorAndMakeException().

◆ getAllAcquiredJobs()

JobQueueRedis::getAllAcquiredJobs ( )
See also
JobQueue::getAllAcquiredJobs()
Returns
Iterator
Exceptions
JobQueueError

Definition at line 552 of file JobQueueRedis.php.

References $e, getConnection(), getJobIterator(), getQueueKey(), and handleErrorAndMakeException().

◆ getAllDelayedJobs()

JobQueueRedis::getAllDelayedJobs ( )
See also
JobQueue::getAllDelayedJobs()
Returns
Iterator
Exceptions
JobQueueError

Definition at line 536 of file JobQueueRedis.php.

References $e, getConnection(), getJobIterator(), getQueueKey(), and handleErrorAndMakeException().

◆ getAllQueuedJobs()

JobQueueRedis::getAllQueuedJobs ( )
See also
JobQueue::getAllQueuedJobs()
Returns
Iterator
Exceptions
JobQueueError

Definition at line 520 of file JobQueueRedis.php.

References $e, getConnection(), getJobIterator(), getQueueKey(), and handleErrorAndMakeException().

◆ getCoalesceLocationInternal()

JobQueueRedis::getCoalesceLocationInternal ( )

Definition at line 596 of file JobQueueRedis.php.

References $server.

◆ getConnection()

JobQueueRedis::getConnection ( )
protected

◆ getGlobalKey()

JobQueueRedis::getGlobalKey (   $name)
private
Parameters
string$name
Returns
string

Definition at line 800 of file JobQueueRedis.php.

References $name, and as.

Referenced by doDelete(), getServerQueuesWithJobs(), and pushBlobs().

◆ getJobFromFields()

JobQueueRedis::getJobFromFields ( array  $fields)
protected
Parameters
array$fields
Returns
RunnableJob|bool

Definition at line 708 of file JobQueueRedis.php.

References $job, $params, and JobQueue\factoryJob().

Referenced by doPop().

◆ getJobFromUidInternal()

JobQueueRedis::getJobFromUidInternal (   $uid,
  $conn 
)

This function should not be called outside JobQueueRedis.

Parameters
string$uid
RedisConnRef | Redis$conn
Returns
RunnableJob|bool Returns false if the job does not exist
Exceptions
JobQueueError
UnexpectedValueException

Definition at line 635 of file JobQueueRedis.php.

References $e, $job, $params, JobQueue\factoryJob(), getQueueKey(), handleErrorAndMakeException(), and unserialize().

Referenced by getJobIterator().

◆ getJobIterator()

JobQueueRedis::getJobIterator ( RedisConnRef  $conn,
array  $uids 
)
protected
Parameters
RedisConnRef$conn
array$uidsList of job UUIDs
Returns
MappedIterator

Definition at line 584 of file JobQueueRedis.php.

References $job, getJobFromUidInternal(), and use.

Referenced by getAllAbandonedJobs(), getAllAcquiredJobs(), getAllDelayedJobs(), and getAllQueuedJobs().

◆ getNewJobFields()

◆ getQueueKey()

JobQueueRedis::getQueueKey (   $prop,
  $type = null 
)
private

◆ getServerQueuesWithJobs()

JobQueueRedis::getServerQueuesWithJobs ( )
Returns
array List of (wiki,type) tuples for queues with non-abandoned jobs
Exceptions
JobQueueConnectionError
JobQueueError

Definition at line 666 of file JobQueueRedis.php.

References $e, $queue, as, decodeQueueName(), getConnection(), getGlobalKey(), and handleErrorAndMakeException().

◆ handleErrorAndMakeException()

◆ optimalOrder()

JobQueueRedis::optimalOrder ( )
protected

Definition at line 112 of file JobQueueRedis.php.

◆ popAndAcquireBlob()

JobQueueRedis::popAndAcquireBlob ( RedisConnRef  $conn)
protected
Parameters
RedisConnRef$conn
Returns
array Serialized string or false
Exceptions
RedisException

Definition at line 348 of file JobQueueRedis.php.

References and(), are, as, getQueueKey(), RedisConnRef\luaEval(), of, that, and then.

Referenced by doPop().

◆ pushBlobs()

JobQueueRedis::pushBlobs ( RedisConnRef  $conn,
array  $items 
)
protected
Parameters
RedisConnRef$conn
array$itemsList of results from JobQueueRedis::getNewJobFields()
Returns
int Number of jobs inserted (duplicates are ignored)
Exceptions
RedisException

Definition at line 250 of file JobQueueRedis.php.

References $args, are, as, encodeQueueName(), First, getGlobalKey(), getQueueKey(), in, is, RedisConnRef\luaEval(), of, or, release, serialize(), string, that, and then.

Referenced by doBatchPush().

◆ serialize()

JobQueueRedis::serialize ( array  $fields)
protected
Parameters
array$fields
Returns
string Serialized and possibly compressed version of $fields

Definition at line 723 of file JobQueueRedis.php.

References $blob, and object.

Referenced by getNewJobFields(), and pushBlobs().

◆ supportedOrders()

JobQueueRedis::supportedOrders ( )
protected

Definition at line 108 of file JobQueueRedis.php.

◆ supportsDelayedJobs()

JobQueueRedis::supportsDelayedJobs ( )
protected

Definition at line 116 of file JobQueueRedis.php.

◆ unserialize()

JobQueueRedis::unserialize (   $blob)
protected
Parameters
string$blob
Returns
array|bool Unserialized version of $blob or false

Definition at line 742 of file JobQueueRedis.php.

References $blob.

Referenced by doPop(), and getJobFromUidInternal().

Member Data Documentation

◆ $compression

string JobQueueRedis::$compression
protected

Compression method to use.

Definition at line 77 of file JobQueueRedis.php.

◆ $logger

LoggerInterface JobQueueRedis::$logger
protected

Definition at line 72 of file JobQueueRedis.php.

◆ $redisPool

RedisConnectionPool JobQueueRedis::$redisPool
protected

Definition at line 70 of file JobQueueRedis.php.

◆ $server

string JobQueueRedis::$server
protected

Server address.

Definition at line 75 of file JobQueueRedis.php.

Referenced by getCoalesceLocationInternal().

◆ MAX_PUSH_SIZE

const JobQueueRedis::MAX_PUSH_SIZE = 25

Definition at line 79 of file JobQueueRedis.php.


The documentation for this class was generated from the following file: