Skip to content

Commit

Permalink
objectcache: Remove $wgMainWANCache and $wgWANObjectCaches
Browse files Browse the repository at this point in the history
We always wrap the local cluster cache, and there are no subclasses
of WANObjectCache. It was never documented or recommended how these
would be used. It is a left-over from the original 2015 Multi-DC plan
in which WANObjectCache would work differently. See task for details.

Note that this requires no configuration changes, even in the
theoretical case of these variables being used, as the only
option is to use the main cache, and that's also the default.

* Update WAN overrides to override the underlying main cache
  instead.
* Fix EditPageTest which was previously implicitly using a 'hash'
  as main cache but also relying on wan cache to be 'none'.
  The part that it actually needs is the 'none'. When WAN cache is
  enabled, testUpdateNoMinor fails due to an edit conflict because
  one of the edits it makes is made with a current timestamp whereas
  it expects to simulate wpEdittime in the year 2012 which, when
  caching is enabled, is ignored and becomes the current time instead.
  I don't understand exactly why, but I'm going to conserve that
  behaviour for now.
* Fix TemplateCategoriesTest, which was failing due to an unexpected
  cache hit:
  > [objectcache] fetchOrRegenerate(…:page:10:…): volatile hit
  This could be solved in a more realistic way by splitting the test,
  or by explicitly resetting services half-way the test to clear
  WikiPageFactory, PageStore and WANCache process state.
  For now, keep the prior behaviour of no cache in this test.

Bug: T305093
Bug: T329680
Depends-On: If890622eed0d0f8b4bd73d36ba1815a3d760ea05
Depends-On: Ie1def75208822bdf19bb2cfd7e6edf32c2000e6b
Depends-On: I35cce61dc3ee90dcee3dd6f0b36f84133be029ed
Change-Id: I53781a8c06ebb2583f6ca83dd91bbfe8a5c88b13
  • Loading branch information
Krinkle committed Mar 7, 2023
1 parent f1fa0aa commit 39ead04
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 230 deletions.
1 change: 0 additions & 1 deletion .phan/config.php
Expand Up @@ -173,7 +173,6 @@ class_exists( WeakMap::class ) ? [] : [ '.phan/stubs/WeakMap.php' ],
'wgLogActionsHandlers' => 'array<string,class-string>',
'wgPasswordPolicy' => 'array<string,array<string,string|array>>',
'wgVirtualRestConfig' => 'array<string,array>',
'wgWANObjectCaches' => 'array[]',
'wgLocalInterwikis' => 'string[]',
'wgDebugLogGroups' => 'string|false|array{destination:string,sample?:int,level:int}',
'wgCookiePrefix' => 'string|false',
Expand Down
6 changes: 6 additions & 0 deletions RELEASE-NOTES-1.40
Expand Up @@ -49,6 +49,12 @@ For notes on 1.39.x and older releases, see HISTORY.
==== Removed configuration ====
* $wgShellboxUrl that was deprecated in 1.37 has now been removed,
set $wgShellboxUrls instead.
* $wgMainWANCache and $wgWANObjectCaches have been removed. To inject
WANObjectCache parameters, use $wgWANObjectCache instead. These variables
were introduced for multi-DC wiki farms to add a separate memcached
proxy for cross-DC relaying of purges. The configuration was never used
because WANObjectCache works based on route prefixes, that can be
transparently handled by the main memcached proxy.
* $wgParserTestFiles which was deprecated in 1.30 has now been removed;
extensions can place their parser test files in `tests/parser` instead.
* (T231412) $wgAutoloadAttemptLowercase, which was deprecated in 1.35,
Expand Down
53 changes: 10 additions & 43 deletions docs/config-schema.yaml
Expand Up @@ -2304,6 +2304,11 @@ config-schema:
- CACHE_ACCEL: APC, APCU or WinCache
- (other): A string may be used which identifies a cache
configuration in $wgObjectCaches.
For a multi-datacenter setup, the underlying service should be configured
to broadcast operations by WANObjectCache using Mcrouter or Dynomite.
See @ref wanobjectcache-deployment "Deploying WANObjectCache".
To configure the `broadcastRoutingPrefix` WANObjectCache parameter,
use $wgWANObjectCache.
@see $wgMessageCacheType, $wgParserCacheType
MessageCacheType:
default: -1
Expand Down Expand Up @@ -2416,51 +2421,13 @@ config-schema:
For MemcachedPhpBagOStuff parameters see {@link MemcachedPhpBagOStuff::__construct}
For MemcachedPeclBagOStuff parameters see {@link MemcachedPeclBagOStuff::__construct}
For RedisBagOStuff parameters see {@link RedisBagOStuff::__construct}
MainWANCache:
default: false
type:
- integer
- string
- boolean
WANObjectCache:
default: { }
type: object
description: |-
Main Wide-Area-Network cache type.
By default, this will wrap $wgMainCacheType (which is disabled, since the basic
stock default of CACHE_DB is not fast enough to make it worthwhile).
For single server or single datacenter setup, setting $wgMainCacheType
is enough.
For a multiple datacenter setup, WANObjectCache should be configured to
broadcast some if its operations using Mcrouter or Dynomite.
Extra parameters to the WANObjectCache constructor.
See @ref wanobjectcache-deployment "Deploying WANObjectCache".
The options are:
- false: Configure the cache using $wgMainCacheType, without using
a relayer (only matters if there are multiple datacenters)
- CACHE_NONE: Do not cache
- (other): A string may be used which identifies a cache
configuration in $wgWANObjectCaches
@since 1.26
WANObjectCaches:
default:
- { class: WANObjectCache, cacheId: 0 }
type: object
description: |-
Advanced WAN object cache configuration.
The format is an associative array where the key is an identifier
that may be referenced by $wgMainWANCache, and the value is an array of options:
- class: (Required) The class to use (must be WANObjectCache or a subclass).
- cacheId: (Required) A cache identifier from $wgObjectCaches.
- secret: (Optional) Stable secret for hashing long strings in key components.
Default: $wgSecretKey.
Any other options are treated as constructor parameters to WANObjectCache,
except for 'cache', 'logger', 'stats' and 'asyncHandler' which are
unconditionally set by MediaWiki core's ServiceWiring.
**Example:**
```
$wgWANObjectCaches['memcached-php'] => [
'class' => WANObjectCache::class,
'cacheId' => 'memcached-php',
];
```
@since 1.26
@since 1.40
MainStash:
default: db-replicated
description: |-
Expand Down
12 changes: 3 additions & 9 deletions docs/config-vars.php
Expand Up @@ -1470,16 +1470,10 @@
$wgObjectCaches = null;

/**
* Config variable stub for the MainWANCache setting, for use by phpdoc and IDEs.
* @see MediaWiki\MainConfigSchema::MainWANCache
* Config variable stub for the WANObjectCache setting, for use by phpdoc and IDEs.
* @see MediaWiki\MainConfigSchema::WANObjectCache
*/
$wgMainWANCache = null;

/**
* Config variable stub for the WANObjectCaches setting, for use by phpdoc and IDEs.
* @see MediaWiki\MainConfigSchema::WANObjectCaches
*/
$wgWANObjectCaches = null;
$wgWANObjectCache = null;

/**
* Config variable stub for the MainStash setting, for use by phpdoc and IDEs.
Expand Down
12 changes: 3 additions & 9 deletions includes/MainConfigNames.php
Expand Up @@ -1485,16 +1485,10 @@ class MainConfigNames {
public const ObjectCaches = 'ObjectCaches';

/**
* Name constant for the MainWANCache setting, for use with Config::get()
* @see MainConfigSchema::MainWANCache
* Name constant for the WANObjectCache setting, for use with Config::get()
* @see MainConfigSchema::WANObjectCache
*/
public const MainWANCache = 'MainWANCache';

/**
* Name constant for the WANObjectCaches setting, for use with Config::get()
* @see MainConfigSchema::WANObjectCaches
*/
public const WANObjectCaches = 'WANObjectCaches';
public const WANObjectCache = 'WANObjectCache';

/**
* Name constant for the MainStash setting, for use with Config::get()
Expand Down
66 changes: 10 additions & 56 deletions includes/MainConfigSchema.php
Expand Up @@ -79,7 +79,6 @@
use UserEditCountInitJob;
use UserGroupExpiryJob;
use UserOptionsUpdateJob;
use WANObjectCache;
use WatchlistExpiryJob;
use WebRequest;
use WikitextContentHandler;
Expand Down Expand Up @@ -3746,6 +3745,12 @@ public static function getDefaultDBerrorLogTZ( $localtimezone ) {
* - (other): A string may be used which identifies a cache
* configuration in $wgObjectCaches.
*
* For a multi-datacenter setup, the underlying service should be configured
* to broadcast operations by WANObjectCache using Mcrouter or Dynomite.
* See @ref wanobjectcache-deployment "Deploying WANObjectCache".
* To configure the `broadcastRoutingPrefix` WANObjectCache parameter,
* use $wgWANObjectCache.
*
* @see $wgMessageCacheType, $wgParserCacheType
*/
public const MainCacheType = [
Expand Down Expand Up @@ -3929,65 +3934,14 @@ public static function getDefaultDBerrorLogTZ( $localtimezone ) {
];

/**
* Main Wide-Area-Network cache type.
*
* By default, this will wrap $wgMainCacheType (which is disabled, since the basic
* stock default of CACHE_DB is not fast enough to make it worthwhile).
*
* For single server or single datacenter setup, setting $wgMainCacheType
* is enough.
* Extra parameters to the WANObjectCache constructor.
*
* For a multiple datacenter setup, WANObjectCache should be configured to
* broadcast some if its operations using Mcrouter or Dynomite.
* See @ref wanobjectcache-deployment "Deploying WANObjectCache".
*
* The options are:
* - false: Configure the cache using $wgMainCacheType, without using
* a relayer (only matters if there are multiple datacenters)
* - CACHE_NONE: Do not cache
* - (other): A string may be used which identifies a cache
* configuration in $wgWANObjectCaches
*
* @since 1.26
*/
public const MainWANCache = [
'default' => false,
'type' => 'integer|string|false',
];

/**
* Advanced WAN object cache configuration.
*
* The format is an associative array where the key is an identifier
* that may be referenced by $wgMainWANCache, and the value is an array of options:
*
* - class: (Required) The class to use (must be WANObjectCache or a subclass).
* - cacheId: (Required) A cache identifier from $wgObjectCaches.
* - secret: (Optional) Stable secret for hashing long strings in key components.
* Default: $wgSecretKey.
*
* Any other options are treated as constructor parameters to WANObjectCache,
* except for 'cache', 'logger', 'stats' and 'asyncHandler' which are
* unconditionally set by MediaWiki core's ServiceWiring.
*
* **Example:**
*
* ```
* $wgWANObjectCaches['memcached-php'] => [
* 'class' => WANObjectCache::class,
* 'cacheId' => 'memcached-php',
* ];
* ```
*
* @since 1.26
* @since 1.40
*/
public const WANObjectCaches = [
'default' => [
CACHE_NONE => [
'class' => WANObjectCache::class,
'cacheId' => CACHE_NONE,
]
],
public const WANObjectCache = [
'default' => [],
'type' => 'map',
];

Expand Down
35 changes: 7 additions & 28 deletions includes/ServiceWiring.php
Expand Up @@ -1018,45 +1018,24 @@ static function () use ( $services ) {
'MainWANObjectCache' => static function ( MediaWikiServices $services ): WANObjectCache {
$mainConfig = $services->getMainConfig();

$wanId = $mainConfig->get( MainConfigNames::MainWANCache );
$wanParams = $mainConfig->get( MainConfigNames::WANObjectCaches )[$wanId] ?? null;
if ( !$wanParams ) {
throw new UnexpectedValueException(
"wgWANObjectCaches must have \"$wanId\" set (via wgMainWANCache)"
);
}

$cacheId = $wanParams['cacheId'];
$wanClass = $wanParams['class'];
unset( $wanParams['cacheId'] );
unset( $wanParams['class'] );

$storeParams = $mainConfig->get( MainConfigNames::ObjectCaches )[$cacheId] ?? null;
if ( !$storeParams ) {
throw new UnexpectedValueException(
"wgObjectCaches must have \"$cacheId\" set (via wgWANObjectCaches)"
);
}
$store = ObjectCache::newFromParams( $storeParams, $services );
$store = $services->get( '_LocalClusterCache' );
$logger = $store->getLogger();
$logger->debug( 'MainWANObjectCache using store {class}', [
'class' => get_class( $store )
] );

$wanParams['cache'] = $store;
$wanParams['logger'] = $logger;
$wanParams['secret'] ??= $mainConfig->get( MainConfigNames::SecretKey );
$wanParams = $mainConfig->get( MainConfigNames::WANObjectCache ) + [
'cache' => $store,
'logger' => $logger,
'secret' => $mainConfig->get( MainConfigNames::SecretKey ),
];
if ( !$GLOBALS[ 'wgCommandLineMode' ] ) {
// Send the statsd data post-send on HTTP requests; avoid in CLI mode (T181385)
$wanParams['stats'] = $services->getStatsdDataFactory();
// Let pre-emptive refreshes happen post-send on HTTP requests
$wanParams['asyncHandler'] = [ DeferredUpdates::class, 'addCallableUpdate' ];
}

$instance = new $wanClass( $wanParams );

'@phan-var WANObjectCache $instance';
return $instance;
return new WANObjectCache( $wanParams );
},

'MediaHandlerFactory' => static function ( MediaWikiServices $services ): MediaHandlerFactory {
Expand Down
9 changes: 0 additions & 9 deletions includes/SetupDynamicConfig.php
Expand Up @@ -14,15 +14,6 @@
$wgLogo = $wgLogos['1x'];
}

if ( $wgMainWANCache === false ) {
// Create a WAN cache from $wgMainCacheType
$wgMainWANCache = 'mediawiki-main-default';
$wgWANObjectCaches[$wgMainWANCache] = [
'class' => WANObjectCache::class,
'cacheId' => $wgMainCacheType,
];
}

// Back-compat
if ( isset( $wgFileBlacklist ) ) {
$wgProhibitedFileExtensions = array_merge( $wgProhibitedFileExtensions, $wgFileBlacklist );
Expand Down
14 changes: 2 additions & 12 deletions includes/config-schema.php
Expand Up @@ -516,12 +516,7 @@
'reportDupes' => false,
],
],
'MainWANCache' => false,
'WANObjectCaches' => [
0 => [
'class' => 'WANObjectCache',
'cacheId' => 0,
],
'WANObjectCache' => [
],
'MainStash' => 'db-replicated',
'ParsoidCacheConfig' => [
Expand Down Expand Up @@ -2619,12 +2614,7 @@
],
'MultiShardSiteStats' => 'boolean',
'ObjectCaches' => 'object',
'MainWANCache' => [
0 => 'integer',
1 => 'string',
2 => 'boolean',
],
'WANObjectCaches' => 'object',
'WANObjectCache' => 'object',
'ParsoidCacheConfig' => 'object',
'ChronologyProtectorStash' => [
0 => 'string',
Expand Down
3 changes: 1 addition & 2 deletions tests/common/TestSetup.php
Expand Up @@ -28,7 +28,7 @@ public static function snapshotGlobals() {
* of a Maintenance subclass which then gets called via MW_SETUP_CALLBACK in Setup.php.
*/
public static function applyInitialConfig() {
global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache, $wgSessionCacheType;
global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgSessionCacheType;
global $wgMainStash, $wgChronologyProtectorStash;
global $wgObjectCaches;
global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
Expand All @@ -53,7 +53,6 @@ public static function applyInitialConfig() {
// See also MediaWikiIntegrationTestCase::run() which mocks CACHE_DB and APC.

// Disabled per default in MainConfigSchema, override local settings
$wgMainWANCache =
$wgMainCacheType = CACHE_NONE;
// Uses CACHE_ANYTHING per default in MainConfigSchema, use hash instead of db
$wgMessageCacheType =
Expand Down
7 changes: 3 additions & 4 deletions tests/phpunit/includes/EditPageTest.php
Expand Up @@ -12,12 +12,8 @@

/**
* @group Editing
*
* @group Database
* ^--- tell jenkins this test needs the database
*
* @group medium
* ^--- tell phpunit that these test cases may take longer than 2 seconds.
*/
class EditPageTest extends MediaWikiLangTestCase {

Expand All @@ -34,6 +30,9 @@ protected function setUp(): void {
[ 'testing' => 'DummyContentHandlerForTesting' ] +
MainConfigSchema::getDefaultValue( MainConfigNames::ContentHandlers ),
] );

// Disable WAN cache to avoid edit conflicts in testUpdateNoMinor
$this->setMainCache( CACHE_NONE );
}

/**
Expand Down
Expand Up @@ -29,8 +29,6 @@ class MessageBlobStoreTest extends \PHPUnit\Framework\TestCase {

protected function setUp(): void {
parent::setUp();
// MediaWiki's test wrapper sets $wgMainWANCache to CACHE_NONE.
// Use HashBagOStuff here so that we can observe caching.
$this->wanCache = new WANObjectCache( [
'cache' => new HashBagOStuff()
] );
Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/includes/TemplateCategoriesTest.php
Expand Up @@ -7,6 +7,13 @@
*/
class TemplateCategoriesTest extends MediaWikiIntegrationTestCase {

protected function setUp(): void {
parent::setUp();

// Don't let PageStore hit WANObjectCache process cache for revision metadata
$this->setMainCache( CACHE_NONE );
}

/**
* @covers Title::getParentCategories
*/
Expand Down

0 comments on commit 39ead04

Please sign in to comment.