From: Daniel Kinzler Date: Wed, 26 Sep 2012 10:29:44 +0000 (+0000) Subject: Begin transactions explicitely in Job class. X-Git-Tag: 1.31.0-rc.0~22269^2 X-Git-Url: http://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=5f598463490312750b71c13ef4b86f12a3ce7517;p=lhc%2Fweb%2Fwiklou.git 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 --- 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