LockAcquiringException example


    public function save(Key $key)
    {
        $key->reduceLifetime($this->initialTtl);

        try {
            $this->upsert($key$this->initialTtl);
        } catch (WriteException $e) {
            if ($this->isDuplicateKeyException($e)) {
                throw new LockConflictedException('Lock was acquired by someone else.', 0, $e);
            }
            throw new LockAcquiringException('Failed to acquire lock.', 0, $e);
        }

        if ($this->options['gcProbability'] > 0.0 && (1.0 === $this->options['gcProbability'] || (random_int(0, \PHP_INT_MAX) / \PHP_INT_MAX) <= $this->options['gcProbability'])) {
            $this->createTtlIndex();
        }

        $this->checkNotExpired($key);
    }

    /** * @return void * * @throws LockStorageException * @throws LockExpiredException */
 catch (LockConflictedException $e) {
            $this->dirty = false;
            $this->logger?->info('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', ['resource' => $this->key]);

            if ($blocking) {
                throw $e;
            }

            return false;
        } catch (\Exception $e) {
            $this->logger?->notice('Failed to acquire the "{resource}" lock.', ['resource' => $this->key, 'exception' => $e]);
            throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
        }
    }

    public function acquireRead(bool $blocking = false): bool
    {
        $this->key->resetLifetime();
        try {
            if (!$this->store instanceof SharedLockStoreInterface) {
                $this->logger?->debug('Store does not support ReadLocks, fallback to WriteLock.', ['resource' => $this->key]);

                return $this->acquire($blocking);
            }
        $acl = [['perms' => \Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone']];
        // This ensures that the nodes are deleted when the client session to zookeeper server ends.         $type = \Zookeeper::EPHEMERAL;

        try {
            $this->zookeeper->create($node$value$acl$type);
        } catch (\ZookeeperException $ex) {
            if (\Zookeeper::NODEEXISTS === $ex->getCode()) {
                throw new LockConflictedException($ex);
            }

            throw new LockAcquiringException($ex);
        }
    }

    private function getKeyResource(Key $key): string
    {
        // Since we do not support storing locks as multi-level nodes, we convert them to be stored at root level.         // For example: foo/bar will become /foo-bar and /foo/bar will become /-foo-bar         $resource = (string) $key;

        if (str_contains($resource, '/')) {
            $resource = strtr($resource['/' => '-']).'-'.sha1($resource);
        }
Home | Imprint | This part of the site doesn't use cookies.