r74737 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74736‎ | r74737 | r74738 >
Date:20:50, 13 October 2010
Author:aaron
Status:ok
Tags:
Comment:
* Removed DIY job insertion batching, batchInsert() already handles this (50 at once)
* Insert all jobs after the read queries are done to reduce the chance of half-assed renames. It's still possible within batchInsert, due to the "commit per 50 jobs" approach, but should be much less likely. Follows up on r74340.
* Added begin() statement mostly for clarity
* Eliminated silly intermediate variables
* Removed duplicate global declarations and moved others up
Modified paths:
  • /trunk/extensions/Renameuser/Renameuser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/Renameuser_body.php
@@ -425,13 +425,14 @@
426426 * Do the rename operation
427427 */
428428 function rename() {
429 - global $wgMemc, $wgAuth;
 429+ global $wgMemc, $wgAuth, $wgUpdateRowsPerJob;
430430
431431 wfProfileIn( __METHOD__ );
432432
 433+ $dbw = wfGetDB( DB_MASTER );
 434+ $dbw->begin();
433435 wfRunHooks( 'RenameUserPreRename', array( $this->uid, $this->old, $this->new ) );
434436
435 - $dbw = wfGetDB( DB_MASTER );
436437 // Rename and touch the user before re-attributing edits,
437438 // this avoids users still being logged in and making new edits while
438439 // being renamed, which leaves edits at the old name.
@@ -450,7 +451,6 @@
451452 $authUser->resetAuthToken();
452453
453454 // Delete from memcached.
454 - global $wgMemc;
455455 $wgMemc->delete( wfMemcKey( 'user', 'id', $this->uid ) );
456456
457457 // Update ipblock list if this user has a block in there.
@@ -486,6 +486,7 @@
487487 wfRestoreWarnings();
488488 }
489489
 490+ $jobs = array(); // jobs for all tables
490491 // Construct jobqueue updates...
491492 // FIXME: if a bureaucrat renames a user in error, he/she
492493 // must be careful to wait until the rename finishes before
@@ -505,11 +506,6 @@
506507 array( 'ORDER BY' => "$timestampC ASC" )
507508 );
508509
509 - global $wgUpdateRowsPerJob;
510 -
511 - $batchSize = 500; // Lets not flood the job table!
512 - $jobSize = $wgUpdateRowsPerJob; // How many rows per job?
513 -
514510 $jobParams = array();
515511 $jobParams['table'] = $table;
516512 $jobParams['column'] = $userTextC;
@@ -523,59 +519,45 @@
524520 $jobParams['maxTimestamp'] = '0';
525521 $jobParams['count'] = 0;
526522
527 - // Insert into queue!
528 - $jobRows = 0;
529 - $done = false;
530 - while ( !$done ) {
531 - $jobs = array();
532 - for ( $i = 0; $i < $batchSize; $i++ ) {
533 - $row = $dbw->fetchObject( $res );
534 - if ( !$row ) {
535 - # If there are any job rows left, add it to the queue as one job
536 - if ( $jobRows > 0 ) {
537 - $jobParams['count'] = $jobRows;
538 - $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams );
539 - $jobParams['minTimestamp'] = '0';
540 - $jobParams['maxTimestamp'] = '0';
541 - $jobParams['count'] = 0;
542 - $jobRows = 0;
543 - }
544 - $done = true;
545 - break;
546 - }
547 - # If we are adding the first item, since the ORDER BY is ASC, set
548 - # the min timestamp
549 - if ( $jobRows == 0 ) {
550 - $jobParams['minTimestamp'] = $row->$timestampC;
551 - }
552 - # Keep updating the last timestamp, so it should be correct when the last item is added.
553 - $jobParams['maxTimestamp'] = $row->$timestampC;
554 - # Update nice counter
555 - $jobRows++;
556 - # Once a job has $jobSize rows, add it to the queue
557 - if ( $jobRows >= $jobSize ) {
558 - $jobParams['count'] = $jobRows;
 523+ // Insert jobs into queue!
 524+ while ( true ) {
 525+ $row = $dbw->fetchObject( $res );
 526+ if ( !$row ) {
 527+ # If there are any job rows left, add it to the queue as one job
 528+ if ( $jobParams['count'] > 0 ) {
559529 $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams );
560 - $jobParams['minTimestamp'] = '0';
561 - $jobParams['maxTimestamp'] = '0';
562 - $jobParams['count'] = 0;
563 - $jobRows = 0;
564530 }
 531+ break;
565532 }
566 - // FIXME: this commits per 50 rows, so when this times out
567 - // (which it does) the DB will be in a half-assed state...
568 - Job::batchInsert( $jobs );
 533+ # Since the ORDER BY is ASC, set the min timestamp with first row
 534+ if ( $jobParams['count'] == 0 ) {
 535+ $jobParams['minTimestamp'] = $row->$timestampC;
 536+ }
 537+ # Keep updating the last timestamp, so it should be correct
 538+ # when the last item is added.
 539+ $jobParams['maxTimestamp'] = $row->$timestampC;
 540+ # Update row counter
 541+ $jobParams['count']++;
 542+ # Once a job has $wgUpdateRowsPerJob rows, add it to the queue
 543+ if ( $jobParams['count'] >= $wgUpdateRowsPerJob ) {
 544+ $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams );
 545+ $jobParams['minTimestamp'] = '0';
 546+ $jobParams['maxTimestamp'] = '0';
 547+ $jobParams['count'] = 0;
 548+ }
569549 }
570550 $dbw->freeResult( $res );
571551 }
 552+ // @FIXME: batchInsert() commits per 50 jobs,
 553+ // which sucks if the DB is rolled-back...
 554+ if ( count( $jobs ) > 0 ) {
 555+ Job::batchInsert( $jobs );
 556+ }
572557
573 - // Commit the transaction
574 - // FIXME: this line is misleading and nearly totally
575 - // useless if the jobqueue was used for any of the tables...
 558+ // Commit the transaction (though batchInsert() above commits)
576559 $dbw->commit();
577560
578561 // Delete from memcached again to make sure
579 - global $wgMemc;
580562 $wgMemc->delete( wfMemcKey( 'user', 'id', $this->uid ) );
581563
582564 // Clear caches and inform authentication plugins

Follow-up revisions

RevisionCommit summaryAuthorDate
r84228* Fixed wfIncrStats calls from r83617 (I assume this wants the # of jobs added)...aaron07:06, 18 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74340* Added comment about total commit() breakage...aaron09:08, 6 October 2010

Status & tagging log