Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/309918

Change subject: Make PurgeJobUtils avoid creating DB replication lag
......................................................................

Make PurgeJobUtils avoid creating DB replication lag

Large affected rows counts were being reported in DBPerformance logs.

Change-Id: Ia5504aa4fbd27473771c65688f0b9e78e3a5caae
---
M includes/jobqueue/utils/PurgeJobUtils.php
1 file changed, 19 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/18/309918/1

diff --git a/includes/jobqueue/utils/PurgeJobUtils.php 
b/includes/jobqueue/utils/PurgeJobUtils.php
index 329bc23..5c545ed 100644
--- a/includes/jobqueue/utils/PurgeJobUtils.php
+++ b/includes/jobqueue/utils/PurgeJobUtils.php
@@ -20,6 +20,8 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
+
 class PurgeJobUtils {
        /**
         * Invalidate the cache of a list of pages from a single namespace.
@@ -35,6 +37,8 @@
                }
 
                $dbw->onTransactionPreCommitOrIdle( function() use ( $dbw, 
$namespace, $dbkeys ) {
+                       $services = MediaWikiServices::getInstance();
+                       $lbFactory = $services->getDBLoadBalancerFactory();
                        // Determine which pages need to be updated.
                        // This is necessary to prevent the job queue from 
smashing the DB with
                        // large numbers of concurrent invalidations of the 
same page.
@@ -50,22 +54,24 @@
                                __METHOD__
                        );
 
-                       if ( $ids === [] ) {
+                       if ( !$ids ) {
                                return;
                        }
 
-                       // Do the update.
-                       // We still need the page_touched condition, in case 
the row has changed since
-                       // the non-locking select above.
-                       $dbw->update(
-                               'page',
-                               [ 'page_touched' => $now ],
-                               [
-                                       'page_id' => $ids,
-                                       'page_touched < ' . $dbw->addQuotes( 
$now )
-                               ],
-                               __METHOD__
-                       );
+                       $batchSize = $services->getMainConfig()->get( 
'UpdateRowsPerQuery' );
+                       $ticket = $lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
+                       foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) 
{
+                               $dbw->update(
+                                       'page',
+                                       [ 'page_touched' => $now ],
+                                       [
+                                               'page_id' => $idBatch,
+                                               'page_touched < ' . 
$dbw->addQuotes( $now ) // handle races
+                                       ],
+                                       __METHOD__
+                               );
+                               $lbFactory->commitAndWaitForReplication( 
__METHOD__, $ticket );
+                       }
                } );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/309918
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5504aa4fbd27473771c65688f0b9e78e3a5caae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to