r83645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83644‎ | r83645 | r83646 >
Date:11:39, 10 March 2011
Author:tstarling
Status:ok
Tags:
Comment:
Fix duplicate removal. Was completely broken, with a "job_id IS NULL" condition in the delete query. Added a COMMIT to pop_type().
Modified paths:
  • /trunk/phase3/includes/job/JobQueue.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/job/JobQueue.php
@@ -68,6 +68,7 @@
6969 /* Ensure we "own" this row */
7070 $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
7171 $affected = $dbw->affectedRows();
 72+ $dbw->commit();
7273
7374 if ( $affected == 0 ) {
7475 wfProfileOut( __METHOD__ );
@@ -81,14 +82,8 @@
8283 $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ),
8384 $row->job_id );
8485
85 - $dbw->delete( 'job', $job->insertFields(), __METHOD__ );
86 - $affected = $dbw->affectedRows();
87 - $dbw->commit();
 86+ $job->removeDuplicates();
8887
89 - if ( $affected ) {
90 - wfIncrStats( 'job-dup-delete', $affected );
91 - }
92 -
9388 wfProfileOut( __METHOD__ );
9489 return $job;
9590 }
@@ -176,16 +171,8 @@
177172 $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id );
178173
179174 // Remove any duplicates it may have later in the queue
180 - // Deadlock prone section
181 - $dbw->begin();
182 - $dbw->delete( 'job', $job->insertFields(), __METHOD__ );
183 - $affected = $dbw->affectedRows();
184 - $dbw->commit();
 175+ $job->removeDuplicates();
185176
186 - if ( $affected ) {
187 - wfIncrStats( 'job-dup-delete', $affected );
188 - }
189 -
190177 wfProfileOut( __METHOD__ );
191178 return $job;
192179 }
@@ -308,6 +295,27 @@
309296 );
310297 }
311298
 299+ /**
 300+ * Remove jobs in the job queue which are duplicates of this job.
 301+ * This is deadlock-prone and so starts its own transaction.
 302+ */
 303+ function removeDuplicates() {
 304+ if ( !$this->removeDuplicates ) {
 305+ return;
 306+ }
 307+
 308+ $fields = $this->insertFields();
 309+ unset( $fields['job_id'] );
 310+ $dbw = wfGetDB( DB_MASTER );
 311+ $dbw->begin();
 312+ $dbw->delete( 'job', $fields, __METHOD__ );
 313+ $affected = $dbw->affectedRows();
 314+ $dbw->commit();
 315+ if ( $affected ) {
 316+ wfIncrStats( 'job-dup-delete', $affected );
 317+ }
 318+ }
 319+
312320 function toString() {
313321 $paramString = '';
314322 if ( $this->params ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r83646MFT r83645: job queue duplicate removal fixtstarling11:40, 10 March 2011

Status & tagging log