Make lock ttl configurable
This commit is contained in:
parent
9b930cd01d
commit
cdedda99e4
|
@ -1193,6 +1193,15 @@ $CONFIG = array(
|
|||
*/
|
||||
'filelocking.enabled' => true,
|
||||
|
||||
/**
|
||||
* Set the time-to-live for locks in secconds.
|
||||
*
|
||||
* Any lock older than this will be automatically cleaned up.
|
||||
*
|
||||
* If not set this defaults to either 1 hour or the php max_execution_time, whichever is higher.
|
||||
*/
|
||||
'filelocking.ttl' => 3600,
|
||||
|
||||
/**
|
||||
* Memory caching backend for file locking
|
||||
*
|
||||
|
|
|
@ -519,14 +519,17 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
);
|
||||
});
|
||||
$this->registerService('LockingProvider', function (Server $c) {
|
||||
if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
|
||||
$ini = $c->getIniWrapper();
|
||||
$config = $c->getConfig();
|
||||
$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
|
||||
if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
|
||||
/** @var \OC\Memcache\Factory $memcacheFactory */
|
||||
$memcacheFactory = $c->getMemCacheFactory();
|
||||
$memcache = $memcacheFactory->createLocking('lock');
|
||||
if (!($memcache instanceof \OC\Memcache\NullCache)) {
|
||||
return new MemcacheLockingProvider($memcache);
|
||||
return new MemcacheLockingProvider($memcache, $ttl);
|
||||
}
|
||||
return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory());
|
||||
return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
|
||||
}
|
||||
return new NoopLockingProvider();
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ use OCP\Lock\ILockingProvider;
|
|||
* to release any left over locks at the end of the request
|
||||
*/
|
||||
abstract class AbstractLockingProvider implements ILockingProvider {
|
||||
const TTL = 3600; // how long until we clear stray locks in seconds
|
||||
protected $ttl; // how long until we clear stray locks in seconds
|
||||
|
||||
protected $acquiredLocks = [
|
||||
'shared' => [],
|
||||
|
|
|
@ -93,11 +93,13 @@ class DBLockingProvider extends AbstractLockingProvider {
|
|||
* @param \OCP\IDBConnection $connection
|
||||
* @param \OCP\ILogger $logger
|
||||
* @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory
|
||||
* @param int $ttl
|
||||
*/
|
||||
public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory) {
|
||||
public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory, $ttl = 3600) {
|
||||
$this->connection = $connection;
|
||||
$this->logger = $logger;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->ttl = $ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +119,7 @@ class DBLockingProvider extends AbstractLockingProvider {
|
|||
* @return int
|
||||
*/
|
||||
protected function getExpireTime() {
|
||||
return $this->timeFactory->getTime() + self::TTL;
|
||||
return $this->timeFactory->getTime() + $this->ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,14 +33,16 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
|
|||
|
||||
/**
|
||||
* @param \OCP\IMemcache $memcache
|
||||
* @param int $ttl
|
||||
*/
|
||||
public function __construct(IMemcache $memcache) {
|
||||
public function __construct(IMemcache $memcache, $ttl = 3600) {
|
||||
$this->memcache = $memcache;
|
||||
$this->ttl = $ttl;
|
||||
}
|
||||
|
||||
private function setTTL($path) {
|
||||
if ($this->memcache instanceof IMemcacheTTL) {
|
||||
$this->memcache->setTTL($path, self::TTL);
|
||||
$this->memcache->setTTL($path, $this->ttl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class DBLockingProvider extends LockingProvider {
|
|||
*/
|
||||
protected function getInstance() {
|
||||
$this->connection = \OC::$server->getDatabaseConnection();
|
||||
return new \OC\Lock\DBLockingProvider($this->connection, \OC::$server->getLogger(), $this->timeFactory);
|
||||
return new \OC\Lock\DBLockingProvider($this->connection, \OC::$server->getLogger(), $this->timeFactory, 3600);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
|
@ -81,7 +81,7 @@ class DBLockingProvider extends LockingProvider {
|
|||
$this->instance->acquireLock('bar', ILockingProvider::LOCK_EXCLUSIVE);
|
||||
$this->instance->changeLock('asd', ILockingProvider::LOCK_SHARED);
|
||||
|
||||
$this->currentTime = 150 + \OC\Lock\DBLockingProvider::TTL;
|
||||
$this->currentTime = 150 + 3600;
|
||||
|
||||
$this->assertEquals(3, $this->getLockEntryCount());
|
||||
|
||||
|
|
Loading…
Reference in New Issue