[JobQueue] In addition to flushing any transaction, be sure to avoid new ones
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 15 May 2013 01:52:33 +0000 (18:52 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 15 May 2013 04:16:01 +0000 (04:16 +0000)
* This probably only matters when jobs are not run via CLI scripts.

Change-Id: Ie04c8baac218f5df770388e17096dcb4f2eb9cba

includes/job/JobQueueDB.php

index 6f4f6d9..55872d1 100644 (file)
@@ -270,6 +270,11 @@ class JobQueueDB extends JobQueue {
 
                list( $dbw, $scope ) = $this->getMasterDB();
                $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
+               $autoTrx = $dbw->getFlag( DBO_TRX ); // get current setting
+               $dbw->clearFlag( DBO_TRX ); // make each query its own transaction
+               $scopedReset = new ScopedCallback( function() use ( $dbw, $autoTrx ) {
+                       $dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore old setting
+               } );
 
                $uuid = wfRandomString( 32 ); // pop attempt
                $job = false; // job popped off
@@ -457,6 +462,11 @@ class JobQueueDB extends JobQueue {
 
                list( $dbw, $scope ) = $this->getMasterDB();
                $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
+               $autoTrx = $dbw->getFlag( DBO_TRX ); // get current setting
+               $dbw->clearFlag( DBO_TRX ); // make each query its own transaction
+               $scopedReset = new ScopedCallback( function() use ( $dbw, $autoTrx ) {
+                       $dbw->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore old setting
+               } );
 
                // Delete a row with a single DELETE without holding row locks over RTTs...
                $dbw->delete( 'job',