mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add doc for storage
This commit is contained in:
parent
d87ee9819b
commit
2dbdf87f86
@ -19,8 +19,8 @@ Package raft provides an implementation of the raft consensus algorithm.
|
|||||||
|
|
||||||
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.
|
||||||
|
storage := raft.NewMemoryStorage()
|
||||||
n := raft.StartNode(0x01, []int64{0x02, 0x03}, 3, 1)
|
n := raft.StartNode(0x01, []int64{0x02, 0x03}, 3, 1, storage)
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
@ -37,6 +37,8 @@ channel returned by n.Ready(). It is important that the user persist any
|
|||||||
entries that require stable storage before sending messages to other peers to
|
entries that require stable storage before sending messages to other peers to
|
||||||
ensure fault-tolerance.
|
ensure fault-tolerance.
|
||||||
|
|
||||||
|
An example MemoryStorage is provided in the raft package.
|
||||||
|
|
||||||
And finally you need to service timeouts with Tick(). Raft has two important
|
And finally you need to service timeouts with Tick(). Raft has two important
|
||||||
timeouts: heartbeat and the election timeout. However, internally to the raft
|
timeouts: heartbeat and the election timeout. However, internally to the raft
|
||||||
package time is represented by an abstract "tick". The user is responsible for
|
package time is represented by an abstract "tick". The user is responsible for
|
||||||
@ -50,7 +52,7 @@ The total state machine handling loop will look something like this:
|
|||||||
case <-s.Ticker:
|
case <-s.Ticker:
|
||||||
n.Tick()
|
n.Tick()
|
||||||
case rd := <-s.Node.Ready():
|
case rd := <-s.Node.Ready():
|
||||||
saveToStable(rd.State, rd.Entries)
|
saveToStorage(rd.State, rd.Entries)
|
||||||
send(rd.Messages)
|
send(rd.Messages)
|
||||||
process(rd.CommittedEntries)
|
process(rd.CommittedEntries)
|
||||||
s.Node.Advance()
|
s.Node.Advance()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user