Fixing force-flag for lock-releasing

This commit is contained in:
Philipp Holzer 2019-02-24 10:08:28 +01:00
parent 9f11476ca0
commit 9b07132b80
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
6 changed files with 23 additions and 11 deletions

View File

@ -122,12 +122,13 @@ class Lock
/** /**
* @brief Releases a lock if it was set by us * @brief Releases a lock if it was set by us
* *
* @param string $key Name of the lock * @param string $key Name of the lock
* @param bool $force Force the lock to get releases
* @return void * @return void
*/ */
public static function release($key) public static function release($key, $force = false)
{ {
self::getDriver()->releaseLock($key); self::getDriver()->releaseLock($key, $force);
} }
/** /**

View File

@ -61,11 +61,15 @@ class CacheLockDriver extends AbstractLockDriver
/** /**
* (@inheritdoc) * (@inheritdoc)
*/ */
public function releaseLock($key) public function releaseLock($key, $force = false)
{ {
$cachekey = self::getLockKey($key); $cachekey = self::getLockKey($key);
$this->cache->compareDelete($cachekey, getmypid()); if ($force) {
$this->cache->delete($key);
} else {
$this->cache->compareDelete($cachekey, getmypid());
}
$this->markRelease($key); $this->markRelease($key);
} }

View File

@ -68,9 +68,15 @@ class DatabaseLockDriver extends AbstractLockDriver
/** /**
* (@inheritdoc) * (@inheritdoc)
*/ */
public function releaseLock($key) public function releaseLock($key, $force = false)
{ {
DBA::delete('locks', ['name' => $key, 'pid' => $this->pid]); if ($force) {
$where = ['name' => $key];
} else {
$where = ['name' => $key, 'pid' => $this->pid];
}
DBA::delete('locks', $where);
$this->markRelease($key); $this->markRelease($key);

View File

@ -33,11 +33,12 @@ interface ILockDriver
/** /**
* Releases a lock if it was set by us * Releases a lock if it was set by us
* *
* @param string $key The Name of the lock * @param string $key The Name of the lock
* @param bool $force Force the lock to get released
* *
* @return void * @return void
*/ */
public function releaseLock($key); public function releaseLock($key, $force = false);
/** /**
* Releases all lock that were set by us * Releases all lock that were set by us

View File

@ -50,7 +50,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
/** /**
* (@inheritdoc) * (@inheritdoc)
*/ */
public function releaseLock($key) public function releaseLock($key, $force = false)
{ {
if (empty(self::$semaphore[$key])) { if (empty(self::$semaphore[$key])) {
return false; return false;

View File

@ -60,7 +60,7 @@ class Update
// In force mode, we release the dbupdate lock first // In force mode, we release the dbupdate lock first
// Necessary in case of an stuck update // Necessary in case of an stuck update
if ($force) { if ($force) {
Lock::release('dbupdate'); Lock::release('dbupdate', true);
} }
$build = Config::get('system', 'build'); $build = Config::get('system', 'build');