From: Aaron Schulz Date: Sun, 27 Dec 2015 23:41:14 +0000 (-0800) Subject: Move MaxUserDBWriteDuration logic to LBFactory X-Git-Tag: 1.31.0-rc.0~8162^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=cca0a7e135bae9cae611a911d500071e9cc253e1;p=lhc%2Fweb%2Fwiklou.git Move MaxUserDBWriteDuration logic to LBFactory Change-Id: If7231af24f10ae29b7137f147abb60a351c9127f --- 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 ) );