Commit b3a2828c authored by Vincent Petry's avatar Vincent Petry
Browse files

Merge pull request #24350 from owncloud/locking-release-memory

optimize releaselock for memcache based locking backends
parents daf5f793 49ad0fcf
......@@ -116,4 +116,8 @@ abstract class AbstractLockingProvider implements ILockingProvider {
$this->releaseLock($path, self::LOCK_EXCLUSIVE);
}
}
protected function getOwnSharedLockCount($path) {
return isset($this->acquiredLocks['shared'][$path]) ? $this->acquiredLocks['shared'][$path] : 0;
}
}
......@@ -88,9 +88,14 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
*/
public function releaseLock($path, $type) {
if ($type === self::LOCK_SHARED) {
if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) {
if ($this->getOwnSharedLockCount($path) === 1) {
$removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go
if (!$removed) { //someone else also has a shared lock, decrease only
$this->memcache->dec($path);
}
} else {
// if we own more than one lock ourselves just decrease
$this->memcache->dec($path);
$this->memcache->cad($path, 0);
}
} else if ($type === self::LOCK_EXCLUSIVE) {
$this->memcache->cad($path, 'exclusive');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment