From: jenkins-bot Date: Wed, 17 Aug 2016 23:01:12 +0000 (+0000) Subject: Merge "Make doAtomicSection() return the callback result" X-Git-Tag: 1.31.0-rc.0~6013 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=550de33b97d1fe45c915420bcc4b35a21a1a010c;p=lhc%2Fweb%2Fwiklou.git Merge "Make doAtomicSection() return the callback result" --- 550de33b97d1fe45c915420bcc4b35a21a1a010c diff --cc includes/db/Database.php index d492def475,2041aca9bb..940c3f7ac6 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@@ -2664,28 -2664,47 +2664,30 @@@ abstract class DatabaseBase implements throw $e; } $this->endAtomic( $fname ); + + return $res; } - final public function begin( $fname = __METHOD__ ) { - if ( $this->mTrxLevel ) { // implicit commit + final public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT ) { + // Protect against mismatched atomic section, transaction nesting, and snapshot loss + if ( $this->mTrxLevel ) { if ( $this->mTrxAtomicLevels ) { - // If the current transaction was an automatic atomic one, then we definitely have - // a problem. Same if there is any unclosed atomic level. $levels = implode( ', ', $this->mTrxAtomicLevels ); - throw new DBUnexpectedError( - $this, - "Got explicit BEGIN from $fname while atomic section(s) $levels are open." - ); + $msg = "Got explicit BEGIN from $fname while atomic section(s) $levels are open."; + throw new DBUnexpectedError( $this, $msg ); } elseif ( !$this->mTrxAutomatic ) { - // We want to warn about inadvertently nested begin/commit pairs, but not about - // auto-committing implicit transactions that were started by query() via DBO_TRX - throw new DBUnexpectedError( - $this, - "$fname: Transaction already in progress (from {$this->mTrxFname}), " . - " performing implicit commit!" - ); - } elseif ( $this->mTrxDoneWrites ) { - // The transaction was automatic and has done write operations - throw new DBUnexpectedError( - $this, - "$fname: Automatic transaction with writes in progress" . - " (from {$this->mTrxFname}), performing implicit commit!\n" - ); - } - - $this->runOnTransactionPreCommitCallbacks(); - $writeTime = $this->pendingWriteQueryDuration(); - $this->doCommit( $fname ); - if ( $this->mTrxDoneWrites ) { - $this->mDoneWrites = microtime( true ); - $this->getTransactionProfiler()->transactionWritingOut( - $this->mServer, $this->mDBname, $this->mTrxShortId, $writeTime ); + $msg = "$fname: Explicit transaction already active (from {$this->mTrxFname})."; + throw new DBUnexpectedError( $this, $msg ); + } else { + // @TODO: make this an exception at some point + $msg = "$fname: Implicit transaction already active (from {$this->mTrxFname})."; + wfLogDBError( $msg ); + return; // join the main transaction set } - - $this->runOnTransactionIdleCallbacks( self::TRIGGER_COMMIT ); + } elseif ( $this->getFlag( DBO_TRX ) && $mode !== self::TRANSACTION_INTERNAL ) { + // @TODO: make this an exception at some point + wfLogDBError( "$fname: Implicit transaction expected (DBO_TRX set)." ); + return; // let any writes be in the main transaction } // Avoid fatals if close() was called