hashicorp / hashicorp/consul

How consul deal with thundering herd in distributed locking?

Open
#7,523 0 comments 1 reaction 0 assignees View on GitHub
theme/internals type/question
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
2d 6h
Merged PRs (30d)
43

Description

after looking into the code of consul's lock function:
in https://github.com/hashicorp/consul/blob/master/api/lock.go 200
`// Look for an existing lock, blocking until not taken`
` pair, meta, err := kv.Get(l.opts.Key, &qOpts)`
` if err != nil {`
` return nil, fmt.Errorf("failed to read lock: %v", err)`
` }`
when the lock is release by other clients or services, the others clients will wake up (modify index is update) and then do the following:
`locked, _, err = kv.Acquire(pair, &wOpts)`
If there are many clients waiting for the lock,they will wake up at the same time and then try to acquire the lock。This may result in a large number of api calls at the same time。

I don’t know if it ’s something wrong with my understanding,please help:)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.