add seperate config option for locking memcache backend

This commit is contained in:
Robin Appelman 2015-05-26 14:41:37 +02:00
parent 72847dbc77
commit 6b965d71d1
3 changed files with 31 additions and 3 deletions

View File

@ -1039,6 +1039,12 @@ $CONFIG = array(
*/ */
'filelocking.enabled' => false, 'filelocking.enabled' => false,
/**
* Memory caching backend for file locking
* Because most memcache backends can clean values without warning using redis is recommended
*/
'memcache.locking' => '\OC\Memcache\Redis',
/** /**
* This entry is just here to show a warning in case somebody copied the sample * This entry is just here to show a warning in case somebody copied the sample
* configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION! * configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION!

View File

@ -46,13 +46,19 @@ class Factory implements ICacheFactory {
*/ */
private $distributedCacheClass; private $distributedCacheClass;
/**
* @var string $lockingCacheClass
*/
private $lockingCacheClass;
/** /**
* @param string $globalPrefix * @param string $globalPrefix
* @param string|null $localCacheClass * @param string|null $localCacheClass
* @param string|null $distributedCacheClass * @param string|null $distributedCacheClass
* @param string|null $lockingCacheClass
*/ */
public function __construct($globalPrefix, public function __construct($globalPrefix,
$localCacheClass = null, $distributedCacheClass = null) $localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null)
{ {
$this->globalPrefix = $globalPrefix; $this->globalPrefix = $globalPrefix;
@ -62,8 +68,23 @@ class Factory implements ICacheFactory {
if (!($distributedCacheClass && $distributedCacheClass::isAvailable())) { if (!($distributedCacheClass && $distributedCacheClass::isAvailable())) {
$distributedCacheClass = $localCacheClass; $distributedCacheClass = $localCacheClass;
} }
if (!($lockingCacheClass && $lockingCacheClass::isAvailable())) {
// dont fallback since the fallback might not be suitable for storing lock
$lockingCacheClass = '\OC\Memcache\Null';
}
$this->localCacheClass = $localCacheClass; $this->localCacheClass = $localCacheClass;
$this->distributedCacheClass = $distributedCacheClass; $this->distributedCacheClass = $distributedCacheClass;
$this->lockingCacheClass = $lockingCacheClass;
}
/**
* create a cache instance for storing locks
*
* @param string $prefix
* @return \OCP\IMemcache
*/
public function createLocking($prefix = '') {
return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix);
} }
/** /**

View File

@ -234,7 +234,8 @@ class Server extends SimpleContainer implements IServerContainer {
$prefix = md5($instanceId.'-'.$version.'-'.$path); $prefix = md5($instanceId.'-'.$version.'-'.$path);
return new \OC\Memcache\Factory($prefix, return new \OC\Memcache\Factory($prefix,
$config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null) $config->getSystemValue('memcache.distributed', null),
$config->getSystemValue('memcache.locking', null)
); );
} }
@ -426,7 +427,7 @@ class Server extends SimpleContainer implements IServerContainer {
if ($c->getConfig()->getSystemValue('filelocking.enabled', false) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { if ($c->getConfig()->getSystemValue('filelocking.enabled', false) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
/** @var \OC\Memcache\Factory $memcacheFactory */ /** @var \OC\Memcache\Factory $memcacheFactory */
$memcacheFactory = $c->getMemCacheFactory(); $memcacheFactory = $c->getMemCacheFactory();
$memcache = $memcacheFactory->createDistributed('lock'); $memcache = $memcacheFactory->createLocking('lock');
if (!($memcache instanceof \OC\Memcache\Null)) { if (!($memcache instanceof \OC\Memcache\Null)) {
return new MemcacheLockingProvider($memcache); return new MemcacheLockingProvider($memcache);
} }