Browse Source

Make lock ttl configurable

tags/v9.1.0beta1
Robin Appelman 8 years ago
parent
commit
cdedda99e4

+ 9
- 0
config/config.sample.php View File

@@ -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
*

+ 6
- 3
lib/private/Server.php View File

@@ -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();
});

+ 1
- 1
lib/private/lock/abstractlockingprovider.php View File

@@ -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' => [],

+ 4
- 2
lib/private/lock/dblockingprovider.php View File

@@ -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;
}

/**

+ 4
- 2
lib/private/lock/memcachelockingprovider.php View File

@@ -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);
}
}


+ 2
- 2
tests/lib/lock/dblockingprovider.php View File

@@ -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…
Cancel
Save