Commit graph

208 commits

Author SHA1 Message Date
jenkins-bot
7139a95efb Merge "objectcache: Use constant for $ttl param default in WANObjectCache::set()" 2019-03-09 00:15:00 +00:00
Andrew Green
b9568e64d9 objectcache: Use constant for $ttl param default in WANObjectCache::set()
Change-Id: I3f936088cd63af4d535d7f46fe5619e8bb866999
2019-03-08 23:48:22 +00:00
jenkins-bot
0d5da03a15 Merge "objectcache: add metrics for WAN cache deletes and check key touches/resets" 2019-03-08 21:40:12 +00:00
Aaron Schulz
74be3a0150 objectcache: move ERR_* constants to IExpiringStore
Also removed unused ERR_* constant from WANObjectCache and fixed
comment in the constructor.

Change-Id: I4377fc3f533113a459b648fad084ba097ff51762
2019-03-08 13:12:01 -08:00
Aaron Schulz
bcf563ef38 objectcache: add metrics for WAN cache deletes and check key touches/resets
Change-Id: I3dc707af53e480b27b7349aca53292f3bb26c45a
2019-03-06 08:48:47 -08:00
Aaron Schulz
b707afa7f4 objectcache: optimize WAN cache key updates during HOLDOFF_TTL
Avoid the ADD operation spam from all threads trying to access
a tombstoned key by checking the interim value cache timestamp.
This also avoids the GET/CAS spam from threads that manage to
get the mutex. If a single thread repeatedly accesses the same
tombstoned value in rapid succession, there will significantly
less cache operation spam.

Do the same for cache updates to keys in the holdoff state
due to "check keys" or the "touchedCallback" function.

Relatedly, fix getWithSetCallback() to disregard interim values
set prior to or at the same time as the latest delete() call.
This can slightly reduce the chance of the cache being behind
replica DBs for a second. It also avoids unit test failures
were a series of deletes and cache access happen at the same
timestamp (via time injection or regular system time calls).

In addition:
* Add PASS_BY_REF flag with backwards compatibility to avoid
  bloating the signature of get()/getMulti() with the new
  tombstone information needed for the above changes.
* Avoid confusing pass-by-reference in getInterimValue() and
  fix use of incorrect $asOf parameter.
* Move some more logic into setInterimValue().
* Update some comments regarding broadcasted operations that
  were not true for the currently assumed mcrouter setup.
* Rename $cValue => $curValue and $versioned => $needsVersion
  for better readability.

Bug: T203786
Change-Id: I0eb3f9b697193d39a70dd3c0967311ad7e194f20
2019-03-04 10:00:29 +00:00
Aaron Schulz
6ee5cdd10b obectcache: split out some WAN cache refresh logic into scheduleAsyncRefresh()
Change-Id: If5f895a0d38cd0d6861125000df4fcfc66f1eeb3
2019-02-27 17:13:40 -08:00
Aaron Schulz
f50ea02994 objectcache: simplify WAN cache unwrap() method by removing FLG_STALE
Instead, make the "high read lag with lockTSE" case just lower FLD_TTL.
This also avoids constant regenerations by threads getting the mutex.

Added logging for TTL adjustments in set() for the lockTSE case.

Also remove some delete() calls from tests that were not needed.

Change-Id: Id7695f0377235e4a2f6e0efc88e870c8a990c3b0
2019-02-27 18:57:45 +00:00
Aaron Schulz
97e0939082 objectcache: improve set() slam prevention in getWithSetCallback()
* Make the SET_DELAY_HIGH_SEC check more sensitive to other types
  of delay, such as increased get() latency. Any such slowness is
  relevant to the set() stampede concern.
* Also added a statsd timing metric for this delay.

Change-Id: I053a73b40dc7e566cc59fc97aeab1a4e1bee0f28
2019-02-22 05:38:52 -08:00
jenkins-bot
8445510fbe Merge "objectcache: avoid duplicate cache sets for missing keys with lockTSE" 2019-02-20 15:37:21 +00:00
Aaron Schulz
2347a15c84 objectcache: avoid duplicate cache sets for missing keys with lockTSE
Follow-up to 70bf85d462 which only affected the case of tombstoned keys.

Improve documentation about getWithSetCallback() options.

Bug: T203786
Change-Id: I683a38f65a79cb98a4ae71cbc5dd88aefe48d022
2019-02-20 02:56:27 +00:00
Aaron Schulz
5414aee495 objectcache: remove dangling WAN cache EventRelayer references
* Remove 'channels' field references from config/setup
* Remove 'relayer'/'channels' field reference in unit tests
* Remove unused DEFAULT_PURGE_CHANNEL class constant
* Also remove long-since bogus 'pool' field references

Follow-up to 4753b0a4ed

Change-Id: If6670ff4e1dccc8ae253a08b46d205601da10024
2019-02-16 20:22:32 -08:00
Aaron Schulz
4753b0a4ed objectcache: remove EventRelayer dependency from WANObjectCache
The use of that class for WAN cache by third parties is extremely unlikely
and the approach was abandoned at WMF in favor of mcrouter (dynomite was
also considered preferable).

Change-Id: I328eb74f21c23db80acc5178bc3c9cf9f823da13
2019-02-16 07:20:38 +00:00
Aaron Schulz
999ff6097d objectcache: refactor and simplify some WANObjectCache code
* Move $value === false checks to isValid()
* Rename $isTombstone variable to avoid confusion with the new value
* Reorganize conditionals around set() calls in doGetWithSetCallback()
* Skip getInterimValue() check when there is no reason to assume anything
  might even be there (e.g. the key is not tombstoned)
* Fold the tombstone case for $useMutex into the ternary

Change-Id: I257110097cffe7fe87c6a9896e875f09d5c936d9
2019-02-13 19:48:44 -08:00
Aaron Schulz
fdb00bf4e2 objectcache: cleanup tombstone/mutex logic in doGetWithSetCallback()
This largely follows-up 6b2f13b055.

* Make the comments and use of temporary variables easier to follow.
* Simplified some conditionals by remove redundant checks.
* Bypass the final set() call if $isTombstone is true. It will almost
  always be rejected due to the tombstone still being there anyway, so
  there is no point in the roundtrips. Also, the most likely case where
  it would succeed is due to the callback taking a long time to run, in
  which case data from the replication lag uncertainty period that the
  tombstone represents would be getting saved to cache with the full
  nominal TTL, which is wrong.

Change-Id: Ic28e15b24f39e128bd72ad4d905edb852bc907aa
2019-02-13 22:57:38 +00:00
Aaron Schulz
70bf85d462 objectcache: avoid duplicate set() calls with lockTSE when no value is in cache
Each thread will still run the callback, but only one will save the value back

Bug: T203786
Change-Id: Idc4738aa005cc44ec0f1adc6dcf2e3f87d0c9480
2019-02-03 02:17:59 +00:00
Aaron Schulz
fe3959e591 objectcache: add more "touchedCallback" comments to WANObjectCache
Change-Id: I55775216154aba0042f7c4cf1cb07336aa4a222e
2019-01-07 18:32:09 +00:00
Aaron Schulz
2190b78987 objectcache: add expiration check callback to WANObjectCache::getWithSetCallback
This is useful when the timestamps to be checked depend on the value or are stored
in the database rather than as check keys.

Change-Id: I81ab08a943ee7d2f96a132d371965501941ed37f
2018-12-21 19:25:26 +00:00
Jakub Vrana
45435d05a5 Change typehint callback to callable
Found by PHPStan.

Change-Id: I09f21da69ad9b9357cee85a47717dbe1bca04070
2018-12-01 10:10:41 +01:00
Aaron Schulz
d2c2bf6553 objectcache: avoid using heavily time-drifted microtime() values in WAN cache
Change-Id: Ifcb9e4b4a1d5adfdaaa6ea505e34956516b871de
2018-10-18 11:42:27 -07:00
Timo Tijhof
2d35c4e997 objectcache: Improve WANObjectCache doc for update strategies
Also add headings to separate docs for deployment/administration,
from docs for developers using an existing instance of it.

Change-Id: Id43c7700564c2979549afa5379f644027fb6585b
2018-08-27 03:46:54 +00:00
Fomafix
0a0d5cb7f7 Fix typos
Bug: T201491
Change-Id: I25a27d11faabe2f5fa02950c7a4fb58b13fb3662
2018-08-14 09:52:19 +00:00
jenkins-bot
55ffac2024 Merge "objectcache: add "epoch" parameter to WANObjectCache" 2018-08-08 23:16:40 +00:00
Aaron Schulz
4af7fbd76a objectcache: add "epoch" parameter to WANObjectCache
This can be used to discard all values before a certain point in
time, such as periods of severe network problems or misconfiguration
that resulted in missed purges.

Change-Id: I612db8f91a5960b912e9f35645a3d3872df47460
2018-08-06 16:43:50 -07:00
Aaron Schulz
de51ba46f6 objectcache: switch WANObjectCache process cache to MapCacheLRU
Change-Id: I60d8de99e9590bfef6009f133723bb10d5837c52
2018-07-18 17:57:00 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Aaron Schulz
626c5f6972 objectcache: change "miss" to "renew" in metric name for preemptive refreshes
This will usually let one distinguish asynchronous preemptive cache refreshes
from synchronous value recomputations due to actual cache misses.

Change-Id: I3424a89cc96a12fe283460eeaf722ee0cf299534
2018-06-20 15:23:35 +00:00
Max Semenik
1e680456b4 Get rid of call_user_func(_array)(), part 3
Also cleaned up nearby code in a couple places.

Change-Id: Ibf44ee7c0ceb739d7e79406e4ff39303c316e285
2018-06-10 02:21:24 +00:00
Aaron Schulz
bde2c5aa9e objectcache: clean up language about expiration/invalidation
Change-Id: I593e7bf9bd4f7fbb615d3d164e77273bd4033dde
2018-06-05 23:45:19 +00:00
jenkins-bot
966e34619b Merge "objectcache: add setMockTime() method to BagOStuff/WANObjectCache" 2018-06-01 13:19:24 +00:00
Aaron Schulz
acace9a049 objectcache: add setMockTime() method to BagOStuff/WANObjectCache
Change-Id: I3e5760814fb7dbe628eb0d979d690c3275fc3c15
2018-06-01 03:46:58 +00: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
Aaron Schulz
5c55f5d912 objectcache: improve TTL reduction warning log entries
Add "lag" and "age" parameters for more context

Change-Id: Iea029e78d4c0bbec0e4334de4fbe7780b1bea524
2018-02-22 10:07:40 -08:00
Aaron Schulz
8e89785e25 objectcache: add IExpiringStore::TTL_SECOND constant
Change-Id: Iec59ce72f3dbb0de68c8f6704d86f1522f86827e
2018-02-16 14:23:49 -08:00
Aaron Schulz
32907f4f99 objectcache: improve WANObjectCache reap method comments
Change-Id: Icec0846b0e66229af39bb819d75144734fd111bf
2018-02-15 11:53:45 -08:00
Aaron Schulz
d9f0a5f685 objectcache: remove unused constant and expand on a comment
Change-Id: I3342497d657291d20325a3d87cc634f53d7776c4
2018-02-07 16:15:32 -08:00
Aaron Schulz
7206bd3468 objectcache: use region prefixes for mcrouter-backed WAN cache
This allows for mcrouter to have proper cross-DC and intra-DC timeouts.

Change-Id: If48f740f435d266a2050839f34611c0c8f36b3a7
2018-02-01 10:09:44 -08:00
Aaron Schulz
9a4dc4b755 objectcache: add some WANObjectCache comments to set() and delete()
Change-Id: I527f1244c5c7cece888ace25e7a01653cf2b9542
2018-01-29 17:29:20 -08:00
Umherirrender
23ef520a1c Improve some parameter docs
Change-Id: I31e983d7ac287158101b18ad95779d83537302a2
2018-01-07 11:39:08 +01:00
Aaron Schulz
32c4831cf1 objectcache: fix getMultiWithUnionSetCallback() doc
Change-Id: I5700ff8ccbe2ef3aa6730e20bdc17314bceade42
2017-12-20 14:24:43 -08:00
Aaron Schulz
b62327eee7 objectcache: add another example case to WANObjectCache::getWithSetCallback()
Change-Id: I4beb1441790f5371d9fe55ca05cd17dc9fcdcf80
2017-12-15 12:05:35 -08:00
Lucas Werkmeister
5f5b79eea2 Remove unused 'pool' param from WANObjectCache::newEmpty()
The 'pool' parameter was removed in commit 09a0a5e4f6 (change
I5631eb1b13), retaining it in this helper method just confuses people
who read the code.

Change-Id: I7907a1fc4c613362d74e9045bc7dc41bbd9bf815
2017-12-11 18:30:55 +01:00
Aaron Schulz
78468c0147 objectcache: various cleanups to WANObjectCache
Change-Id: Ibc3c7e59b47b4f9b982176f81dff9f81d99de460
2017-12-01 15:25:40 -08:00
Aaron Schulz
e3b6f7ef4d objectcache: add example use case to WANObjectCache::getMultiCheckKeyTime()
Change-Id: I874070d2f770be7f9e06c381b2413f6e133418b8
2017-12-01 14:29:56 -08:00
Aaron Schulz
b29ee7a960 objectcache: add WANObjectCache::getMultiCheckKeyTime method
Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
2017-12-01 21:45:32 +00:00
jenkins-bot
bd78292e75 Merge "objectcache: Run preemptive WAN cache refreshes post-send" 2017-12-01 19:08:31 +00: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
976cb7035b objectcache: fix a few documentation mistakes
* Fix useInterimHoldOffCaching() description
* Mention when staleTTL and graceTTL where added

Change-Id: Iea24b77f6816251e9dac814dc57f6a44382a3cea
2017-12-01 06:16:16 +00:00
Aaron Schulz
e90eafdf61 objectcache: Make WANObjectCache interim caching not interfere with ChronologyProtector
Also removed useless line from testLockTSE(). That would have needed
to be using $this->internalCache and those locks are freed immediately.

Bug: T180035
Change-Id: Ida1a923f779aaf8410da76643457d2200da6cb20
2017-11-30 23:54:22 +00:00
Aaron Schulz
ee14393358 objectcache: use INTERIM_KEY_TTL constant in WANObjectCache for readability
Change-Id: I13936397def11a13849fe14491b752dd797f6759
2017-11-28 21:59:28 -08:00