From 257d0e3efbb77a31fd4d7acf4c4addb869520067 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 17 Aug 2016 23:50:21 -0700 Subject: [PATCH] Add sanity check to getScopedLockAndFlush() for pending writes Also made a few related exception message more uniform. Change-Id: I4491f16493b3d9f8ab8fad45fc6373e0d7f7d67b --- includes/db/Database.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; } -- 2.20.1