Skip to content
Snippets Groups Projects
Commit 744ef614 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #21073 from owncloud/memcache-lock-ttl

Add ttl for redis based locking
parents 3c2a637d e41f7b00
No related branches found
No related tags found
No related merge requests found
......@@ -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' => []
......
......@@ -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
*
......
......@@ -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);
}
}
......@@ -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', '>=');
......
<?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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment