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

Breadcrumb

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

function PostgreSqlStore::waitAndSave

Overrides BlockingStoreInterface::waitAndSave

File

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

Class

PostgreSqlStore
PostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks.

Namespace

Symfony\Component\Lock\Store

Code

public function waitAndSave(Key $key) : void {
    // prevent concurrency within the same connection
    // Internal store does not allow blocking mode, because there is no way to acquire one in a single process
    $this->getInternalStore()
        ->save($key);
    $lockAcquired = false;
    $sql = 'SELECT pg_advisory_lock(:key)';
    try {
        $stmt = $this->getConnection()
            ->prepare($sql);
        $stmt->bindValue(':key', $this->getHashedKey($key));
        $stmt->execute();
        $lockAcquired = true;
    } finally {
        if (!$lockAcquired) {
            $this->getInternalStore()
                ->delete($key);
        }
    }
    // release lock in case of promotion
    $this->unlockShared($key);
}

API Navigation

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