From 6463cd02f73c21ee148f0f66053dbc1f97019293 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 20 Oct 2015 21:50:27 -0700 Subject: [PATCH] Improve MultiWriteBagOStuff::merge() cross-DC performance Implement merge() by getting a lock on the tier 1 cache, getting it's value, generating the new one, writing to all tiers, and then unlocking tier 1. This is done by just using the stock mergeViaLock(). This means that if tier 1 is in the same DC, the other tiers only need 1 request each, just for set(). Change-Id: I4b0c303ef3b86b63e7630032ed0b010e79706324 --- includes/objectcache/MultiWriteBagOStuff.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/includes/objectcache/MultiWriteBagOStuff.php b/includes/objectcache/MultiWriteBagOStuff.php index 50dd215146..98380d9e21 100644 --- a/includes/objectcache/MultiWriteBagOStuff.php +++ b/includes/objectcache/MultiWriteBagOStuff.php @@ -106,6 +106,13 @@ class MultiWriteBagOStuff extends BagOStuff { } protected function doGet( $key, $flags = 0 ) { + if ( ( $flags & self::READ_LATEST ) == self::READ_LATEST ) { + // If the latest write was a delete(), we do NOT want to fallback + // to the other tiers and possibly see the old value. Also, this + // is used by mergeViaLock(), which only needs to hit the primary. + return $this->caches[0]->get( $key, $flags ); + } + $misses = 0; // number backends checked $value = false; foreach ( $this->caches as $cache ) { @@ -192,17 +199,6 @@ class MultiWriteBagOStuff extends BagOStuff { return $this->caches[0]->unlock( $key ); } - /** - * @param string $key - * @param callable $callback Callback method to be executed - * @param int $exptime Either an interval in seconds or a unix timestamp for expiry - * @param int $attempts The amount of times to attempt a merge in case of failure - * @return bool Success - */ - public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) { - return $this->doWrite( self::ALL, 'merge', $key, $callback, $exptime ); - } - public function getLastError() { return $this->caches[0]->getLastError(); } -- 2.20.1