Page MenuHomePhabricator

wfGetCache in ObjectCache.php has incorrect values for type?
Closed, ResolvedPublic

Description

Author: dallan

Description:
On lines 63 and 65 of ObjectCache.php, inside the "if ($type ==
CACHE_MEMCACHED).." statement, on lines 63 and 65:

$wgCaches[CACHE_DB] = new MemCachedClientforWiki(...)
$cache =& $wgCaches[CACHE_DB];

it seems like CACHE_DB should be changed to CACHE_MEMCACHED

Also, would it make sense to add some instructions in docs/memcached to tell
people that they should also set the following if they're using memcached?
$wgMainCacheType = CACHE_MEMCACHED


Version: 1.7.x
Severity: normal

Details

Reference
bz7474

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:26 PM
bzimport set Reference to bz7474.
bzimport added a subscriber: Unknown Object (MLST).

dallan wrote:

Also, I think the $cache =& $wgCaches[CACHE_MEMCACHED] should go outside the IF
statement. In summary, I think the last lines of the IF statement should be

$wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
    array('persistant' => $wgMemCachedPersistent, 'compress_threshold' =>

1500 ) );

  $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
  $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
}
$cache =& $wgCaches[CACHE_MEMCACHED];

} elseif ($type == CACHE_ACCEL) {

dallan wrote:

One additional thing: When the key to store contains a space, the memcached
process returns a CLIENT_ERROR because its keys can't contain spaces. Does the
MemCachedClientforWiki class in ObjectCache.php need to override the various
get/set functions and convert spaces in keys to underscores before passing them
to memcached? Would that work? Or would it need to convert spaces in keys to a
magic string like 'SPACE'?

Is the main wikipedia site using memcached, or one of the other cache alternatives?

Keys cannot contain spaces, so that's user error.

Wikipedia uses memcached.

dallan wrote:

Thanks for the reply. It seems like there are instances where the mediawiki
software tries to inject keys with spaces, in particular keys of the form
"wikidb:messages:message text". When I go to Special:Upload for example it
tries to inject a key for each of the possible license types, and many of them
contain spaces.

I've reverted r16928 as this causes the objectcache table to be used instead of
memcached, grinding Wikimedia's servers to a halt.

dallan wrote:

I looked at the diff -- looks good. I think you may also need to add the
following line after the if statement:

if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){
...
}
//NEW LINE AFTER IF STATEMENT
$cache =& $wgCaches[CACHE_MEMCACHED];

to handle the case when another request for a memcached cache is made but the
memcached cache has been set up already. This is similar to what you do for
CACHE_DBA and CACHE_DB.