Comments (5)
Oh damn, I missed that note!! I let you know for the reactive. Thank a lot, you can close the non issue :)
from distributed-lock.
There is a note in the documentation that says:
Make sure you create TTL index in your
@Locked#storeId()
collection onexpireAt
field to enable lock expiration.
As far as reactive goes, please make a PR, that seems like a great idea!
from distributed-lock.
@alturkovic After reading documentation on TTL indexes (https://docs.mongodb.com/manual/core/index-ttl/), this part scared me :
Timing of the Delete Operation
When you build a TTL index in the background, the TTL thread can begin deleting documents while the index is building. If you build a TTL index in the foreground, MongoDB begins removing expired documents as soon as the index finishes building.The TTL index does not guarantee that expired data will be deleted immediately upon expiration. There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.
The background task that removes expired documents runs every 60 seconds. As a result, documents may remain in a collection during the period between the expiration of the document and the running of the background task.
Because the duration of the removal operation depends on the workload of your mongod instance, expired data may exist for some time beyond the 60 second period between runs of the background task.
That means Mongo does not guarantee deletion after expireAt. If I am trying to acquire a lock on a specific key already locked, the document containing the lock even if expired would not be deleted and I won't be able to acquired the lock.
We may need to be defensive and remove existing document with same key and expireAt < now() ?
Or maybe, just include this criteria in the query : final Query query = Query.query(Criteria.where("_id").is(key).and("expireAt").gt(now()));
What do you think about it?
Thanks
from distributed-lock.
The implementation uses expireAt
rather than expireAfterSeconds
as explained here. I do not believe this is the same behavior and that records should be deleted at the specified time.
TBH, I haven't used MongoDB much myself, so this implementation might be flawed. If you could write a test case and reproduce inconsistencies I could look into this, but for now, I think this works as intended.
from distributed-lock.
Thanks for the quick answer. It seems alright according to the doc you pointed to me. Thanks
from distributed-lock.
Related Issues (20)
- Allow re-entrant code within same Thread? HOT 9
- Need a help HOT 13
- `scriptExecutor` of `RedisTempate` is null HOT 1
- JDBC lock is not working with MySql due to wrong SQL syntax
- JDBC lock not working with PSQL due to SQL syntax HOT 9
- MongoLocked: Don't retry on "fail to acquire" HOT 2
- Cant create a table with reserved name 'lock' for jdbclock as HOT 1
- Need a hand :) ! HOT 3
- Null lock token versus LockNotAvailableException HOT 4
- "RetriableLock should return null if lock is not acquired after the last retry" - ok.. but why? HOT 2
- RedisLock throws RedisReadOnlyException when using RedisStaticMasterReplicaConfiguration and ReadFrom.REPLICA_PREFERRED HOT 2
- Importing the whole library causes auto wiring issues in Spring Boot HOT 5
- Does it Support Spring Boot 3 ? HOT 7
- Getting Started HOT 2
- Option not to throw exception on lock fail HOT 1
- JDBC Manual Controlled Lock HOT 4
- Testing Annotated Locks HOT 8
- What is the reason behind only using JitPack? HOT 1
- About throwing option added in recent PR HOT 1
- Wrong documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from distributed-lock.