From 793d01401c9718cce16328d424a9a10297da4ccd Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 29 Apr 2015 19:19:23 -0700 Subject: [PATCH] Added ObjectCache::getMainStashInstance() and $wgMainStash * This provides factory/config more appropriate for stashes * Cleaned up some neighboring config comments while at it Bug: T88493 Bug: T97620 Change-Id: Id370ee50be6e493a4700c858df863a183abc05fd --- includes/DefaultSettings.php | 22 +++++++++++++++++++-- includes/objectcache/ObjectCache.php | 29 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 857d69ee51..2ea8b294b6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2160,7 +2160,7 @@ $wgObjectCaches = array( ); /** - * Main cache Wide-Area-Network cache type. This should be a cache with fast access, + * Main Wide-Area-Network cache type. This should be a cache with fast access, * but it may have limited space. By default, it is disabled, since the basic stock * cache is not fast enough to make it worthwhile. For single data-center setups, this can * simply be pointed to a cache in $wgWANObjectCaches that uses a local $wgObjectCaches @@ -2171,7 +2171,8 @@ $wgObjectCaches = array( * a relayer (only matters if there are multiple data-centers) * - CACHE_NONE: Do not cache * - (other): A string may be used which identifies a cache - * configuration in $wgWANObjectCaches. + * configuration in $wgWANObjectCaches + * @since 1.26 */ $wgMainWANCache = false; @@ -2187,6 +2188,8 @@ $wgMainWANCache = false; * 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. + * + * @since 1.26 */ $wgWANObjectCaches = array( CACHE_NONE => array( @@ -2205,6 +2208,21 @@ $wgWANObjectCaches = array( */ ); +/** + * Main object stash type. This should be a fast storage system for storing + * lightweight data like hit counters and user activity. Sites with multiple + * data-centers should have this use a store that replicates all writes. The + * store should have enough consistency for CAS operations to be usable. + * + * The options are: + * - db: Store cache objects in the DB + * - (other): A string may be used which identifies a cache + * configuration in $wgObjectCaches + * + * @since 1.26 + */ +$wgMainStash = 'db'; + /** * The expiry time for the parser cache, in seconds. * The default is 86400 (one day). diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 5da22f0fd2..7faf4bb6a8 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -26,6 +26,13 @@ use MediaWiki\Logger\LoggerFactory; /** * Functions to get cache objects * + * The word "cache" has two main dictionary meanings, and both + * are used in this factory class. They are: + * - a) A place to store copies or computations on existing data + * for higher access speeds (the computer science definition) + * - b) A place to store lightweight data that is not canonically + * stored anywhere else (e.g. a "hoard" of objects) + * * @ingroup Cache */ class ObjectCache { @@ -227,4 +234,26 @@ class ObjectCache { return self::getWANInstance( $wgMainWANCache ); } + + /** + * Stash objects are BagOStuff instances suitable for storing light + * weight data that is not canonically stored elsewhere (such as RDBMS). + * Stashes should be configured to propagate changes to all data-centers. + * + * Callers should be prepared for: + * - a) Writes to be slower in non-"primary" (e.g. HTTP GET/HEAD only) DCs + * - b) Reads to be eventually consistent, e.g. for get()/getMulti() + * In general, this means avoiding updates on idempotent HTTP requests and + * avoiding an assumption of perfect serializability (or accepting anomalies). + * Reads may be eventually consistent or data might rollback as nodes flap. + * + * + * @return BagOStuff + * @since 1.26 + */ + static function getMainStashInstance() { + global $wgMainStash; + + return self::getInstance( $wgMainStash ); + } } -- 2.20.1