-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About etcd clientv3 non-blocking distributed locks #10493
Comments
As described in the function comment, you can pass a context with timeout when calling Lock(). Upon timeout, the context is canceled, and Lock() returns with error. etcd/clientv3/concurrency/mutex.go Lines 40 to 41 in 8c228d6
|
@jingyih For example: |
I see what you mean. I think 'tryLock' is a nice to have function. In the meantime, for your use case, can you try not to hold the lock while processing the event. Instead, use a flag to record if the event is being processed or not. And use the lock to protect this flag. |
@jingyih @technoweenie @bmizerany @drnic This feature will not be added? |
Personally I am not aware of any ongoing effort on this. You are welcome to add this feature if you are interested:) |
@jingyih @technoweenie @bmizerany @xiang90 |
@Dglei, I have read your case and my understanding is that you have two go-routines which are trying to use lock as flag that some event is processed. But for event processing it should be more natural to implement the following in each thread:
Then second thread after acquiring lock will find that queue is empty and event will be processed only once. |
TryLock locks the mutex is not already locked by another session. If lock is held by another session, return immediately after attempting necessary cleanup Fixes etcd-io#10493
TryLock locks the mutex if not already locked by another session. If lock is held by another session, return immediately after attempting necessary cleanup Fixes etcd-io#10493
TryLock locks the mutex if not already locked by another session. If lock is held by another session, return immediately after attempting necessary cleanup Fixes etcd-io#10493
TryLock locks the mutex if not already locked by another session. If lock is held by another session, return immediately after attempting necessary cleanup Added integration test Fixes etcd-io#10493
File: etcd/clientv3/concurrency/mutex.go#L42
func (*Mutex).Lock(ctx Context) error {}
This function always blocks when it requests a lock that has been occupied. How can i make it non-blocking return with error?
The text was updated successfully, but these errors were encountered: