Fix flush-like commit in DeferredUpdates.
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 9 Oct 2012 13:34:47 +0000 (15:34 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 9 Oct 2012 13:34:47 +0000 (15:34 +0200)
In the presence of DBO_TRX, commit() may be used like a "flush".
Added a flag to trigger this mode to commit() and changed DeferredUpdates
to used the flush mode.

Change-Id: I529117618194a2669535f3c5c0fed07588597299

includes/DeferredUpdates.php
includes/db/Database.php
includes/db/LoadBalancer.php

index b4989a6..716e65c 100644 (file)
@@ -92,7 +92,7 @@ class DeferredUpdates {
                                $update->doUpdate();
 
                                if ( $doCommit && $dbw->trxLevel() ) {
-                                       $dbw->commit( __METHOD__ );
+                                       $dbw->commit( __METHOD__, 'flush' );
                                }
                        } catch ( MWException $e ) {
                                // We don't want exceptions thrown during deferred updates to
index d703134..a942afe 100644 (file)
@@ -758,7 +758,7 @@ abstract class DatabaseBase implements DatabaseType {
                                                " performing implicit commit before closing connection!" );
                                }
 
-                               $this->commit( __METHOD__, true );
+                               $this->commit( __METHOD__, 'flush' );
                        }
 
                        $ret = $this->closeConnection();
@@ -2980,11 +2980,13 @@ abstract class DatabaseBase implements DatabaseType {
         * Nesting of transactions is not supported.
         *
         * @param $fname string
-        * @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.
+        * @param $flush String Flush flag, set to 'flush' to disable warnings about explicitly committing implicit
+        *        transactions, or calling commit when no transaction is in progress.
+        *        This will silently break any ongoing explicit transaction. Only set the flush flag if you are sure
+        *        that it is safe to ignore these warnings in your context.
         */
-       final public function commit( $fname = 'DatabaseBase::commit', $suppressWarnings = false ) {
-               if ( !$suppressWarnings ) {
+       final public function commit( $fname = 'DatabaseBase::commit', $flush = '' ) {
+               if ( $flush != 'flush' ) {
                        if ( !$this->mTrxLevel ) {
                                wfWarn( "$fname: No transaction to commit, something got out of sync!" );
                        } elseif( $this->mTrxAutomatic ) {
index cac7046..46d24fc 100644 (file)
@@ -908,7 +908,7 @@ class LoadBalancer {
                        foreach ( $conns2 as $conns3 ) {
                                foreach ( $conns3 as $conn ) {
                                        if ( $conn->trxLevel() ) {
-                                               $conn->commit( __METHOD__, true );
+                                               $conn->commit( __METHOD__, 'flush' );
                                        }
                                }
                        }
@@ -927,7 +927,7 @@ class LoadBalancer {
                        }
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->doneWrites() ) {
-                                       $conn->commit( __METHOD__, true );
+                                       $conn->commit( __METHOD__, 'flush' );
                                }
                        }
                }