Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PostgreSqlStore.php

function PostgreSqlStore::save

Overrides PersistingStoreInterface::save

File

vendor/symfony/lock/Store/PostgreSqlStore.php, line 70

Class

PostgreSqlStore
PostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks.

Namespace

Symfony\Component\Lock\Store

Code

public function save(Key $key) : void {
    // prevent concurrency within the same connection
    $this->getInternalStore()
        ->save($key);
    $lockAcquired = false;
    try {
        $sql = 'SELECT pg_try_advisory_lock(: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 sharedLock in case of promotion
            $this->unlockShared($key);
            $lockAcquired = true;
            return;
        }
    } finally {
        if (!$lockAcquired) {
            $this->getInternalStore()
                ->delete($key);
        }
    }
    throw new LockConflictedException();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal