Index: trunk/phase3/includes/job/JobQueue.php |
— | — | @@ -68,6 +68,7 @@ |
69 | 69 | /* Ensure we "own" this row */ |
70 | 70 | $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ ); |
71 | 71 | $affected = $dbw->affectedRows(); |
| 72 | + $dbw->commit(); |
72 | 73 | |
73 | 74 | if ( $affected == 0 ) { |
74 | 75 | wfProfileOut( __METHOD__ ); |
— | — | @@ -81,14 +82,8 @@ |
82 | 83 | $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), |
83 | 84 | $row->job_id ); |
84 | 85 | |
85 | | - $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); |
86 | | - $affected = $dbw->affectedRows(); |
87 | | - $dbw->commit(); |
| 86 | + $job->removeDuplicates(); |
88 | 87 | |
89 | | - if ( $affected ) { |
90 | | - wfIncrStats( 'job-dup-delete', $affected ); |
91 | | - } |
92 | | - |
93 | 88 | wfProfileOut( __METHOD__ ); |
94 | 89 | return $job; |
95 | 90 | } |
— | — | @@ -176,16 +171,8 @@ |
177 | 172 | $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); |
178 | 173 | |
179 | 174 | // 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(); |
185 | 176 | |
186 | | - if ( $affected ) { |
187 | | - wfIncrStats( 'job-dup-delete', $affected ); |
188 | | - } |
189 | | - |
190 | 177 | wfProfileOut( __METHOD__ ); |
191 | 178 | return $job; |
192 | 179 | } |
— | — | @@ -308,6 +295,27 @@ |
309 | 296 | ); |
310 | 297 | } |
311 | 298 | |
| 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 | + |
312 | 320 | function toString() { |
313 | 321 | $paramString = ''; |
314 | 322 | if ( $this->params ) { |