-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Lock] Refine the contract and implementation for Stores to handle Not Expirable Store cases. #28727
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
[Lock] Refine the contract and implementation for Stores to handle Not Expirable Store cases. #28727
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Lock\Exception; | ||
|
||
/** | ||
* NotExpirableStoreException is thrown when a store doesn't support expiration of locks. | ||
* | ||
* @author Ganesh Chandrasekaran <gchandrasekaran@wayfair.com> | ||
*/ | ||
class NotExpirableStoreException extends \LogicException implements ExceptionInterface | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Symfony\Component\Lock\Exception\InvalidArgumentException; | ||
use Symfony\Component\Lock\Exception\LockConflictedException; | ||
use Symfony\Component\Lock\Exception\LockStorageException; | ||
use Symfony\Component\Lock\Exception\NotExpirableStoreException; | ||
use Symfony\Component\Lock\Key; | ||
use Symfony\Component\Lock\StoreInterface; | ||
|
||
|
@@ -108,7 +109,7 @@ private function lock(Key $key, $blocking) | |
*/ | ||
public function putOffExpiration(Key $key, $ttl) | ||
{ | ||
// do nothing, the flock locks forever. | ||
throw new NotExpirableStoreException(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's should be treated like a BC break. ping @nicolas-grekas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a BC break to me, but might be worth doing anyway instead of silently ignoring the call. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use Symfony\Component\Lock\Key; | ||
use Symfony\Component\Lock\Store\CombinedStore; | ||
use Symfony\Component\Lock\Store\RedisStore; | ||
use Symfony\Component\Lock\Store\ZookeeperStore; | ||
use Symfony\Component\Lock\StoreInterface; | ||
use Symfony\Component\Lock\Strategy\StrategyInterface; | ||
use Symfony\Component\Lock\Strategy\UnanimousStrategy; | ||
|
@@ -46,7 +47,10 @@ public function getStore() | |
self::markTestSkipped($e->getMessage()); | ||
} | ||
|
||
return new CombinedStore(array(new RedisStore($redis)), new UnanimousStrategy()); | ||
$zookeeper_server = getenv('ZOOKEEPER_HOST').':2181'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small typo, should be |
||
$zookeeper = new \Zookeeper(implode(',', array($zookeeper_server))); | ||
|
||
return new CombinedStore(array(new RedisStore($redis), new ZookeeperStore($zookeeper)), new UnanimousStrategy()); | ||
} | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Lock\Tests\Store; | ||
|
||
use Symfony\Component\Lock\Key; | ||
|
||
/** | ||
* @author Ganesh Chandrasekaran <gchandrasekaran@wayfair.com> | ||
*/ | ||
trait NotExpiringStoreTestTrait | ||
{ | ||
/** | ||
* @see AbstractStoreTest::getStore() | ||
*/ | ||
abstract protected function getStore(); | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Lock\Exception\NotExpirableStoreException | ||
*/ | ||
public function testPutOffExpirationThrowsException() | ||
{ | ||
$store = $this->getStore(); | ||
$key = new Key(uniqid(__METHOD__, true)); | ||
|
||
$store->save($key); | ||
$store->putOffExpiration($key, 10.0); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
refresh
is called internally when callingacquire
with a non-null TTL (which is the default case when using the Factory with default arguments)When using a NotExpirableStore (like flock) the logger will be full of notice.
Same comment when combining a non-expirable store and expirable one (flock + redis for instance)
IMHO You should either silent this exception when calling
acquire
or update the factory to set a null TTL when the store does not support expiration.Would be great from a user point of view to known whether or not the store supports expiration.