Commit graph

791 commits

Author SHA1 Message Date
Derick Alangi
cc7f3757b5
objectcache: Drop SerializedValueContainer::isUnified
This method was deprecated in 1.42 and now can be dropped from
MW core.

In addition, some cosmetic changes in this patch:
* Type-hint `isSegmented()` to return bool.

Bug: T344521
Change-Id: Idace008e9a961953041bd21b499bfec3f8226142
2024-04-23 15:49:32 +01:00
Aaron Schulz
ec90b543ab objectcache: remove deprecated QOS_EMULATION_SQL constant
Change-Id: I8dec3f73faec44a00ef12614039c323dd07b695f
2024-03-27 15:10:21 -07:00
Derick Alangi
b3b491d292
objectcache: Deprecate SerializedValueContainer::isUnified()
Since the method for constructing a serialized value container via
`newUnified()` has been removed in Id5179be032d45732db659d506d2781,
its corresponding `isUnified()` method is now obsolete and this
patch deprecates it to be removed in 1.43.

Bug: T344521
Change-Id: I5a90028c2a596dfec9a1df306cc9d0ab90dfedd6
2024-03-19 13:28:51 +03:00
jenkins-bot
802c0c0d74 Merge "objectcache: Drop SerializedValueContainer::newUnified()" 2024-03-18 13:46:14 +00:00
Tim Starling
bd6ed0acdf Fix some spelling errors
Change-Id: I3632ce1ae00527f806652deb96cafb473aed3dcf
2024-03-18 20:58:11 +11:00
Derick Alangi
77ec7bf998
objectcache: Drop SerializedValueContainer::newUnified()
This patch deletes the `::newUnified()` method from this class, it's
already hard deprecated and due for removal.

Bug: T344521
Change-Id: Id5179be032d45732db659d506d2781752f03f8be
2024-03-18 12:50:22 +03:00
Umherirrender
f3524224f0 build: Fix line indents
Fixed SkinModuleTest::provideGetFeatureFilePathsOrder as nesting of
arrays for parameters is wrong

Change-Id: I9875008adf62d284c48662ebfbd245d72e5be064
2024-03-11 00:14:16 +01:00
Derick Alangi
dc91d2d6c5
objectcache: Migrate BagOStuff from StatsdD to StatsLib
This patch migrates BagOStuff metrics capture from StatsdD to
StatsLib. `updateOpStats()` definition significantly changed with
this migration thereby affecting the changes in the test case.

What we tried to do in the test is to assert that the metrics
match the StatsLib equivalent ones which is the new format we're
using and that the values corresponding to the samples are also
in the range of values written to the cache.

Notes
=====

* And the cache key also uses underscore (_) instead of (.) because
  of StatsLib as well.
* The most important thing which is tested is that the keys inserted
  into the cache are all there and correspond to their values. The way
  we do this is observe the metrics stream after `->flush()`.

Bug: T356062
Change-Id: Ia6c14746de5bddeaca7917c76f1c9d1e100ae2b2
2024-02-27 19:23:10 +03:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
jenkins-bot
41bb695a68 Merge "objectcache: Soft deprecate ReplicatedBagOStuff" 2023-12-21 00:59:21 +00:00
Bartosz Dziewoński
a9305ab8d4 ServiceWiring: Replace $wgCommandLineMode checks with MW_ENTRY_POINT (follow-up)
Follow-up to 94bbc1db01,
I missed the relevant documentation.

Bug: T313841
Change-Id: Icc63d8ad4b9ebb5a88913b16c6f97af3d64886eb
2023-12-19 22:02:49 +01:00
Derick Alangi
a83f4dccca objectcache: Soft deprecate ReplicatedBagOStuff
The MainStash use case is already covered by the use of CACHE_DB
(SqlBagOStuff) and at this point, we no longer have any uses of
ReplicatedBagOStuff. So, it can be deprecated and removed.

Bug: T352481
Change-Id: Id691eafd60040792ae8ab767ee6013c1681461c1
2023-12-19 16:14:34 +00:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
Ammarpad
5c6684b970 objectcache: rename TINY_POSTIVE constant to TINY_POSITIVE
More intuitive and saving one letter is not worthwhile here

Change-Id: Ibab9bc8262a4c0252c7f8471deb276d9df76dae3
2023-12-09 09:22:31 +00:00
Derick Alangi
b4a02f37ed
objectcache: Hard-deprecate BagOStuff::setNewPreparedValues()
Per code search, no longer used anywhere:
https://codesearch.wmcloud.org/search/?q=setNewPreparedValues&files=&excludeFiles=&repos=

Change-Id: I38e12610112aad7f7e9e59b348aff9d80eb78254
2023-11-22 16:04:58 +01:00
Amir Sarabadani
89799e0e20 objectcache: Stop using wfGetDb() in documentation
Change-Id: I2bff59492205ee4709562a0f732619a95a02814c
2023-10-31 13:43:20 +01:00
Aaron Schulz
7e8513e58a objectcache: fix BagOStuff::watchErrors() comment
Change-Id: I60e2fcd32daad2e0f4d6db89882a03313fc6b7c4
2023-10-04 13:31:15 -07: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
Derick Alangi
223aeae06d objectcache: Hard deprecate SerializedValueContainer::newUnified()
Introduced in I0667a02612526d8ddfd91d5de48b6faa78bd1ab5 (in 2019)
and used for consistency by default in BagOStuff::set(), even for the
99% of values that don't need segmentation.

The method was removed from use in I830c78a50efd1ba83fbe2aa39c1, due
to the overhead of SerializedValueContainer being undesirable, so there
is no longer a use case for it. If a value doesn't need segmentation,
it shouldn't be wrapped in SerializedValueContainer.

See https://codesearch.wmcloud.org/search/?q=SerializedValueContainer%3A%3AnewUnified&files=&excludeFiles=&repos=

Bug: T344521
Change-Id: Id1c283201cd42c4eabac8ef4d949329959016b18
2023-08-18 21:29:12 +00:00
Tim Starling
7f00b40340 WANObjectCache: don't set a hold-off when the cache is empty
When getWithSetCallback() is called with check keys, if the keys are
missing, a check key is inserted with the current time, as if
touchCheckKey() were called. This causes cache misses for
HOLDOFF_TTL = 11 seconds. This seems unnecessary since in the case of
an empty cache, there is no expectation of replication delay.

However, it's reasonable for it to be a cache miss when the check key is
missing, and a cache hit subsequently, so we do need to add a purge
value.

So, in getWithSetCallback(), set the holdoff to zero when inserting a
purge value.

Also, use a holdoff of zero when initialising a missing touch key in
getCheckKeyTime().

Bug: T344191
Change-Id: Ib3ae4b963816e5b090e87e4cb93624afefbf8058
2023-08-15 16:37:10 +00:00
Derick Alangi
0393cd20b7 objectcache: Remove unused $walltime parameter in WANObjectCache
Introduced in I4060b19583cdfd9fa36c91d7014441eeef4b3609 and removed
in I62ec1c269ffb87eca03003b3f3c5336ee562a7b3 but the parameter was
not cleaned up.

This patch removes the parameter from the method and callers including
other methods that passed this in.

NOTE: These are all private methods so we can go ahead and remove this
paramter without deprecation.

Change-Id: Ifa76334e671ba8a8577be886bd407a6ac8038fa6
2023-08-09 20:34:32 +00:00
Derick Alangi
2abbb1a774 objectcache: Remove IExpiringStore interface
Interface was deprecated since 1.35 in favor of ExpirationAwareness
or StorageAwareness interfaces. No longer used anywhere, see dependent
patches.

Depends-On: Ida557b3180eb5e7ebae46968142b4f154f26ffbc
Depends-On: I3d6fbf535560655472ade27c37b0e42b3e11a535
Depends-On: I2b0a669d41d9e6a8a859cba314c0e9e4c0ef40d7
Depends-On: I776040c2c8f61e25ae986e93bb1975fdd8bf9dd5
Change-Id: I9c5ffa9f51aec6356e3e27458fd098a37cd754ad
2023-08-08 20:15:03 +00:00
Timo Tijhof
75aec3686a objectcache: Reduce boilerplate and indirection around makeKey()
== Background

Most of this was introduced in commit 5c335f9d77 (I1eb897c2cea3f5b7).
The original motivation was:

* Ensure wrappers like MultiWriteBagOStuff naturally do the right
  thing. In practice, makeKey() results are interchangeable, with
  the most contrained one (Memcached) also generally used as the first
  tier. However, this is not intuitive and may change in the future.
  To make it more intuitive, the default implemention became known
  as "generic", with proxyCall() responsible for decoding these,
  and then re-encoding them with makeKey() from the respective
  underlying BagOStuff. This meant that MultiWriteBag would no longer
  use the result of the Memcached-formatted cache key and pass it
  to SqlBagOStuff.

* Allow extraction of the key group from a given key cache,
  for use in statistics.

Both motivations remains valid and addressed after this refactor.

== Change

* Remove boilerplate and indirection around makeKey from a dozen
  classes. E.g. copy-paste stubs for makeKey, makeKeyInternal, and
  convertGenericKey.

  Instead, let BagOStuff::makeKey and ::makeKeyInternal hold the
  defaults. I believe this makes the logic easier to find, understand,
  and refer to.

  The three non-default implementations (Memcached, WinCache, Sql)
  now naturally reflect what they are in terms of business logic,
  they are a method override.

  Introduce a single boolean requireConvertGenericKey() to let the
  three non-default implementations signal their need to convert
  keys before use.

* Further improve internal consistently of BagOStuff::makeKeyInternal.

  The logic of genericKeyFromComponents() was moved up into
  BagOStuff::makeKeyInternal. As a result of caling this directly
  from BagOStuff::makeKey(), this code now sees $keyspace and $components
  as separate arguments. To keep the behaviour the same, we would
  have to either unshift $keyspace into $components, or duplicate
  the strtr() call to escape it.

  Instead, excempt keyspace from escaping. This matches how the most
  commonly used BagOStuff implementations (MemcachedBag, and SqlBag)
  already worked for 10+ years, thus this does not introduce any new
  responsibility on callers. In particular, keyspace (not key group)
  is set by MediaWiki core in service wiring to the wiki ID, and so
  is not the concern of individual callers anyway.

* Docs: Explain in proxyCall() why this indirection and complexity
  exists. It lets wrapping classes decode and re-encode keys.

* Docs: Explain the cross-wiki and local-wiki semantics of makeKey
  and makeKeyGlobal, and centralise this and other important docs
  about this method in the place with the most eye balls where it is
  most likely seen and discovered, namely BagOStuff::makeKey.
  Remove partial docs from other places in favour of references to this one.

  Previously, there was no particular reason to follow `@see IStoreKeyEncoder`
  much less to know that it holds critical that communicate the
  responsibility to limit the key group to 48 chars.

* Docs: Consistently refer to the first component as the "key group",
  thus unifying what was known as "key class", "collection",
  "key collection name", or "collection name".

  The term "key group" seems to be what is used by developers in
  conversations for this concept, matching WMF on-boarding docs and
  WMF's Grafana dashboard for WANObjectCache.

Change-Id: I6b3167cac824d8bd8773bc66c386f41e4d380021
2023-08-03 10:42:56 +02:00
Aaron Schulz
92a1639dcf objectcache: remove deprecated BagOStuff::addBusyCallback() method
Change-Id: I523faa6c8c516edd9f6cd81e9275c3a54a169818
2023-08-01 22:36:21 +01:00
jenkins-bot
0d62f5f661 Merge "objectcache: Fix foreach warning in ReplicatedBagOStuff" 2023-07-31 09:56:41 +00:00
Timo Tijhof
83f2f714c2 objectcache: Remove unused WRAPPER_COLLECTION_CALLBACK feature
This was introduced for use by WANObjectCache, however, this never
worked in practice.

The feature only influences determineKeyPrefixForStats(), which in
turn is only called by MediumSpecificBagOStuff::updateOpStats, which
in turn is exclusively called within BagOStuff subclasses that aren't
used with WANObjectCache (RESTBag, RedisBag, SqlBag).

The next commit simplifies BagOStuff::makeKey, which can make a bigger
impact if this feature doesn't need to be supported.

During drafting of the next commit, I found that the feature doesn't
appear to work well in practice, because getCollectionFromSisterKey
did not account for mcrouter-style route prefixes, as inserted by
makeSisterKey().

Change-Id: Iecea959c88abbd7a0a17b92c1c4d854602748280
2023-07-24 05:01:17 +01:00
Timo Tijhof
d51b99941c objectcache: Fix foreach warning in ReplicatedBagOStuff
When enabling $wgResourceLoaderUseObjectCacheForDeps in I79299f80fe06,
I get the following warning:

> PHP Warning: Invalid argument supplied for foreach()
> > BagOStuff.php(772): MWExceptionHandler::handleError()
> > ReplicatedBagOStuff.php(218): BagOStuff->proxyCall()
> > KeyValueDependencyStore.php(81): ReplicatedBagOStuff->setMulti(array, …)
> > ResourceLoader.php(547): KeyValueDependencyStore->storeMulti()
> > …

This is happening because setMulti is configured as RES_KEYMAP,
which sets the expectation of an array return value, when actually
BagOStuff::setMulti returns bool.

There is similar code in MultiWriteBagOStuff, which already used
RES_NONKEY correctly.

Change-Id: Ifc9db0758f0e150862d163eb7a4df03042f54e83
2023-07-17 18:08:24 +01:00
Matěj Suchánek
676fcf4379 Replace substr with cleaner string methods
Use str_starts_with, str_ends_with or string offset where appropriate.

This fixes a bug in MimeAnalyzer where the "UTF-16LE" header could not
be identified because of wrong constant. This is the exact type of bug
that the new functions can avoid.

Change-Id: I9f30881e7e895f011db29cf5dcbe43bc4f341062
2023-05-20 15:40:21 +02:00
Aaron Schulz
731af1e059 objectcache: deprecate ATTR_EMULATION/QOS_EMULATION_SQL
QOS_DURABILITY_RDBMS can be checked instead

Bug: T279977
Change-Id: I42a00275995dd855c60c8f45a01d2da11bab7029
2023-05-17 19:36:35 +00:00
Amir Sarabadani
8c33cfa728 objectcache: Remove keyHigh* attributes from WANObjectCache
Unused since Ie3a2215d3325f

Change-Id: I5a7b1164ba4f06913ba578bc418a94a8935b25e6
2023-05-16 23:01:55 +02:00
Umherirrender
eded494d83 objectcache: Remove stat keys also from README
No longer used since f83f75d3e6

Change-Id: I663418469fcb46c97bb14267877d038adbf737c2
2023-05-05 19:22:28 +02:00
Timo Tijhof
f83f75d3e6 objectcache: Remove WANObjectCache's internal cool-off bounce feature
Bug: T203786
Bug: T302623
Bug: T321634
Change-Id: Ie3a2215d3325fe7290658e1013adaac4f4565884
2023-04-29 01:23:56 +01:00
Tim Starling
b2f3accb0f Simplify RedisBagOStuff::incrWithInit
* Combine the scripts.
* Use luaEval() to reduce the network overhead.
* Remove "r" prefix on local variables

Change-Id: I7c3097e18dd8570023d9a711327e139e395dfbbb
2023-03-27 12:13:03 +11:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
Tim Starling
580ec48e5b Fix more PHPStorm inspections (#2)
* Illegal string offset and invalid argument supplied to foreach, due to incorrect type information
* Array internal pointer reset is unnecessary
* $hookData unused since MW 1.35 due to incomplete revert
* array_push() with single element
* Unnecessary sprintf()
* for loop can be replaced with str_repeat()
* preg_replace() can be replaced with rtrim()
* array_values() call is redundant
* Unnecessary cast to string
* Unnecessary ternary. Often the result relies on short-circuit evaluation, but I find it more readable nonetheless.

Change-Id: I4c45bdb59b51b243fa96286bec8b58deb097d707
2023-03-25 00:19:58 +00:00
jenkins-bot
7c92610ada Merge "Fix some typos" 2023-03-23 12:20:11 +00:00
jenkins-bot
253d96d21b Merge "objectcache: fix RedisBagOStuff::incrWithInit() return value" 2023-03-22 05:31:06 +00:00
jenkins-bot
241fa13345 Merge "objectcache: fix connections in RedisBagOStuff multi methods" 2023-03-22 05:17:30 +00:00
jenkins-bot
3aa0cbe404 Merge "objectcache: remove FLD_GENERATION_TIME field from WANCache entries" 2023-03-22 05:00:34 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
Aaron Schulz
641a0dfbbf objectcache: fix connections in RedisBagOStuff multi methods
Previously, a bug resulted in a connection per key for getMulti()
and similar methods. RedisConnRef instances are treated as if they
belong to different callers, so RedisConnectionPool::getConnection
cannot be used in naive loops to build (key => RedisConnRef) arrays.

Create a RedisBagOStuff::getConnectionsForKeys() method to properly
get connection handles for multiple keys and reduce code duplication.

Bug: T332371
Change-Id: Id58b9ac61c59277f7cd8f17821c1905b930b02cb
2023-03-20 18:17:48 -07:00
Aaron Schulz
199db2e921 objectcache: fix RedisBagOStuff::incrWithInit() return value
Return the new value as per the base class. Also, avoid use
the "setex" command when the TTL is zero (which is invalid).

This fixes a failing test in RedisBagOStuffIntegrationTest.

Follow-up to 79ea356f1b.

Change-Id: Ia33bed959928788252fdf7bf37d56fa9e5946765
2023-03-20 15:51:25 -07:00
jenkins-bot
0f31699b07 Merge "objectcache: improve WANObjectCache::worthRefreshExpiring() scalability" 2023-03-19 03:50:41 +00:00
Aaron Schulz
8a95567fd7 objectcache: remove FLD_GENERATION_TIME field from WANCache entries
This value was unused and rarely set. LOW_TTL should be sufficient to
avoid stampedes without needing to use the generation time cost.

Change-Id: I62ec1c269ffb87eca03003b3f3c5336ee562a7b3
2023-03-19 03:32:29 +00:00
Aaron Schulz
5b349cb4d7 objectcache: improve WANObjectCache::worthRefreshExpiring() scalability
Make it use a power function and increase LOW_TTL from 30 to 60 so
that higher regeneration times (e.g. 1+ seconds) are more resistant
to regeneration stampedes.

Also fix code that was using LOW_TTL instead of TTL_LAGGED.

Bug: T331914
Change-Id: I2c0b35fbbce6b5a692b6d7885a2a921d7ffdd031
2023-03-18 00:23:32 +00:00
Aaron Schulz
79ea356f1b objectcache: make RedisBagOStuff::incrWithInit() atomic via Lua
Change-Id: Iccddf0f4a0c944ea57b9f570e91c9ab4891bcab1
2023-03-14 22:31:53 +00:00
Aaron Schulz
a1cb96ee19 objectcache: remove deprecate BagOStuff::incr() method
Change-Id: I107c04e05585c975dc37ce402746a4671f2f43b5
2023-03-10 13:31:34 -08:00
Aaron Schulz
7fe2000005 objectcache: remove deprecate BagOStuff::decr() method
Change-Id: I8284289f3d37c763eabdecba9b8d0c4beed4e5de
2023-03-10 13:07:20 -08:00