diff options
author | Robin Appelman <robin@icewind.nl> | 2018-05-04 13:30:18 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-05-04 13:30:18 +0200 |
commit | 25565dd7d808dd33cc523525209ff5cfd5b9b6cd (patch) | |
tree | b94a6f516fbdb342bd4477b9f68b08bccb1dc692 /lib/private/Lock | |
parent | c8cb42fd2671c8b6ed3257e62fa9f6a24474acb8 (diff) | |
download | nextcloud-server-25565dd7d808dd33cc523525209ff5cfd5b9b6cd.tar.gz nextcloud-server-25565dd7d808dd33cc523525209ff5cfd5b9b6cd.zip |
Log more info about locking conflicts for memcache locking backends
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Lock')
-rw-r--r-- | lib/private/Lock/MemcacheLockingProvider.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php index 70ad972b46d..55a82b22781 100644 --- a/lib/private/Lock/MemcacheLockingProvider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php @@ -72,12 +72,12 @@ class MemcacheLockingProvider extends AbstractLockingProvider { public function acquireLock(string $path, int $type) { if ($type === self::LOCK_SHARED) { if (!$this->memcache->inc($path)) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } else { $this->memcache->add($path, 0); if (!$this->memcache->cas($path, 0, 'exclusive')) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } $this->setTTL($path); @@ -115,15 +115,26 @@ class MemcacheLockingProvider extends AbstractLockingProvider { public function changeLock(string $path, int $targetType) { if ($targetType === self::LOCK_SHARED) { if (!$this->memcache->cas($path, 'exclusive', 1)) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } else if ($targetType === self::LOCK_EXCLUSIVE) { // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock if (!$this->memcache->cas($path, 1, 'exclusive')) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } $this->setTTL($path); $this->markChange($path, $targetType); } + + private function getExistingLockForException($path) { + $existing = $this->memcache->get($path); + if (!$existing) { + return 'none'; + } else if ($existing === 'exclusive') { + return $existing; + } else { + return $existing . ' shared locks'; + } + } } |