Add sanity check to getScopedLockAndFlush() for pending writes
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 18 Aug 2016 06:50:21 +0000 (23:50 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 18 Aug 2016 06:52:20 +0000 (23:52 -0700)
Also made a few related exception message more uniform.

Change-Id: I4491f16493b3d9f8ab8fad45fc6373e0d7f7d67b

includes/db/Database.php

index be0399d..933bea6 100644 (file)
@@ -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;
                }