8000 [Lock] feature: lock split interface fix post-merge review by Simperfit · Pull Request #32492 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Lock] feature: lock split interface fix post-merge review #32492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Lock
----

* Deprecated `Symfony\Component\Lock\StoreInterface` in favor of `Symfony\Component\Lock\BlockingStoreInterface` and
`Symfony\Component\Lock\PersistStoreInterface`.
`Symfony\Component\Lock\PersistingStoreInterface`.
* `Factory` is deprecated, use `LockFactory` instead

Messenger
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Lock
----

* Removed `Symfony\Component\Lock\StoreInterface` in favor of `Symfony\Component\Lock\BlockingStoreInterface` and
`Symfony\Component\Lock\PersistStoreInterface`.
`Symfony\Component\Lock\PersistingStoreInterface`.
* Removed `Factory`, use `LockFactory` instead

Messenger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
use Symfony\Component\Lock\Lock;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Lock\PersistStoreInterface;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\FlockStore;
use Symfony\Component\Lock\Store\StoreFactory;
use Symfony\Component\Lock\StoreInterface;
Expand Down Expand Up @@ -1606,7 +1606,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
$container->setDefinition($connectionDefinitionId, $connectionDefinition);
}

$storeDefinition = new Definition(PersistStoreInterface::class);
$storeDefinition = new Definition(PersistingStoreInterface::class);
$storeDefinition->setPublic(false);
$storeDefinition->setFactory([StoreFactory::class, 'createStore']);
$storeDefinition->setArguments([new Reference($connectionDefinitionId)]);
Expand Down Expand Up @@ -1649,13 +1649,13 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
$container->setAlias('lock', new Alias('lock.'.$resourceName, false));
$container->setAlias(StoreInterface::class, new Alias('lock.store', false));
$container->setAlias(PersistStoreInterface::class, new Alias('lock.store', false));
$container->setAlias(PersistingStoreInterface::class, new Alias('lock.store', false));
$container->setAlias(Factory::class, new Alias('lock.factory', false));
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
$container->setAlias(LockInterface::class, new Alias('lock', false));
} else {
$container->registerAliasForArgument('lock.'.$resourceName.'.store', StoreInterface::class, $resourceName.'.lock.store');
$container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistStoreInterface::class, $resourceName.'.lock.store');
$container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistingStoreInterface::class, $resourceName.'.lock.store');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', Factory::class, $resourceName.'.lock.factory');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock');
Expand Down
9 changes: 0 additions & 9 deletions src/Symfony/Component/Lock/BlockingStoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Lock;

use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Exception\NotSupportedException;

/**
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
Expand All @@ -22,15 +21,7 @@ interface BlockingStoreInterface
/**
* Waits until a key becomes free, then stores the resource.
*
* If the store does not support this feature it should throw a NotSupportedException.
*
* @throws LockConflictedException
* @throws NotSupportedException
*/
public function waitAndSave(Key $key);

/**
* Checks if the store can wait until a key becomes free before storing the resource.
*/
public function supportsWaitAndSave(): bool;
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Lock/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGELOG
-----

* added InvalidTtlException
* deprecated `Symfony\Component\Lock\StoreInterface` in favor of `Symfony\Component\Lock\BlockingStoreInterface` and `Symfony\Component\Lock\PersistStoreInterface`
* deprecated `StoreInterface` in favor of `BlockingStoreInterface` and `PersistingStoreInterface`

4.2.0
-----
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Lock/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ final class Lock implements LockInterface, LoggerAwareInterface
private $dirty = false;

/**
* @param Key $key Resource to lock
* @param PersistStoreInterface $store Store used to handle lock persistence
* @param float|null $ttl Maximum expected lock duration in seconds
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
* @param Key $key Resource to lock
* @param PersistingStoreInterface $store Store used to handle lock persistence
* @param float|null $ttl Maximum expected lock duration in seconds
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
*/
public function __construct(Key $key, PersistStoreInterface $store, float $ttl = null, bool $autoRelease = true)
public function __construct(Key $key, PersistingStoreInterface $store, float $ttl = null, bool $autoRelease = true)
{
$this->store = $store;
$this->key = $key;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function acquire($blocking = false)
{
try {
if ($blocking) {
if (!$this->store instanceof StoreInterface && !($this->store instanceof BlockingStoreInterface && $this->store->supportsWaitAndSave())) {
if (!$this->store instanceof StoreInterface && !$this->store instanceof BlockingStoreInterface) {
throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this->store)));
}
$this->store->waitAndSave($this->key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Jérémy Derussé <jeremy@derusse.com>
*/
interface PersistStoreInterface
interface PersistingStoreInterface
{
/**
* Stores the resource if it's not locked by someone else.
Expand Down
22 changes: 8 additions & 14 deletions src/Symfony/Component/Lock/Store/CombinedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Exception\NotSupportedException;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistStoreInterface;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\StoreInterface;
use Symfony\Component\Lock\Strategy\StrategyInterface;

Expand All @@ -32,22 +32,22 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
use LoggerAwareTrait;
use ExpiringStoreTrait;

/** @var PersistStoreInterface[] */
/** @var PersistingStoreInterface[] */
private $stores;
/** @var StrategyInterface */
private $strategy;

/**
* @param PersistStoreInterface[] $stores The list of synchronized stores
* @param StrategyInterface $strategy
* @param PersistingStoreInterface[] $stores The list of synchronized stores
* @param StrategyInterface $strategy
*
* @throws InvalidArgumentException
*/
public function __construct(array $stores, StrategyInterface $strategy)
{
foreach ($stores as $store) {
if (!$store instanceof PersistStoreInterface) {
throw new InvalidArgumentException(sprintf('The store must implement "%s". Got "%s".', PersistStoreInterface::class, \get_class($store)));
if (!$store instanceof PersistingStoreInterface) {
throw new InvalidArgumentException(sprintf('The store must implement "%s". Got "%s".', PersistingStoreInterface::class, \get_class($store)));
}
}

Expand Down Expand Up @@ -95,6 +95,8 @@ public function save(Key $key)

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.4.
*/
public function waitAndSave(Key $key)
{
Expand Down Expand Up @@ -186,12 +188,4 @@ public function exists(Key $key)

return false;
}

/**
* {@inheritdoc}
*/
public function supportsWaitAndSave(): bool
{
return false;
}
}
8 changes: 0 additions & 8 deletions src/Symfony/Component/Lock/Store/FlockStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public function waitAndSave(Key $key)
$this->lock($key, true);
}

/**
* {@inheritdoc}
*/
public function supportsWaitAndSave(): bool
{
return true;
}

private function lock(Key $key, $blocking)
{
// The lock is maybe already acquired.
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Lock/Store/MemcachedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ public function save(Key $key)

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.4.
*/
public function waitAndSave(Key $key)
{
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__));
@trigger_error(sprintf('%s() is deprecated since Symfony 4.4 and will be removed in Symfony 5.0.', __METHOD__), E_USER_DEPRECATED);
throw new InvalidArgumentException(sprintf('The store "%s" does not supports blocking locks.', \get_class($this)));
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Lock/Store/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function save(Key $key)

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.4.
*/
public function waitAndSave(Key $key)
{
Expand Down
20 changes: 6 additions & 14 deletions src/Symfony/Component/Lock/Store/RetryTillSaveStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\Lock\BlockingStoreInterface;
use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistStoreInterface;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\StoreInterface;

/**
Expand All @@ -26,7 +26,7 @@
*
* @author Jérémy Derussé <jeremy@derusse.com>
*/
class RetryTillSaveStore implements PersistStoreInterface, BlockingStoreInterface, StoreInterface, LoggerAwareInterface
class RetryTillSaveStore implements PersistingStoreInterface, BlockingStoreInterface, StoreInterface, LoggerAwareInterface
{
use LoggerAwareTrait;

Expand All @@ -35,11 +35,11 @@ class RetryTillSaveStore implements PersistStoreInterface, BlockingStoreInterfac
private $retryCount;

/**
* @param PersistStoreInterface $decorated The decorated StoreInterface
* @param int $retrySleep Duration in ms between 2 retry
* @param int $retryCount Maximum amount of retry
* @param PersistingStoreInterface $decorated The decorated StoreInterface
* @param int $retrySleep Duration in ms between 2 retry
* @param int $retryCount Maximum amount of retry
*/
public function __construct(PersistStoreInterface $decorated, int $retrySleep = 100, int $retryCount = PHP_INT_MAX)
public function __construct(PersistingStoreInterface $decorated, int $retrySleep = 100, int $retryCount = PHP_INT_MAX)
{
$this->decorated = $decorated;
$this->retrySleep = $retrySleep;
Expand Down Expand Up @@ -101,12 +101,4 @@ public function exists(Key $key)
{
return $this->decorated->exists($key);
}

/**
* {@inheritdoc}
*/
public function supportsWaitAndSave(): bool
{
return true;
}
}
8 changes: 0 additions & 8 deletions src/Symfony/Component/Lock/Store/SemaphoreStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,4 @@ public function exists(Key $key)
{
return $key->hasState(__CLASS__);
}

/**
* {@inheritdoc}
*/
public function supportsWaitAndSave(): bool
{
return true;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Lock/Store/ZookeeperStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function exists(Key $key): bool

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.4.
*/
public function waitAndSave(Key $key)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Lock/StoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*
* @author Jérémy Derussé <jeremy@derusse.com>
*
* @deprecated "Symfony\Component\Lock\StoreInterface" is deprecated since Symfony 4.4 and has been split into "Symfony\Component\Lock\PersistStoreInterface", "Symfony\Component\Lock\BlockingStoreInterface".'
* @deprecated since Symfony 4.4, use PersistingStoreInterface and BlockingStoreInterface instead
*/
interface StoreInterface extends PersistStoreInterface
interface StoreInterface extends PersistingStoreInterface
{
/**
* Waits until a key becomes free, then stores the resource.
Expand Down
Loading
0