Added support for enqueueable DataUpdates
* Updates can now declare themselves as having enqueueUpdate() as an alternative to doUpdate(). This lets more expensive or slave lag producing updates use the job queue if desired. * Added a $mode flag to DataUpdate::runUpdates() to prefer pushing jobs over calling doUpdate(). * Made page deletions defer deletion updates when possible. Bug: T95501 Change-Id: Ic6f50f92768089ba0fbc223b8d178f5a91512959
This commit is contained in:
parent
21206c8fbe
commit
25a44aa3e4
3 changed files with 45 additions and 14 deletions
|
|
@ -384,6 +384,7 @@ $wgAutoloadLocalClasses = array(
|
||||||
'EnhancedChangesList' => __DIR__ . '/includes/changes/EnhancedChangesList.php',
|
'EnhancedChangesList' => __DIR__ . '/includes/changes/EnhancedChangesList.php',
|
||||||
'EnotifNotifyJob' => __DIR__ . '/includes/jobqueue/jobs/EnotifNotifyJob.php',
|
'EnotifNotifyJob' => __DIR__ . '/includes/jobqueue/jobs/EnotifNotifyJob.php',
|
||||||
'EnqueueJob' => __DIR__ . '/includes/jobqueue/jobs/EnqueueJob.php',
|
'EnqueueJob' => __DIR__ . '/includes/jobqueue/jobs/EnqueueJob.php',
|
||||||
|
'EnqueueableDataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
|
||||||
'EraseArchivedFile' => __DIR__ . '/maintenance/eraseArchivedFile.php',
|
'EraseArchivedFile' => __DIR__ . '/maintenance/eraseArchivedFile.php',
|
||||||
'ErrorPageError' => __DIR__ . '/includes/exception/ErrorPageError.php',
|
'ErrorPageError' => __DIR__ . '/includes/exception/ErrorPageError.php',
|
||||||
'EventRelayer' => __DIR__ . '/includes/libs/eventrelayer/EventRelayer.php',
|
'EventRelayer' => __DIR__ . '/includes/libs/eventrelayer/EventRelayer.php',
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,8 @@
|
||||||
* subclasses can override the beginTransaction() and commitTransaction() methods.
|
* subclasses can override the beginTransaction() and commitTransaction() methods.
|
||||||
*/
|
*/
|
||||||
abstract class DataUpdate implements DeferrableUpdate {
|
abstract class DataUpdate implements DeferrableUpdate {
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
# noop
|
//noop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,22 +70,23 @@ abstract class DataUpdate implements DeferrableUpdate {
|
||||||
* This allows for limited transactional logic across multiple backends for storing
|
* This allows for limited transactional logic across multiple backends for storing
|
||||||
* secondary data.
|
* secondary data.
|
||||||
*
|
*
|
||||||
* @param array $updates A list of DataUpdate instances
|
* @param DataUpdate[] $updates A list of DataUpdate instances
|
||||||
|
* @param string $mode Use "enqueue" to use the job queue when possible [Default: run]
|
||||||
* @throws Exception|null
|
* @throws Exception|null
|
||||||
*/
|
*/
|
||||||
public static function runUpdates( $updates ) {
|
public static function runUpdates( array $updates, $mode = 'run' ) {
|
||||||
if ( empty( $updates ) ) {
|
if ( $mode === 'enqueue' ) {
|
||||||
return; # nothing to do
|
// When possible, push updates as jobs instead of calling doUpdate()
|
||||||
|
$updates = self::enqueueUpdates( $updates );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !count( $updates ) ) {
|
||||||
|
return; // nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
$open_transactions = array();
|
$open_transactions = array();
|
||||||
$exception = null;
|
$exception = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var $update DataUpdate
|
|
||||||
* @var $trans DataUpdate
|
|
||||||
*/
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// begin transactions
|
// begin transactions
|
||||||
foreach ( $updates as $update ) {
|
foreach ( $updates as $update ) {
|
||||||
|
|
@ -122,4 +120,36 @@ abstract class DataUpdate implements DeferrableUpdate {
|
||||||
throw $exception; // rethrow after cleanup
|
throw $exception; // rethrow after cleanup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue jobs for every DataUpdate that support enqueueUpdate()
|
||||||
|
* and return the remaining DataUpdate objects (those that do not)
|
||||||
|
*
|
||||||
|
* @param DataUpdate[] $updates A list of DataUpdate instances
|
||||||
|
* @return DataUpdate[]
|
||||||
|
* @since 1.26
|
||||||
|
*/
|
||||||
|
protected static function enqueueUpdates( array $updates ) {
|
||||||
|
$remaining = array();
|
||||||
|
|
||||||
|
foreach ( $updates as $update ) {
|
||||||
|
if ( $update instanceof EnqueueableDataUpdate ) {
|
||||||
|
$update->enqueueUpdate();
|
||||||
|
} else {
|
||||||
|
$remaining[] = $update;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $remaining;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.26
|
||||||
|
*/
|
||||||
|
interface EnqueueableDataUpdate {
|
||||||
|
/**
|
||||||
|
* Push the update into the job queue
|
||||||
|
*/
|
||||||
|
public function enqueueUpdate();
|
||||||
}
|
}
|
||||||
|
|
@ -2916,7 +2916,7 @@ class WikiPage implements Page, IDBAccessObject {
|
||||||
|
|
||||||
// remove secondary indexes, etc
|
// remove secondary indexes, etc
|
||||||
$updates = $this->getDeletionUpdates( $content );
|
$updates = $this->getDeletionUpdates( $content );
|
||||||
DataUpdate::runUpdates( $updates );
|
DataUpdate::runUpdates( $updates, 'enqueue' );
|
||||||
|
|
||||||
// Reparse any pages transcluding this page
|
// Reparse any pages transcluding this page
|
||||||
LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
|
LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue