Skip to content

Commit

Permalink
mvcc: fix deadlock bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcong committed May 8, 2020
1 parent 1b5e2f4 commit 5f79992
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ func NewStore(b backend.Backend, le lease.Lessor, ig ConsistentIndexGetter) *sto

func (s *store) compactBarrier(ctx context.Context, ch chan struct{}) {
if ctx == nil || ctx.Err() != nil {
s.mu.Lock()
select {
case <-s.stopc:
default:
// fix deadlock in mvcc,for more information, please refer to pr 11817.
// s.stopc is only updated in restore operation, which is called by apply
// snapshot call, compaction and apply snapshot requests are serialized by
// raft, and do not happen at the same time.
s.mu.Lock()
f := func(ctx context.Context) { s.compactBarrier(ctx, ch) }
s.fifoSched.Schedule(f)
s.mu.Unlock()
}
s.mu.Unlock()
return
}
close(ch)
Expand Down

0 comments on commit 5f79992

Please sign in to comment.