Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/raftexample: save snapshot to WAL first #8088

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions contrib/raftexample/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,19 @@ func newRaftNode(id int, peers []string, join bool, getSnapshot func() ([]byte,
}

func (rc *raftNode) saveSnap(snap raftpb.Snapshot) error {
if err := rc.snapshotter.SaveSnap(snap); err != nil {
return err
}
// must save the snapshot index to the WAL before saving the
// snapshot to maintain the invariant that we only Open the
// wal at previously-saved snapshot indexes.
walSnap := walpb.Snapshot{
Index: snap.Metadata.Index,
Term: snap.Metadata.Term,
}
if err := rc.wal.SaveSnapshot(walSnap); err != nil {
return err
}
if err := rc.snapshotter.SaveSnap(snap); err != nil {
return err
}
return rc.wal.ReleaseLockTo(snap.Metadata.Index)
}

Expand Down