From 985368cb9a1cb97c389687ab21c851c8dcfa1582 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 9 Oct 2012 12:26:47 +0200 Subject: [PATCH] Silenice trx warnings from LoadBalancer. This is a follow-up to Idbe4a903. LoadBalancer::commitMasterChanges used to cause a warning if an implicite transaction was in progress. This is now supressed. Note that warnign when an automatic transaction is committed explicitely, it does make sense to issue a warning. But that should not be done for summary commits when closing a connection, etc. Change-Id: Id68c3607f6b9d930c00422baa6658b0651f2e42e --- includes/db/Database.php | 23 ++++++++++++----------- includes/db/LoadBalancer.php | 6 ++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 465f25dd34..d703134fed 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -753,15 +753,12 @@ abstract class DatabaseBase implements DatabaseType { $this->mOpened = false; if ( $this->mConn ) { if ( $this->trxLevel() ) { - if ( $this->mTrxAutomatic ) { - // clear flag, so commit() doesn't complain about an explicit commit of an implicit transaction. - $this->mTrxAutomatic = false; - } else { + if ( !$this->mTrxAutomatic ) { wfWarn( "Transaction still in progress (from {$this->mTrxFname}), " . " performing implicit commit before closing connection!" ); } - $this->commit( __METHOD__ ); + $this->commit( __METHOD__, true ); } $ret = $this->closeConnection(); @@ -2983,12 +2980,16 @@ abstract class DatabaseBase implements DatabaseType { * Nesting of transactions is not supported. * * @param $fname string - */ - final public function commit( $fname = 'DatabaseBase::commit' ) { - if ( !$this->mTrxLevel ) { - wfWarn( "$fname: No transaction to commit, something got out of sync!" ); - } elseif( $this->mTrxAutomatic ) { - wfWarn( "$fname: Explicit commit of implicit transaction. Something may be out of sync!" ); + * @param $suppressWarnings bool Suppress any warnings about open transactions (default_ false). + * Only set this if you are absolutely sure that it is safe to ignore these warnings in your context. + */ + final public function commit( $fname = 'DatabaseBase::commit', $suppressWarnings = false ) { + if ( !$suppressWarnings ) { + if ( !$this->mTrxLevel ) { + wfWarn( "$fname: No transaction to commit, something got out of sync!" ); + } elseif( $this->mTrxAutomatic ) { + wfWarn( "$fname: Explicit commit of implicit transaction. Something may be out of sync!" ); + } } $this->doCommit( $fname ); diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index e66923fff0..cac70467fb 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -907,7 +907,9 @@ class LoadBalancer { foreach ( $this->mConns as $conns2 ) { foreach ( $conns2 as $conns3 ) { foreach ( $conns3 as $conn ) { - $conn->commit( __METHOD__ ); + if ( $conn->trxLevel() ) { + $conn->commit( __METHOD__, true ); + } } } } @@ -925,7 +927,7 @@ class LoadBalancer { } foreach ( $conns2[$masterIndex] as $conn ) { if ( $conn->trxLevel() && $conn->doneWrites() ) { - $conn->commit( __METHOD__ ); + $conn->commit( __METHOD__, true ); } } } -- 2.20.1