From: Aaron Schulz Date: Thu, 18 Aug 2016 06:50:21 +0000 (-0700) Subject: Add sanity check to getScopedLockAndFlush() for pending writes X-Git-Tag: 1.31.0-rc.0~6006^2 X-Git-Url: http://git.cyclocoop.org//%22%22._DIR_PLUGIN_FULLCALENDAR.%22prive/themes/spip/images/event_edit.png/%22?a=commitdiff_plain;h=257d0e3efbb77a31fd4d7acf4c4addb869520067;p=lhc%2Fweb%2Fwiklou.git Add sanity check to getScopedLockAndFlush() for pending writes Also made a few related exception message more uniform. Change-Id: I4491f16493b3d9f8ab8fad45fc6373e0d7f7d67b --- diff --git a/includes/db/Database.php b/includes/db/Database.php index be0399d62f..933bea60a9 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2673,7 +2673,7 @@ abstract class DatabaseBase implements IDatabase { if ( $this->mTrxLevel ) { if ( $this->mTrxAtomicLevels ) { $levels = implode( ', ', $this->mTrxAtomicLevels ); - $msg = "Got explicit BEGIN from $fname while atomic section(s) $levels are open."; + $msg = "$fname: Got explicit BEGIN while atomic section(s) $levels are open."; throw new DBUnexpectedError( $this, $msg ); } elseif ( !$this->mTrxAutomatic ) { $msg = "$fname: Explicit transaction already active (from {$this->mTrxFname})."; @@ -2727,7 +2727,7 @@ abstract class DatabaseBase implements IDatabase { $levels = implode( ', ', $this->mTrxAtomicLevels ); throw new DBUnexpectedError( $this, - "Got COMMIT while atomic sections $levels are still open." + "$fname: Got COMMIT while atomic sections $levels are still open." ); } @@ -3286,6 +3286,14 @@ abstract class DatabaseBase implements IDatabase { } public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) { + if ( $this->writesOrCallbacksPending() ) { + // This only flushes transactions to clear snapshots, not to write data + throw new DBUnexpectedError( + $this, + "$fname: Cannot COMMIT to clear snapshot because writes are pending." + ); + } + if ( !$this->lock( $lockKey, $fname, $timeout ) ) { return null; }