Commit graph

144 commits

Author SHA1 Message Date
Derick Alangi
87b479113b
objectcache: Drop support for $wgObjectCaches['db-replicated']
This was introduced but never really used outside of core[1]. The only
place that used it in core was MainStash setting which under the hood
will use CACHE_DB (SqlBagOStuff).

This patch removes the "db-replicated" key in $wgObjectCaches without
deprecation because it was never really used in the first place and
had a replacement already when it got released, see: T352481.

[1] https://codesearch.wmcloud.org/search/?q=ReplicatedBagOStuff&files=&excludeFiles=&repos=

Bug: T352481
Change-Id: I8e19ee262a64b00742bb9203b2a2610ec0cc39fa
2023-12-08 18:14:37 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Piotr Miazga
8009e9d027 http: MultiHttpClient supports TelemetryHeadersInterface
Introduce a new interface Wikimedia/Http/TelemetryHeadersInterface
that provides telemetry information that could be attached to
HTTP Requests. MultiHttpClient is expecting `telemetry` option
of TelemetryHeadersInterface type.

The MediaWiki/Http/Telemetry implements the interface, therefore
ObjectCache can inject it to RESTBagOStuff, that further injects
it to MultiHttpClient.

Bug: T344926
Change-Id: I59a3f1048c403fe2e4ef0c74353dfe74ff9ca893
2023-09-12 18:05:17 +02:00
Tim Starling
dcb784311b Fix infinite recursion in DBLoadBalancerFactoryConfigBuilder service
When $wgMainCache is CACHE_ANYTHING, recursion proceeds via
LoadBalancer::isPrimaryRunningReadOnly() until the DB server hits its
maximum connection limit. The try/catch blocks in ServiceWiring were no
longer effectively preventing this.

So, inspect the configuration to detect whether the main cache type will
be CACHE_DB, without actually instantiating it.

Bug: T334970
Change-Id: Ibdbc19c45eb20bb85df720669f7ce1d50e3656ff
2023-05-03 13:39:44 +10:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
Timo Tijhof
d16eba24df objectcache: Move main cache to internal "_LocalClusterCache" service
This is preparation for re-using it in the MainWANObjectCache
service in a way that preserves proper dependency injection.

This is related to a declined task (T243233) which proposed offering
it as a non-internal service. It is expected to remain internal, with
public callers generally migrated to WANObjectCache or WRStats or
in some cases to a (not yet implemented) lock manager service.

Bug: T329680
Change-Id: I8af9667529b4896f17a22b66823e7eac859d4229
2023-02-21 21:31:42 +00:00
daniel
7dcfbf2a62 Allow some maintenance scripts to be called without a LocalSettings
Subclasses of Maintenance that can function without database access can
now override canExecuteWithoutLocalSettings to return true.
This is useful for scripts that need to be able to run before or without
installing MediaWiki.

When no config file is present, the storage backend will be disabled.
Any attempt to access the database will result in an error.

NOTE: This makes MediaWikiServices::disableBackendServices() more
comprehensive, to avoid premature failures during service
construction. This change makes it necessary to adjust how the
installer manages service overrides.

The CLI installer is covered by CI, I tested the web installer
manually.

Change-Id: Ie84010c80f32cbdfd34aff9dde1bfde1ed531793
2023-02-16 21:11:33 +00:00
Timo Tijhof
ae944fc38b ObjectCache: Make newFromParams() more suitable for internal re-use
I added the `Config` parameter not so long ago, but this still seems
awkward and insufficient. Instead of requiring the caller in
ServiceWiring to unpack each service, do this here instead to better
separate the concerns between what a service owner should know vs
what maintainers of ObjectCache need to know.

Document the parameter as internal going forward. There exist no
callers Codesearch Everywhere outside these two core files.

Bug: T329680
Change-Id: I37e3fcae0551ba96d480071b2da5166ac966092e
2023-02-15 00:21:37 +00:00
Timo Tijhof
4e596f5112 objectcache: Fix DI for MultiWriteBagOStuff sub caches
Follows-up Ia893ddb36427eb5, which added unreachable code because
is_subclass_of is strictly for matching subclasses.

Test plan:
* Add the following to your LocalSettings:
 $wgParserCacheType = 'mysql-multiwrite';
 $wgObjectCaches['mysql-multiwrite'] = [
	'class' => 'MultiWriteBagOStuff',
	'caches' => [
		0 => [
			'factory' => [ 'ObjectCache', 'getInstance' ],
			'args' => [ CACHE_DB ]
		],
		1 => [
			'class' => SqlBagOStuff::class,
			'loggroup' => 'SQLBagOStuff',
			'server' => [
				'type' => 'sqlite',
				'dbname' => 'wikicache',
				'tablePrefix' => '',
				'variables' => [ 'synchronous' => 'NORMAL' ],
				'dbDirectory' => $wgSQLiteDataDir,
				'trxMode' => 'IMMEDIATE',
				'flags' => 0
			]
		],
	],
	'replication' => 'async',
 ];
* Main_Page fatals without this patch, renders with.

Bug: T327158
Change-Id: I59266726ad72e78c9f99d3cc8f9c8838fabed3b5
2023-01-17 13:18:46 +00:00
Timo Tijhof
d6a8cc4454 objectcache: Fix lack of DI for MultiWriteBagOStuff sub caches
I noticed that things like 'logger', 'keyspace', and 'stats' are
unset in WMF production for the SqlBag embedded in MultiWriteBag.

This is a regression from switching its constructor from
calling ObjectCache::newFromParams to calling ObjectFactory directly.

It happens to have little to no impact on prod, but only thanks to
various coincidences, each of which can change and start to cause
problems.

Bug: T318272
Change-Id: Ia893ddb36427eb5e9bff0a3776a6856d10d01adc
2023-01-13 23:48:47 +00:00
Timo Tijhof
407e1f906c objectcache: Move default 'stats' assignment with the others
Change-Id: Ia3b318d84e7636a0b8b682d4d9e7dca274217ff3
2023-01-11 20:14:27 +00:00
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