diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-10 13:51:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-10 13:51:01 +0100 |
commit | 744ef6141bc190e21ddd24a9cad5829443ca0c1e (patch) | |
tree | 19098f934e4c56b7bbd34f8e65eeb76c26f7aa31 | |
parent | 3c2a637d66293e58cdeb0c3b91f366b4d1efe65f (diff) | |
parent | e41f7b005db6b03d2ab29f37dbbeac3ba892e5fe (diff) | |
download | nextcloud-server-744ef6141bc190e21ddd24a9cad5829443ca0c1e.tar.gz nextcloud-server-744ef6141bc190e21ddd24a9cad5829443ca0c1e.zip |
Merge pull request #21073 from owncloud/memcache-lock-ttl
Add ttl for redis based locking
-rw-r--r-- | lib/private/lock/abstractlockingprovider.php | 2 | ||||
-rw-r--r-- | lib/private/lock/dblockingprovider.php | 2 | ||||
-rw-r--r-- | lib/private/lock/memcachelockingprovider.php | 9 | ||||
-rw-r--r-- | lib/private/memcache/redis.php | 8 | ||||
-rw-r--r-- | lib/public/imemcachettl.php | 38 |
5 files changed, 55 insertions, 4 deletions
diff --git a/lib/private/lock/abstractlockingprovider.php b/lib/private/lock/abstractlockingprovider.php index c7a29380efe..db5f1c72dd7 100644 --- a/lib/private/lock/abstractlockingprovider.php +++ b/lib/private/lock/abstractlockingprovider.php @@ -28,6 +28,8 @@ 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 $acquiredLocks = [ 'shared' => [], 'exclusive' => [] diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php index 90657e6725f..b3a12bb9a07 100644 --- a/lib/private/lock/dblockingprovider.php +++ b/lib/private/lock/dblockingprovider.php @@ -51,8 +51,6 @@ class DBLockingProvider extends AbstractLockingProvider { private $sharedLocks = []; - const TTL = 3600; // how long until we clear stray locks in seconds - /** * Check if we have an open shared lock for a path * diff --git a/lib/private/lock/memcachelockingprovider.php b/lib/private/lock/memcachelockingprovider.php index e4158dcdfdf..af95200d159 100644 --- a/lib/private/lock/memcachelockingprovider.php +++ b/lib/private/lock/memcachelockingprovider.php @@ -21,6 +21,7 @@ namespace OC\Lock; +use OCP\IMemcacheTTL; use OCP\Lock\LockedException; use OCP\IMemcache; @@ -37,6 +38,12 @@ class MemcacheLockingProvider extends AbstractLockingProvider { $this->memcache = $memcache; } + private function setTTL($path) { + if ($this->memcache instanceof IMemcacheTTL) { + $this->memcache->setTTL($path, self::TTL); + } + } + /** * @param string $path * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE @@ -69,6 +76,7 @@ class MemcacheLockingProvider extends AbstractLockingProvider { throw new LockedException($path); } } + $this->setTTL($path); $this->markAcquire($path, $type); } @@ -106,6 +114,7 @@ class MemcacheLockingProvider extends AbstractLockingProvider { throw new LockedException($path); } } + $this->setTTL($path); $this->markChange($path, $targetType); } } diff --git a/lib/private/memcache/redis.php b/lib/private/memcache/redis.php index 83be662eabf..68b62e7534a 100644 --- a/lib/private/memcache/redis.php +++ b/lib/private/memcache/redis.php @@ -25,9 +25,9 @@ namespace OC\Memcache; -use OCP\IMemcache; +use OCP\IMemcacheTTL; -class Redis extends Cache implements IMemcache { +class Redis extends Cache implements IMemcacheTTL { /** * @var \Redis $cache */ @@ -195,6 +195,10 @@ class Redis extends Cache implements IMemcache { return false; } + public function setTTL($key, $ttl) { + self::$cache->expire($this->getNamespace() . $key, $ttl); + } + static public function isAvailable() { return extension_loaded('redis') && version_compare(phpversion('redis'), '2.2.5', '>='); diff --git a/lib/public/imemcachettl.php b/lib/public/imemcachettl.php new file mode 100644 index 00000000000..a4a7a530549 --- /dev/null +++ b/lib/public/imemcachettl.php @@ -0,0 +1,38 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP; + +/** + * Interface for memcache backends that support setting ttl after the value is set + * + * @since 9.0.0 + */ +interface IMemcacheTTL extends IMemcache { + /** + * Set the ttl for an existing value + * + * @param string $key + * @param int $ttl time to live in seconds + * @since 9.0.0 + */ + public function setTTL($key, $ttl); +} |