From 2e8d14593abba8658da342941a3bf282d1f4eb81 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 7 Sep 2016 08:40:39 -0700 Subject: [PATCH] Style and IDEA warning cleanups * Avoid deprecated method use in MediaWiki.php. * Move LBFactory::beginMasterChanges down a bit, next to LBFactory::commitMasterChanges. * Rename $factory => $lbFactory. * Remove redundant $conn->trxLevel() check. Change-Id: I309ff3b8e3f586f0ac40b2f3be26b161993b58d2 --- includes/MediaWiki.php | 18 ++++----- includes/db/loadbalancer/LBFactory.php | 46 +++++++++++------------ includes/db/loadbalancer/LoadBalancer.php | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 77a19691d6..52eca31c8d 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -554,9 +554,9 @@ class MediaWiki { $config = $context->getConfig(); - $factory = wfGetLBFactory(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); // Commit all changes - $factory->commitMasterChanges( + $lbFactory->commitMasterChanges( __METHOD__, // Abort if any transaction was too big [ 'maxWriteDuration' => $config->get( 'MaxUserDBWriteDuration' ) ] @@ -566,14 +566,14 @@ class MediaWiki { wfDebug( __METHOD__ . ': pre-send deferred updates completed' ); // Record ChronologyProtector positions - $factory->shutdown(); + $lbFactory->shutdown(); wfDebug( __METHOD__ . ': all transactions committed' ); // Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that handles this // POST request (e.g. the "master" data center). Also have the user briefly bypass CDN so // ChronologyProtector works for cacheable URLs. $request = $context->getRequest(); - if ( $request->wasPosted() && $factory->hasOrMadeRecentMasterChanges() ) { + if ( $request->wasPosted() && $lbFactory->hasOrMadeRecentMasterChanges() ) { $expires = time() + $config->get( 'DataCenterUpdateStickTTL' ); $options = [ 'prefix' => '' ]; $request->response()->setCookie( 'UseDC', 'master', $expires, $options ); @@ -582,7 +582,7 @@ class MediaWiki { // Avoid letting a few seconds of replica DB lag cause a month of stale data. This logic is // also intimately related to the value of $wgCdnReboundPurgeDelay. - if ( $factory->laggedReplicaUsed() ) { + if ( $lbFactory->laggedReplicaUsed() ) { $maxAge = $config->get( 'CdnMaxageLagged' ); $context->getOutput()->lowerCdnMaxage( $maxAge ); $request->response()->header( "X-Database-Lagged: true" ); @@ -763,9 +763,9 @@ class MediaWiki { * @param string $mode Use 'fast' to always skip job running */ public function restInPeace( $mode = 'fast' ) { - $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); // Assure deferred updates are not in the main transaction - $factory->commitMasterChanges( __METHOD__ ); + $lbFactory->commitMasterChanges( __METHOD__ ); // Loosen DB query expectations since the HTTP client is unblocked $trxProfiler = Profiler::instance()->getTransactionProfiler(); @@ -791,8 +791,8 @@ class MediaWiki { wfLogProfilingData(); // Commit and close up! - $factory->commitMasterChanges( __METHOD__ ); - $factory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT ); + $lbFactory->commitMasterChanges( __METHOD__ ); + $lbFactory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT ); wfDebug( "Request ended normally\n" ); } diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index fa4eb337f6..62a5286566 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -223,6 +223,29 @@ abstract class LBFactory implements DestructibleService { ); } + /** + * Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot + * + * @param string $fname Caller name + * @since 1.28 + */ + public function flushReplicaSnapshots( $fname = __METHOD__ ) { + $this->forEachLBCallMethod( 'flushReplicaSnapshots', [ $fname ] ); + } + + /** + * Commit on all connections. Done for two reasons: + * 1. To commit changes to the masters. + * 2. To release the snapshot on all connections, master and replica DB. + * @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 commitAll( $fname = __METHOD__, array $options = [] ) { + $this->commitMasterChanges( $fname, $options ); + $this->forEachLBCallMethod( 'commitAll', [ $fname ] ); + } + /** * Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) * @@ -249,29 +272,6 @@ abstract class LBFactory implements DestructibleService { $this->forEachLBCallMethod( 'beginMasterChanges', [ $fname ] ); } - /** - * Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot - * - * @param string $fname Caller name - * @since 1.28 - */ - public function flushReplicaSnapshots( $fname = __METHOD__ ) { - $this->forEachLBCallMethod( 'flushReplicaSnapshots', [ $fname ] ); - } - - /** - * Commit on all connections. Done for two reasons: - * 1. To commit changes to the masters. - * 2. To release the snapshot on all connections, master and replica DB. - * @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 commitAll( $fname = __METHOD__, array $options = [] ) { - $this->commitMasterChanges( $fname, $options ); - $this->forEachLBCallMethod( 'commitAll', [ $fname ] ); - } - /** * Commit changes on all master connections * @param string $fname Caller name diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 9ceae20f04..12dea3d3ca 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -1350,7 +1350,7 @@ class LoadBalancer { } /** @var DatabaseBase $conn */ foreach ( $conns2[$masterIndex] as $conn ) { - if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) { + if ( $conn->writesOrCallbacksPending() ) { return true; } } -- 2.20.1