Giter Site home page Giter Site logo

Comments (2)

ucirello avatar ucirello commented on July 29, 2024

@BrunoDelor -- thanks for opening this issue.

Your line of reasoning makes me believe that you might need to take a bit of a harder look at how this library works and more specifically what is meant by the last block of the README.md

The lock client never stores absolute times in PostgreSQL. The way locks are expired is that a call to tryAcquire reads in the current lock, checks the record version number of the lock and starts a timer. If the lock still has the same after the lease duration time has passed, the client will determine that the lock is stale and expire it.

What you seem to be calling obsolete locks is termed, in this library, as stale locks. Locks whose owner is gone and it is no longer sending heartbeats. And that is by design. The stale lock must be left behind so that the time skew logic works.

If you have configured everything correctly, as soon as the current leader stops working, the next follower will attempt grabbing the lock and wait until the lease time runs out and effectively grab the lock.

Answering your question directly:

So the question is the following: How to deal with obsolete keys ? I can't just try acquire with fail on lock because that would not help distinguish between a legit lock, and an obsolete one. And I can't just blindly release that lock after the error because it could be legit.

Assuming you are using a lock leader election pattern, you need to make sure the followers are always attempting to grab the lock from the leader. You can use loops (in which the lock grabbing succeeds upon leader-loss), or you might want postgresql-based notifications to speed this process up (https://www.postgresql.org/docs/current/sql-notify.html).

With all that said, you might be missing a feature common in other lock server which is the recapture of the lock by the current owner upon missed heartbeats. This feature has not been implemented yet because I couldn't quite design a DX that wouldn't let people misuse it.

from pglock.

ucirello avatar ucirello commented on July 29, 2024

To make it less confusing to you, make sure you're not using:
https://github.com/cirello-io/pglock/blob/v1.9.0/lock.go#L107-L112

from pglock.

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.