Merge "Made DB rollback() method properly bail out if no trx is active"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 26 Jun 2014 03:51:26 +0000 (03:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Jun 2014 03:51:26 +0000 (03:51 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
@@@ -268,13 -268,6 +268,13 @@@ abstract class DatabaseBase implements 
         */
        protected $mTrxLevel = 0;
  
 +      /**
 +       * Either a short hexidecimal string if a transaction is active or ""
 +       *
 +       * @var string
 +       */
 +      protected $mTrxShortId = '';
 +
        /**
         * Remembers the function name given for starting the most recent transaction via begin().
         * Used to provide additional context for error reporting.
                # Keep track of whether the transaction has write queries pending
                if ( $this->mTrxLevel && !$this->mTrxDoneWrites && $this->isWriteQuery( $sql ) ) {
                        $this->mTrxDoneWrites = true;
 -                      $id = spl_object_hash( $this );
 -                      Profiler::instance()->transactionWritingIn( $this->mServer, $this->mDBname, $id );
 +                      Profiler::instance()->transactionWritingIn(
 +                              $this->mServer, $this->mDBname, $this->mTrxShortId );
                }
  
                $queryProf = '';
                                $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
                                $totalProf = 'DatabaseBase::query';
                        }
 +                      # Include query transaction state
 +                      $queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : "";
 +
 +                      $trx = $this->mTrxLevel ? 'TRX=yes' : 'TRX=no';
                        wfProfileIn( $totalProf );
                        wfProfileIn( $queryProf );
                }
                        $this->runOnTransactionPreCommitCallbacks();
                        $this->doCommit( $fname );
                        if ( $this->mTrxDoneWrites ) {
 -                              $id = spl_object_hash( $this );
 -                              Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
 +                              Profiler::instance()->transactionWritingOut(
 +                                      $this->mServer, $this->mDBname, $this->mTrxShortId );
                        }
                        $this->runOnTransactionIdleCallbacks();
                }
                $this->mTrxAtomicLevels = new SplStack;
                $this->mTrxIdleCallbacks = array();
                $this->mTrxPreCommitCallbacks = array();
 +              $this->mTrxShortId = wfRandomString( 12 );
        }
  
        /**
                $this->runOnTransactionPreCommitCallbacks();
                $this->doCommit( $fname );
                if ( $this->mTrxDoneWrites ) {
 -                      $id = spl_object_hash( $this );
 -                      Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
 +                      Profiler::instance()->transactionWritingOut(
 +                              $this->mServer, $this->mDBname, $this->mTrxShortId );
                }
                $this->runOnTransactionIdleCallbacks();
        }
                if ( $flush !== 'flush' ) {
                        if ( !$this->mTrxLevel ) {
                                wfWarn( "$fname: No transaction to rollback, something got out of sync!" );
+                               return; // nothing to do
                        } elseif ( $this->mTrxAutomatic ) {
                                wfWarn( "$fname: Explicit rollback of implicit transaction. Something may be out of sync!" );
                        }
                $this->mTrxPreCommitCallbacks = array(); // cancel
                $this->mTrxAtomicLevels = new SplStack;
                if ( $this->mTrxDoneWrites ) {
 -                      $id = spl_object_hash( $this );
 -                      Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
 +                      Profiler::instance()->transactionWritingOut(
 +                              $this->mServer, $this->mDBname, $this->mTrxShortId );
                }
        }