Skip to content

Commit

Permalink
Separate memory and disk snapshot indexes
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 c076cab commit 8eadac8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,11 @@ func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus) {
}

type etcdProgress struct {
confState raftpb.ConfState
diskSnapshotIndex uint64
appliedt uint64
appliedi uint64
confState raftpb.ConfState
diskSnapshotIndex uint64
memorySnapshotIndex uint64
appliedt uint64
appliedi uint64
}

// raftReadyHandler contains a set of EtcdServer operations to be called by raftNode,
Expand Down Expand Up @@ -809,10 +810,11 @@ func (s *EtcdServer) run() {
s.r.start(rh)

ep := etcdProgress{
confState: sn.Metadata.ConfState,
diskSnapshotIndex: sn.Metadata.Index,
appliedt: sn.Metadata.Term,
appliedi: sn.Metadata.Index,
confState: sn.Metadata.ConfState,
diskSnapshotIndex: sn.Metadata.Index,
memorySnapshotIndex: sn.Metadata.Index,
appliedt: sn.Metadata.Term,
appliedi: sn.Metadata.Index,
}

defer func() {
Expand Down Expand Up @@ -1133,6 +1135,7 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, toApply *toApply) {
ep.appliedt = toApply.snapshot.Metadata.Term
ep.appliedi = toApply.snapshot.Metadata.Index
ep.diskSnapshotIndex = ep.appliedi
ep.memorySnapshotIndex = ep.appliedi
ep.confState = toApply.snapshot.Metadata.ConfState

// As backends and implementations like alarmsStore changed, we need
Expand Down Expand Up @@ -2160,6 +2163,7 @@ func (s *EtcdServer) snapshot(ep *etcdProgress) {
lg.Panic("failed to save snapshot", zap.Error(err))
}
ep.diskSnapshotIndex = ep.appliedi
ep.memorySnapshotIndex = ep.appliedi
if err = s.r.storage.Release(snap); err != nil {
lg.Panic("failed to release wal", 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 @@ -688,6 +688,9 @@ func TestSnapshot(t *testing.T) {
if ep.diskSnapshotIndex != 1 {
t.Errorf("ep.diskSnapshotIndex = %d, want 1", ep.diskSnapshotIndex)
}
if ep.memorySnapshotIndex != 1 {
t.Errorf("ep.memorySnapshotIndex = %d, want 1", ep.memorySnapshotIndex)
}
}

// TestSnapshotOrdering ensures raft persists snapshot onto disk before
Expand Down

0 comments on commit 8eadac8

Please sign in to comment.