diff --git a/CHANGELOG-3.5.md b/CHANGELOG-3.5.md index d39b38cb8..b4a559d8a 100644 --- a/CHANGELOG-3.5.md +++ b/CHANGELOG-3.5.md @@ -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` diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index ebf7c0afb..ba3854615 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -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)