From 5f799922a84795a7dbd5c0577bc3c3e6e42baaf5 Mon Sep 17 00:00:00 2001 From: tangcong Date: Sun, 26 Apr 2020 21:05:30 +0800 Subject: [PATCH] mvcc: fix deadlock bug --- mvcc/kvstore.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index ba34cd1f314..2a8a0361a0b 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -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)