Comments (2)
@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.
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)
- Lock not marked as released when heartbeat cannot be sent HOT 3
- relation "locks" does not exist HOT 3
- Support for pgx HOT 2
- SQLSTATE 400001 error on multiple boxes trying to acquire the same named lock HOT 6
- ERROR: could not serialize access due to XXX (SQLSTATE 40001) HOT 7
- CreateTable should be idempotent HOT 5
- Solve CreateTable Conundrum
- Concurrent lock creation with different names leads to deadlock while releasing the lock
- Cancelled heartbeat causes release failures HOT 4
- Thoughts on Supporting GetAllLocksMetadata HOT 3
- Add Table schema in README HOT 1
- Errors while acquiring/releasing locks HOT 16
- Heartbeat not retried in case of errors HOT 1
- Enable Linters
- Introduce configurable logging levels HOT 3
- Create Sequence Fails HOT 3
- Support for `pgxpool`? HOT 5
- `TestFailIfLocked` doesn't finish when used with `pgxpool` HOT 1
- Don't log missed heartbeat as error when context is canceled HOT 4
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 pglock.