r84228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84227‎ | r84228 | r84229 >
Date:07:06, 18 March 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Fixed wfIncrStats calls from r83617 (I assume this wants the # of jobs added)
* Follow up r83494, r74737: allow for proper db rollback of a user renames (addresses code comments added in r74737)
Modified paths:
  • /trunk/extensions/Renameuser/Renameuser_body.php (modified) (history)
  • /trunk/phase3/includes/job/JobQueue.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/job/JobQueue.php
@@ -221,12 +221,12 @@
222222 * @param $jobs array of Job objects
223223 */
224224 static function batchInsert( $jobs ) {
225 - if( !count( $jobs ) ) {
 225+ if ( !count( $jobs ) ) {
226226 return;
227227 }
228228 $dbw = wfGetDB( DB_MASTER );
229229 $rows = array();
230 - foreach( $jobs as $job ) {
 230+ foreach ( $jobs as $job ) {
231231 $rows[] = $job->insertFields();
232232 if ( count( $rows ) >= 50 ) {
233233 # Do a small transaction to avoid slave lag
@@ -236,14 +236,42 @@
237237 $rows = array();
238238 }
239239 }
240 - if ( $rows ) {
241 - wfIncrStats( 'job-insert', count( $rows ) );
 240+ if ( $rows ) { // last chunk
242241 $dbw->begin();
243242 $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' );
244243 $dbw->commit();
245244 }
 245+ wfIncrStats( 'job-insert', count( $jobs ) );
246246 }
247247
 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+
248276 /*-------------------------------------------------------------------------
249277 * Non-static functions
250278 *------------------------------------------------------------------------*/
Index: trunk/extensions/Renameuser/Renameuser_body.php
@@ -521,13 +521,12 @@
522522 }
523523 $dbw->freeResult( $res );
524524 }
525 - // @FIXME: batchInsert() commits per 50 jobs,
526 - // which sucks if the DB is rolled-back...
 525+
527526 if ( count( $jobs ) > 0 ) {
528 - Job::batchInsert( $jobs );
 527+ Job::safeBatchInsert( $jobs ); // don't commit yet
529528 }
530529
531 - // Commit the transaction (though batchInsert() above commits)
 530+ // Commit the transaction
532531 $dbw->commit();
533532
534533 // Delete from memcached again to make sure

Follow-up revisions

RevisionCommit summaryAuthorDate
r844201.17wmf1: MFT r76372, r76377, r83586, r83587, r83817, r83876, r83979, r84118,...catrope21:04, 20 March 2011
r85033MFT more extension revs: r82601, r82654, r82698, r82755, r82756, r82759, r829...demon18:49, 30 March 2011
r85434MFT: r83885, r83891, r83897, r83902, r83903, r83934, r83965, r83979, r83988, ...demon13:38, 5 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74737* Removed DIY job insertion batching, batchInsert() already handles this (50 ...aaron20:50, 13 October 2010
r83494Remove the limit on edit count, it is unnecessary now that we have job queue ...tstarling01:12, 8 March 2011
r83617* Add a $count argument to wfIncrStats(), to allow it to increase the count b...tstarling00:00, 10 March 2011

Comments

#Comment by Catrope (talk | contribs)   19:49, 20 March 2011

Surely this can be refactored to be nicer, e.g. with a boolean $commit parameter to batchInsert() ?

Looks good otherwise.

#Comment by Aaron Schulz (talk | contribs)   19:52, 20 March 2011

I really considered that at first (but using a string not a bool), but the function would be littered with if ( $commit == "nocommit" ) all over the place and it seemed better to just make a separate function. The duplication is minuscule.

#Comment by 😂 (talk | contribs)   18:50, 30 March 2011

Still needs phase3 merge

Status & tagging log