Browse Source

raft: only allow one message to Step

Blake Mizerany 11 years ago
parent
commit
1eb2512961
1 changed files with 14 additions and 22 deletions
  1. 14 22
      raft/node.go

+ 14 - 22
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
-		}
+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()
-		}
+	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.