Verify consistent index is latest at the time of snapshot
Signed-off-by: Geeta Gharpure <geetagh@amazon.com>
This commit is contained in:
@ -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) {
|
func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *toApply) {
|
||||||
if len(apply.entries) == 0 {
|
if len(apply.entries) == 0 {
|
||||||
return
|
return
|
||||||
@ -2082,6 +2090,9 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
|
|||||||
}
|
}
|
||||||
lg.Panic("failed to create snapshot", zap.Error(err))
|
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.
|
// SaveSnap saves the snapshot to file and appends the corresponding WAL entry.
|
||||||
if err = s.r.storage.SaveSnap(snap); err != nil {
|
if err = s.r.storage.SaveSnap(snap); err != nil {
|
||||||
lg.Panic("failed to save snapshot", zap.Error(err))
|
lg.Panic("failed to save snapshot", zap.Error(err))
|
||||||
|
@ -1017,6 +1017,9 @@ func TestSyncTrigger(t *testing.T) {
|
|||||||
|
|
||||||
// TestSnapshot should snapshot the store and cut the persistent
|
// TestSnapshot should snapshot the store and cut the persistent
|
||||||
func TestSnapshot(t *testing.T) {
|
func TestSnapshot(t *testing.T) {
|
||||||
|
revertFunc := verify.DisableVerifications()
|
||||||
|
defer revertFunc()
|
||||||
|
|
||||||
be, _ := betesting.NewDefaultTmpBackend(t)
|
be, _ := betesting.NewDefaultTmpBackend(t)
|
||||||
|
|
||||||
s := raft.NewMemoryStorage()
|
s := raft.NewMemoryStorage()
|
||||||
|
Reference in New Issue
Block a user