Index: trunk/phase3/includes/job/JobQueue.php |
— | — | @@ -221,12 +221,12 @@ |
222 | 222 | * @param $jobs array of Job objects |
223 | 223 | */ |
224 | 224 | static function batchInsert( $jobs ) { |
225 | | - if( !count( $jobs ) ) { |
| 225 | + if ( !count( $jobs ) ) { |
226 | 226 | return; |
227 | 227 | } |
228 | 228 | $dbw = wfGetDB( DB_MASTER ); |
229 | 229 | $rows = array(); |
230 | | - foreach( $jobs as $job ) { |
| 230 | + foreach ( $jobs as $job ) { |
231 | 231 | $rows[] = $job->insertFields(); |
232 | 232 | if ( count( $rows ) >= 50 ) { |
233 | 233 | # Do a small transaction to avoid slave lag |
— | — | @@ -236,14 +236,42 @@ |
237 | 237 | $rows = array(); |
238 | 238 | } |
239 | 239 | } |
240 | | - if ( $rows ) { |
241 | | - wfIncrStats( 'job-insert', count( $rows ) ); |
| 240 | + if ( $rows ) { // last chunk |
242 | 241 | $dbw->begin(); |
243 | 242 | $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); |
244 | 243 | $dbw->commit(); |
245 | 244 | } |
| 245 | + wfIncrStats( 'job-insert', count( $jobs ) ); |
246 | 246 | } |
247 | 247 | |
| 248 | + /** |
| 249 | + * Insert a group of jobs into the queue. |
| 250 | + * |
| 251 | + * Same as batchInsert() but does not commit and can thus |
| 252 | + * be rolled-back as part of a larger transaction. However, |
| 253 | + * large batches of jobs can cause slave lag. |
| 254 | + * |
| 255 | + * @param $jobs array of Job objects |
| 256 | + */ |
| 257 | + static function safeBatchInsert( $jobs ) { |
| 258 | + if ( !count( $jobs ) ) { |
| 259 | + return; |
| 260 | + } |
| 261 | + $dbw = wfGetDB( DB_MASTER ); |
| 262 | + $rows = array(); |
| 263 | + foreach ( $jobs as $job ) { |
| 264 | + $rows[] = $job->insertFields(); |
| 265 | + if ( count( $rows ) >= 500 ) { |
| 266 | + $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); |
| 267 | + $rows = array(); |
| 268 | + } |
| 269 | + } |
| 270 | + if ( $rows ) { // last chunk |
| 271 | + $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); |
| 272 | + } |
| 273 | + wfIncrStats( 'job-insert', count( $jobs ) ); |
| 274 | + } |
| 275 | + |
248 | 276 | /*------------------------------------------------------------------------- |
249 | 277 | * Non-static functions |
250 | 278 | *------------------------------------------------------------------------*/ |
Index: trunk/extensions/Renameuser/Renameuser_body.php |
— | — | @@ -521,13 +521,12 @@ |
522 | 522 | } |
523 | 523 | $dbw->freeResult( $res ); |
524 | 524 | } |
525 | | - // @FIXME: batchInsert() commits per 50 jobs, |
526 | | - // which sucks if the DB is rolled-back... |
| 525 | + |
527 | 526 | if ( count( $jobs ) > 0 ) { |
528 | | - Job::batchInsert( $jobs ); |
| 527 | + Job::safeBatchInsert( $jobs ); // don't commit yet |
529 | 528 | } |
530 | 529 | |
531 | | - // Commit the transaction (though batchInsert() above commits) |
| 530 | + // Commit the transaction |
532 | 531 | $dbw->commit(); |
533 | 532 | |
534 | 533 | // Delete from memcached again to make sure |