Comments (6)
Thanks for the issue, I'll add capability for this tonight :)
from etcd3.
Thanks for your fast reply.
Also, wanted to clarify something with you.
If I take lock on mylock2 key using etcdctl and then try to take lock using this library on the same key, both of them goes through.
As far as I understood from the source code, the lock API underlying is using lease. Hence I guess it is not the blocking etcd lock that you offer, rather a non blocking lock implementation using the lease feature. Is that understanding correct ?
from etcd3.
The locks this library provides should be compatible with those in the etcdctl as this is in large part based upon the official etcd Go client which the ctl consumes, however I have not verified this myself, so there might be a subtle difference or two. I'll give it a look. PRs also welcome of course.
from etcd3.
Just to explain it in more detail,
I have written a code like this.
const {
Etcd3
} = require('etcd3');
const client = new Etcd3({
hosts: "10.244.14.255:4001"
});
const lock = client.lock("mylock2");
lock.ttl(5).acquire()
.then(lock => {
console.log("Lock taken", lock);
})
When I run the code, it acquires the lock.
Now at the same time, if I run the command etcdctl --endpoints=10.244.14.255:4001 --insecure-skip-tls-verify=true lock mylock2
then that acquires the lock as well,
$ etcdctl --endpoints=10.244.14.255:4001 --insecure-skip-tls-verify=true lock mylock2
mylock2/16ce63390ae29664
Is this really expected?
from etcd3.
Heyo, sorry for the delay here. The etcdct Go client client implements locks a little differently. Specifically, their lock implementation blocks on Lock() and attempts to guarantee fairness as to who gets the lock when it releases. Whereas in this implementation, we simply throw if we cannot acquire the lock.
It may be good to get closed to the etcd implementation as theirs is more robust and closer to a 'true' mutex. But, as a result, they use slightly different keys which don't conflict with the ones that this client provides.
from etcd3.
In 56ea496 I've added a new method to the lock, leaseId()
, which returns the owner lessor of the lock. Using this, in your second process, you can run this to release the lock:
client
.if(myLockKey, 'lease', '==', leaseId)
.then(client.delete(myLockKey))
from etcd3.
Related Issues (20)
- WatchBuilder.create() doesn't reject an error when erred
- Waiting two ttl-periods before declaring a lease lost seems wrong
- When a timeout is happens the node process is hanging and not finalized.
- Need a way to alter the hosts/endpoints at runtime? HOT 1
- Election example from doc elects 2 leaders after etcd restart, starts multiple workers, or fails to elect a leader HOT 3
- How to specify limit and offset? HOT 1
- ./node_modules/@grpc/grpc-js/build/src/server.js Module not found: Can't resolve 'http2' in 'node_modules/@grpc/grpc-js/build/src' HOT 1
- GRPCUnavailableError:UNAVAILABLE: No connection established HOT 1
- This library has no debug or verbose options.
- Set host:port in the source code HOT 2
- Best way to `getAll(keys)`? HOT 1
- Elections probably choose more than one leader HOT 1
- Deadlock when EtcdInvalidAuthTokenError HOT 2
- pkg was pack success, but crash in use pack file, error for rpc.proto file path HOT 1
- Send custom header along with requests
- Lease expiration does not fire delete event HOT 1
- ILeaseTimeToLiveResponse returns an empty array of keys
- break in nodejs v14 HOT 3
- Updates to the repository and fixes but no release HOT 3
- getAll() / MultiRangeBuilder not available under SoftwareTransaction
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 etcd3.