Commit graph

131 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
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
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