mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #8088 from jbowens/snap-example
contrib/raftexample: save snapshot to WAL first
This commit is contained in:
commit
750dc7f157
@ -107,9 +107,9 @@ func newRaftNode(id int, peers []string, join bool, getSnapshot func() ([]byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *raftNode) saveSnap(snap raftpb.Snapshot) error {
|
func (rc *raftNode) saveSnap(snap raftpb.Snapshot) error {
|
||||||
if err := rc.snapshotter.SaveSnap(snap); err != nil {
|
// must save the snapshot index to the WAL before saving the
|
||||||
return err
|
// snapshot to maintain the invariant that we only Open the
|
||||||
}
|
// wal at previously-saved snapshot indexes.
|
||||||
walSnap := walpb.Snapshot{
|
walSnap := walpb.Snapshot{
|
||||||
Index: snap.Metadata.Index,
|
Index: snap.Metadata.Index,
|
||||||
Term: snap.Metadata.Term,
|
Term: snap.Metadata.Term,
|
||||||
@ -117,6 +117,9 @@ func (rc *raftNode) saveSnap(snap raftpb.Snapshot) error {
|
|||||||
if err := rc.wal.SaveSnapshot(walSnap); err != nil {
|
if err := rc.wal.SaveSnapshot(walSnap); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := rc.snapshotter.SaveSnap(snap); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return rc.wal.ReleaseLockTo(snap.Metadata.Index)
|
return rc.wal.ReleaseLockTo(snap.Metadata.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user