Skip to content

Commit 9d55044

Browse files
committed
Move updating snapshot index just after we safe snapshot to disk
Signed-off-by: Marek Siarkowicz <[email protected]>
1 parent 1529734 commit 9d55044

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

server/etcdserver/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,8 @@ func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) {
12061206
)
12071207
s.forceDiskSnapshot = false
12081208

1209-
s.snapshot(ep.appliedi, ep.confState)
1209+
s.snapshot(ep)
12101210
s.compactRaftLog(ep.appliedi)
1211-
ep.diskSnapshotIndex = ep.appliedi
12121211
}
12131212

12141213
func (s *EtcdServer) shouldSnapshot(ep *etcdProgress) bool {
@@ -2128,7 +2127,7 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con
21282127
}
21292128

21302129
// TODO: non-blocking snapshot
2131-
func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
2130+
func (s *EtcdServer) snapshot(ep *etcdProgress) {
21322131
d := GetMembershipInfoInV2Format(s.Logger(), s.cluster)
21332132
// commit kv to write metadata (for example: consistent index) to disk.
21342133
//
@@ -2144,7 +2143,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
21442143
lg := s.Logger()
21452144

21462145
// For backward compatibility, generate v2 snapshot from v3 state.
2147-
snap, err := s.r.raftStorage.CreateSnapshot(snapi, &confState, d)
2146+
snap, err := s.r.raftStorage.CreateSnapshot(ep.appliedi, &ep.confState, d)
21482147
if err != nil {
21492148
// the snapshot was done asynchronously with the progress of raft.
21502149
// raft might have already got a newer snapshot.
@@ -2160,6 +2159,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
21602159
if err = s.r.storage.SaveSnap(snap); err != nil {
21612160
lg.Panic("failed to save snapshot", zap.Error(err))
21622161
}
2162+
ep.diskSnapshotIndex = ep.appliedi
21632163
if err = s.r.storage.Release(snap); err != nil {
21642164
lg.Panic("failed to release wal", zap.Error(err))
21652165
}

server/etcdserver/server_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,13 @@ func TestSnapshot(t *testing.T) {
679679
t.Errorf("action = %s, want Release", gaction[1])
680680
}
681681
}()
682-
683-
srv.snapshot(1, raftpb.ConfState{Voters: []uint64{1}})
682+
ep := etcdProgress{appliedi: 1, confState: raftpb.ConfState{Voters: []uint64{1}}}
683+
srv.snapshot(&ep)
684684
<-ch
685685
if len(st.Action()) != 0 {
686686
t.Errorf("no action expected on v2store. Got %d actions", len(st.Action()))
687687
}
688+
assert.Equal(t, uint64(1), ep.diskSnapshotIndex)
688689
}
689690

690691
// TestSnapshotOrdering ensures raft persists snapshot onto disk before

0 commit comments

Comments
 (0)