Commit graph

334 commits

Author SHA1 Message Date
Umherirrender
ace44e2064 Use correct variable name in @param documentation
For some varargs a variable name is added with suffix ,... as seen for
many other varargs

Some @param are swapped, because there are in the wrong order

Enable Sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch

Change-Id: I60fec6025bce824d5c67563ab7b65ad6cd628ad8
2017-08-11 19:27:19 +02:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Brad Jorsch
edf69e62d8 MultiWriteBagOStuff: Fix async writes of mutable objects
If someone writes an object into a BagOStuff, they typically expect that
later changes to the object will not affect the value stored.
MultiWriteBagOStuff's async write handling was violating this
expectation, which is potentially causing T168040.

Bug: T168040
Change-Id: Ie897b900befdc8998614af06f9339cd07665703e
2017-07-25 02:08:00 +00:00
Thiemo Mättig
91a920fd85 Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

This is similar to I994d11e. Even more trivial, because this here is
about comments that don't say anything but "constructor".

Change-Id: I474dcdb5997bea3aafd11c0760ee072dfaff124c
2017-07-21 12:19:30 +02:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
Timo Tijhof
dd629564df objectcache: Forward MultiWriteBagOStuff::makeKey to primary backend
Similar to what WANObjectCache and CachedBagOStuff are already doing.

Also add missing tests for WANObjectCache (similar to those for CachedBagOStuff).

Bug: T167465
Change-Id: I1a0c9324726aa6a1b221def985773b1b819181fd
2017-06-14 18:11:55 +01:00
jenkins-bot
95b63ec8a1 Merge "objectcache: Use faster getArrayCopy() in WAN cache methods" 2017-06-10 15:38:30 +00:00
Aaron Schulz
914274c58c objectcache: Use faster getArrayCopy() in WAN cache methods
Change-Id: I5f0543a59bdc59656c54fab4d7c4ae33fd233f9a
2017-06-10 15:26:37 +00:00
Aaron Schulz
cceefaadee Remove unused key in WANObjectCache::newEmpty()
Change-Id: I5d11736b95fbba1debcf80f80cbdb4753caf15f7
2017-06-08 07:27:14 -07:00
Aaron Schulz
83fcb86dfa objectcache: add getMultiWithUnionSetCallback() method
This supports callbacks that fetch all the missing values at once.

Change-Id: I74747cc06f97edc9163178180597e6651743b048
2017-05-30 23:34:28 +00:00
Aaron Schulz
6ddaf52d32 objectcache: respect process cache in getMultiWithSetCallback()
Backend cache queries are now avoided if they are fresh in memory.

Also factor out some code into private methods for clarity.

Change-Id: Ib343fde3dbf63f39e8cb09eca6278811a7d9738b
2017-05-26 15:34:45 -07:00
Aaron Schulz
0c24cefa12 objectcache: fix cache warmup bug in getMultiWithSetCallback()
The warmup cache was not properly prefixed and was also using the entity
IDs instead of the cache keys. Thus, it effectively just wasted a
getMulti() query and resulted in the usual separate GETs anyway.

Added some unit tests for this.

Change-Id: I75b7a31214b515511856f9d95db32e8881d80ccc
2017-05-26 04:28:13 +00:00
Aaron Schulz
cbff84a5b9 Add missing ampersand to getMultiWithSetCallback() callback
Also fixed a php example block comment

Change-Id: Ib6967180ad0d45aec7b7d4b6d383723e2c95fefa
2017-05-25 03:40:26 -07:00
Aaron Schulz
1180a859ba Avoid treating mcrouter set()s as failing due to AllAsyncRoute
Per https://github.com/facebook/mcrouter/wiki/List-of-Route-Handles
a NullRoute response is always given for DELETE and SET. The former
already is already handled by MediaWiki treating NOT_FOUND as success.

Change-Id: I79c26bcd6b8ffe7eea73e0d45badcc4ed63f05e6
2017-05-24 10:50:09 -07:00
Timo Tijhof
8e81621dcf objectcache: Complete code coverage for CachedBagOStuff
Change-Id: I8a228d68701f1ad4d37f60de53d105c32898dc8b
2017-04-07 23:31:41 +00:00
Timo Tijhof
a116bc58b5 objectcache: Fix CachedBagOStuff to use backend makeKey()
Follows-up 25dbd91513.

Change-Id: Ib727c57cb27f05c0462bfdfee89a185ef6603ddd
2017-04-07 23:31:25 +00:00
Timo Tijhof
50a035cd6b Clean up get_class($this) -> static::class in /includes/cache and /includes/libs
* get_class()        -> __CLASS__ (same as self::class)
* get_called_class() -> static::class
* get_class($this)   -> static::class

Change-Id: I22c62851bcc88405f4bdd77258d6e28ec1a14924
2017-03-07 21:06:06 +00:00
Aaron Schulz
d46d8bb58d Add dynomite comments to WANObjectCache
Change-Id: I7ac9961e6acdecf90b766643138bb64b5ea9ec4a
2017-03-04 11:31:11 -08:00
jenkins-bot
aa3319c4c0 Merge "Miscellaneous indentation tweaks" 2017-02-28 18:38:36 +00:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
James D. Forrester
b715f432f4 includes/libs: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Skipping jsminplus.php as those bug numbers aren't Wikimedia's, nor obviously
someone else's.

Change-Id: I9a2210e17852ee56f11282b980ac66d8c7a95671
2017-02-21 18:13:08 +00:00
Aaron Schulz
8c0400c9ba objectcache: Avoid using deprecated ScopedCallback alias
Change-Id: Ica8a066c3f28adc710ee11919c07dd188144beb5
2017-01-31 00:53:31 +00:00
Aaron Schulz
2e5eb693de objectcache: add WANObjectCacheReaper for assuring purges
* This fixes keys based on some sort of change log.
  Updates are wrapped in a mutex and keep track of the
  last known good position.
* Make WANObjectReapUpdate class that cleans up title
  related keys using the recentchanges table. This triggers
  as a deferred updates on RC view.

Change-Id: I7f14b9ca2533032147e62b1a3cc004a23da86579
2017-01-27 02:21:06 +00:00
jenkins-bot
2116f0926b Merge "Reduce WAN object cache logging spam for reject set() calls" 2017-01-10 22:00:13 +00:00
jenkins-bot
8b3265736f Merge "Add an refresh probability comment to worthRefreshPopular()" 2017-01-10 21:42:09 +00:00
Aaron Schulz
8972104ba2 Reduce WAN object cache logging spam for reject set() calls
Change-Id: I276c91b3b3b47d337f9c1d91a8348ca8f3d57194
2017-01-10 13:20:02 -08:00
Aaron Schulz
b0e0f6e3b3 Add an refresh probability comment to worthRefreshPopular()
Change-Id: Ia6717881c7d5c19481c87ade5972c0ff641d6e11
2017-01-07 19:00:00 -08:00
Aaron Schulz
02d6133fd8 Avoid IDEA warning about $keys being both a parameter and loop variable
Change-Id: Id562053a71f135fa863cb88b5f081982c01575cf
2017-01-07 16:10:23 -08:00
Aaron Schulz
343f94f1fe objectcache: Remove broken apcu_set() calls
The method call was misnamed (should be apcu_store) and not needed anyway,
since the other BagOStuff classes fail if no key is present.

Change-Id: I726965e665c2d0c5843d8dd33504810d130b9e98
2016-12-06 15:39:42 +00:00
Hashar
4d487d1942 Revert "objectcache: detect default getWithSetCallback() set options"
Causes HHVM 3.12.7 to segfault and or:
Fatal error: Stack overflow in includes/libs/objectcache/BagOStuff.php on line 754

This reverts commit b47ce21cec.

Bug: T150833
Change-Id: Ia52fdf65f5e386c0eaa1046328680fb5c8a9081a
2016-11-16 10:35:27 +00:00
jenkins-bot
32f3a99575 Merge "objectcache: Remove broken cas() method from WinCacheBagOStuff" 2016-11-16 05:12:26 +00:00
Aaron Schulz
d1b53e32c7 objectcache: Remove broken cas() method from WinCacheBagOStuff
Bug: T120896
Change-Id: I9406a50df8e900b4fc5861c2174ba7a63a0dd765
2016-11-16 05:02:37 +00:00
Aaron Schulz
b47ce21cec objectcache: detect default getWithSetCallback() set options
This works by setting a callback to return the cache set
options. The callback will watch DB reads and create a
merged result from said usage.

This handles callers that are missing getCacheSetOptions().

Change-Id: Ia264f011e45e8cf105480955dad7e2c4c2357b73
2016-11-16 04:53:53 +00:00
Aaron Schulz
43ff2a83b5 objectcache: avoid using process cache in nested callbacks
Because the process cache can be lagged by virtue of blind TTL,
the HOLDOFF_TTL might not be enough to account for it, so avoid
using it when already inside a callback.

Also split of the tests from the MediaWiki test class, so this
does not require DB access anymore.

Change-Id: I743a1233a5efc7f036fad140a9ff8a30b32f8f27
2016-10-20 22:13:29 +00:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
fdce245e9f objectcache: use a default "since" timestamp in getWithSetCallback()
* Renamed mDoneWrites to be clearer at what type it is.
* Also cleaned up a few callers of this method

Change-Id: I45856b210c289c2e2f193cc4328a208e20b4e0a8
2016-10-14 23:31:09 +00:00
Aaron Schulz
ec0b9d55c3 Fix WANObjectCache doc typo
Change-Id: I74ef6598d86bdf43ae35f776878cfbb8e9695907
2016-10-13 01:15:12 -07:00
Aaron Schulz
24200e88d2 objectcache: add WANObjectCache::getMultiWithSetCallback()
This does what it says on the tin, e.g. a way to fetch
multiple keys at once. Callbacks are still called in a
serial manner when needed.

Change-Id: I8e24a6de7f46499a53ec41636c5a4f106b9b3d09
2016-10-05 15:50:18 +00:00
Reedy
c214c9a952 Detect/use APCu properly
In PHP 5.5 and above, userland APC caching moved to an extension

Bug: T140587
Change-Id: Ie0871776cd7e67838471a4fe95451cf4164079b7
2016-10-01 23:07:47 +01:00
Kunal Mehta
090d0267da Use wikimedia/wait-condition-loop
Since the WaitConditionLoop class was first introduced in 1.28 (current
master), no back-compat alias is added.

Bug: T146256
Depends-On: Ia84774d83da79fea1e167fe065c69549981f753b
Change-Id: Ibd4f15c87105b8caccbd1f661b74b6efa012b77f
2016-10-01 00:25:43 -07:00
Aaron Schulz
a2dd3480da Cleanup MemcLockManager and move it to /libs
* Remove wf* function and ObjectCache dependencies.
* Use the base class session field.
* Lower physical lock structure TTL and move it to the base
  class as a constant.
* Resolve TODO about acquiring mixed lock types in one pass.
* Only mark servers down for 30 seconds in case of long-running
  scripts.

Change-Id: Icd4be407e599524cc620975d27e85666d2532b95
2016-09-30 06:33:32 -07:00
Aaron Schulz
8729167f13 Move RedisBagOStuff to /libs
Change-Id: Ia49fb044aacb44e53d36c80277783cd806aca439
2016-09-23 20:13:36 -07:00
Kunal Mehta
d2fd3109a3 Avoid Wikimedia\Assert in HashBagOStuff
This is the only usage of wikimedia/assert in the planned objectcache
library, so it doesn't make much sense to have a dependency upon the
entire library just for one usage that is trivially replaced.

Change-Id: I8f967fb2b861852c7fc74f7d42e2cbab1df05bc4
2016-09-20 23:00:54 -07:00
Aaron Schulz
faac856f21 Fix broken wincache merge() implementation
Bug: T145664
Change-Id: I2f841779108df281e24003c586775b71aa176909
2016-09-15 04:50:25 -07:00
jenkins-bot
d9f412635f Merge "Move PECL memcached class to /libs" 2016-09-14 01:45:02 +00:00
Aaron Schulz
a3dacac90f Support masking the WRITE_SYNC latency from ChronologyProtector
* Use OutputPage::output() as the method to mask latency, since it
  takes a good while to run. By the time it runs, cache replication
  should have caught up, so the reap call will likely not block.
* For redirects emitted after changes in POST, instead of masking
  with OutputPage, add a parameter to the redirect and block on
  the positions appearing. This uses the redirection RTT to mask
  the replication latency.

Change-Id: Ib23690c302e8033610fef9a0ef451dafe8a5803e
2016-09-12 23:58:49 +00:00
Aaron Schulz
ad0f205feb Add more version notes to WANObjectCache
Change-Id: Ia1b74b568d2b5137c7096a3b4549ac2cd4c7fa93
2016-09-09 13:41:03 -07:00
Aaron Schulz
843c112884 objectcache: add "staleTTL" option to WANObjectCache::set()
Change-Id: Ib9386a8ad4ab98d07d0a3784e3afffeeca9bbd6e
2016-09-09 01:05:55 -07:00
Aaron Schulz
55b4d2f620 Cleanup and re-indent some WANObjectCache docs
Change-Id: Ibf7092297ce53fd21e478a6f87a16f9b4373ad85
2016-09-09 00:57:57 -07:00
jenkins-bot
945b8ee0d4 Merge "Switch some callers to WaitConditionLoop" 2016-09-09 02:57:13 +00:00
Aaron Schulz
d32b64235f Switch some callers to WaitConditionLoop
Also fixed up backwards documentation

Change-Id: I00c36aa751a79ca86a754e049a6da78cbb417b81
2016-09-08 19:29:18 -07:00
Aaron Schulz
6d1d6c90f1 objectcache: expose "minTime" in WAN cache and call it "minAsOf" instead
Change-Id: Iabb639dddb9458d961dbbaee6a0dfb2323c2739a
2016-09-08 13:42:17 -07:00
Aaron Schulz
8db4c163e8 objectcache: pass in the $oldValue as-of time in getWithSetCallback()
This lets callers use adaptive TTLs on the near-expiration
preemptive refreshes if the new and current values match,
using the as-of time as $mtime.

Change-Id: Ie541c35f890c9f789d1accf9f2a43506daaf31f0
2016-09-08 18:36:25 +00:00
Aaron Schulz
05589cad6b Move PECL memcached class to /libs
Remove IP class dependency, which is simple enough here

Change-Id: I3aed6ae6747d8d2b9e75b492e5d5293ba4ce9edd
2016-09-07 22:55:11 -07:00
Aaron Schulz
b9f4168b56 objectcache: Avoid doxygen misformatting for pcGroup comments
Change-Id: I970bc9ccb04b046c563a357d87f814da652e23d2
2016-09-08 01:22:31 +00:00
Aaron Schulz
5316e7d700 objectcache: add "pcGroup" option to WANObjectCache::getWithSetCallback()
This lets callers have their own process cache but keep it
managed in a central location, making it easier to reset
when DB transaction snapshot are flushed or when unit tests
want to clear caches between runs.

Use this to replace the Revision text process cache.

Change-Id: Ic61ee9140d4ce9836cc4650adb5bb75a291fea18
2016-09-07 16:35:15 -07:00
James D. Forrester
960e4d09ca Documentation: Replace misuse of 'later' when we meant 'latter'
Change-Id: I01bfdb8e0bfaa132533732873f7c840cea7935eb
2016-09-07 13:13:42 -07:00
Aaron Schulz
3348200473 Make adaptiveTTL() less strict about $mtime type
Callers using wfTimestamp( TS_UNIX, ... ) where getting $minTTL
due to the output being a string number.

Change-Id: I6b67a941940f40ef9a543f11d0dbccacafaaa53b
2016-09-07 09:18:37 -07:00
jenkins-bot
c118951f57 Merge "objectcache: add "hotTTR" and "ageNew" options to getWithSetCallback()" 2016-09-07 07:04:59 +00:00
Aaron Schulz
afcc7d772b objectcache: add "hotTTR" and "ageNew" options to getWithSetCallback()
These control worthRefreshPopular(), which will try to make sure that
heavily used keys are kept more consistent than others.

Change-Id: I2d351b50462a96d0fa8ca8fa6d28d51d3a5c94ff
2016-09-07 06:40:43 +00:00
Aaron Schulz
58038b2621 Turn off "reportDupes" in CachedBagOStuff
Change-Id: I79148be842a940c92e555e10b24c32cdf7609539
2016-09-06 13:36:16 -07:00
jenkins-bot
00ac2882bb Merge "Turn off duplicate key gets for ReplicatedBagOStuff" 2016-09-06 18:18:07 +00:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Aaron Schulz
45adeddf1b Turn off duplicate key gets for ReplicatedBagOStuff
This is used as the main stash by default, which is not a
performance cache but a stash for ephemeral values typically.

Change-Id: Ie3740c0387f36a3f9b2d8d7d3b4e04ee9238ab1a
2016-09-05 14:23:41 -07:00
Aaron Schulz
16266edff3 Change "slave" => "replica DB" in /includes
Change-Id: Icb716219c9335ff8fa447b1733d04b71d9712bf9
2016-09-05 21:01:01 +00:00
Aaron Schulz
e99bb1b7dc objectcache: allow for callbacks to mask SYNC_WRITE latency
Change-Id: I908222ad3788ebe330aa58831cda139da32becd8
2016-09-01 13:44:18 -07:00
Aaron Schulz
52511952de objectcache: add and use adaptiveTTL() method
* This better handles delayed/lost cache purges by
  having lower TTLs for entries that often changes.
* Use this for foreign upload description page caches,
  we purges are never received from the source wiki.
* Also use this for User and LocalFile cache TTLs.
* Also move the Database::getCacheSetOptions() call in
  User *before* doing the queries, which is preferred.
* Fixed some IDEA errors too, like the undeclared
  mApiBase field.

Change-Id: I70f8ebb29ac853c2a530d9eedb9e7facc1b7b710
2016-08-31 03:40:56 +00:00
Aaron Schulz
d110a67082 Clarify some WANObjectCache docs
Change-Id: I819a630ebba4122a757f04fbf702122069af4fb1
2016-08-18 20:53:20 -07:00
jenkins-bot
b33cbac370 Merge "objectcache: add mcrouter support to WANObjectCache" 2016-08-19 02:57:18 +00:00
Aaron Schulz
70547f3fa3 objectcache: add mcrouter support to WANObjectCache
* Update documentation about relay methods.
* Change interim key set() to add() to avoid broadcasting it.
* Remove the behavior of doing purges synchronously in the
  local DC first before relay. In both the event relayer and
  mcrouter case, they will be asynchronous. It was hardly
  even possible to use such behavior since loads come from
  slave DBs, which do not see changes right after COMMIT.

Bug: T97562
Change-Id: I7759c82ae6e1b72fc227882a99c9a712a46374f6
2016-08-18 22:42:11 +00:00
Aaron Schulz
6da50011e4 objectcache: expand getWithSetCallback() docs a bit
Change-Id: Ifc8304848fd5e4b8f7ea5555271de09609cdbe10
2016-08-15 02:07:31 -07:00
Aaron Schulz
55f6639c2e objectcache: Add changeTTL() method
This can change the TTL without fetching the object
so that keys can be renewed or set to expire soon.

Change-Id: Id1c2c9f89b3445cfa34263057dc5029cbe170833
2016-08-11 19:55:32 -07:00
Aaron Schulz
5f921702d2 Avoid stack overflow in LoadBalancer with CACHE_DB WAN/server cache
* Add the ability to expose key BagOStuff attributes like whether the
  emulation SQL cache is being used. Several callers use hacks to detect
  this and can be updated later.
* Fallback to a safe empty WAN cache in the CACHE_DB case. This fixes
  a regression from f4bf52e843.
* Also add this protection to the server cache, which could break
  similarly before too.
* Also fix CACHE_ANYTHING by avoid the recursion risk from
  fc1d4d7960 by just checking the disabled service map.

Bug: T123829
Bug: T141804
Change-Id: I17ee26138f69e01ec1aaddb55ab27caa4d542193
2016-08-02 13:06:49 +00:00
Aaron Schulz
cbd2f3937f objectcache: Add callable doc comments for WANObjectCache
Change-Id: I28a705ae12e065dc8a3921e33c873f9a7fbb7490
2016-07-25 18:40:39 +00:00
Aaron Schulz
1a081c6707 objectcache: Add "busyValue" option to WANObjectCache::getWithSetCallback
This is useful for avoiding stampedes in the one case that lockTSE
does not alone cover, which is when the key does not exist or is
tombstoned.

Also avoid saving interim values unless the key is tombstoned
since there is no point in doing that otherwise.

Change-Id: I70997e90217a0979e0589afa7a5107b0e623c7cf
2016-07-22 22:24:38 +00:00
Timo Tijhof
272c14db8f objectcache: Fix RESTBagOStuff class doc
Currently renders slightly broken since a single line break
is ignored in Markdown (Doxygen parses these as Markdown).

Change-Id: Ibdff93e103f98b7bd8d3ef9118f246fedab288cf
2016-07-20 16:40:08 +00:00
Stanislav Malyshev
7ade0a7c67 Create BagOStuff implementation to talk to RestBase
Or any other HTTP REST server.

Bug: T137272
Change-Id: Iefef24ffa831ba59d7725da8d20d5addb544b3ab
2016-07-06 17:52:07 +00:00
Aaron Schulz
fd4940a1b6 Fix WAN cache stashing bug due to missing list() call
Fixes regression from 0a38dbc809.

Bug: T137877
Change-Id: I4ea960966c084ada36dc54d4ec8729126c17ccdc
2016-06-15 09:40:34 -07:00
Aaron Schulz
6aaf0f9359 Avoid getWithSetCallback() warnings on unversioned key migration
If an unversioned key is present, this generated a warning
previously.

Bug: T137244
Change-Id: I92df9b9fe0436348b5b27e684d239238d57c9b5f
2016-06-08 10:25:25 -07:00
Kunal Mehta
4a8ae0a0b4 Use callable type-hint in a few places
Mostly places which immediately had a:
 if ( !is_callable( $callback ) ) {
  throw new Exception(...);
 }
check at the beginning of the function.

Change-Id: Ia78663b2231629010816bd1cda8814b996968d1d
2016-06-07 16:39:22 -07:00
Aaron Schulz
e30b0199ac Fix key prefix comment after 0a38dbc809
Change-Id: I9085d1f0020917b431d9ef7afd4de93e54df0abc
2016-05-31 22:27:46 -07:00
Aaron Schulz
0a38dbc809 objectcache: Support key versioning in WANObjectCache
* getWithSetCallback() takes a 'version' parameter.
* If the value at a key has a different version, then
  getWithSetCallback() will automatically use a separate
  key. Which value "wins" the main key does not matter.
* Purges are handled by using the main key as a sort of
  check key (with no hold-off). Note that this key is always
  purged on delete().
* Changed stash keys to track the same info as other keys
  both for consistency and because this change needs the
  generation timestamp. Renamed the stash prefix to avoid
  corrupt results with Het Deploy.
* This is useful for things like the User class that use
  versioning and have cross-wiki key access and purges.
  Currently, bumps to version must be deployed to all wikis
  at once, which this aims to avoid.

Change-Id: I26ae62f116e32b48bcf06bc13f8b9e79ae976745
2016-05-25 18:03:21 +00:00
jenkins-bot
045ca4ca47 Merge "Let BagOStuff::merge() callbacks override the TTL" 2016-05-17 09:33:16 +00:00
jenkins-bot
f3d45a2d72 Merge "Document WAN cache FLD_* constants" 2016-05-12 19:44:17 +00:00
Aaron Schulz
451fec8da4 objectcache: Inject current time into WANObjectCache::wrap()
Change-Id: Iaba8e09b904e12c0f6883cf6f10211e82a7d75db
2016-05-12 19:08:52 +00:00
Aaron Schulz
9c93a53af1 Document WAN cache FLD_* constants
Change-Id: Ie6a19ae2c5ab6f60a3c6818eb1c9016402bc86c9
2016-05-11 20:25:14 -07:00
Aaron Schulz
ac5512b48d Let BagOStuff::merge() callbacks override the TTL
This is useful if the TTL depends on what is in cache now.

Change-Id: Idde6eb9e156f9ae847f9bc7e3b1f3f511f39ffe4
2016-05-11 13:50:33 -07:00
jenkins-bot
3bb0950b03 Merge "Avoid spamming the duplicate key fetch log in BagOStuff::merge()" 2016-05-10 12:33:23 +00:00
Aaron Schulz
ea1f4e8a53 Add TTL_PROC_* constants for clarity
This makes the reason for the cache times more obvious

Change-Id: Ie75df6be77c513feeb6cff3417ccbc124a6a1141
2016-05-06 23:45:41 +00:00
Roan Kattouw
4b004068c0 MemcachedClient: Always return an array from get_multi(), don't return false
MemcachedPhpBagOStuff::getMulti() wraps around this method directly,
so get_multi() returning false was causing it to violate
BagOStuff's requirement that getMulti() always return an array.

Change-Id: Ia8f076323aed5b4a12de82d519eb530ed29d7060
2016-05-06 18:37:59 +00:00
Aaron Schulz
629f063bb9 Avoid spamming the duplicate key fetch log in BagOStuff::merge()
Change-Id: I68b10208f222f81f173f6e282c9ecf0bfcdde1fc
2016-04-29 12:03:50 -07:00
Aaron Schulz
431dd729ce Convert array() => [] in some comments
Change-Id: Ibdaf92617f2971aaf977d99c8674b4236ffa5a1f
2016-04-25 22:38:47 +00:00
Aaron Schulz
09a0a5e4f6 Make WAN cache config use $wgEventRelayerConfig
This makes the channels more explicit and defined in a less
ad-hoc way. Systems like Kafka would prefer explicit channel
definitions anyway, so the channel prefix just obscures things.

Change-Id: I5631eb1b1382083396a0f08904d9273cc92601e8
2016-04-25 12:08:09 -07:00
Bryan Davis
450bb6723d BagOStuff: Optionally log duplicate key lookups
Add new 'reportDupes' parameter to BagOStuff. This parameter enables scheduling
of a callback after the current web request ends. This callback will emit warning
log messages for all keys that were requested more than once.

The default ObjectCache factory for MediaWiki enables this option by default.
Not by default for plain BagOStuff instances, however. E.g. `new HashBagOStuff()`.

It also set 'asyncHandler' for all classes now (not just MultiWriteBagOStuff).

Bug: T128125
Co-Authored-By: Timo Tijhof <krinklemail@gmail.com>
Change-Id: I8a2b06cf54d2acf5950eed71756ecdf50e224be1
2016-04-22 04:21:20 +00:00
Stanislav Malyshev
49eb12efa4 Create Kafka event relayer
Bug: T125138
Change-Id: I9d7705cb164bc975c3a0ddf4a33ac54fe7de931c
2016-04-20 11:25:58 -07:00
Ori Livneh
d1c4eafef5 Request-local caching of image_redirect
LocalRepo::checkRedirect() cache image redirect checks in memory to avoid
unnecessary trips to memcached. Same idea as Idbd11637.

Change-Id: Idaa12376382aaa0bd8cb988240ec1da0b688359d
2016-03-25 12:09:10 -07:00
Reedy
6dcd124356 Use imported namespaces, don't fully qualify
Remove unused import in CachedBagOStuff

Change-Id: I60ca8acc0e34384ce6ad6cde1cfb3a5dc8021e5f
2016-03-18 14:02:26 +00:00
Timo Tijhof
bfb94f6f58 objectcache: Fix MultiWriteBagOStuff docs ('asyncHandler', not 'asyncCallback')
Follows-up 1171cc00cd.

Change-Id: I97189e916d0aba507273216e3e9ab28ce0d5ffec
2016-03-02 02:49:53 +00:00
Bartosz Dziewoński
c161c46d26 Improve code suffering from PHP 5.3's lack of support for foo()[]
I searched for /\$(\S+) = (.+?\(.*?\);)\n.*?\$\1\[/, ignored
everything involving isset(), unset() or array assigments, then
skimmed through the remaining results and changed things where they
made sense. These changes were not automated, so please review them.

Change-Id: Ib37b4c66fc57648470f151ad412210b3629c2538
2016-02-28 22:49:20 +01:00
Bryan Davis
2bcf34421a CachedBagOStuff: cache backend misses
Cache misses from the backend cache the same as hits.

Bug: T127772
Change-Id: If2fe1920411b24862acea888c627db13717da8bd
2016-02-22 18:45:20 -07:00
Brad Jorsch
405c2c8b6b Fix session store logging
Two things were wrong here:
1. SessionManager shouldn't override the configured logger of the
   underlying store.
2. CachedBagOStuff shouldn't override the configured logger of the
   backend store on construction.

Change-Id: I24ed5a81d5b238a42934a7890dd8d0a9f9bb3b6f
2016-02-22 17:13:03 +00:00
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
jenkins-bot
ca8aa5a6a6 Merge "Remove extra line breaks in memcached debug output" 2016-02-11 04:05:51 +00:00
Ricordisamoa
60be0296c3 Stop doing $that = $this in includes/libs
Closures support $this as of PHP 5.4

Change-Id: I1b5a5d7e619029684cb8d2a8d150fcc13051c2e0
2016-02-10 18:26:25 +01:00
Tim Starling
a57eb53907 Remove extra line breaks in memcached debug output
Possibly introduced by ed90263776

Change-Id: Ibbead449289eb1ffeec737c4c520925542b2fcfc
2016-02-08 09:01:30 +11:00
Brad Jorsch
25dbd91513 Clean up after Ie161e0f
Ie161e0f was done in a hurry, and so didn't do things in the best ways.
This introduces a new "CachedBagOStuff" that transparently handles all
the logic that had been copy-pasted all over in Ie161e0f.

The differences between CachedBagOStuff and MultiWriteBagOStuff are:
* CachedBagOStuff supports only one "backend".
* There's a flag for writes to only go to the in-memory cache.
* The in-memory cache is always updated.
* Locks go to the backend cache (with MultiWriteBagOStuff, it would wind
  up going to the HashBagOStuff used for the in-memory cache).

Change-Id: Iea494729bd2e8c6c5ab8facf4c241232e31e8215
2016-02-03 21:45:18 +00:00
Aaron Schulz
9ea5cfe377 Make sure docs encourage __METHOD__ use for begin/commit
Change-Id: Id9c2d1b30f9dd758b418894b5751556daff20f0e
2015-12-23 17:23:15 -08:00
Aaron Schulz
5ffaa6ae0d Avoid "Unable to set value to APCBagOStuff" exceptions
* This can happen due to incr/add races. Use incrWithInit()
  instead to handle such cases.
* Also made BagOStuff:incrWithInit() return the new value like incr().

Change-Id: I0e3b02a4cff7c20544a9db2eaabd3f61e5a470b1
2015-12-21 20:41:43 -08:00
Ori Livneh
ad3c2d0202 Work around APCu memory corruption bug
APCu's object serialization causes memory corruption when apc.serializer is set
to 'default' (see https://github.com/krakjoe/apcu/issues/38). We can work
around this bug by falling back to the pre-I4b2cf17155 behavior of
APCBagOStuff, which is not to trust apc_store() with anything other than
strings and integers, and instead serialize everything in user-space PHP code.

Bug: T120267
Change-Id: If34a1d959e2700792514b372af52919940222d83
2015-12-13 21:35:59 -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
304eaf2868 objectcache: Reduce MediaWiki-specificness from Memcached classes
Follows-up f36b73e96c, which moved these classes to libs/objectcache.

* Fix wrong @throws in MemcachedPeclBagOStuff.
* Fix wrong @returns in MemcachedBagOStuff::getClient().
* Rename MWMemcached to MemcachedClient.
* Remove mention of 'memcached.php', which doesn't exist anymore.

Change-Id: I34dbc859be4778cea489fd2344f233f30452605c
2015-11-10 03:32:58 +00:00
Aaron Schulz
209217da8a objectcache: Make HashBagOStuff LRU instead of least-recently-set
Refresh key in get() in addition to just set().

Change-Id: I7985b98b6a346eaed8bf0a7349b95fabea8e8614
2015-11-04 01:30:39 +00:00
Aaron Schulz
5b3ad3a46b Merge "objectcache: Add a clear() method to HashBagOStuff" 2015-11-03 10:16:19 +00:00
jenkins-bot
fb5516524c Merge "objectcache: Refresh key in HashBagOStuff::set() for maxKeys eviction" 2015-11-03 10:13:08 +00:00
Timo Tijhof
caa3e2ea06 objectcache: Add a clear() method to HashBagOStuff
Including tests for delete() and clear().

Change-Id: If39d729838e312523f0df3ae8b235ebe939a17fd
2015-11-03 10:07:10 +00:00
Timo Tijhof
4ec550812b objectcache: Refresh key in HashBagOStuff::set() for maxKeys eviction
* Match behaviour of MapCacheLRU and ProcessCacheLRU.
* Add missing unit tests for TTL and maxCacheKeys eviction behaviour.

Change-Id: I559eae1cd336274b21728e86775cfbad7e2f2c6d
2015-11-03 01:59:30 -08: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
d2d935483f Make makeKeyInternal() limit more conservative
This should avoid error log entries for long WAN cache keys

Change-Id: I401482d25dd5bf47052a3c6729c5f8bc9fd68770
2015-11-01 19:37:21 -08: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
jenkins-bot
30135f1dec Merge "Protect WAN cache sets() against uncommitted data" 2015-10-27 10:18:52 +00: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
b9778e1a10 Merge "Fix bogus calls to encodeKey/decodeKey in the PHP memcached class" 2015-10-24 23:39:50 +00:00
Timo Tijhof
22b9599cda objectcache: Remove outdated comment about back-compat defaults
Follows-up 0dd27b1da9.

Change-Id: Ic21b02d93d6047eb4713dfec3cbb2fff4d51fdff
2015-10-24 23:41:44 +01:00
Aaron Schulz
51fe42fc1a Fix bogus calls to encodeKey/decodeKey in the PHP memcached class
* Follow up to cdb5432728
* These are no longer needed

Change-Id: Id41c3aae50a13f3c53f2bbd9662027b36a1f4142
2015-10-24 15:38:23 -07:00
Aaron Schulz
f36b73e96c Move some memcached classes to /libs
Also removed a few MW dependencies from MemcachedPeclBagOStuff.
It still uses an IP class method, so it has to stay for now.

Change-Id: I8c5c83046c58fb58091d6ce11b2385208262460f
2015-10-24 15:27:42 -07:00
Aaron Schulz
cce813a922 Move MultiWriteBagOStuff to /libs
Also moved related tests files to /libs.

Change-Id: I806eeaa30205733d497adde933baf0c4157f7aae
2015-10-24 12:15:26 -07:00
Ori Livneh
0c9fb12265 Escape colons in BagOStuff key segments
For the sake of safety and correctness, the following BagOStuff::makeKey()
invocations should return distinct keys:

   $cache->makeKey( 'ab:', 'cd' );
   $cache->makeKey( 'ab', ':cd' );

That is not currently the case, because while we use ':' as a key path
separator, we don't escape ':' in the input supplied to makeKey(). So, make
BagOStuff::makeKeyInternal() URL-encode colons.

To prevent this from messing up the max. key length calculations, reproduce
this logic in MemcachedBagOStuff::makeKeyInternal(), in lieu of having the
method call its parent.

Change-Id: I83ea7e7336a1c9e64aa42284c2517089a736efe5
2015-10-23 20:26:49 -07:00
Aaron Schulz
fb7022c54d Bound BagOStuff::lock() RTT estimate for sanity
The timestamp difference might be 0 (or in rare cases, less)

Change-Id: I0298b413df637d9da5ff33c078ad49dadc8a46ce
2015-10-21 20:14:54 -07:00
jenkins-bot
409e7d6a70 Merge "objectcache: Fix grammar error in BagOStuff::getWithToken doc" 2015-10-22 02:33:16 +00:00
Aaron Schulz
5c8ef13306 Add WRITE_SYNC flag to BagOStuff::set()/merge()
* This blocks on writing to all replicas
  and returns false if any failed.
* This is useful if ChronologyProtector is to work across
  domains by having the writes go everywhere so that later
  reads will see them (and be local at the same time).
* Redundant doc comments were also removed.

Change-Id: I9ed098d563c64dba605e7809bc96731da3b3e79d
2015-10-22 01:44:09 +00:00
Timo Tijhof
92b197dc59 objectcache: Fix grammar error in BagOStuff::getWithToken doc
Follows-up 1fa1235d32.

Change-Id: I19a4430609423f5ff32a1014ed21131175469adf
2015-10-22 02:35:35 +01:00
Aaron Schulz
922f15e8e0 Remove ObjectCache dependency from MultiWriteBagOStuff
This brings it closer to being able to move to /libs.

Change-Id: Ia733f9023e56d4a25ffcb99ca0cc8b29cbb2ad45
2015-10-20 00:16:51 +00:00
jenkins-bot
f17437d8c2 Merge "Add make(Global)Key() method to WANObjectCache" 2015-10-20 00:14:54 +00:00