From 47038593e9eba0993156a6ddef2e1500758685a1 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Mon, 4 Apr 2022 19:56:38 +0800 Subject: [PATCH] set the consistent_index directly when applyV3 isn't performed --- server/etcdserver/server.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 6a89f4592..612454227 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1815,6 +1815,14 @@ func (s *EtcdServer) apply( // applyEntryNormal applies an EntryNormal type raftpb request to the EtcdServer func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { shouldApplyV3 := membership.ApplyV2storeOnly + applyV3Performed := false + defer func() { + // The txPostLock callback will not get called in this case, + // so we should set the consistent index directly. + if s.consistIndex != nil && !applyV3Performed && membership.ApplyBoth == shouldApplyV3 { + s.consistIndex.SetConsistentIndex(e.Index, e.Term) + } + }() index := s.consistIndex.ConsistentIndex() if e.Index > index { // set the consistent index of current executing entry @@ -1870,6 +1878,7 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { if !needResult && raftReq.Txn != nil { removeNeedlessRangeReqs(raftReq.Txn) } + applyV3Performed = true ar = s.applyV3.Apply(&raftReq, shouldApplyV3) } @@ -1912,6 +1921,12 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con if err := s.cluster.ValidateConfigurationChange(cc); err != nil { cc.NodeID = raft.None s.r.ApplyConfChange(cc) + + // The txPostLock callback will not get called in this case, + // so we should set the consistent index directly. + if s.consistIndex != nil && membership.ApplyBoth == shouldApplyV3 { + s.consistIndex.SetConsistentIndex(s.consistentIdx, s.consistentTerm) + } return false, err }