Improve MultiWriteBagOStuff::merge() cross-DC performance
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Oct 2015 04:50:27 +0000 (21:50 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Oct 2015 04:50:27 +0000 (21:50 -0700)
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

index 50dd215..98380d9 100644 (file)
@@ -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();
        }