objectcache: remove EventRelayer dependency from WANObjectCache
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 16 Feb 2019 07:17:23 +0000 (23:17 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 16 Feb 2019 07:20:38 +0000 (07:20 +0000)
The use of that class for WAN cache by third parties is extremely unlikely
and the approach was abandoned at WMF in favor of mcrouter (dynomite was
also considered preferable).

Change-Id: I328eb74f21c23db80acc5178bc3c9cf9f823da13

includes/libs/objectcache/WANObjectCache.php

index c1428e6..f9debaf 100644 (file)
@@ -74,13 +74,11 @@ use Psr\Log\NullLogger;
  *
  * ### Deploying WANObjectCache
  *
- * There are three supported ways to set up broadcasted operations:
+ * There are two supported ways to set up broadcasted operations:
  *
- *   - A) Configure the 'purge' EventRelayer to point to a valid PubSub endpoint
- *        that has subscribed listeners on the cache servers applying the cache updates.
- *   - B) Omit the 'purge' EventRelayer parameter and set up mcrouter as the underlying cache
- *        backend, using a memcached BagOStuff class for the 'cache' parameter. The 'region'
- *        and 'cluster' parameters must be provided and 'mcrouterAware' must be set to `true`.
+ *   - A) Set up mcrouter as the underlying cache backend, using a memcached BagOStuff class
+ *        for the 'cache' parameter. The 'region' and 'cluster' parameters must be provided
+ *        and 'mcrouterAware' must be set to `true`.
  *        Configure mcrouter as follows:
  *          - 1) Use Route Prefixing based on region (datacenter) and cache cluster.
  *               See https://github.com/facebook/mcrouter/wiki/Routing-Prefix and
@@ -90,11 +88,11 @@ use Psr\Log\NullLogger;
  *               configure 'set' and 'delete' operations to go to all servers in the cache
  *               cluster, instead of just one server determined by hashing.
  *               See https://github.com/facebook/mcrouter/wiki/List-of-Route-Handles.
- *   - C) Omit the 'purge' EventRelayer parameter and set up dynomite as cache middleware
- *        between the web servers and either memcached or redis. This will broadcast all
- *        key setting operations, not just purges, which can be useful for cache warming.
- *        Writes are eventually consistent via the Dynamo replication model.
- *        See https://github.com/Netflix/dynomite.
+ *   - B) Set up dynomite as a cache middleware between the web servers and either memcached
+ *        or redis and use it as the underlying cache backend, using a memcached BagOStuff
+ *        class for the 'cache' parameter. This will broadcast all key setting operations,
+ *        not just purges, which can be useful for cache warming. Writes are eventually
+ *        consistent via the Dynamo replication model. See https://github.com/Netflix/dynomite.
  *
  * Broadcasted operations like delete() and touchCheckKey() are done asynchronously
  * in all datacenters this way, though the local one should likely be near immediate.
@@ -120,10 +118,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        protected $cache;
        /** @var MapCacheLRU[] Map of group PHP instance caches */
        protected $processCaches = [];
-       /** @var string Purge channel name */
-       protected $purgeChannel;
-       /** @var EventRelayer Bus that handles purge broadcasts */
-       protected $purgeRelayer;
        /** @bar bool Whether to use mcrouter key prefixing for routing */
        protected $mcrouterAware;
        /** @var string Physical region for mcrouter use */
@@ -141,9 +135,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /** @var float Unix timestamp of the oldest possible valid values */
        protected $epoch;
 
-       /** @var int ERR_* constant for the "last error" registry */
-       protected $lastRelayError = self::ERR_NONE;
-
        /** @var int Callback stack depth for getWithSetCallback() */
        private $callbackDepth = 0;
        /** @var mixed[] Temporary warm-up cache */
@@ -235,8 +226,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /**
         * @param array $params
         *   - cache    : BagOStuff object for a persistent cache
-        *   - channels : Map of (action => channel string). Actions include "purge".
-        *   - relayers : Map of (action => EventRelayer object). Actions include "purge".
         *   - logger   : LoggerInterface object
         *   - stats    : LoggerInterface object
         *   - asyncHandler : A function that takes a callback and runs it later. If supplied,
@@ -260,8 +249,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        public function __construct( array $params ) {
                $this->cache = $params['cache'];
-               $this->purgeChannel = $params['channels']['purge'] ?? self::DEFAULT_PURGE_CHANNEL;
-               $this->purgeRelayer = $params['relayers']['purge'] ?? new EventRelayerNull( [] );
                $this->region = $params['region'] ?? 'main';
                $this->cluster = $params['cluster'] ?? 'wan-main';
                $this->mcrouterAware = !empty( $params['mcrouterAware'] );
@@ -1752,15 +1739,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @return int ERR_* class constant for the "last error" registry
         */
        final public function getLastError() {
-               if ( $this->lastRelayError ) {
-                       // If the cache and the relayer failed, focus on the latter.
-                       // An update not making it to the relayer means it won't show up
-                       // in other DCs (nor will consistent re-hashing see up-to-date values).
-                       // On the other hand, if just the cache update failed, then it should
-                       // eventually be applied by the relayer.
-                       return $this->lastRelayError;
-               }
-
                $code = $this->cache->getLastError();
                switch ( $code ) {
                        case BagOStuff::ERR_NONE:
@@ -1779,7 +1757,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function clearLastError() {
                $this->cache->clearLastError();
-               $this->lastRelayError = self::ERR_NONE;
        }
 
        /**
@@ -1928,26 +1905,13 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                                $this->makePurgeValue( $this->getCurrentTime(), self::HOLDOFF_NONE ),
                                $ttl
                        );
-               } elseif ( $this->purgeRelayer instanceof EventRelayerNull ) {
+               } else {
                        // This handles the mcrouter and the single-DC case
                        $ok = $this->cache->set(
                                $key,
                                $this->makePurgeValue( $this->getCurrentTime(), self::HOLDOFF_NONE ),
                                $ttl
                        );
-               } else {
-                       $event = $this->cache->modifySimpleRelayEvent( [
-                               'cmd' => 'set',
-                               'key' => $key,
-                               'val' => 'PURGED:$UNIXTIME$:' . (int)$holdoff,
-                               'ttl' => max( $ttl, self::TTL_SECOND ),
-                               'sbt' => true, // substitute $UNIXTIME$ with actual microtime
-                       ] );
-
-                       $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
-                       if ( !$ok ) {
-                               $this->lastRelayError = self::ERR_RELAY;
-                       }
                }
 
                return $ok;
@@ -1964,19 +1928,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                        // See https://github.com/facebook/mcrouter/wiki/Multi-cluster-broadcast-setup
                        // Wildcards select all matching routes, e.g. the WAN cluster on all DCs
                        $ok = $this->cache->delete( "/*/{$this->cluster}/{$key}" );
-               } elseif ( $this->purgeRelayer instanceof EventRelayerNull ) {
+               } else {
                        // Some other proxy handles broadcasting or there is only one datacenter
                        $ok = $this->cache->delete( $key );
-               } else {
-                       $event = $this->cache->modifySimpleRelayEvent( [
-                               'cmd' => 'delete',
-                               'key' => $key,
-                       ] );
-
-                       $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
-                       if ( !$ok ) {
-                               $this->lastRelayError = self::ERR_RELAY;
-                       }
                }
 
                return $ok;