r83646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83645‎ | r83646 | r83647 >
Date:11:40, 10 March 2011
Author:tstarling
Status:ok
Tags:
Comment:
MFT r83645: job queue duplicate removal fix
Modified paths:
  • /branches/wmf/1.17wmf1/includes/job/JobQueue.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/job/JobQueue.php
@@ -63,6 +63,7 @@
6464 /* Ensure we "own" this row */
6565 $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
6666 $affected = $dbw->affectedRows();
 67+ $dbw->commit();
6768
6869 if ( $affected == 0 ) {
6970 wfProfileOut( __METHOD__ );
@@ -76,14 +77,8 @@
7778 $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ),
7879 $row->job_id );
7980
80 - $dbw->delete( 'job', $job->insertFields(), __METHOD__ );
81 - $affected = $dbw->affectedRows();
82 - $dbw->commit();
 81+ $job->removeDuplicates();
8382
84 - if ( $affected ) {
85 - wfIncrStats( 'job-dup-delete', $affected );
86 - }
87 -
8883 wfProfileOut( __METHOD__ );
8984 return $job;
9085 }
@@ -171,16 +166,8 @@
172167 $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id );
173168
174169 // Remove any duplicates it may have later in the queue
175 - // Deadlock prone section
176 - $dbw->begin();
177 - $dbw->delete( 'job', $job->insertFields(), __METHOD__ );
178 - $affected = $dbw->affectedRows();
179 - $dbw->commit();
 170+ $job->removeDuplicates();
180171
181 - if ( $affected ) {
182 - wfIncrStats( 'job-dup-delete', $affected );
183 - }
184 -
185172 wfProfileOut( __METHOD__ );
186173 return $job;
187174 }
@@ -297,6 +284,27 @@
298285 );
299286 }
300287
 288+ /**
 289+ * Remove jobs in the job queue which are duplicates of this job.
 290+ * This is deadlock-prone and so starts its own transaction.
 291+ */
 292+ function removeDuplicates() {
 293+ if ( !$this->removeDuplicates ) {
 294+ return;
 295+ }
 296+
 297+ $fields = $this->insertFields();
 298+ unset( $fields['job_id'] );
 299+ $dbw = wfGetDB( DB_MASTER );
 300+ $dbw->begin();
 301+ $dbw->delete( 'job', $fields, __METHOD__ );
 302+ $affected = $dbw->affectedRows();
 303+ $dbw->commit();
 304+ if ( $affected ) {
 305+ wfIncrStats( 'job-dup-delete', $affected );
 306+ }
 307+ }
 308+
301309 function toString() {
302310 $paramString = '';
303311 if ( $this->params ) {
Property changes on: branches/wmf/1.17wmf1/includes/job/JobQueue.php
___________________________________________________________________
Modified: svn:mergeinfo
304312 Merged /trunk/phase3/includes/job/JobQueue.php:r83645

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83645Fix duplicate removal. Was completely broken, with a "job_id IS NULL" conditi...tstarling11:39, 10 March 2011

Status & tagging log