From 80ef84d3fccfebf2f0fb2881888f3f909a68d71d Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 29 Nov 2024 12:13:55 +0100 Subject: [PATCH] Move updating snapshot index just after we safe snapshot to disk Signed-off-by: Marek Siarkowicz --- server/etcdserver/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index f789dbc42ffc..bb76acde50d2 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1206,9 +1206,8 @@ func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) { ) s.forceDiskSnapshot = false - s.snapshot(ep.appliedi, ep.confState) + s.snapshot(ep) s.compactRaftLog(ep.appliedi) - ep.diskSnapshotIndex = ep.appliedi } func (s *EtcdServer) shouldSnapshot(ep *etcdProgress) bool { @@ -2132,7 +2131,7 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con } // TODO: non-blocking snapshot -func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { +func (s *EtcdServer) snapshot(ep *etcdProgress) { d := GetMembershipInfoInV2Format(s.Logger(), s.cluster) // commit kv to write metadata (for example: consistent index) to disk. // @@ -2148,7 +2147,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { lg := s.Logger() // For backward compatibility, generate v2 snapshot from v3 state. - snap, err := s.r.raftStorage.CreateSnapshot(snapi, &confState, d) + snap, err := s.r.raftStorage.CreateSnapshot(ep.appliedi, &ep.confState, d) if err != nil { // the snapshot was done asynchronously with the progress of raft. // raft might have already got a newer snapshot. @@ -2164,6 +2163,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { if err = s.r.storage.SaveSnap(snap); err != nil { lg.Panic("failed to save snapshot", zap.Error(err)) } + ep.diskSnapshotIndex = ep.appliedi if err = s.r.storage.Release(snap); err != nil { lg.Panic("failed to release wal", zap.Error(err)) }