Minor transaction callback cleanups
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 22 Jul 2016 23:56:10 +0000 (16:56 -0700)
committerReedy <reedy@wikimedia.org>
Sun, 24 Jul 2016 18:47:34 +0000 (18:47 +0000)
* Give the flush commit() in close() a chance to handle callbacks.
  Also detect onTransactionResolution() callbacks when an error is
  thrown.
* Avoid resetting callbacks redundantly, as they already get
  cleared when they actually run.
* Fix a few doc comments.

Change-Id: I5c62262661b97a6c28ce0ab0949307dc119953ca

includes/db/Database.php

index 9b73584..bda4ccf 100644 (file)
@@ -694,9 +694,6 @@ abstract class DatabaseBase implements IDatabase {
        }
 
        public function close() {
-               if ( count( $this->mTrxIdleCallbacks ) ) { // sanity
-                       throw new MWException( "Transaction idle callbacks still pending." );
-               }
                if ( $this->mConn ) {
                        if ( $this->trxLevel() ) {
                                if ( !$this->mTrxAutomatic ) {
@@ -709,6 +706,8 @@ abstract class DatabaseBase implements IDatabase {
 
                        $closed = $this->closeConnection();
                        $this->mConn = false;
+               } elseif ( $this->mTrxIdleCallbacks || $this->mTrxEndCallbacks ) { // sanity
+                       throw new MWException( "Transaction callbacks still pending." );
                } else {
                        $closed = true;
                }
@@ -2473,7 +2472,7 @@ abstract class DatabaseBase implements IDatabase {
        }
 
        /**
-        * Actually any "on transaction idle" callbacks.
+        * Actually run and consume any "on transaction idle" callbacks.
         *
         * @param integer $trigger IDatabase::TRIGGER_* constant
         * @since 1.20
@@ -2519,7 +2518,7 @@ abstract class DatabaseBase implements IDatabase {
        }
 
        /**
-        * Actually any "on transaction pre-commit" callbacks.
+        * Actually run and consume any "on transaction pre-commit" callbacks.
         *
         * This method should not be used outside of Database/LoadBalancer
         *
@@ -2637,8 +2636,6 @@ abstract class DatabaseBase implements IDatabase {
                $this->mTrxAutomatic = false;
                $this->mTrxAutomaticAtomic = false;
                $this->mTrxAtomicLevels = [];
-               $this->mTrxIdleCallbacks = [];
-               $this->mTrxPreCommitCallbacks = [];
                $this->mTrxShortId = wfRandomString( 12 );
                $this->mTrxWriteDuration = 0.0;
                $this->mTrxWriteCallers = [];