From 4002aa51bd7dbc50349342ff13e8095381a245c7 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Tue, 12 Apr 2022 15:56:14 +0800 Subject: [PATCH] set backend to cindex before recovering the lessor in applySnapshot --- server/etcdserver/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index bba431971cb..64255cf43e3 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1247,6 +1247,13 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) { lg.Panic("failed to open snapshot backend", zap.Error(err)) } + // We need to set the backend to consistIndex before recovering the lessor, + // because lessor.Recover will commit the boltDB transaction, accordingly it + // will get the old consistent_index persisted into the db in OnPreCommitUnsafe. + // Eventually the new consistent_index value coming from snapshot is overwritten + // by the old value. + s.consistIndex.SetBackend(newbe) + // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. if s.lessor != nil { @@ -1263,7 +1270,6 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) { lg.Panic("failed to restore mvcc store", zap.Error(err)) } - s.consistIndex.SetBackend(newbe) newbe.SetTxPostLockInsideApplyHook(s.getTxPostLockInsideApplyHook()) lg.Info("restored mvcc store", zap.Uint64("consistent-index", s.consistIndex.ConsistentIndex()))