rdbms: consolidate LBFactory code for running callbacks
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 4 May 2018 22:33:34 +0000 (15:33 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 4 May 2018 23:14:00 +0000 (16:14 -0700)
This makes sure rollbackMasterChanges() has the same looping logic
for consistency.

Also clarify some code comments.

Change-Id: Id34ba8ff7377c9f3842e2db675c8050a6e68407e

includes/libs/rdbms/lbfactory/LBFactory.php
includes/libs/rdbms/loadbalancer/ILoadBalancer.php

index ccaebd3..fbc413e 100644 (file)
@@ -254,6 +254,29 @@ abstract class LBFactory implements ILBFactory {
                $this->logIfMultiDbTransaction();
                // Actually perform the commit on all master DB connections and revert DBO_TRX
                $this->forEachLBCallMethod( 'commitMasterChanges', [ $fname ] );
+               // Run all post-commit callbacks in a separate step
+               $e = $this->executePostTransactionCallbacks();
+               $this->trxRoundStage = self::ROUND_CURSORY;
+               // Throw any last post-commit callback error
+               if ( $e instanceof Exception ) {
+                       throw $e;
+               }
+       }
+
+       final public function rollbackMasterChanges( $fname = __METHOD__ ) {
+               $this->trxRoundStage = self::ROUND_ROLLING_BACK;
+               $this->trxRoundId = false;
+               // Actually perform the rollback on all master DB connections and revert DBO_TRX
+               $this->forEachLBCallMethod( 'rollbackMasterChanges', [ $fname ] );
+               // Run all post-commit callbacks in a separate step
+               $this->executePostTransactionCallbacks();
+               $this->trxRoundStage = self::ROUND_CURSORY;
+       }
+
+       /**
+        * @return Exception|null
+        */
+       private function executePostTransactionCallbacks() {
                // Run all post-commit callbacks until new ones stop getting added
                $e = null; // first callback exception
                do {
@@ -267,20 +290,8 @@ abstract class LBFactory implements ILBFactory {
                        $ex = $lb->runMasterTransactionListenerCallbacks();
                        $e = $e ?: $ex;
                } );
-               $this->trxRoundStage = self::ROUND_CURSORY;
-               // Throw any last post-commit callback error
-               if ( $e instanceof Exception ) {
-                       throw $e;
-               }
-       }
 
-       final public function rollbackMasterChanges( $fname = __METHOD__ ) {
-               $this->trxRoundStage = self::ROUND_ROLLING_BACK;
-               $this->trxRoundId = false;
-               $this->forEachLBCallMethod( 'rollbackMasterChanges', [ $fname ] );
-               $this->forEachLBCallMethod( 'runMasterTransactionIdleCallbacks' );
-               $this->forEachLBCallMethod( 'runMasterTransactionListenerCallbacks' );
-               $this->trxRoundStage = self::ROUND_CURSORY;
+               return $e;
        }
 
        public function hasTransactionRound() {
index dd257e5..e69ec26 100644 (file)
@@ -416,7 +416,7 @@ interface ILoadBalancer {
        public function commitMasterChanges( $fname = __METHOD__ );
 
        /**
-        * Consume and run all pending post-COMMIT/ROLLBACK callbacks
+        * Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions
         *
         * @return Exception|null The first exception or null if there were none
         */