From cca0a7e135bae9cae611a911d500071e9cc253e1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 27 Dec 2015 15:41:14 -0800 Subject: [PATCH] Move MaxUserDBWriteDuration logic to LBFactory Change-Id: If7231af24f10ae29b7137f147abb60a351c9127f --- includes/MediaWiki.php | 19 +++++-------------- includes/db/loadbalancer/LBFactory.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 6342d713d8..8385a0670d 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -551,21 +551,12 @@ class MediaWiki { $config = $context->getConfig(); $factory = wfGetLBFactory(); - // Check if any transaction was too big - $limit = $config->get( 'MaxUserDBWriteDuration' ); - $factory->forEachLB( function ( LoadBalancer $lb ) use ( $limit ) { - $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $limit ) { - $time = $db->pendingWriteQueryDuration(); - if ( $limit > 0 && $time > $limit ) { - throw new DBTransactionError( - $db, - wfMessage( 'transaction-duration-limit-exceeded', $time, $limit )->text() - ); - } - } ); - } ); // Commit all changes - $factory->commitMasterChanges( __METHOD__ ); + $factory->commitMasterChanges( + __METHOD__, + // Abort if any transaction was too big + array( 'maxWriteDuration' => $config->get( 'MaxUserDBWriteDuration' ) ) + ); // Record ChronologyProtector positions $factory->shutdown(); wfDebug( __METHOD__ . ': all transactions committed' ); diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index 25fdea97d3..606f4f4b78 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -228,9 +228,24 @@ abstract class LBFactory { /** * Commit changes on all master connections * @param string $fname Caller name + * @param array $options Options map: + * - maxWriteDuration: abort if more than this much time was spent in write queries */ - public function commitMasterChanges( $fname = __METHOD__ ) { + public function commitMasterChanges( $fname = __METHOD__, array $options = array() ) { + $limit = isset( $options['maxWriteDuration'] ) ? $options['maxWriteDuration'] : 0; + $this->logMultiDbTransaction(); + $this->forEachLB( function ( LoadBalancer $lb ) use ( $limit ) { + $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $limit ) { + $time = $db->pendingWriteQueryDuration(); + if ( $limit > 0 && $time > $limit ) { + throw new DBTransactionError( + $db, + wfMessage( 'transaction-duration-limit-exceeded', $time, $limit )->text() + ); + } + } ); + } ); $start = microtime( true ); $this->forEachLBCallMethod( 'commitMasterChanges', array( $fname ) ); -- 2.20.1