mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: start tick
This commit is contained in:
parent
8d37587e47
commit
e17f79ee70
@ -19,6 +19,7 @@ type Node struct {
|
||||
propc chan proposal
|
||||
recvc chan Message
|
||||
statec chan stateResp
|
||||
tickc chan struct{}
|
||||
}
|
||||
|
||||
func Start(ctx context.Context, name string, election, heartbeat int) *Node {
|
||||
@ -27,6 +28,7 @@ func Start(ctx context.Context, name string, election, heartbeat int) *Node {
|
||||
propc: make(chan proposal),
|
||||
recvc: make(chan Message),
|
||||
statec: make(chan stateResp),
|
||||
tickc: make(chan struct{}),
|
||||
}
|
||||
r := &raft{
|
||||
name: name,
|
||||
@ -55,6 +57,8 @@ func (n *Node) run(r *raft) {
|
||||
r.propose(p.id, p.data)
|
||||
case m := <-n.recvc:
|
||||
r.step(m)
|
||||
case <-n.tickc:
|
||||
r.tick()
|
||||
case n.statec <- stateResp{r.State, r.ents, r.msgs}:
|
||||
r.resetState()
|
||||
case <-n.ctx.Done():
|
||||
@ -63,6 +67,15 @@ func (n *Node) run(r *raft) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Node) Tick() error {
|
||||
select {
|
||||
case n.tickc <- struct{}{}:
|
||||
return nil
|
||||
case <-n.ctx.Done():
|
||||
return n.ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
// Propose proposes data be appended to the log.
|
||||
func (n *Node) Propose(id int64, data []byte) error {
|
||||
select {
|
||||
@ -83,7 +96,7 @@ func (n *Node) Step(m Message) error {
|
||||
}
|
||||
}
|
||||
|
||||
// ReadMessages returns the current point-in-time state.
|
||||
// ReadState returns the current point-in-time state.
|
||||
func (n *Node) ReadState() (State, []Entry, []Message, error) {
|
||||
select {
|
||||
case sr := <-n.statec:
|
||||
|
@ -32,3 +32,4 @@ func (sm *raft) hasLeader() bool { return false }
|
||||
func (sm *raft) step(m Message) {}
|
||||
func (sm *raft) resetState() {}
|
||||
func (sm *raft) propose(id int64, data []byte) {}
|
||||
func (sm *raft) tick() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user