diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-08 14:53:26 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-08 14:53:26 +0200 |
commit | 1d3d43b1e9cf423e8ce65ef5ad95a9da54a703b5 (patch) | |
tree | bd27c4603778ccb602de4ba427cebfa68bf7222e /lib | |
parent | 53acb4a65fc72e2f383db4d978907e7ce219a4b2 (diff) | |
parent | cdedda99e4b7f66f136d7db4788c2f033df2d442 (diff) | |
download | nextcloud-server-1d3d43b1e9cf423e8ce65ef5ad95a9da54a703b5.tar.gz nextcloud-server-1d3d43b1e9cf423e8ce65ef5ad95a9da54a703b5.zip |
Merge pull request #23553 from owncloud/lock-ttl-execution-time
Make lock ttl configurable
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Server.php | 9 | ||||
-rw-r--r-- | lib/private/lock/abstractlockingprovider.php | 2 | ||||
-rw-r--r-- | lib/private/lock/dblockingprovider.php | 6 | ||||
-rw-r--r-- | lib/private/lock/memcachelockingprovider.php | 6 |
4 files changed, 15 insertions, 8 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php index 581a2b44cea..2ce895c6f72 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -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(); }); diff --git a/lib/private/lock/abstractlockingprovider.php b/lib/private/lock/abstractlockingprovider.php index 7dee8c709a0..f96358778c1 100644 --- a/lib/private/lock/abstractlockingprovider.php +++ b/lib/private/lock/abstractlockingprovider.php @@ -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' => [], diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php index c10cd8636ad..9e97df44d3f 100644 --- a/lib/private/lock/dblockingprovider.php +++ b/lib/private/lock/dblockingprovider.php @@ -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; } /** diff --git a/lib/private/lock/memcachelockingprovider.php b/lib/private/lock/memcachelockingprovider.php index 08c92950e49..536b29e2c28 100644 --- a/lib/private/lock/memcachelockingprovider.php +++ b/lib/private/lock/memcachelockingprovider.php @@ -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); } } |