Skip to content

Commit

Permalink
Move updating snapshot index just after we safe snapshot to disk
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
serathius committed Nov 29, 2024
1 parent 55a27c1 commit 80ef84d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
//
Expand All @@ -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.
Expand All @@ -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))
}
Expand Down

0 comments on commit 80ef84d

Please sign in to comment.