objectcache: optimize WAN cache key updates during HOLDOFF_TTL
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 27 Feb 2019 01:04:24 +0000 (17:04 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 4 Mar 2019 10:00:29 +0000 (10:00 +0000)
commitb707afa7f485e4908a069931f689852c493bac8b
treeb3deea83f366a53cb94e2a5eab4086a64b95cd43
parent9b4461c1b8027049d575bc66b45a1545bd506188
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
includes/libs/objectcache/WANObjectCache.php
tests/phpunit/includes/Storage/NameTableStoreTest.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php