Skip to content

Commit

Permalink
Merge pull request #11817 from tangcong/fix-mvcc-deadlock-bug
Browse files Browse the repository at this point in the history
mvcc: fix a deadlock bug in mvcc
  • Loading branch information
gyuho authored May 7, 2020
2 parents 6d06799 + a7423f2 commit d472f67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
- Improve [count-only range performance](https://github.com/etcd-io/etcd/pull/11771).
- Remove [redundant storage restore operation to shorten the startup time](https://github.com/etcd-io/etcd/pull/11779).
- With 40 million key test data,it can shorten the startup time from 5 min to 2.5 min.
- [Fix deadlock bug in mvcc](https://github.com/etcd-io/etcd/pull/11817).

### Package `embed`

Expand Down
8 changes: 6 additions & 2 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,18 @@ func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, ci cindex.Cons

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 d472f67

Please sign in to comment.