mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: only allow one message to Step
This commit is contained in:
parent
38e8f3b764
commit
1eb2512961
38
raft/node.go
38
raft/node.go
@ -2,8 +2,6 @@
|
||||
package raft
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
@ -111,31 +109,25 @@ func (n *Node) Tick() error {
|
||||
|
||||
// Propose proposes data be appended to the log.
|
||||
func (n *Node) Propose(ctx context.Context, id int64, data []byte) error {
|
||||
return n.Step(ctx, []Message{{Type: msgProp, Entries: []Entry{{Id: id, Data: data}}}})
|
||||
return n.Step(ctx, Message{Type: msgProp, Entries: []Entry{{Id: id, Data: data}}})
|
||||
}
|
||||
|
||||
// Step advances the state machine using msgs. Proposals are priotized last so
|
||||
// that any votes and vote requests will not be wedged behind proposals and
|
||||
// prevent this cluster from making progress. The ctx.Err() will be returned,
|
||||
// Step advances the state machine using msgs. The ctx.Err() will be returned,
|
||||
// if any.
|
||||
func (n *Node) Step(ctx context.Context, msgs []Message) error {
|
||||
sort.Sort(sort.Reverse(byMsgType(msgs)))
|
||||
for _, m := range msgs {
|
||||
ch := n.recvc
|
||||
if m.Type == msgProp {
|
||||
ch = n.propc
|
||||
}
|
||||
|
||||
select {
|
||||
case ch <- m:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-n.ctx.Done():
|
||||
return n.ctx.Err()
|
||||
}
|
||||
func (n *Node) Step(ctx context.Context, m Message) error {
|
||||
ch := n.recvc
|
||||
if m.Type == msgProp {
|
||||
ch = n.propc
|
||||
}
|
||||
|
||||
select {
|
||||
case ch <- m:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-n.ctx.Done():
|
||||
return n.ctx.Err()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadState returns the current point-in-time state.
|
||||
|
Loading…
x
Reference in New Issue
Block a user