function PostgreSqlStore::saveRead
Overrides SharedLockStoreInterface::saveRead
File
-
vendor/
symfony/ lock/ Store/ PostgreSqlStore.php, line 102
Class
- PostgreSqlStore
- PostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks.
Namespace
Symfony\Component\Lock\StoreCode
public function saveRead(Key $key) : void {
// prevent concurrency within the same connection
$this->getInternalStore()
->saveRead($key);
$lockAcquired = false;
try {
$sql = 'SELECT pg_try_advisory_lock_shared(:key)';
$stmt = $this->getConnection()
->prepare($sql);
$stmt->bindValue(':key', $this->getHashedKey($key));
$result = $stmt->execute();
// Check if lock is acquired
if (true === $stmt->fetchColumn()) {
$key->markUnserializable();
// release lock in case of demotion
$this->unlock($key);
$lockAcquired = true;
return;
}
} finally {
if (!$lockAcquired) {
$this->getInternalStore()
->delete($key);
}
}
throw new LockConflictedException();
}