53 $this->cluster = isset(
$params[
'cluster'] ) ?
$params[
'cluster'] :
false;
58 return [
'random',
'timestamp',
'fifo' ];
72 $found =
$dbr->selectField(
73 'job',
'1', [
'job_cmd' => $this->
type,
'job_token' =>
'' ], __METHOD__
89 $size = $this->
cache->get( $key );
90 if ( is_int( $size ) ) {
96 $size = (int)
$dbr->selectField(
'job',
'COUNT(*)',
97 [
'job_cmd' => $this->type,
'job_token' =>
'' ],
103 $this->
cache->set( $key, $size, self::CACHE_TTL_SHORT );
113 if ( $this->claimTTL <= 0 ) {
126 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
127 [
'job_cmd' => $this->type,
"job_token != {$dbr->addQuotes( '' )}" ],
133 $this->
cache->set( $key,
$count, self::CACHE_TTL_SHORT );
144 if ( $this->claimTTL <= 0 ) {
157 $count = (int)
$dbr->selectField(
'job',
'COUNT(*)',
159 'job_cmd' => $this->type,
160 "job_token != {$dbr->addQuotes( '' )}",
161 "job_attempts >= " .
$dbr->addQuotes( $this->maxTries )
169 $this->
cache->set( $key,
$count, self::CACHE_TTL_SHORT );
184 $method = __METHOD__;
185 $dbw->onTransactionIdle(
186 function ()
use ( $dbw, $jobs,
$flags, $method ) {
203 if ( !count( $jobs ) ) {
209 foreach ( $jobs
as $job ) {
211 if (
$job->ignoreDuplicates() ) {
212 $rowSet[$row[
'job_sha1']] = $row;
218 if (
$flags & self::QOS_ATOMIC ) {
223 if ( count( $rowSet ) ) {
227 'job_sha1' => array_keys( $rowSet ),
232 foreach (
$res as $row ) {
233 wfDebug(
"Job with hash '{$row->job_sha1}' is a duplicate.\n" );
234 unset( $rowSet[$row->job_sha1] );
238 $rows = array_merge( $rowList, array_values( $rowSet ) );
240 foreach ( array_chunk( $rows, 50 )
as $rowBatch ) {
241 $dbw->
insert(
'job', $rowBatch, $method );
245 count( $rowSet ) + count( $rowList ) - count( $rows )
248 if (
$flags & self::QOS_ATOMIC ) {
253 if (
$flags & self::QOS_ATOMIC ) {
267 $dbw->commit( __METHOD__,
'flush' );
268 $autoTrx = $dbw->getFlag(
DBO_TRX );
271 $dbw->setFlag( $autoTrx ?
DBO_TRX : 0 );
278 if ( in_array( $this->
order, [
'fifo',
'timestamp' ] ) ) {
281 $rand = mt_rand( 0, self::MAX_JOB_RANDOM );
282 $gte = (bool)mt_rand( 0, 1 );
293 self::extractBlob( $row->job_params ), $row->job_id );
294 $job->metadata[
'id'] = $row->job_id;
295 $job->metadata[
'timestamp'] = $row->job_timestamp;
299 if ( !
$job || mt_rand( 0, 9 ) == 0 ) {
325 $invertedDirection =
false;
334 $ineq = $gte ?
'>=' :
'<=';
335 $dir = $gte ?
'ASC' :
'DESC';
336 $row = $dbw->selectRow(
'job', self::selectFields(),
338 'job_cmd' => $this->
type,
340 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ],
342 [
'ORDER BY' =>
"job_random {$dir}" ]
344 if ( !$row && !$invertedDirection ) {
346 $invertedDirection =
true;
353 $row = $dbw->selectRow(
'job', self::selectFields(),
355 'job_cmd' => $this->
type,
359 [
'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) ]
371 'job_token' => $uuid,
372 'job_token_timestamp' => $dbw->timestamp(),
373 'job_attempts = job_attempts+1' ],
374 [
'job_cmd' => $this->type,
'job_id' => $row->job_id,
'job_token' =>
'' ],
379 if ( !$dbw->affectedRows() ) {
401 if ( $dbw->getType() ===
'mysql' ) {
406 $dbw->query(
"UPDATE {$dbw->tableName( 'job' )} " .
408 "job_token = {$dbw->addQuotes( $uuid ) }, " .
409 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
410 "job_attempts = job_attempts+1 " .
412 "job_cmd = {$dbw->addQuotes( $this->type )} " .
413 "AND job_token = {$dbw->addQuotes( '' )} " .
414 ") ORDER BY job_id ASC LIMIT 1",
422 'job_token' => $uuid,
423 'job_token_timestamp' => $dbw->timestamp(),
424 'job_attempts = job_attempts+1' ],
426 $dbw->selectSQLText(
'job',
'job_id',
427 [
'job_cmd' => $this->type,
'job_token' =>
'' ],
429 [
'ORDER BY' =>
'job_id ASC',
'LIMIT' => 1 ] ) .
436 if ( $dbw->affectedRows() ) {
437 $row = $dbw->selectRow(
'job', self::selectFields(),
438 [
'job_cmd' => $this->
type,
'job_token' => $uuid ], __METHOD__
441 wfDebug(
"Row deleted as duplicate by another process.\n" );
457 if ( !isset(
$job->metadata[
'id'] ) ) {
458 throw new MWException(
"Job of type '{$job->getType()}' has no ID." );
463 $dbw->commit( __METHOD__,
'flush' );
464 $autoTrx = $dbw->getFlag(
DBO_TRX );
467 $dbw->setFlag( $autoTrx ?
DBO_TRX : 0 );
472 [
'job_cmd' => $this->
type,
'job_id' => $job->metadata[
'id'] ], __METHOD__ );
488 if ( !isset(
$params[
'rootJobSignature'] ) ) {
489 throw new MWException(
"Cannot register root job; missing 'rootJobSignature'." );
490 } elseif ( !isset(
$params[
'rootJobTimestamp'] ) ) {
491 throw new MWException(
"Cannot register root job; missing 'rootJobTimestamp'." );
521 $dbw->delete(
'job', [
'job_cmd' => $this->
type ] );
541 foreach ( [
'size',
'acquiredcount' ]
as $type ) {
570 $dbr->select(
'job', self::selectFields(), $conds ),
575 strlen( $row->job_params ) ?
unserialize( $row->job_params ) : []
577 $job->metadata[
'id'] = $row->job_id;
578 $job->metadata[
'timestamp'] = $row->job_timestamp;
589 return $this->cluster
590 ?
"DBCluster:{$this->cluster}:{$this->wiki}"
591 :
"LBFactory:{$this->wiki}";
600 $res =
$dbr->select(
'job',
'DISTINCT job_cmd',
601 [
'job_cmd' => $types ], __METHOD__ );
604 foreach (
$res as $row ) {
605 $types[] = $row->job_cmd;
613 $res =
$dbr->select(
'job', [
'job_cmd',
'COUNT(*) AS count' ],
614 [
'job_cmd' => $types ], __METHOD__, [
'GROUP BY' =>
'job_cmd' ] );
617 foreach (
$res as $row ) {
618 $sizes[$row->job_cmd] = (int)$row->count;
635 if ( !$dbw->lock(
"jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
640 if ( $this->claimTTL > 0 ) {
641 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
645 $res = $dbw->select(
'job',
'job_id',
647 'job_cmd' => $this->
type,
648 "job_token != {$dbw->addQuotes( '' )}",
649 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}",
650 "job_attempts < {$dbw->addQuotes( $this->maxTries )}" ],
656 }, iterator_to_array(
$res )
658 if ( count( $ids ) ) {
665 'job_token_timestamp' => $dbw->timestamp( $now ) ],
670 $affected = $dbw->affectedRows();
673 $this->aggr->notifyQueueNonEmpty( $this->
wiki, $this->
type );
678 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
681 "job_token != {$dbw->addQuotes( '' )}",
682 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}"
684 if ( $this->claimTTL > 0 ) {
685 $conds[] =
"job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
689 $res = $dbw->select(
'job',
'job_id', $conds, __METHOD__ );
693 }, iterator_to_array(
$res )
695 if ( count( $ids ) ) {
696 $dbw->delete(
'job', [
'job_id' => $ids ], __METHOD__ );
697 $affected = $dbw->affectedRows();
702 $dbw->unlock(
"jobqueue-recycle-{$this->type}", __METHOD__ );
720 'job_namespace' =>
$job->getTitle()->getNamespace(),
721 'job_title' =>
$job->getTitle()->getDBkey(),
724 'job_id' => $dbw->nextSequenceValue(
'job_job_id_seq' ),
725 'job_timestamp' => $dbw->timestamp(),
726 'job_sha1' => Wikimedia\base_convert(
730 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
762 protected function getDB( $index ) {
763 $lb = ( $this->cluster !==
false )
767 return $lb->getConnectionRef( $index, [], $this->
wiki );
776 $cluster = is_string( $this->cluster ) ? $this->cluster :
'main';
798 if ( (
string)
$blob !==
'' ) {
829 'job_token_timestamp',
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
unserialize( $serialized)
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the slaves to catch up to the master position.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
wfGetLB( $wiki=false)
Get a load balancer object.
wfSplitWikiID( $wiki)
Split a wiki ID into DB name and table prefix.
wfGetLBFactory()
Get the load balancer factory object.
wfForeignMemcKey( $db, $prefix)
Make a cache key for a foreign DB.
Database error base class.
Class to handle job queues stored in the DB.
claimOldest( $uuid)
Reserve a row with a single UPDATE without holding row locks over RTTs...
supportedOrders()
Get the allowed queue orders for configuration validation.
insertFields(IJobSpecification $job)
doGetSiblingQueueSizes(array $types)
bool string $cluster
Name of an external DB cluster.
__construct(array $params)
Additional parameters include:
doBatchPush(array $jobs, $flags)
throwDBException(DBError $e)
static makeBlob( $params)
claimRandom( $uuid, $rand, $gte)
Reserve a row with a single UPDATE without holding row locks over RTTs...
doGetSiblingQueuesWithJobs(array $types)
recycleAndDeleteStaleJobs()
Recycle or destroy any jobs that have been claimed for too long.
doBatchPushInternal(IDatabase $dbw, array $jobs, $flags, $method)
This function should not be called outside of JobQueueDB.
optimalOrder()
Get the default queue order to use if configuration does not specify one.
getCoalesceLocationInternal()
Do not use this function outside of JobQueue/JobQueueGroup.
static extractBlob( $blob)
doDeduplicateRootJob(IJobSpecification $job)
static selectFields()
Return the list of job fields that should be selected.
getJobIterator(array $conds)
Class to handle enqueueing and running of background jobs.
static incrStats( $key, $type, $delta=1)
Call wfIncrStats() for the queue overall and for the queue type.
getRootJobCacheKey( $signature)
Class to both describe a background job and handle jobs.
static factory( $command, Title $title, $params=[])
Create the appropriate object to handle a specific job.
Convenience class for generating iterators from iterators.
static getMainWANInstance()
Get the main WAN cache object.
Class for asserting that a callback happens when an dummy object leaves scope.
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Multi-datacenter aware caching interface.
get( $key, &$curTTL=null, array $checkKeys=[])
Fetch the value of a key from cache.
set( $key, $value, $ttl=0, array $opts=[])
Set the value of a key in cache.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
when a variable name is used in a function
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any order
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace and then decline to actually register it file or subcat img or subcat $title
it s the revision text itself In either if gzip is the revision text is gzipped $flags
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
if(count( $args)==0) $dir
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Basic database interface for live and lazy-loaded DB handles.
insert( $table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
startAtomic( $fname=__METHOD__)
Begin an atomic section of statements.
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
rollback( $fname=__METHOD__, $flush='')
Rollback a transaction previously started using begin().
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
Job queue task description interface.
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
you have access to all of the normal MediaWiki so you can get a DB use the cache
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
if(count( $args)< 1) $job