Commit graph

120 commits

Author SHA1 Message Date
Aaron Schulz
6a8943d8c5 objectcache: dependency inject LoadBalancer into SqlBagOStuff
Clean up the recursive DB dependency mitigation logic by having
ServiceContainer detect recursion and throw an appropriate error.
Catch the error and use EmptyBagOStuff in such cases. This works
better than checking getQoS() since that begs the question by
requiring the cache instance to begin with.

Also add support for using different LoadBalancer instances for
local and global keys in SqlBagOStuff. This makes it easier to
share keys between projects.

Bug: T229062
Change-Id: Ib8ec1845bcf1b86cbb3bededa0ca7621a0ca293a
2020-05-18 21:04:17 -07:00
Timo Tijhof
ae6b99bf65 objectcache: Restore 'keyspace' for LocalServerCache service
Follows-up 746d67f5fc which implicitly caused the APCUBagOStuff
object to no longer have a wiki-dependent keyspace. This meant
that all cache keys were shared across wikis, even if they used
makeKey() instead of makeGlobalKey() because the keyspace was
not defined (e.g. it was the string "local" for all wikis, instead
of a string like "enwiki").

Bug: T247562
Change-Id: I469e107a54aae91b8782a4dd9a2f1390ab9df2e5
2020-03-18 01:44:19 +00:00
Timo Tijhof
a85c033464 objectcache: Remove temporary HashConfig in newFromParams()
This was added in ce84590988e, and is no longer needed as
of 10dce13709.

Also remove the comment that announces deprecation/removal,
given newFromParams is used as callback in wgObjectCaches,
that might not be feasible. We can keep supporting it as an
optional parameter for now for uses in tests and for uses
outside configuration (e.g ServiceWiring), so that best
practices can be followed where they make sense, but still
allow bypass for config use case, since that would only ever
inject the One True Config object anyway.

Change-Id: I8cc4bfb1862b81df2c31fdc0886364b092636cc2
2020-03-04 22:53:24 +00:00
Timo Tijhof
746d67f5fc objectcache: Add makeLocalServerCache() method
This bypasses the indirection of global wgObjectCaches config and
ObjectCache::newFromParams static methods, which don't do anything
in practice.

This solves the ExtensionRegistry use-case where it couldn't use
the service container, which in turn opens the path for
being able to deprecate absence of Config being passed to
ObjectCache::newFromParams(), which isn't possible right now because
ExtensionRegistry depended on being able to call it without that,
and that is a hard requirement because ExtensionRegistry isn't
allowed to use the service container.

Change-Id: Ic88da279662f33d3585cb2232358d6faf590b5b3
2020-03-04 22:35:14 +00:00
Timo Tijhof
8d4aaa43cb objectcache: Inject Config object to ObjectCache::newFromParams
* Avoid direct $GLOBALS lookups.
* Avoid MediaWikiServices singleton for Config object.

Also given that newFromParams() constructs its Logger object
unconditionally as of I2aa835c5ec79, stop creating it ahead of
time in ServiceWiring.

This code, including the default loggroup value, was duplicated by
me from ObjectCache.php to ServiceWiring.php in commits 3828558140
and bd16c5eb34 because I needed to obtain the Logger object
in order to send a message to it about how it was created.

Solve this debt by letting ServiceWiring access the actual logger
that was created by newFromParams() through a new getLogger()
object.

Change-Id: Ib2de7b22f6c79db0c700fae06269d04fbe27831d
2020-03-04 22:34:30 +00:00
Aaron Schulz
5780011ec5 objectcache: make ObjectCache::newFromParams() defaults more consistent
Apply the same duplication logging and asyncHandler defaults for
factory-based entries as constructor-based entries.

Change-Id: I2aa835c5ec7932432d2c739ffa761a7bd9c21198
2020-03-02 21:07:32 +00:00
Aaron Schulz
758e980427 objectcache: remove APCBagOStuff class
apcu comes with PHP 5.5+ and the minimum version for MediaWiki is 7.2

Change-Id: I69a988c6c2999766a3c7e56b841cd4f4091b4d95
2020-01-29 17:27:47 +00:00
Umherirrender
17436be6de Allow int on ObjectCache::getInstance
It is possible to called with CACHE_NONE or CACHE_ANYTHING
These constant defines with int values

Change-Id: I9661ed8dd80cb827d7a1414c1eef952c0933a1f0
2019-12-29 20:03:05 +01:00
jenkins-bot
a93b8e7d0b Merge "objectcache: Remove deprecated WAN-methods in ObjectCache" 2019-10-11 18:24:49 +00:00
jenkins-bot
3300dc7b17 Merge "objectcache: Log debug message for backend of MainObjectStash" 2019-10-11 15:43:53 +00:00
Timo Tijhof
0cfc89dbc3 objectcache: Remove deprecated WAN-methods in ObjectCache
Deprecated as of 1.34, not used anywhere.

Change-Id: I4974f55a415115d2cbeb8be944e82c949e7b8c36
2019-10-11 02:26:05 +01:00
Timo Tijhof
bd16c5eb34 objectcache: Log debug message for backend of MainObjectStash
Bug: T234361
Change-Id: I8e33591dc92198269f45a25d14014af633a351f2
2019-10-10 21:30:47 +01:00
Timo Tijhof
b10b56dc69 objectcache: Deprecate ObjectCache::getWANInstance
This is not used anywhere. Once removed we can remove a bunch
more protected/private methods in this class that are all only
here still due to this one public method.

It was obsolete when the creation of WANObjectCache was
moved to ServiceWiring. In theory multiple instances can be
created but in the future that should be done by either constructing
the WANObjectCache directly where needed, or by implementing
it as a custom service.

Also deprecate ObjectCache::newWANCacheFromParams. This should
have been `@internal`, but oh well. Deprecate as well since
only needed by getWANInstance(). No longer used internally
either as of I118b6f01e4940.

Change-Id: Icc500e76c860c35ff40fdee47142c63091829dfe
2019-10-10 20:23:36 +00:00
Aaron Schulz
7c2d1be7d8 objectcache: remove references to recently removed methods
Follow-up to 9d5e3f56d5

Change-Id: Idca42b5ca405c31953a516aa3f96cf64cc0e0a12
2019-09-15 13:52:07 -07:00
Zoranzoki21
9d5e3f56d5 Remove getMainWANInstance and getMainStashInstance functions
from ObjectCache as they were deprecated in 1.28

Change-Id: I133470a1c69c836f38b1ae5fecc05e50b70f4457
2019-09-15 15:18:51 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
jenkins-bot
6ba38fa942 Merge "Remove $wgMemCachedDebug" 2019-08-29 18:06:20 +00:00
Aaron Schulz
f78e39d3d7 Remove $wgMemCachedDebug
Change-Id: I98380ac1cb66e33719b4836410311aea3513115c
2019-08-29 17:16:31 +00:00
Aaron Schulz
1b57f6a81b Make ObjectCache check the value of apc.enable_cli in CLI mode
Add HashBagOStuff fallback for APC in MWLBFactory::injectObjectCaches.

Also fix APC-cache variable typo in MWLBFactory.

Bug: T227838
Change-Id: I71cb2ca58972ea09ab2f64f7e47bda7a5096c19b
2019-08-29 09:04:18 -07:00
Aaron Schulz
d421f22eb6 objectcache: make newFromId()/newWANcacheFromId()/getDefaultKeyspace() private
Change-Id: I30b99f23dbd9637ca8178d3a3650b4c38ec43e7d
2019-08-20 13:11:27 +00:00
Aaron Schulz
49025f52b2 objectcache: clean up MemcachedBagOStuff expiry handling
Partly a follow-up to 88640fd902.

Use real time in changeTTL() tests to fix all remaining
failures for BagOStuff sub-classes.

Change-Id: I537d665d6c8770a68a5a79233a913f1714881dfb
2019-08-10 12:12:12 -07:00
Aaron Schulz
12f4ce87e9 objectcache: make getMultiWith(Union)SetCallback() usage easier
Add WANObjectCache::multiRemap() as an array_combine() wrapper for
easily working with IDs after getMultiWith(Union)SetCallback() calls.
Make the enforcement of uniqueness in makeMultiKeys() stricter and
discourage poor key design in comments. Add WANObjectCache::hash256()
method for getting good key component hashes.

Also avoid pointless use of ArrayIterator::getArrayCopy().

Change-Id: I61ffdbf4af4374864bac180df590b4dddc8da56b
2019-07-14 14:51:51 +00:00
jenkins-bot
b5f06bbd12 Merge "objectcache: Hard deprecate ObjectCache::getMainWANInstance()" 2019-07-13 21:34:28 +00:00
Aaron Schulz
d3c2e4d385 Update $wgMainStash comments and merge in those from a deprecated ObjectCache method
Change-Id: I807f36d9c51476a969d7046d57bfc32cf37c2745
2019-07-10 14:02:41 -07:00
Derick Alangi
ff320d9e49 objectcache: Hard deprecate ObjectCache::getMainWANInstance()
This method was soft-deprecated in 1.28 and this patch cleans up
usage (via object cache) in core and uses services. So, this is now
fit for hard deprecation.

Usage
=====

https://codesearch.wmflabs.org/search/?q=getMainWANInstance&i=nope&files=&repos=

Change-Id: I081a979ed6ed7acf37168a6d81ca4048aae5dd9c
2019-07-09 09:29:57 +00:00
Derick Alangi
f415b57749 objectcache: Hard deprecate ObjectCache::getMainStashInstance()
This method was soft deprecated in 1.28 and usage is no longer in core
except for FlaggedRevs ext (here in removed in patch I3ada0b53e8b2a6f118f).

Usage
=====

https://codesearch.wmflabs.org/search/?q=getMainStashInstance&i=nope&files=&repos=

Depends-On: I3ada0b53e8b2a6f118fae37e7fc644b187bf95f8
Change-Id: I3f06b3732f67b703cdc12ec5849b67067475cdda
2019-07-02 18:27:24 +01:00
Aaron Schulz
e742701091 objectcache: make detectLocalServerCache() prefer apcu over apc
Bug: T220470
Change-Id: I8b85859b3991d2360a74107299d44da2c60d0214
2019-05-22 22:23:22 +00:00
Aaron Schulz
384a27e7ac Remove unused EventRelayer code from ObjectCache::newWANCacheFromParams()
Change-Id: I6c0f274e3c49312b63446732f22123af9dac8a2b
2019-05-09 16:13:15 -07:00
Derick Alangi
47e7f59682 objectcache: Remove unused variable $cache which is overriden
This variable was defined to false and immediately overriden in the
if condition below it which makes the assignment above useless.

Change-Id: Ie72ec7a8860d2a38f59f38b3d861217d39da3e29
2019-03-25 15:20:19 +01:00
Fomafix
4b46994799 Fix usage of MediaWikiServices in comments and documentation
MediaWikiServices::getFoo()

is wrong. Right is:

MediaWikiServices::getInstance()->getFoo()

Change-Id: Ib6d844ddfe5bd6ccd72b887a63d9ad476c8d196f
2019-03-03 14:09:33 +00:00
Aaron Schulz
5196ac32c6 Rename WikiMap DB domain ID methods to reduce confusion with web domains
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094
2019-02-06 12:28:45 -08:00
jenkins-bot
988af574cb Merge "Use new WikiMap::getCurrentWikiDomain() for objectcache and profiler keyspace" 2018-10-30 07:08:27 +00:00
Aaron Schulz
42a6f991e0 Use new WikiMap::getCurrentWikiDomain() for objectcache and profiler keyspace
Change-Id: I0e77c58a55b7ce908ec1d6399ec6629d00a48953
2018-10-30 06:41:07 +00:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Max Semenik
69aecc2eea Don't initialize MediaWikiServices before extensions have been loaded
Bug: T153256
Bug: T190425
Change-Id: I749f66d13a8c8a8ae4a83661b83c56f0db74a187
2018-05-03 23:36:10 -07:00
Aaron Schulz
8350329922 Avoid warnings in ObjectCache::newWANCacheFromParams if "channels" is not set"
Bug: T192473
Change-Id: I150eef62285e99fc1269a58fee3827e5fbb0537b
2018-04-19 07:53:13 +00:00
Aaron Schulz
8ed0b8db05 Only send statsd data for WAN cache in non-CLI mode
Bug: T181385
Change-Id: Ic51a084206cea93621393359ded4ff77beef5f13
2017-12-02 12:34:22 -08:00
Aaron Schulz
73b928750c objectcache: Run preemptive WAN cache refreshes post-send
This keeps HTTP request time consistent in case of expensive keys

Change-Id: I0746fde29a6e2f27d1b92f1af599c741d5972f46
2017-12-01 08:15:26 +00:00
Aaron Schulz
4432e898be Add statsd metric support to WANObjectCache
Bug: T178531
Change-Id: I3037281d09cd5195347789f544deae89711f128b
2017-10-25 01:41:31 +00:00
Brian Wolff
c5a0fa5bed objectcache: Never use CACHE_NONE for CACHE_ANYTHING
If $wgMainCacheType = CACHE_ACCEL, but there is no APC, then its
possible that CACHE_ANYTHING will default to CACHE_NONE because
that's what CACHE_ACCEL would do.

Possibly also T147161

Bug: T160519
Change-Id: I9ac2d071437b35a0f9cd3678e2279628f7b1931e
2017-03-30 01:38:15 +00:00
Amir Sarabadani
bcf61a7080 Fix mistake in ObjectCache doc
Change-Id: Iafe3c460ca462aa160cfea6769fd78f8b023548c
2017-03-10 13:12:43 +03:30
Aaron Schulz
f19a4a1566 Clean up newWANCacheFromParams() getInstance() calls
Change-Id: I0daa2531708d0a110e8028c4a5641153a23c0a97
2016-10-23 21:01:03 -07:00
Aaron Schulz
5c59e46a72 Remove deprecated ObjectCache::newAccelerator method
Change-Id: I2be2afe3f2bba830aea4e985005adb72f0e45a82
2016-10-12 15:15:15 -07:00
jenkins-bot
1d95c68977 Merge "ObjectCache::newFromParams fix SqlBagOStuff backcompat" 2016-10-05 21:55:45 +00:00
addshore
b63b3ce036 ObjectCache::newFromParams fix SqlBagOStuff backcompat
Bug: T147407
Change-Id: I718d01b309d96deeb9f7aa1fdcdee9f824657f9d
2016-10-05 22:11:48 +01:00
Aaron Schulz
514d759b58 Add the main stash, WAN, and server caches to MediaWikiServices
Leave getLocalServerInstance() array fallback logic.

Restores 6d99fa5824
Which got reverted by 7ab9283292.

Change-Id: Id1f48e10753d6aaf64eecb4d3c2228740abc1340
2016-10-03 18:36:06 +00:00
Reedy
c214c9a952 Detect/use APCu properly
In PHP 5.5 and above, userland APC caching moved to an extension

Bug: T140587
Change-Id: Ie0871776cd7e67838471a4fe95451cf4164079b7
2016-10-01 23:07:47 +01:00
Hashar
7ab9283292 Revert "Add the main stash, WAN, and server caches to MediaWikiServices"
$ php maintenance/eval.php
 > $wgMessageCacheType = CACHE_ACCEL;

 > wfGetMessageCacheStorage();
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 93
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 125
 PHP Notice:  Array to string conversion in includes/objectcache/ObjectCache.php on line 133
 Caught exception InvalidArgumentException: Invalid object cache type "Array" requested. It is not present in $wgObjectCaches.
 #0 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(Array)
 #1 includes/objectcache/ObjectCache.php(287): ObjectCache::getInstance(Array)
 #2 [internal function]: ObjectCache::getLocalServerInstance(Array)
 #3 includes/objectcache/ObjectCache.php(181): call_user_func('ObjectCache::ge...', Array)
 #4 includes/objectcache/ObjectCache.php(137): ObjectCache::newFromParams(Array)
 #5 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(3)
 #6 includes/GlobalFunctions.php(3430): ObjectCache::getInstance(3)
 #7 maintenance/eval.php(78) : eval()'d code(1): wfGetMessageCacheStorage()
 #8 maintenance/eval.php(78): eval()
 #9 {main}

This reverts commit 6d99fa5824.

Change-Id: I4d756eb6f66318a12d8cbbc1ba546397be8a29bf
2016-09-29 10:46:48 +02:00
Aaron Schulz
6d99fa5824 Add the main stash, WAN, and server caches to MediaWikiServices
Also removed unused getLocalServerInstance() b/c $fallback logic.

Change-Id: Ifa5f798de10783741a7b079f22d283bb9cb7f4c0
2016-09-28 15:35:44 -07:00