Commit graph

374 commits

Author SHA1 Message Date
Aaron Schulz
c2150cdc3c objectcache: make BagOStuff::changeTTL() more atomic
Change-Id: I86493498ef3359046b12d51795cf7875af6c3a6c
2019-03-20 09:46:33 -07:00
Aaron Schulz
560774814d Make BagOStuff::incr abstract to discourage bad implementations
Callers should really use atomic TTL-preserving implementations
so that calling code works correctly. The old default base class
code did not do either.

Change-Id: Icf66db05e48b86c8d481dc08dc9041bd1fa6dbe9
2019-03-18 16:09:26 -07:00
jenkins-bot
4d1478c76f Merge "Fix WatchedItemStore last-seen stashing logic" 2019-03-15 21:46:07 +00:00
Aaron Schulz
6612673b20 objectcache: make BagOStuff::add() abstract to discourage non-atomic versions
Change-Id: If3c3fbf21207b0c74cad8a29fa5bbabe0af896e3
2019-03-15 00:38:28 +00:00
Aaron Schulz
fea9ebbd6f objectcache: make the BagOStuff::add() operation more atomic for WinCache
Change-Id: I285ed9a7d0894adfe29b0bdc106b7518f655ba45
2019-03-15 00:38:18 +00:00
Aaron Schulz
1899a82c80 objectcache: make the BagOStuff::add() operation more atomic for APC
Change-Id: Ifb72b1c17439c80e6d431d5fe2ec9ad9437e3ad7
2019-03-15 00:38:11 +00:00
Aaron Schulz
e2b03d5d30 objectcache: add BagOStuff::deleteMulti() method for consistency
Also:
* Make the BagOStuff tests actually pass for memcached and sql
* Add more unit tests for BagOStuff
* Make SqlBagOStuff::add() more atomic

Change-Id: Ic1eec0990a66b595b57c646498c3bd229442230c
2019-03-14 23:12:30 +00:00
Aaron Schulz
588a464682 Fix WatchedItemStore last-seen stashing logic
This should be the "last revision seen" timestamp, which is
different than the "first revision not seen" timestamp in the DB.

Also make sure that SpecialWatchlist accounts for the stash values.

Relatedly, better document the callback usage in BagOStuff::merge().

Change-Id: I98b03a5cd40fec5b4a2633d499ff77079d264e3c
2019-03-14 14:52:29 -07:00
Aaron Schulz
547f207fa6 objectcache: make the $flags argument appear more consistently in BagOStuff
Change-Id: I08879ede5e9f0ab227497bb1dab89ea61b65abce
2019-03-12 22:55:18 +00:00
jenkins-bot
501ca07005 Merge "Streamline code involving .= string concatenations" 2019-03-11 12:39:04 +00:00
Thiemo Kreuz
cfda5e7efa Streamline code involving .= string concatenations
This was inspired by Idbbdb31. Originally, I did a regex search for
code that did string concatenations like `$str = $str . …` and replaced
them all with the .= operator. A duplicate patch was uploaded by another
author. I rebeased this patch on top of the other, which leaves all
the manual optimizations I did.

Change-Id: Iaeb73d9c63302c9409bd1051b91e0d2bd77788a7
2019-03-11 12:43:45 +01:00
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
jenkins-bot
dbe54b46e6 Merge "objectcache: move ERR_* constants to IExpiringStore" 2019-03-08 21:40:04 +00:00
Aaron Schulz
9fe2e8eb7e objectcache: remove BagOStuff::modifySimpleRelayEvent()
This was only there as part of EventRelayer use by WAN cache, which
has since been removed. No other usage really makes sense.

Change-Id: I201425bb88739dd8febbfbc3d24a15e6d3d88d9c
2019-03-08 13:17:26 -08: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
jenkins-bot
db1f41172f Merge "objectcache: add $flags argument to BagOStuff::delete()" 2019-03-08 00:51:25 +00:00
jenkins-bot
a8caf02564 Merge "objectcache: fix comment typo for addBusyCallback()" 2019-03-07 23:58:51 +00:00
Aaron Schulz
5dd409cd38 objectcache: add $flags argument to BagOStuff::delete()
This makes it consistent with set() and merge(). Also, one subclass
was already using the field in this manner.

Clean up the code related to WRITE_SYNC in SqlBagOStuff.

Change-Id: I0fb84f4475311889507d3ef98afd4476fb81174f
2019-03-07 13:15:29 -08:00
Aaron Schulz
84cc936ab6 objectcache: fix comment typo for addBusyCallback()
Change-Id: I05a4d84d40b81ba25b89238b36cdb64c71e2de1e
2019-03-07 12:25:02 -08:00
Fomafix
f17c297624 Use short assignment operator in PHP
Use
  $var .= $foo
instead of
  $var = $var . $foo

Change-Id: I5dcdd7278e618c14968e5ac1fb8ea43ac2200deb
2019-03-07 09:55:49 +01: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
jenkins-bot
855787ca31 Merge "objectcache: Fixes WinCache increment losing TTL." 2019-02-06 00:51:12 +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
jenkins-bot
d24cb5054c Merge "objectcache: add expiration check callback to WANObjectCache::getWithSetCallback" 2018-12-21 22:42:41 +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
Juan Osorio
7572c9097a objectcache: Fixes WinCache increment losing TTL.
WinCache incr function adds a number to the value of a key, but
in the process loses the Time To Live of the cache entry. This
fixes such bug.

Bug: T211914
Change-Id: I02889e63b95188b8d5123a9788a020ca3aa7d1b1
2018-12-13 14:36:06 -08:00
Juan Osorio
5bae617f0f objectcache: Fix WinCache keys longer than 150 chars
Adds MD5 hashing to the generation of keys for WinCache. This
fixes the issue of keys (e.g. sub-headings) longer than 150
characters.

Bug: T210794
Change-Id: Ieabf6b014a0660198077a23760a05564bf268535
2018-12-12 18:48:21 +00:00
jenkins-bot
d0081b3504 Merge "RedisBagOStuff: Do not pass unused parameter" 2018-12-02 00:20:08 +00:00
jenkins-bot
97b467d8ac Merge "Remove unused use in anonymous function" 2018-12-02 00:00:53 +00:00
jenkins-bot
448386e304 Merge "Change typehint callback to callable" 2018-12-02 00:00:32 +00:00
Jakub Vrana
ff09f00b6a RedisBagOStuff: Do not pass unused parameter
Found by PHPStan.

Change-Id: I20fe8ca713362d115d620a22e04c5dc984ae279e
2018-12-01 23:54:48 +00:00
Jakub Vrana
ff48659011 Remove unused use in anonymous function
Found by PHPStan.

Change-Id: I88247514703820a6afb7c9861dcf64326aa32d19
2018-12-01 10:17:34 +01:00
Jakub Vrana
45435d05a5 Change typehint callback to callable
Found by PHPStan.

Change-Id: I09f21da69ad9b9357cee85a47717dbe1bca04070
2018-12-01 10:10:41 +01:00
Jakub Vrana
3fc3b9e578 Change typehint callback to callable
Found by PHPStan.

Change-Id: I77877a18131bd69996bad07f2ee1c5f3ba3ba2e7
2018-12-01 10:02:48 +01:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02: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