1
0
Fork 0

Merge pull request #9537 from annando/item-lock

Fallback to database lock if locking fails
This commit is contained in:
Hypolite Petovan 2020-11-16 16:05:24 -05:00 committed by GitHub
commit ba0d3b2435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -122,7 +122,7 @@ class LockFactory
try { try {
return new Lock\SemaphoreLock(); return new Lock\SemaphoreLock();
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->logger->debug('Using Semaphore driver for locking failed.', ['exception' => $exception]); $this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]);
} }
} }
@ -135,7 +135,7 @@ class LockFactory
return new Lock\CacheLock($cache); return new Lock\CacheLock($cache);
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->logger->debug('Using Cache driver for locking failed.', ['exception' => $exception]); $this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]);
} }
} }

View file

@ -1888,10 +1888,16 @@ class Item
} }
} }
if (DI::lock()->acquire(self::LOCK_INSERT, 0)) { $locked = DI::lock()->acquire(self::LOCK_INSERT, 0);
if ($locked || DBA::lock('item')) {
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']]; $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
if (DBA::exists('item', $condition)) { if (DBA::exists('item', $condition)) {
if ($locked) {
DI::lock()->release(self::LOCK_INSERT); DI::lock()->release(self::LOCK_INSERT);
} else {
DBA::unlock();
}
Logger::notice('Item is already inserted - aborting', $condition); Logger::notice('Item is already inserted - aborting', $condition);
return 0; return 0;
} }
@ -1900,7 +1906,11 @@ class Item
// When the item was successfully stored we fetch the ID of the item. // When the item was successfully stored we fetch the ID of the item.
$current_post = DBA::lastInsertId(); $current_post = DBA::lastInsertId();
if ($locked) {
DI::lock()->release(self::LOCK_INSERT); DI::lock()->release(self::LOCK_INSERT);
} else {
DBA::unlock();
}
} else { } else {
Logger::warning('Item lock had not been acquired'); Logger::warning('Item lock had not been acquired');
$result = false; $result = false;