mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3856 from xiang90/raft_doc_restart
raft: add doc to make restart clear
This commit is contained in:
commit
2990249c1d
26
raft/doc.go
26
raft/doc.go
@ -24,6 +24,9 @@ Usage
|
|||||||
|
|
||||||
The primary object in raft is a Node. You either start a Node from scratch
|
The primary object in raft is a Node. You either start a Node from scratch
|
||||||
using raft.StartNode or start a Node from some initial state using raft.RestartNode.
|
using raft.StartNode or start a Node from some initial state using raft.RestartNode.
|
||||||
|
|
||||||
|
To start a node from scratch:
|
||||||
|
|
||||||
storage := raft.NewMemoryStorage()
|
storage := raft.NewMemoryStorage()
|
||||||
c := &Config{
|
c := &Config{
|
||||||
ID: 0x01,
|
ID: 0x01,
|
||||||
@ -35,6 +38,29 @@ using raft.StartNode or start a Node from some initial state using raft.RestartN
|
|||||||
}
|
}
|
||||||
n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}})
|
n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}})
|
||||||
|
|
||||||
|
To restart a node from previous state:
|
||||||
|
|
||||||
|
storage := raft.NewMemoryStorage()
|
||||||
|
|
||||||
|
// recover the in-memory storage from persistent
|
||||||
|
// snapshot, state and entries.
|
||||||
|
storage.ApplySnapshot(snapshot)
|
||||||
|
storage.SetHardState(state)
|
||||||
|
storage.Append(entries)
|
||||||
|
|
||||||
|
c := &Config{
|
||||||
|
ID: 0x01,
|
||||||
|
ElectionTick: 10,
|
||||||
|
HeartbeatTick: 1,
|
||||||
|
Storage: storage,
|
||||||
|
MaxSizePerMsg: 4096,
|
||||||
|
MaxInflightMsgs: 256,
|
||||||
|
}
|
||||||
|
|
||||||
|
// restart raft without peer information.
|
||||||
|
// peer information is already included in the storage.
|
||||||
|
n := raft.RestartNode(c)
|
||||||
|
|
||||||
Now that you are holding onto a Node you have a few responsibilities:
|
Now that you are holding onto a Node you have a few responsibilities:
|
||||||
|
|
||||||
First, you must read from the Node.Ready() channel and process the updates
|
First, you must read from the Node.Ready() channel and process the updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user