EBernhardson (WMF) has submitted this change and it was merged. Change subject: Adding Echo jobs to deferred update along with master wait ......................................................................
Adding Echo jobs to deferred update along with master wait This is in case job queue is picking up the job too fast when the current transaction is not completed and job queue is trying to access non-committed data When job is popped, some of the object is re-initialized from the database, this will handle the replication lag Change-Id: Ia7debb4db0103f27a3e326beb52db0f63bc7c0bc --- M controller/NotificationController.php M jobs/NotificationJob.php 2 files changed, 27 insertions(+), 3 deletions(-) Approvals: EBernhardson (WMF): Verified; Looks good to me, approved diff --git a/controller/NotificationController.php b/controller/NotificationController.php index 035d004..554f5f4 100644 --- a/controller/NotificationController.php +++ b/controller/NotificationController.php @@ -138,10 +138,27 @@ */ public static function notify( $event, $defer = true ) { if ( $defer ) { - $title = $event->getTitle() ? $event->getTitle() : Title::newMainPage(); + // defer job insertion till end of request when all primary db transactions + // have been committed + DeferredUpdates::addCallableUpdate( + function() use ( $event ) { + global $wgEchoCluster; + $params = array( 'event' => $event ); + if ( wfGetLB()->getServerCount() > 1 ) { + $params['mainDbMasterPos'] = wfGetLB()->getMasterPos(); + } + if ( $wgEchoCluster ) { + $lb = wfGetLBFactory()->getExternalLB( $wgEchoCluster ); + if ( $lb->getServerCount() > 1 ) { + $params['echoDbMasterPos'] = $lb->getMasterPos(); + } + } - $job = new EchoNotificationJob( $title, array( 'event' => $event ) ); - $job->insert(); + $title = $event->getTitle() ? $event->getTitle() : Title::newMainPage(); + $job = new EchoNotificationJob( $title, $params ); + $job->insert(); + } + ); return; } diff --git a/jobs/NotificationJob.php b/jobs/NotificationJob.php index 619b97e..13a135f 100644 --- a/jobs/NotificationJob.php +++ b/jobs/NotificationJob.php @@ -7,6 +7,13 @@ } function run() { + if ( !empty( $this->params['mainDbMasterPos'] ) ) { + wfGetLB()->waitFor( $this->params['mainDbMasterPos'] ); + } + if ( !empty( $this->params['echoDbMasterPos'] ) ) { + global $wgEchoCluster; + wfGetLBFactory()->getExternalLB( $wgEchoCluster )->waitFor( $this->params['echoDbMasterPos'] ); + } EchoNotificationController::notify( $this->event, false ); return true; } -- To view, visit https://gerrit.wikimedia.org/r/81888 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia7debb4db0103f27a3e326beb52db0f63bc7c0bc Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Bsitu <bs...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Bsitu <bs...@wikimedia.org> Gerrit-Reviewer: EBernhardson (WMF) <ebernhard...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits