etcd/raft/example_test.go

32 lines
633 B
Go
Raw Normal View History

2014-08-23 02:45:39 +04:00
package raft
2014-08-28 05:53:18 +04:00
import (
pb "github.com/coreos/etcd/raft/raftpb"
)
func applyToStore(ents []pb.Entry) {}
func sendMessages(msgs []pb.Message) {}
func saveStateToDisk(st pb.State) {}
func saveToDisk(ents []pb.Entry) {}
2014-08-23 02:45:39 +04:00
func Example_Node() {
2014-09-03 03:59:29 +04:00
n := Start(0, nil, 0, 0)
2014-08-23 02:45:39 +04:00
2014-08-24 03:06:55 +04:00
// stuff to n happens in other goroutines
2014-08-23 02:45:39 +04:00
2014-08-23 03:53:56 +04:00
// the last known state
2014-08-28 05:53:18 +04:00
var prev pb.State
2014-08-23 02:45:39 +04:00
for {
// ReadState blocks until there is new state ready.
rd := <-n.Ready()
2014-08-28 05:53:18 +04:00
if !isStateEqual(prev, rd.State) {
2014-08-27 03:19:49 +04:00
saveStateToDisk(rd.State)
prev = rd.State
2014-08-23 02:45:39 +04:00
}
2014-08-27 03:19:49 +04:00
saveToDisk(rd.Entries)
go applyToStore(rd.CommittedEntries)
sendMessages(rd.Messages)
2014-08-23 02:45:39 +04:00
}
}