From 1eb2512961dc5be18dbf16e68330ad7f4c98417e Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Wed, 27 Aug 2014 17:22:34 -0700 Subject: [PATCH] raft: only allow one message to Step --- raft/node.go | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/raft/node.go b/raft/node.go index a2a4c9f00..7e8ac8902 100644 --- a/raft/node.go +++ b/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.