From 5f598463490312750b71c13ef4b86f12a3ce7517 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Wed, 26 Sep 2012 10:29:44 +0000 Subject: [PATCH] Begin transactions explicitely in Job class. This reverts commit dfbf524d3561e3fc54a9a072fda173435acc2e14 which was "Removed unmatched commits in Job class". The original change was reverted n the light of the recent discussion about the DBO_TRX flag and the intended use and bahavior of begin and commit. See http://www.gossamer-threads.com/lists/wiki/wikitech/300087 for Tim's explanation of DBO_TRX. This change now implements a new, alternative solution to the original problem of unmatched calls to commit: The Job class originally relied on implicitely started transactions. Introducing explicit calls to begin() avoids warnings while running tests, and causes transaxctiosn to be used also in cli (maintenance) mode. Change-Id: I6ecb8faad06449331a79b81860fe64624d3694d4 --- includes/job/Job.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/job/Job.php b/includes/job/Job.php index 45f057062c..b47acc4ae7 100644 --- a/includes/job/Job.php +++ b/includes/job/Job.php @@ -151,16 +151,21 @@ abstract class Job { // Try to delete it from the master $dbw = wfGetDB( DB_MASTER ); + $dbw->begin( __METHOD__ ); $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); $affected = $dbw->affectedRows(); + $dbw->commit( __METHOD__ ); if ( !$affected ) { + $dbw->begin( __METHOD__ ); + // Failed, someone else beat us to it // Try getting a random row $row = $dbw->selectRow( 'job', array( 'minjob' => 'MIN(job_id)', 'maxjob' => 'MAX(job_id)' ), '1=1', __METHOD__ ); if ( $row === false || is_null( $row->minjob ) || is_null( $row->maxjob ) ) { // No jobs to get + $dbw->rollback( __METHOD__ ); wfProfileOut( __METHOD__ ); return false; } @@ -170,12 +175,14 @@ abstract class Job { if ( $row === false ) { // Random job gone before we got the chance to select it // Give up + $dbw->rollback( __METHOD__ ); wfProfileOut( __METHOD__ ); return false; } // Delete the random row $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); $affected = $dbw->affectedRows(); + $dbw->commit( __METHOD__ ); if ( !$affected ) { // Random job gone before we exclusively deleted it -- 2.20.1