Merge "Add sanity check to getScopedLockAndFlush() for pending writes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 18 Aug 2016 18:31:54 +0000 (18:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 18 Aug 2016 18:31:54 +0000 (18:31 +0000)
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;
                }