Skip to content

Commit

Permalink
id: lock the Generate function (tikv#3310)
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xiangsheng <hundundm@gmail.com>

Co-authored-by: Ti Prow Robot <71242396+ti-community-prow-bot@users.noreply.github.com>
  • Loading branch information
HunDunDM and ti-chi-bot authored Dec 28, 2020
1 parent 7489f2d commit b6d036b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/id/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (alloc *AllocatorImpl) Alloc() (uint64, error) {
defer alloc.mu.Unlock()

if alloc.base == alloc.end {
err := alloc.Generate()
if err != nil {
if err := alloc.generateLocked(); err != nil {
return 0, err
}

Expand All @@ -70,6 +69,13 @@ func (alloc *AllocatorImpl) Alloc() (uint64, error) {

// Generate synchronizes and generates id range.
func (alloc *AllocatorImpl) Generate() error {
alloc.mu.Lock()
defer alloc.mu.Unlock()

return alloc.generateLocked()
}

func (alloc *AllocatorImpl) generateLocked() error {
key := alloc.getAllocIDPath()
value, err := etcdutil.GetValue(alloc.client, key)
if err != nil {
Expand Down

0 comments on commit b6d036b

Please sign in to comment.