aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-04-29 17:00:44 +0200
committerVincent Petry <pvince81@owncloud.com>2016-04-29 17:00:44 +0200
commitb3a2828c461772359bc33f685fbf247f87f334b2 (patch)
tree8a8165f7a7d6482d7087047c2120bb78bc1f5473
parentdaf5f793a472b03e67e7f96b29367b544694645d (diff)
parent49ad0fcfa9eba188d5032f8ffcd95d7cc235db80 (diff)
downloadnextcloud-server-b3a2828c461772359bc33f685fbf247f87f334b2.tar.gz
nextcloud-server-b3a2828c461772359bc33f685fbf247f87f334b2.zip
Merge pull request #24350 from owncloud/locking-release-memory
optimize releaselock for memcache based locking backends
-rw-r--r--lib/private/Lock/AbstractLockingProvider.php4
-rw-r--r--lib/private/Lock/MemcacheLockingProvider.php9
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/private/Lock/AbstractLockingProvider.php b/lib/private/Lock/AbstractLockingProvider.php
index f96358778c1..1886fbea082 100644
--- a/lib/private/Lock/AbstractLockingProvider.php
+++ b/lib/private/Lock/AbstractLockingProvider.php
@@ -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;
+ }
}
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php
index 536b29e2c28..56e581b2192 100644
--- a/lib/private/Lock/MemcacheLockingProvider.php
+++ b/lib/private/Lock/MemcacheLockingProvider.php
@@ -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');