Merge pull request #11856 from tangcong/automated-cherry-pick-of-#11817-origin-release-3.3

Automated cherry pick of #11817 on release-3.3
This commit is contained in:
Gyuho Lee 2020-05-07 20:00:11 -07:00 committed by GitHub
commit 23337471d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)