Commit graph

76 commits

Author SHA1 Message Date
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
9ea5cfe377 Make sure docs encourage __METHOD__ use for begin/commit
Change-Id: Id9c2d1b30f9dd758b418894b5751556daff20f0e
2015-12-23 17:23:15 -08:00
Timo Tijhof
5d5b269e0e resourceloader: Migrate from msg_resource table to object cache
MessageBlobStore class:
* Make logger aware.
* Log an error if json encoding fails.
* Stop using the DB table. WANObjectCache supports everything we need:
  - Batch retrieval.
  - Invalidate keys with wildcard selects or cascading check keys.
* Update tests slightly since the actual update now happens on-demand as
  part of get() instead of within updateMessage().

ResourceLoader class:
* Remove all interaction with the msg_resource table. Remove db table later.
* Refactor code to use a hash of the blob instead of a timestamp.
  Timestamps are unreliable and roll over too frequently for message blob store
  because there is no authoritative source. The timestamps were inferred based on
  when a change is observed. Message overrides from the local wiki have an
  explicit update event when the page is edited. All other messages, such as
  from MediaWiki core and extensions using LocalisationCache, have a single
  timestamp for all messages which rolls over every time the cache is rebuilt.
  A hash is deterministic, and won't cause needless invalidation (T102578).
* Remove redundant pre-fetching in makeModuleResponse().
  This is already done by preloadModuleInfo() in respond().
* Don't bother storing and retreiving empty "{}" objects.
  Instead, detect whether a module's message list is empty at runtime.

ResourceLoaderModule class:
* Make logger aware.
* Log if a module's message blob was not preloaded.

cleanupRemovedModules:
* Now that blobs have a TTL, there's no need to prune old entries.

Bug: T113092
Bug: T92357
Change-Id: Id8c26f41a82597e34013f95294cdc3971a4f52ae
2015-12-08 14:02:38 +00:00
Timo Tijhof
8065936ec3 objectcache: Make protected WANObjectCache::makePurgeValue non-static
It was already used everywhere as non-static via $this.
This is needed in order to allow MessageBlobStore unit tests
to disable the holdoff via a mock (mocks can't override static methods).

Change-Id: I3aad5b6e780addf1b6ce9de56c81b91f5ab358b2
2015-12-06 14:34:03 +00:00
Aaron Schulz
ba06ccb394 Fix get()/getMulti() check key race condition in WANObjectCache
If a set() happened around the exact same time as check key was
initialized via get(), the curTTL in future get() calls could
sometimes be 0 instead of a negative value, even though hold-off
should apply.

Change-Id: Ide1fd65112aff425a4798e2ec406d71f2a8e84a7
2015-12-04 14:46:18 -08:00
jenkins-bot
df629219aa Merge "Make getCacheSetOptions() and WAN cache handle broken replication" 2015-12-03 12:24:37 +00:00
Aaron Schulz
cb8842dbab Make getCacheSetOptions() and WAN cache handle broken replication
TTL_LAGGED now triggers if the slave or I/O threads stopped

Change-Id: I5e7bf2d33b8d3a60182ec53a93d65f7e55f02222
2015-12-02 15:38:23 -08:00
jenkins-bot
cd42bfbe24 Merge "Fix relayPurge() IDEA warnings" 2015-12-02 22:41:43 +00:00
Aaron Schulz
2f1f8d9bf2 Fix relayPurge() IDEA warnings
Change-Id: I6e6c0f611c344eab79350468552a2ccbf4cd1d18
2015-12-02 14:31:51 -08:00
Timo Tijhof
ff1bd769ef objectcache: Add $holdoff parameter to WANObjectCache::touchCheckKey()
Change-Id: I14b6d7660b34271826b77875c660c34343712648
2015-12-02 21:33:05 +00:00
Timo Tijhof
4b7f59bdcc objectcache: Move WANObjectCache holdoff from get() to purge value
Move the holdoff period into the purge value instead of deciding
it at runtime. This opens the way for touchCheckKey() to support
a custom $holdoff parameter, which will allow callers to invalidate
keys without a holdoff period. Similar to what we already support
in delete().

Right now the holdoff period is decided at run time.

Change-Id: Id10c036272e92ae4429effc823b75e08fb11a48b
2015-12-02 21:33:04 +00:00
Aaron Schulz
680f152715 Add 0 hold-off TTL support to WANObjectCache::delete()
This removes the peculiar >= 1 restriction

Change-Id: I255dc6ef9750ad2ed6234e3fcfed9ae22a038748
2015-11-23 21:46:36 -08:00
Timo Tijhof
a0cce5e4b6 objectcache: Implement check keys per cache key in WANObjectCache::getMulti()
To allow batch queries for multiple keys that themselves have different check
keys. Previously check keys always applied to all keys being retrieved.

Change-Id: I9e5ba198d79020ce05a802a510762e29fcfb2f1b
2015-11-17 04:15:33 +00:00
Timo Tijhof
03b281d55b objectcache: Add TTL_INDEFINITE to IExpiringStore
Especially useful when interacting with getWithSetCallback of
HashBagOStuff where a $exptime is required before the callback.

In set() it is typically left out and thus not as counter-intuitive.

Change-Id: Ic2f7adda3c00cefe701d77bea91a7e8e77ef1439
2015-11-03 06:36:06 +00:00
Aaron Schulz
7cddc22fb8 objectcache: Allow bounded HashBagOStuff sizes and limit it in WANObjectCache
Change-Id: Icca2474b1ea6feb7134f8958aecf79aa51b7f71e
2015-10-31 02:04:01 +00:00
Aaron Schulz
6d0108d533 Fix slow callbacks in getWithSetCallback() using lockTSE
* Keys that take a long time to generate would run into
  the MAX_SNAPSHOT_LAG check and have set() no-op. This
  would be fine except that leaves no key there to figure
  out the time since expiry and therefore whether to use
  the mutex, so it didn't. This now saves the keys but with
  a FLG_STALE bit set, making the next caller that sees it
  perform a regeneration (unless it can't get the mutex).
* Bumped LOCK_TTL so that keys can stay locked much longer.
* This is easy to test via sleep(5) in tagUsageStatistics()
  and two Special:Tags browser tabs.

Bug: T91535
Change-Id: I549e70ace3d2e7da40d3c4346ebacc36024cd522
2015-10-28 23:31:37 +00:00
jenkins-bot
33859dfcf5 Merge "Make WAN cache HOLDOFF_TTL smaller by combining db/snapshot lag" 2015-10-28 15:10:40 +00:00
Aaron Schulz
31b144a7cf Improve WAN cache delete() docs a bit
Also use more TTL constants in getWithSetCallback() examples

Change-Id: I866f0464c07fa0c8977c6e908e92186b2ef9de43
2015-10-27 22:06:46 -07:00
Timo Tijhof
e8275758fe objectcache: Introduce IExpiringStore for convenient TTL constants
Also consistently use self:: instead of BagOStuff:: for constants
referenced within the BagOStuff class.

Change-Id: I20fde9fa5cddcc9e92fa6a02b05dc7effa846742
2015-10-28 04:07:25 +00:00
Aaron Schulz
05a3ee2468 Make WAN cache HOLDOFF_TTL smaller by combining db/snapshot lag
* In the common ~0 second lag case, transactions up to ~7 seconds
  long will have normal set() behavior (instead of just ~5 seconds).
* Like wise with ~0 second transactions tolerating ~7 seconds of
  lag (instead of just ~5).
* The lower hold-off time lets caching resume 3 seconds sooner.

Change-Id: I21e2a0a6915492cec422b6a6af5541937745c15b
2015-10-27 11:38:54 -07:00
Aaron Schulz
dc646b464c Protect WAN cache sets() against uncommitted data
This generally only effects wikis with no slave DBs,
but also matters if the master has non-zero LB load.
If the master ends up being used for DB_SLAVE, care
should be shown for cache-aside writes

Interesting WAN cache events are now logged.

Change-Id: I2cd8e84138263c13ea23beb9ab3d7562340e1fd3
2015-10-24 17:21:22 -07:00
jenkins-bot
f17437d8c2 Merge "Add make(Global)Key() method to WANObjectCache" 2015-10-20 00:14:54 +00:00
jenkins-bot
105517c68c Merge "objectcache: Remove getWithSetCallback() signature backwards-compatability" 2015-10-19 23:56:11 +00:00
Aaron Schulz
f84b32af37 objectcache: Remove getWithSetCallback() signature backwards-compatability
All callers have been migrated

Change-Id: I7b6b87594dd724434ba24d8206fe07d66c1d5d25
2015-10-19 23:47:04 +00:00
Aaron Schulz
d4895d5c70 Add make(Global)Key() method to WANObjectCache
Change-Id: I8e739fbe8614c9bd1c3595bbf16c8cd423aff7cc
2015-10-19 12:55:30 -07:00
Aaron Schulz
d7021c077d Mention WANObjectCache::TTL_INDEFINITE in set() method
Change-Id: I6e5cb2e7ba34ceaf4ca128e4b32da99d08917156
2015-10-15 08:09:48 -07:00
Timo Tijhof
68a54d6d7a objectcache: Rename WANObjectCache TTL_NONE to TTL_INDEFINITE
"None" has a somewhat unobvious meaning, also ambiguous with "uncachable".

Change-Id: I799de385427aeb8f581d51800606552bdc998252
2015-10-14 17:08:59 -04:00
Aaron Schulz
1a6151e3a6 Caching documentation tweaks and doxygen cleanups
Change-Id: I4b37a6c7d267d4eb0b39b313d92e6c0bf87d460e
2015-10-10 01:06:37 -07:00
Aaron Schulz
968e28f894 Add process cache support to WANObjectCache
* Make getWithSetCallback() accept a TTL field for this
* Make ChangeTag callers use this flag to avoid hundreds of
  duplicate queries at Special:Tags

Change-Id: Ic1ed28294f5d557e02f39a7f20d36766244b9ded
2015-10-10 06:14:50 +00:00
jenkins-bot
9e56569f9f Merge "Minor getWithSetCallback() example formatting tweaks" 2015-10-10 04:55:52 +00:00
Aaron Schulz
17e8bd3f32 Better explain WANObjectCache::TTL_NONE constant
Change-Id: I2ce363c957f35e75a17f05b2160979a6fa4aa642
2015-10-10 00:12:37 +00:00
Aaron Schulz
3c021116e4 Minor getWithSetCallback() example formatting tweaks
Change-Id: I6fc7164770fbbd32374b01d1aa27dbaa9263c940
2015-10-08 15:49:57 -07:00
Aaron Schulz
e5878c522b Update getWithSetCallback() examples to use the new signature
Change-Id: I81916b4d1884bad5d30f689698aa35cdb9f139eb
2015-10-07 21:52:43 -07:00
Aaron Schulz
5aee45ee9e Fix default $oldOpts from 09cbebb224
This fixes the default $oldOpts value for the case when
$opts is given check keys and no $oldOpts value is passed
in. In that case, the getWithSetCallback() method
variable $opts would be null instead of array().

Change-Id: I825062533478b37766511aae1d06dd4b81f8dba1
2015-10-07 20:26:38 -07:00
Timo Tijhof
09cbebb224 WANObjectCache: Change getWithSetCallback() signature to key/ttl/callback/opts
* Put 'checkKeys' param in opts array instead of as a separate parameter.
  It's neat to not have to skip unnamed/positional arguments that are optional.
* Move TTL to be before callback instead of after. This avoids dangling integers
  toward the bottom of a large code block that have no obvious meaning.
  Matches BagOStuff::getWithSetCallback.

Add unit test for lockTSE to confirm

Change-Id: I60d6b64fc5dff14108741bafe801fd1fde16d1df
2015-10-07 18:03:15 -07:00
Aaron Schulz
667e9ef44b Bump WANObjectCache::LOW_TTL to 30
This better handles values that take a long time to
generate. For example if it took 10 sec, then the old
value would not regenerate in time. 30 is a good, high,
value that is the default PHP timeout.

Change-Id: I2e4372bf4c6d28d09347012926d8c0a9deda4183
2015-10-06 23:50:28 -07:00
Aaron Schulz
54758dd160 Change getCacheSetOptions() callers to use "Database"
* This is less verbose that DatabaseBase
* Also add a few WAN cache doc comments

Change-Id: I5b6de6d0ffa06753ea96c50b63db7dae796475dc
2015-10-05 22:06:46 -07:00
Aaron Schulz
db0b9ef264 Make WANObjectCache sets account for slave lag
* This gets lag information that is useful when
  the calling code is about to run queries that
  will have their results cached.
* This is now used in place of trxTimestamp() for
  WANObjectCache set() and getWithSetCallback().
* The WAN cache will use a low TTL if the lag is
  too high to avoid caching stale data for weeks.
* Bumped MAX_COMMIT_DELAY as nothing enforces it.

Bug: T113204
Change-Id: I2a95b4088cff42d6e980351555f81a4b13519e24
2015-10-05 16:45:13 -07:00
Aaron Schulz
7aea96befa objectcache: Add some newlines to WANObjectCache docs
* Doxygen needs this or the paragraph ends up in the
  last bullet point
* Also removed some redundant comments

Change-Id: Ie4bf2b67fff27ecad5f24f55688161fe484c300d
2015-10-01 20:42:16 +00:00
Aaron Schulz
3f3d5a10b9 Cleaned up WANObjectCache toy example code blocks
The list order logic was backwards

Change-Id: Id26e13b69d9e1e6ef132792bdcc693836757cbd8
2015-09-29 23:05:33 -07:00
Aaron Schulz
4ff4296333 Improved getWithSetCallback() docs to have more use cases
Change-Id: I428617c159009f22fa78129c16a8964ac2e830b9
2015-09-29 17:25:38 -07:00
Aaron Schulz
a9665bf4d6 Clarified WAN cache docs by using "datacenter" consistently
Change-Id: I448c57cebd0481809fc17a7c2ac698c73b17dcba
2015-09-28 18:22:52 -07:00
Aaron Schulz
75f06d5294 Added $opts to WANObjectCache::set() to detect snapshot lag
* This can avoid some stale write race conditions
* Made use of this option in a few key places
* HOLDOFF_TTL was also bumped

Change-Id: I83505a59cce0119e456191c3100f7d97bc86bdbf
2015-09-28 23:03:36 +00:00
Aaron Schulz
d02b98b8f3 Updated key WANObjectCache::delete() callers to avoid races
* They now issue the delete() write before COMMIT of
  the relevant DB (or immediately if no trx is active)
* This can avoid some stale write race conditions
* Updated the WAN cache delete() docs

Change-Id: Id54887976051120b76528070d5f2ceb357d57897
2015-09-26 18:02:00 +00:00
Aaron Schulz
859cc75432 Assorted WANObjectCache doc tweaks
Change-Id: If207fc64279e344218d3b617eae7e69f88b23b27
2015-09-26 04:53:58 +00:00
Aaron Schulz
1ed292fa9e Improvements to WANObjectCache::getWithSetCallback()
* If lockTSE is set, make sure it applies during during
  the entire duration of a key being tombstoned. This lets
  regenerations happen during that whole time, which lowers
  the chance of seeing stale data if the DBs are lagged.
* If lockTSE is not set, do not apply tempTTL (for tomstoned keys).
  If traffic is high, a stale value would usually be "stashed" and
  used for 5 seconds. If the lag was only 1 second, then this
  is suboptimal.
* Determine tempTTL from lockTSE as they no longer make sense
  being separate. This makes things easier to understand and
  also makes the lockTSE value account for the last regeneration
  time (via stash key TTL). Since LOCK_TSE << HOLDOFF_TTL, this
  helps avoid stale reads without adding stampede risk.

Change-Id: I3b01f0ec67935a238b30e02e42004fd3b2dcfb9d
2015-09-23 15:24:01 +00:00
jenkins-bot
e3d0743904 Merge "objectcache: Fix some doc bullet points in WANObjectCache" 2015-09-23 05:28:18 +00:00
Aaron Schulz
901dcffd80 objectcache: Fix some doc bullet points in WANObjectCache
Change-Id: Id3e65b0768d45087aaf83ed3f432923c82acc713
2015-09-23 05:17:48 +00:00
Aaron Schulz
c1931c2933 objectcache: Add comments about DB isolation to WANObjectCache
Change-Id: Ic3454d0ebfdb05488dd650f77e09264842caea1c
2015-09-23 05:16:35 +00:00
Aaron Schulz
73b27a3d32 Small cleanups to WANObjectCache
* Added a few comments
* Renamed $locked => $lockAcquired for clarity

Change-Id: I45710974971731205d072a1f4b0f9cb37e2cb2a2
2015-09-17 11:00:23 -07:00