Silenice trx warnings from LoadBalancer.
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 9 Oct 2012 10:26:47 +0000 (12:26 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 9 Oct 2012 10:30:54 +0000 (12:30 +0200)
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
includes/db/LoadBalancer.php

index 465f25d..d703134 100644 (file)
@@ -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 );
index e66923f..cac7046 100644 (file)
@@ -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 );
                                }
                        }
                }