Make WAN cache config use $wgEventRelayerConfig
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 22 Apr 2016 19:52:06 +0000 (12:52 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 25 Apr 2016 19:08:09 +0000 (12:08 -0700)
This makes the channels more explicit and defined in a less
ad-hoc way. Systems like Kafka would prefer explicit channel
definitions anyway, so the channel prefix just obscures things.

Change-Id: I5631eb1b1382083396a0f08904d9273cc92601e8

includes/DefaultSettings.php
includes/Setup.php
includes/libs/eventrelayer/EventRelayer.php
includes/libs/objectcache/WANObjectCache.php
includes/objectcache/ObjectCache.php

index 2a30352..7d771c1 100644 (file)
@@ -2223,27 +2223,24 @@ $wgMainWANCache = false;
  *
  * The format is an associative array where the key is a cache identifier, and
  * the value is an associative array of parameters. The "cacheId" parameter is
- * a cache identifier from $wgObjectCaches. The "relayerConfig" parameter is an
- * array used to construct an EventRelayer object. The "pool" parameter is a
- * string that is used as a PubSub channel prefix. The "loggroup" parameter
- * controls where log events are sent.
+ * a cache identifier from $wgObjectCaches. The "channels" parameter is a map of
+ * actions ('purge') to PubSub channels defined in $wgEventRelayerConfig.
+ * The "loggroup" parameter controls where log events are sent.
  *
  * @since 1.26
  */
 $wgWANObjectCaches = [
        CACHE_NONE => [
-               'class'         => 'WANObjectCache',
-               'cacheId'       => CACHE_NONE,
-               'pool'          => 'mediawiki-main-none',
-               'relayerConfig' => [ 'class' => 'EventRelayerNull' ]
+               'class'    => 'WANObjectCache',
+               'cacheId'  => CACHE_NONE,
+               'channels' => []
        ]
        /* Example of a simple single data-center cache:
-       'memcached-php' => array(
-               'class'         => 'WANObjectCache',
-               'cacheId'       => 'memcached-php',
-               'pool'          => 'mediawiki-main-memcached',
-               'relayerConfig' => array( 'class' => 'EventRelayerNull' )
-       )
+       'memcached-php' => [
+               'class'    => 'WANObjectCache',
+               'cacheId'  => 'memcached-php',
+               'channels' => [ 'purge' => 'wancache-main-memcached-purge' ]
+       ]
        */
 ];
 
index cddb436..9898b84 100644 (file)
@@ -618,10 +618,9 @@ if ( $wgMainWANCache === false ) {
        // Sites using multiple datacenters can configure a relayer.
        $wgMainWANCache = 'mediawiki-main-default';
        $wgWANObjectCaches[$wgMainWANCache] = [
-               'class'         => 'WANObjectCache',
-               'cacheId'       => $wgMainCacheType,
-               'pool'          => 'mediawiki-main-default',
-               'relayerConfig' => [ 'class' => 'EventRelayerNull' ]
+               'class'    => 'WANObjectCache',
+               'cacheId'  => $wgMainCacheType,
+               'channels' => [ 'purge' => 'wancache-main-default-purge' ]
        ];
 }
 
index f28a4c0..b0cd413 100644 (file)
@@ -54,10 +54,6 @@ abstract class EventRelayer implements LoggerAwareInterface {
                return $this->doNotify( $channel, $events );
        }
 
-       /**
-        * Set logger instance.
-        * @param LoggerInterface $logger
-        */
        public function setLogger( LoggerInterface $logger ) {
                $this->logger = $logger;
        }
index dd2e0d5..57cecd0 100644 (file)
@@ -69,10 +69,10 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        protected $cache;
        /** @var HashBagOStuff Script instance PHP cache */
        protected $procCache;
-       /** @var string Cache pool name */
-       protected $pool;
+       /** @var string Purge channel name */
+       protected $purgeChannel;
        /** @var EventRelayer Bus that handles purge broadcasts */
-       protected $relayer;
+       protected $purgeRelayer;
        /** @var LoggerInterface */
        protected $logger;
 
@@ -134,25 +134,27 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
        const MAX_PC_KEYS = 1000; // max keys to keep in process cache
 
+       const DEFAULT_PURGE_CHANNEL = 'wancache-purge';
+
        /**
         * @param array $params
-        *   - cache   : BagOStuff object
-        *   - pool    : pool name
-        *   - relayer : EventRelayer object
-        *   - logger  : LoggerInterface object
+        *   - 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
         */
        public function __construct( array $params ) {
                $this->cache = $params['cache'];
-               $this->pool = $params['pool'];
-               $this->relayer = $params['relayer'];
                $this->procCache = new HashBagOStuff( [ 'maxKeys' => self::MAX_PC_KEYS ] );
+               $this->purgeChannel = isset( $params['channels']['purge'] )
+                       ? $params['channels']['purge']
+                       : self::DEFAULT_PURGE_CHANNEL;
+               $this->purgeRelayer = isset( $params['relayers']['purge'] )
+                       ? $params['relayers']['purge']
+                       : new EventRelayerNull( [] );
                $this->setLogger( isset( $params['logger'] ) ? $params['logger'] : new NullLogger() );
        }
 
-       /**
-        * Set logger instance.
-        * @param LoggerInterface $logger
-        */
        public function setLogger( LoggerInterface $logger ) {
                $this->logger = $logger;
        }
@@ -950,7 +952,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                        'sbt' => true, // substitute $UNIXTIME$ with actual microtime
                ] );
 
-               $ok = $this->relayer->notify( "{$this->pool}:purge", $event );
+               $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
                if ( !$ok ) {
                        $this->lastRelayError = self::ERR_RELAY;
                }
@@ -970,7 +972,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                        'key' => $key,
                ] );
 
-               $ok = $this->relayer->notify( "{$this->pool}:purge", $event );
+               $ok = $this->purgeRelayer->notify( $this->purgeChannel, $event );
                if ( !$ok ) {
                        $this->lastRelayError = self::ERR_RELAY;
                }
index bf152b6..e9f2211 100644 (file)
@@ -298,8 +298,10 @@ class ObjectCache {
                }
 
                $params = $wgWANObjectCaches[$id];
-               $class = $params['relayerConfig']['class'];
-               $params['relayer'] = new $class( $params['relayerConfig'] );
+               foreach ( $params['channels'] as $action => $channel ) {
+                       $params['relayers'][$action] = EventRelayerGroup::singleton()->getRelayer( $channel );
+                       $params['channels'][$action] = $channel;
+               }
                $params['cache'] = self::newFromId( $params['cacheId'] );
                if ( isset( $params['loggroup'] ) ) {
                        $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );