Log more info about locking conflicts for memcache locking backends
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
642ebea490
commit
a070c1177a
|
@ -71,12 +71,12 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
|
||||||
public function acquireLock($path, $type) {
|
public function acquireLock($path, $type) {
|
||||||
if ($type === self::LOCK_SHARED) {
|
if ($type === self::LOCK_SHARED) {
|
||||||
if (!$this->memcache->inc($path)) {
|
if (!$this->memcache->inc($path)) {
|
||||||
throw new LockedException($path);
|
throw new LockedException($path, null, $this->getExistingLockForException($path));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->memcache->add($path, 0);
|
$this->memcache->add($path, 0);
|
||||||
if (!$this->memcache->cas($path, 0, 'exclusive')) {
|
if (!$this->memcache->cas($path, 0, 'exclusive')) {
|
||||||
throw new LockedException($path);
|
throw new LockedException($path, null, $this->getExistingLockForException($path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setTTL($path);
|
$this->setTTL($path);
|
||||||
|
@ -114,15 +114,26 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
|
||||||
public function changeLock($path, $targetType) {
|
public function changeLock($path, $targetType) {
|
||||||
if ($targetType === self::LOCK_SHARED) {
|
if ($targetType === self::LOCK_SHARED) {
|
||||||
if (!$this->memcache->cas($path, 'exclusive', 1)) {
|
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) {
|
} 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
|
// 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')) {
|
if (!$this->memcache->cas($path, 1, 'exclusive')) {
|
||||||
throw new LockedException($path);
|
throw new LockedException($path, null, $this->getExistingLockForException($path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->setTTL($path);
|
$this->setTTL($path);
|
||||||
$this->markChange($path, $targetType);
|
$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';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,15 @@ class LockedException extends \Exception {
|
||||||
*
|
*
|
||||||
* @param string $path locked path
|
* @param string $path locked path
|
||||||
* @param \Exception|null $previous previous exception for cascading
|
* @param \Exception|null $previous previous exception for cascading
|
||||||
*
|
* @param string $existingLock since 13.0.3
|
||||||
* @since 8.1.0
|
* @since 8.1.0
|
||||||
*/
|
*/
|
||||||
public function __construct($path, \Exception $previous = null) {
|
public function __construct($path, \Exception $previous = null, $existingLock = null) {
|
||||||
parent::__construct('"' . $path . '" is locked', 0, $previous);
|
$message = '"' . $path . '" is locked';
|
||||||
|
if ($existingLock) {
|
||||||
|
$message .= ', existing lock on file: ' . $existingLock;
|
||||||
|
}
|
||||||
|
parent::__construct($message, 0, $previous);
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue