MediaWiki  1.32.5
JobQueueFederated Class Reference

Class to handle enqueueing and running of background jobs for federated queues. More...

Inheritance diagram for JobQueueFederated:
Collaboration diagram for JobQueueFederated:

Public Member Functions

 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...
 
- Public Member Functions inherited from JobQueue
 ack (Job $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...
 
 getDelayedCount ()
 Get the number of delayed jobs (these are temporarily out of the queue). More...
 
 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...
 

Protected Member Functions

 __construct (array $params)
 
 doAck (Job $job)
 
 doBatchPush (array $jobs, $flags)
 
 doDeduplicateRootJob (IJobSpecification $job)
 
 doDelete ()
 
 doFlushCaches ()
 
 doGetAbandonedCount ()
 
 doGetAcquiredCount ()
 
 doGetDelayedCount ()
 
 doGetSiblingQueueSizes (array $types)
 
 doGetSiblingQueuesWithJobs (array $types)
 
 doGetSize ()
 
 doIsEmpty ()
 
 doIsRootJobOldDuplicate (Job $job)
 
 doPop ()
 
 doWaitForBackups ()
 
 getCrossPartitionSum ( $type, $method)
 
 logException (Exception $e)
 
 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...
 
 throwErrorIfAllPartitionsDown ( $down)
 Throw an error if no partitions available. More...
 
 tryJobInsertions (array $jobs, HashRing &$partitionRing, $flags)
 
- Protected Member Functions inherited from JobQueue
 assertNotReadOnly ()
 
 getRootJobCacheKey ( $signature)
 
 isRootJobOldDuplicate (Job $job)
 Check if the "root" job of a given job has been superseded by a newer one. More...
 

Protected Attributes

int $maxPartitionsTry
 Maximum number of partitions to try. More...
 
JobQueue[] $partitionQueues = []
 (partition name => JobQueue) reverse sorted by weight More...
 
HashRing $partitionRing
 
- Protected Attributes inherited from JobQueue
JobQueueAggregator $aggr
 
int $claimTTL
 Time to live in seconds. More...
 
BagOStuff $dupCache
 
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...
 
string $type
 Job type. More...
 
string $wiki
 Wiki ID. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from JobQueue
static factory (array $params)
 Get a job queue object of the specified type. More...
 
static incrStats ( $key, $type, $delta=1)
 Call wfIncrStats() for the queue overall and for the queue type. More...
 
- Public Attributes inherited from JobQueue
const QOS_ATOMIC = 1
 
const ROOTJOB_TTL = 2419200
 

Detailed Description

Class to handle enqueueing and running of background jobs for federated queues.

This class allows for queues to be partitioned into smaller queues. A partition is defined by the configuration for a JobQueue instance. For example, one can set $wgJobTypeConf['refreshLinks'] to point to a JobQueueFederated instance, which itself would consist of three JobQueueRedis instances, each using their own redis server. This would allow for the jobs to be split (evenly or based on weights) across multiple servers if a single server becomes impractical or expensive. Different JobQueue classes can be mixed.

The basic queue configuration (e.g. "order", "claimTTL") of a federated queue is inherited by the partition queues. Additional configuration defines what section each wiki is in, what partition queues each section uses (and their weight), and the JobQueue configuration for each partition. Some sections might only need a single queue partition, like the sections for groups of small wikis.

If used for performance, then $wgMainCacheType should be set to memcached/redis. Note that "fifo" cannot be used for the ordering, since the data is distributed. One can still use "timestamp" instead, as in "roughly timestamp ordered". Also, queue classes used by this should ignore down servers (with TTL) to avoid slowness.

Since
1.22

Definition at line 48 of file JobQueueFederated.php.

Constructor & Destructor Documentation

◆ __construct()

JobQueueFederated::__construct ( array  $params)
protected
Parameters
array$paramsPossible keys:
  • sectionsByWiki : A map of wiki IDs to section names. Wikis will default to using the section "default".
  • partitionsBySection : Map of section names to maps of (partition name => weight). A section called 'default' must be defined if not all wikis have explicitly defined sections.
  • configByPartition : Map of queue partition names to configuration arrays. These configuration arrays are passed to JobQueue::factory(). The options set here are overridden by those passed to this the federated queue itself (e.g. 'order' and 'claimTTL').
  • maxPartitionsTry : Maximum number of times to attempt job insertion using different partition queues. This improves availability during failure, at the cost of added latency and somewhat less reliable job de-duplication mechanisms.
Exceptions
MWException

Reimplemented from JobQueue.

Definition at line 74 of file JobQueueFederated.php.

References $params, $section, JobQueue\$wiki, as, and JobQueue\factory().

Member Function Documentation

◆ doAck()

JobQueueFederated::doAck ( Job  $job)
protected
See also
JobQueue::ack()
Parameters
Job$job

Reimplemented from JobQueue.

Definition at line 303 of file JobQueueFederated.php.

References $job.

◆ doBatchPush()

JobQueueFederated::doBatchPush ( array  $jobs,
  $flags 
)
protected
See also
JobQueue::batchPush()
Parameters
IJobSpecification[]$jobs
int$flags

Reimplemented from JobQueue.

Definition at line 177 of file JobQueueFederated.php.

References $e, $partitionRing, captcha-old\count, HashRing\getLiveLocationWeights(), and tryJobInsertions().

◆ doDeduplicateRootJob()

JobQueueFederated::doDeduplicateRootJob ( IJobSpecification  $job)
protected
See also
JobQueue::deduplicateRootJob()
Parameters
IJobSpecification$job
Exceptions
MWException
Returns
bool

Reimplemented from JobQueue.

Definition at line 326 of file JobQueueFederated.php.

References $e, and $job.

◆ doDelete()

JobQueueFederated::doDelete ( )
protected
See also
JobQueue::delete()
Exceptions
MWException

Reimplemented from JobQueue.

Definition at line 341 of file JobQueueFederated.php.

References $e, $queue, as, logException(), and throwErrorIfAllPartitionsDown().

◆ doFlushCaches()

JobQueueFederated::doFlushCaches ( )
protected
See also
JobQueue::flushCaches()
Returns
void

Reimplemented from JobQueue.

Definition at line 370 of file JobQueueFederated.php.

References $queue, and as.

◆ doGetAbandonedCount()

JobQueueFederated::doGetAbandonedCount ( )
protected
See also
JobQueue::getAbandonedCount()
Returns
int

Reimplemented from JobQueue.

Definition at line 152 of file JobQueueFederated.php.

References getCrossPartitionSum().

◆ doGetAcquiredCount()

JobQueueFederated::doGetAcquiredCount ( )
protected
See also
JobQueue::getAcquiredCount()
Returns
int

Reimplemented from JobQueue.

Definition at line 144 of file JobQueueFederated.php.

References getCrossPartitionSum().

◆ doGetDelayedCount()

JobQueueFederated::doGetDelayedCount ( )
protected
See also
JobQueue::getDelayedCount()
Returns
int

Reimplemented from JobQueue.

Definition at line 148 of file JobQueueFederated.php.

References getCrossPartitionSum().

◆ doGetSiblingQueueSizes()

JobQueueFederated::doGetSiblingQueueSizes ( array  $types)
protected
See also
JobQueue::getSiblingQueuesSize()
Parameters
array$typesList of queues types
Returns
array|null (list of queue types) or null if unsupported

Reimplemented from JobQueue.

Definition at line 452 of file JobQueueFederated.php.

References $e, $queue, JobQueue\$type, as, logException(), and throwErrorIfAllPartitionsDown().

◆ doGetSiblingQueuesWithJobs()

JobQueueFederated::doGetSiblingQueuesWithJobs ( array  $types)
protected
See also
JobQueue::getSiblingQueuesWithJobs()
Parameters
array$typesList of queues types
Returns
array|null (list of queue types) or null if unsupported

Reimplemented from JobQueue.

Definition at line 426 of file JobQueueFederated.php.

References $e, $queue, as, captcha-old\count, logException(), and throwErrorIfAllPartitionsDown().

◆ doGetSize()

JobQueueFederated::doGetSize ( )
protected
See also
JobQueue::getSize()
Returns
int

Reimplemented from JobQueue.

Definition at line 140 of file JobQueueFederated.php.

References getCrossPartitionSum().

◆ doIsEmpty()

JobQueueFederated::doIsEmpty ( )
protected
See also
JobQueue::isEmpty()
Returns
bool

Reimplemented from JobQueue.

Definition at line 124 of file JobQueueFederated.php.

References $e, $queue, as, logException(), and throwErrorIfAllPartitionsDown().

◆ doIsRootJobOldDuplicate()

JobQueueFederated::doIsRootJobOldDuplicate ( Job  $job)
protected
See also
JobQueue::isRootJobOldDuplicate()
Parameters
Job$job
Returns
bool

Reimplemented from JobQueue.

Definition at line 311 of file JobQueueFederated.php.

References $e, and $job.

◆ doPop()

JobQueueFederated::doPop ( )
protected
See also
JobQueue::pop()
Returns
Job|bool

Reimplemented from JobQueue.

Definition at line 271 of file JobQueueFederated.php.

References $e, $job, $queue, captcha-old\count, logException(), ArrayUtils\pickRandom(), and throwErrorIfAllPartitionsDown().

◆ doWaitForBackups()

JobQueueFederated::doWaitForBackups ( )
protected
See also
JobQueue::waitForBackups()
Returns
void

Reimplemented from JobQueue.

Definition at line 356 of file JobQueueFederated.php.

References $e, $queue, as, logException(), and throwErrorIfAllPartitionsDown().

◆ getAllAbandonedJobs()

JobQueueFederated::getAllAbandonedJobs ( )

Get an iterator to traverse over all abandoned jobs in this queue.

Returns
Iterator
Exceptions
JobQueueError
Since
1.25

Reimplemented from JobQueue.

Definition at line 410 of file JobQueueFederated.php.

References $queue, and as.

◆ getAllAcquiredJobs()

JobQueueFederated::getAllAcquiredJobs ( )

Get an iterator to traverse over all claimed jobs in this queue.

Callers should be quick to iterator over it or few results will be returned due to jobs being acknowledged and deleted

Returns
Iterator
Exceptions
JobQueueError
Since
1.26

Reimplemented from JobQueue.

Definition at line 399 of file JobQueueFederated.php.

References $queue, and as.

◆ getAllDelayedJobs()

JobQueueFederated::getAllDelayedJobs ( )

Get an iterator to traverse over all delayed jobs in this queue.

Note: results may be stale if the queue is concurrently modified.

Returns
Iterator
Exceptions
JobQueueError
Since
1.22

Reimplemented from JobQueue.

Definition at line 388 of file JobQueueFederated.php.

References $queue, and as.

◆ getAllQueuedJobs()

JobQueueFederated::getAllQueuedJobs ( )

Get an iterator to traverse over all available jobs in this queue.

This does not include jobs that are currently acquired or delayed. Note: results may be stale if the queue is concurrently modified.

Returns
Iterator
Exceptions
JobQueueError

Reimplemented from JobQueue.

Definition at line 377 of file JobQueueFederated.php.

References $queue, and as.

◆ getCoalesceLocationInternal()

JobQueueFederated::getCoalesceLocationInternal ( )

Do not use this function outside of JobQueue/JobQueueGroup.

Returns
string
Since
1.22

Reimplemented from JobQueue.

Definition at line 421 of file JobQueueFederated.php.

References serialize().

◆ getCrossPartitionSum()

JobQueueFederated::getCrossPartitionSum (   $type,
  $method 
)
protected
Parameters
string$type
string$method
Returns
int

Definition at line 161 of file JobQueueFederated.php.

References $e, $queue, as, logException(), and throwErrorIfAllPartitionsDown().

Referenced by doGetAbandonedCount(), doGetAcquiredCount(), doGetDelayedCount(), and doGetSize().

◆ logException()

JobQueueFederated::logException ( Exception  $e)
protected

◆ optimalOrder()

JobQueueFederated::optimalOrder ( )
protected

Get the default queue order to use if configuration does not specify one.

Returns
string One of (random, timestamp, fifo, undefined)

Reimplemented from JobQueue.

Definition at line 110 of file JobQueueFederated.php.

◆ supportedOrders()

JobQueueFederated::supportedOrders ( )
protected

Get the allowed queue orders for configuration validation.

Returns
array Subset of (random, timestamp, fifo, undefined)

Reimplemented from JobQueue.

Definition at line 105 of file JobQueueFederated.php.

◆ supportsDelayedJobs()

JobQueueFederated::supportsDelayedJobs ( )
protected

Find out if delayed jobs are supported for configuration validation.

Returns
bool Whether delayed jobs are supported

Reimplemented from JobQueue.

Definition at line 114 of file JobQueueFederated.php.

References $queue, and as.

◆ throwErrorIfAllPartitionsDown()

JobQueueFederated::throwErrorIfAllPartitionsDown (   $down)
protected

Throw an error if no partitions available.

Parameters
int$downThe number of up partitions down
Returns
void
Exceptions
JobQueueError

Definition at line 487 of file JobQueueFederated.php.

References captcha-old\count.

Referenced by doDelete(), doGetSiblingQueueSizes(), doGetSiblingQueuesWithJobs(), doIsEmpty(), doPop(), doWaitForBackups(), and getCrossPartitionSum().

◆ tryJobInsertions()

JobQueueFederated::tryJobInsertions ( array  $jobs,
HashRing $partitionRing,
  $flags 
)
protected
Parameters
array$jobs
HashRing&$partitionRing
int$flags
Exceptions
JobQueueError
Returns
array List of Job object that could not be inserted

Definition at line 205 of file JobQueueFederated.php.

References $e, $job, $partitionRing, $queue, as, HashRing\ejectFromLiveRing(), HashRing\getLiveLocation(), HashRing\getLiveLocationWeights(), logException(), ArrayUtils\pickRandom(), and serialize().

Referenced by doBatchPush().

Member Data Documentation

◆ $maxPartitionsTry

int JobQueueFederated::$maxPartitionsTry
protected

Maximum number of partitions to try.

Definition at line 55 of file JobQueueFederated.php.

◆ $partitionQueues

JobQueue [] JobQueueFederated::$partitionQueues = []
protected

(partition name => JobQueue) reverse sorted by weight

Definition at line 52 of file JobQueueFederated.php.

◆ $partitionRing

HashRing JobQueueFederated::$partitionRing
protected

Definition at line 50 of file JobQueueFederated.php.

Referenced by doBatchPush(), and tryJobInsertions().


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