Giter Site home page Giter Site logo

Comments (5)

lgaudez avatar lgaudez commented on July 19, 2024 1

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.

alturkovic avatar alturkovic commented on July 19, 2024

There is a note in the documentation that says:

Make sure you create TTL index in your @Locked#storeId() collection on expireAt field to enable lock expiration.

As far as reactive goes, please make a PR, that seems like a great idea!

from distributed-lock.

lgaudez avatar lgaudez commented on July 19, 2024

@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.

alturkovic avatar alturkovic commented on July 19, 2024

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.

lgaudez avatar lgaudez commented on July 19, 2024

Thanks for the quick answer. It seems alright according to the doc you pointed to me. Thanks

from distributed-lock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.