From dee83538c43015fc425de698d6552ec339ff7100 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 24 Aug 2015 14:31:06 -0700 Subject: [PATCH] Move job running till after deferred updates * If $wgJobRunRate is > 0, such jobs should be run *after* all of the request-specific updates and job insertions. That way, some random job fatal does not interfere with the request updates. Change-Id: I4bdb4e34404ce2d00997b545d681f3a0fb910d4f --- includes/MediaWiki.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index f488aa2485..012d20e58e 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -502,29 +502,26 @@ class MediaWiki { * This function does work that can be done *after* the * user gets the HTTP response so they don't block on it * + * This manages deferred updates, job insertion, + * final commit, and the logging of profiling data + * * @param string $mode Use 'fast' to always skip job running * @since 1.26 */ public function doPostOutputShutdown( $mode = 'normal' ) { - // Show profiling data if enabled + // Show visible profiling data if enabled (which cannot be post-send) Profiler::instance()->logDataPageOutputOnly(); $that = $this; $callback = function () use ( $that, $mode ) { try { - // Assure deferred updates are not in the main transaction - wfGetLBFactory()->commitMasterChanges(); - // Run jobs occasionally, if enabled - if ( $mode === 'normal' ) { - $that->triggerJobs(); - } - // Do deferred updates and job insertion and final commit - $that->restInPeace(); + $that->restInPeace( $mode ); } catch ( Exception $e ) { MWExceptionHandler::handleException( $e ); } }; + // Defer everything else... if ( function_exists( 'register_postsend_function' ) ) { // https://github.com/facebook/hhvm/issues/1230 register_postsend_function( $callback ); @@ -687,8 +684,12 @@ class MediaWiki { /** * Ends this task peacefully + * @param string $mode Use 'fast' to always skip job running */ - public function restInPeace() { + public function restInPeace( $mode = 'fast' ) { + // Assure deferred updates are not in the main transaction + wfGetLBFactory()->commitMasterChanges(); + // Ignore things like master queries/connections on GET requests // as long as they are in deferred updates (which catch errors). Profiler::instance()->getTransactionProfiler()->resetExpectations(); @@ -699,6 +700,12 @@ class MediaWiki { // Make sure any lazy jobs are pushed JobQueueGroup::pushLazyJobs(); + // Now that everything specific to this request is done, + // try to occasionally run jobs (if enabled) from the queues + if ( $mode === 'normal' ) { + $this->triggerJobs(); + } + // Log profiling data, e.g. in the database or UDP wfLogProfilingData(); -- 2.20.1