AndyRussG has uploaded a new change for review.

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

Change subject: Account for DB lag when refreshing cached ChoiceData
......................................................................

Account for DB lag when refreshing cached ChoiceData

This fixes an apparent race condition in which ObjectCache cached ChoiceData
is invalidated following a change in campaign or banner settings, then a
client request causes a cache miss and the cache is re-set using a laggy
DB slave, causing the caching and serving of old ChoiceData. See
https://github.com/wikimedia/mediawiki/blob/ce504f2d19b7450c75f0a332089a720e2ea402ce/
includes/libs/objectcache/WANObjectCache.php#L665

Bug: T144393
Change-Id: Id4e46b653554d39ac5721c4327774ccfce63b734
---
M includes/ChoiceDataProvider.php
1 file changed, 12 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/26/308126/1

diff --git a/includes/ChoiceDataProvider.php b/includes/ChoiceDataProvider.php
index 0d765fb..0f7dd91 100644
--- a/includes/ChoiceDataProvider.php
+++ b/includes/ChoiceDataProvider.php
@@ -42,8 +42,17 @@
                $choices = $cache->getWithSetCallback(
                        $dataKey,
                        self::CACHE_TTL,
-                       function () use ( $project, $language ) {
-                               return self::fetchChoices( $project, $language 
);
+                       function ( $oldValue, &$ttl, array &$setOpts )
+                               use ( $project, $language ) {
+
+                               $dbr = CNDatabase::getDb( DB_SLAVE );
+
+                               // Account for slave lag to prevent a race 
condition when
+                               // campaigns are updated, the cache is 
invalidated, and
+                               // a client queries a yet-unsynced slave DBs
+                               $setOpts += Database::getCacheSetOptions( $dbr 
);
+
+                               return self::fetchChoices( $project, $language, 
$dbr );
                        },
                        [
                                'checkKeys' => [ $checkKey ],
@@ -59,11 +68,10 @@
                } );
        }
 
-       private static function fetchChoices( $project, $language ) {
+       private static function fetchChoices( $project, $language, $dbr ) {
                // For speed, we'll do our own queries instead of using methods 
in
                // Campaign and Banner.
 
-               $dbr = CNDatabase::getDb( DB_SLAVE );
                $cache = ObjectCache::getMainWANInstance();
 
                // Set up conditions

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4e46b653554d39ac5721c4327774ccfce63b734
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <andrew.green...@gmail.com>

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

Reply via email to