*/ class CombinedStore implements SharedLockStoreInterface, LoggerAwareInterface { use ExpiringStoreTrait; use LoggerAwareTrait; /** @var PersistingStoreInterface[] */ private array $stores; private StrategyInterface $strategy; /** * @param PersistingStoreInterface[] $stores The list of synchronized stores * * @throws InvalidArgumentException */ public function __construct(array $stores, StrategyInterface $strategy) { foreach ($stores as $store) { if (!$store instanceof PersistingStoreInterface) { throw new InvalidArgumentException(sprintf('The store must implement "%s". Got "%s".', PersistingStoreInterface::class, get_debug_type($store))); } } $this->stores = $stores; $this->strategy = $strategy; $this->logger = new NullLogger(); } /** * {@inheritdoc} */ public function save(Key $key) { $successCount = 0; $failureCount = 0; $storesCount = \count($this->stores); foreach ($this->stores as $store) { try { $store->save($key); ++$successCount; } catch (\Exception $e) { $this->logger->debug('One store failed to save the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]); ++$failureCount; } if (!$this->strategy->canBeMet($failureCount, $storesCount)) { break; } } $this->checkNotExpired($key); if ($this->strategy->isMet($successCount, $storesCount)) { return; } $this->logger->info('Failed to store the "{resource}" lock. Quorum has not been met.', ['resource' => $key, 'success' => $successCount, 'failure' => $failureCount]); // clean up potential locks $this->delete($key); throw new LockConflictedException(); } public function saveRead(Key $key) { $successCount = 0; $failureCount = 0; $storesCount = \count($this->stores); foreach ($this->stores as $store) { try { if ($store instanceof SharedLockStoreInterface) { $store->saveRead($key); } else { $store->save($key); } ++$successCount; } catch (\Exception $e) { $this->logger->debug('One store failed to save the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]); ++$failureCount; } if (!$this->strategy->canBeMet($failureCount, $storesCount)) { break; } } $this->checkNotExpired($key); if ($this->strategy->isMet($successCount, $storesCount)) { return; } $this->logger->info('Failed to store the "{resource}" lock. Quorum has not been met.', ['resource' => $key, 'success' => $successCount, 'failure' => $failureCount]); // clean up potential locks $this->delete($key); throw new LockConflictedException(); } /** * {@inheritdoc} */ public function putOffExpiration(Key $key, float $ttl) { $successCount = 0; $failureCount = 0; $storesCount = \count($this->stores); $expireAt = microtime(true) + $ttl; foreach ($this->stores as $store) { try { if (0.0 >= $adjustedTtl = $expireAt - microtime(true)) { $this->logger->debug('Stores took to long to put off the expiration of the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'ttl' => $ttl]); $key->reduceLifetime(0); break; } $store->putOffExpiration($key, $adjustedTtl); ++$successCount; } catch (\Exception $e) { $this->logger->debug('One store failed to put off the expiration of the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]); ++$failureCount; } if (!$this->strategy->canBeMet($failureCount, $storesCount)) { break; } } $this->checkNotExpired($key); if ($this->strategy->isMet($successCount, $storesCount)) { return; } $this->logger->notice('Failed to define the expiration for the "{resource}" lock. Quorum has not been met.', ['resource' => $key, 'success' => $successCount, 'failure' => $failureCount]); // clean up potential locks $this->delete($key); throw new LockConflictedException(); } /** * {@inheritdoc} */ public function delete(Key $key) { foreach ($this->stores as $store) { try { $store->delete($key); } catch (\Exception $e) { $this->logger->notice('One store failed to delete the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]); } } } /** * {@inheritdoc} */ public function exists(Key $key): bool { $successCount = 0; $failureCount = 0; $storesCount = \count($this->stores); foreach ($this->stores as $store) { try { if ($store->exists($key)) { ++$successCount; } else { ++$failureCount; } } catch (\Exception $e) { $this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]); ++$failureCount; } if ($this->strategy->isMet($successCount, $storesCount)) { return true; } if (!$this->strategy->canBeMet($failureCount, $storesCount)) { return false; } } return false; } } __halt_compiler();----SIGNATURE:----D8PqaxdQZ31Wv6PHgOCUOj11ovQMpceBlx808xj419X3mVB/bL/lH7hPDgame6aqRwqSulCT0izK4+J9akjOSRrJz5dpwSqyVQHoVf/oweYzDOYWNaBpBgUULtBE5RVPkDqJ8S3DJwuiUmJPCJG+g/Rw8zsXjHQMwwuv6tR4hUc8/qjfs8ABdRkLnE+hwYydOCcSoX6jQT/9RVnTeY7oqlu0zsfYCxYf04sQ5NHXPg8ZdrmtgXu4AG9Eg18JFDJyg4abdfHnfgvNoGbuixrlJLbfgYmpdyn0EVD8AgSsC8xowgx2HHvbMqW9gRfwEIDxX0tEtmtunpMvpq6eelSJ6zolIgqhRImE78ZdJYfJSUcNvV2+oFnliuGjxS6GPxwkwZ2Xv92lRabbF38XrO8u5PnW8zZNXiMYZ9dfng4lAh54wfMPpk1f2+0QE3YceiEBXqqJH34xXPjchYWmxCESONALEYibU/0qpWLpW0r4ascCXu17NOGszEn7ks23oWsvUp4oXNvhAHe8ipKrNBCGzbl5xf2w7XrjWGn7kCQHqxewwxMB4AzoCaB2nocxhK4Za2fPZcMgpyMgbRb82tSzD/U9WyJ9LwaxuszRzKQvMzIrGGWTFcsKAlo114oAfQtFFyKNLkR00sj1IXAWgYvkjattkw3hhS1fgAE7cfIyjUs=----ATTACHMENT:----MzM3MzE3MzIyMjMzOTIwNiA5MjM2ODM1NjcxOTkxOTA4IDE3MTM5MzI0NjY5NTExOTQ=