-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Lock] Added Symfony/Component/Lock/Store/MongoDbStore #27346
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
Changes from 1 commit
157fcd7
e73f663
3838412
1a660e6
d65fddf
f3cc220
ec8d217
a1a3be7
1b150ba
73bb802
5e86904
8572c21
dbdad36
84c4d15
d577191
2ce68f5
5446b11
a9b85d6
6fdc602
9d80a0d
1ac702a
4ba5b41
58ef873
36c3af4
168f194
abc72f8
e062bf2
f2e23b4
97e5711
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ class MongoDbStore implements StoreInterface | |
* * collection: The name of the collection [default: lock] | ||
* * resource_field: The field name for storing the lock id [default: _id] MUST be uniquely indexed if you chage it | ||
* * token_field: The field name for storing the lock token [default: token] | ||
* * aquired_field: The field name for storing the acquisition timestamp [default: aquired_at] | ||
* * acquired_field: The field name for storing the acquisition timestamp [default: acquired_at] | ||
* * expiry_field: The field name for storing the expiry-timestamp [default: expires_at]. | ||
* | ||
* It is strongly recommended to put an index on the `expiry_field` for | ||
|
@@ -70,7 +70,7 @@ public function __construct(\MongoDB\Client $mongo, array $options = [], float $ | |
'collection' => 'lock', | ||
'resource_field' => '_id', | ||
'token_field' => 'token', | ||
'aquired_field' => 'aquired_at', | ||
'acquired_field' => 'acquired_at', | ||
'expiry_field' => 'expires_at', | ||
], $options); | ||
|
||
|
@@ -90,7 +90,7 @@ public function __construct(\MongoDB\Client $mongo, array $options = [], float $ | |
* { | ||
* _id: "test", | ||
* token: {# unique token #}, | ||
* aquired: new Date(), | ||
* acquired: new Date(), | ||
* expires_at: new Date({# now + ttl #}) | ||
* }, | ||
* { | ||
|
@@ -120,7 +120,7 @@ public function save(Key $key) | |
'$set' => [ | ||
$this->options['resource_field'] => (string)$key, | ||
$this->options['token_field'] => $this->getToken($key), | ||
$this->options['aquired_field'] => $this->createDateTime(), | ||
$this->options['acquired_field'] => $this->createDateTime(), | ||
$this->options['expiry_field'] => $expiry, | ||
], | ||
]; | ||
|
@@ -133,7 +133,7 @@ public function save(Key $key) | |
try { | ||
$this->getCollection()->updateOne($filter, $update, $options); | ||
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. Is it atomic? on every version of mongodb? What's about réplication propagation? 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. MongoDB is atomic on a singular statement / document only. Hence the use of a update with filter (1 statement). MongoDB 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. With regards to I have added some documentation regarding this decision to |
||
} catch (\MongoDB\Driver\Exception\BulkWriteException $e) { | ||
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. IMHO you should distringuished 2 cases
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've improved the exception handling, I also noticed |
||
throw new LockConflictedException('Failed to aquire lock', 0, $e); | ||
throw new LockConflictedException('Failed to acquire lock', 0, $e); | ||
} | ||
|
||
if ($key->isExpired()) { | ||
|
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
$this->getToken($key)
is already called at line 108There 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.
fixed