Commit graph

133 commits

Author SHA1 Message Date
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
daniel
bf092744c9 PHPUnit: introduce setMainCache
The main object cache is disabled during testing. Some integration tests
need it though. This provides a clean way to enable it, to replace the hacks
that were used so far.

Note that we may want to enable the main cache during testing soon. When
that happens, this method is still useful to disable the cache in certain
tests, and to set a specific cache instance.

Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
2022-07-07 16:25:59 +10:00
Tim Starling
bcfb90cdd7 objectcache: Simplify SqlBagOStuff class configuration
Substantive changes:

* Remove the parameters globalKeyLB and localKeyLB, not needed in
  production, probably not used anywhere.
* Add a "cluster" parameter, for production.
* Don't call markServerDown() in LoadBalancer mode.

Style changes:

* Document config parameters separately from constructor parameters, to
  clarify the role of the wiring normalisation.
* Inject a load balancer from ObjectCache to SqlBagOStuff, using a
  closure to defer construction.
* Clarify the split between LoadBalancer mode and server array mode by
  introducing a useLB property. Use it instead of special shard index
  values and array counts.
* multiPrimaryModeType wasn't needed anywhere and wasn't available in
  the constructor, so it just became a boolean multiPrimaryMode.
* Add a test covering most of the server array (!useLB) branches.

Bug: T212129
Change-Id: Ib097082efb40b514a29a42286dc362f2e3743ee4
2022-05-27 15:04:43 +00:00
Aryeh Gregor
4a52bf553f Use MainConfigNames instead of string literals, #3
This edition brought to you by:

grep -ERIn $(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | tr
"\n" '|' | sed 's/|$/\n/') includes/

I only corrected a fraction of the results provided by that command. I'm
submitting the partial patch now so it doesn't bitrot.

Bug: T305805
Change-Id: If1918c0b3d88cdf90403921e4310740e206d6962
2022-04-26 14:31:26 +03:00
Aaron Schulz
b81b5fee46 installer: make 'db-replicated' an alias for CACHE_DB for sqlite
By default, CACHE_DB and db-replicated are similar, with the main
difference being that db-replicated will prefer to read from a local
replica server rather than the primary server. Setups using sqlite
do not have use for replication logic, since everything uses local
database files. To reduce contention, SqliteInstaller makes CACHE_DB
use a different database file (rather than a table in the main wiki
database file).

This change makes 'db-replicated' reuse the same cache instance.

Tweak ObjectCache::newFromParams() to make ObjectFactory usable.

Also set $wgResourceLoaderUseObjectCacheForDeps to true to avoid
similar contention in SqlModuleDependencyStore.

Bug: T303225
Change-Id: Ia644f35698b69fe340fc1bcae8899c7e332f332d
2022-04-05 12:40:18 -07:00
daniel
a5277ce87f Avoid references to DefaultSettings.
This replaces references to DefaultSettings with
references to config-schema.yaml where appropriate.

NOTE: this does not yet change Setup.php. DefaultSettings.php
remains intact and is still being used.

NOTE: this does not remove usages in the installer, see I5d8843a1062fbf
for that.

Bug: T300129
Change-Id: Ie6152cf510c3be61bc22167ca6d90dfc28910a45
2022-02-22 19:43:50 +01:00
Aaron Schulz
6894873abe objectcache: cleanup config injection and method names in SqlBagOStuff
Dependency inject the write batch size into SqlBagOStuff.

Clean up SqlBagOStuff method names and comments.

Renamed getServerIndexByTag() to getShardServerIndexForTag() and
getServerShardIndexes() to getShardServerIndexes(). Since each of these
servers manages one of the shards, it makes sense to call them "shard
servers".

Change-Id: I9af1f64602dabe85288937ab52c08470138f4c91
2021-08-28 22:52:04 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
jenkins-bot
0aa2c00fde Merge "objectcache: remove ObjectCache::detectLocalServerCache() method" 2021-03-08 05:57:14 +00:00
Aaron Schulz
bd7cf4dce9 Add $wgChronologyProtectorStash and improve $wgMainStash comments
Remove WRITE_SYNC flag from ChronologyProtector since the current
plan is to simply use a datacenter-local storage cluster.

Move the touched timestamps into the same stash key that holds the
replication positions. Update the ChronologyProtector::getTouched()
comments.

Also:
* Use $wgMainCacheType as a $wgChronologyProtectorStash fallback
  since the main stash will be 'db-replicated' for most sites.
* Remove HashBagOStuff default for position store since that can
  result in timeouts waiting on a write position index to appear
  since the data does not actually persist accress requests.
* Rename ChronologyProtector::saveSessionReplicationPosition()
  since it does not actually save replication positions to storage.
* Make ChronologyProtector::getTouched() check the "enabled" field.
* Allow mocking the current time in ChronologyProtector.
* Mark some internal methods with @internal.
* Migrate various comments from $wgMainStash to BagOStuff.
* Update some other ObjectCache related comments.

Bug: T254634
Change-Id: I0456f5d40a558122a1b50baf4ab400c5cf0b623d
2021-03-01 20:34:34 +00:00
Aaron Schulz
05a1a44f86 objectcache: remove ObjectCache::detectLocalServerCache() method
Change-Id: I322e4e8d3117d33a5456c6c4161014c5f3589dd1
2021-02-25 16:29:47 -08:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Aaron Schulz
57325ba3bd objectcache: add statsd key metrics to BagOStuff classes
Update SQL, REST, and redis subclasses to emit call count and
payload size metrics for cache key operations. These metrics
are bucketed by cache key collection (similar to WANCache).

Bug: T235705
Change-Id: Icaa3fa1ae9c8b0f664c26ce70b7e1c4fc5f92767
2021-01-25 14:36:29 -08:00
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