Skip to content

Commit

Permalink
Merge pull request #8088 from jbowens/snap-example
Browse files Browse the repository at this point in the history
contrib/raftexample: save snapshot to WAL first
  • Loading branch information
gyuho committed Jun 13, 2017
2 parents 3993f37 + 74e020b commit 750dc7f
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 750dc7f

Please sign in to comment.