BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
DeferredUpdates Class Reference
Collaboration diagram for DeferredUpdates:

Static Public Member Functions

static addUpdate (DeferrableUpdate $update, $stage=self::POSTSEND)
 
static addCallableUpdate ($callable, $stage=self::POSTSEND, $dbw=null)
 
static doUpdates ($mode= 'run', $stage=self::ALL)
 
static setImmediateMode ($value)
 
static tryOpportunisticExecute ($mode= 'run')
 
static pendingUpdatesCount ()
 
static getPendingUpdates ($stage=self::ALL)
 
static clearPendingUpdates ()
 

Public Attributes

const ALL = 0
 
const PRESEND = 1
 
const POSTSEND = 2
 
const BIG_QUEUE_SIZE = 100
 

Detailed Description

Class for managing the deferred updates

In web request mode, deferred updates can be run at the end of the request, either before or after the HTTP response has been sent. In either case, they run after the DB commit step. If an update runs after the response is sent, it will not block clients. If sent before, it will run synchronously. These two modes are defined via PRESEND and POSTSEND constants, the latter being the default for addUpdate() and addCallableUpdate().

Updates that work through this system will be more likely to complete by the time the client makes their next request after this one than with the JobQueue system.

In CLI mode, deferred updates will run:

  • a) During DeferredUpdates::addUpdate if no LBFactory DB handles have writes pending
  • b) On commit of an LBFactory DB handle if no other such handles have writes pending
  • c) During an LBFactory::waitForReplication call if no LBFactory DBs have writes pending
  • d) When the queue is large and an LBFactory DB handle commits (EnqueueableDataUpdate only)
  • e) At the completion of Maintenance::execute()
See Also
Maintenance::setLBFactoryTriggers

When updates are deferred, they go into one two FIFO "top-queues" (one for pre-send and one for post-send). Updates enqueued during doUpdate() of a "top" update go into the "sub-queue" for that update. After that method finishes, the sub-queue is run until drained. This continues for each top-queue job until the entire top queue is drained. This happens for the pre-send top-queue, and later on, the post-send top-queue, in execute().

Since
1.19

Member Function Documentation

static DeferredUpdates::addCallableUpdate (   $callable,
  $stage = self::POSTSEND,
  $dbw = null 
)
static

Add a callable update. In a lot of cases, we just need a callback/closure, defining a new DeferrableUpdate object is not necessary

See Also
MWCallableUpdate::__construct()
Parameters
callable$callable
int$stageDeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)
IDatabase|IDatabase[]|null$dbw Abort if this DB is rolled back optional
static DeferredUpdates::addUpdate ( DeferrableUpdate  $update,
  $stage = self::POSTSEND 
)
static

Add an update to the deferred list to be run later by execute()

In CLI mode, callback magic will also be used to run updates when safe

Parameters
DeferrableUpdate$updateSome object that implements doUpdate()
int$stageDeferredUpdates constant (PRESEND or POSTSEND) (since 1.27)
static DeferredUpdates::clearPendingUpdates ( )
static

Clear all pending updates without performing them. Generally, you don't want or need to call this. Unit tests need it though.

static DeferredUpdates::doUpdates (   $mode = 'run',
  $stage = self::ALL 
)
static

Do any deferred updates and clear the list

Parameters
string$modeUse "enqueue" to use the job queue when possible [Default: "run"]
int$stageDeferredUpdates constant (PRESEND, POSTSEND, or ALL) (since 1.27)
static DeferredUpdates::getPendingUpdates (   $stage = self::ALL)
static
Parameters
int$stageDeferredUpdates constant (PRESEND, POSTSEND, or ALL)
Returns
DeferrableUpdate[]
Since
1.29
static DeferredUpdates::pendingUpdatesCount ( )
static
Returns
int Number of enqueued updates
Since
1.28
static DeferredUpdates::setImmediateMode (   $value)
static
Parameters
bool$valueWhether to just immediately run updates in addUpdate()
Since
1.28
Deprecated:
1.29 Causes issues in Web-executed jobs - see T165714 and T100085.
static DeferredUpdates::tryOpportunisticExecute (   $mode = 'run')
static

Run all deferred updates immediately if there are no DB writes active

If there are many deferred updates pending, $mode is 'run', and there are still busy LBFactory database handles, then any EnqueueableDataUpdate tasks might be enqueued as jobs to be executed later.

Parameters
string$modeUse "enqueue" to use the job queue when possible
Returns
bool Whether updates were allowed to run
Since
1.28

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