Skip to content

Commit

Permalink
Merge pull request #16100 from geetasg/pr4
Browse files Browse the repository at this point in the history
Verify consistent index is latest at the time of snapshot
  • Loading branch information
ahrtr authored Jun 22, 2023
2 parents 54fab1c + 550aa15 commit 04d24c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,14 @@ func verifySnapshotIndex(snapshot raftpb.Snapshot, cindex uint64) {
})
}

func verifyConsistentIndexIsLatest(lg *zap.Logger, snapshot raftpb.Snapshot, cindex uint64) {
verify.Verify(func() {
if cindex < snapshot.Metadata.Index {
lg.Panic(fmt.Sprintf("consistent_index(%d) is older than snapshot index (%d)", cindex, snapshot.Metadata.Index))
}
})
}

func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *toApply) {
if len(apply.entries) == 0 {
return
Expand Down Expand Up @@ -2082,6 +2090,9 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
}
lg.Panic("failed to create snapshot", zap.Error(err))
}

verifyConsistentIndexIsLatest(lg, snap, s.consistIndex.ConsistentIndex())

// SaveSnap saves the snapshot to file and appends the corresponding WAL entry.
if err = s.r.storage.SaveSnap(snap); err != nil {
lg.Panic("failed to save snapshot", zap.Error(err))
Expand Down
3 changes: 3 additions & 0 deletions server/etcdserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@ func TestSyncTrigger(t *testing.T) {

// TestSnapshot should snapshot the store and cut the persistent
func TestSnapshot(t *testing.T) {
revertFunc := verify.DisableVerifications()
defer revertFunc()

be, _ := betesting.NewDefaultTmpBackend(t)

s := raft.NewMemoryStorage()
Expand Down

0 comments on commit 04d24c2

Please sign in to comment.