Skip to content

Commit

Permalink
Expose Raft Comms
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain authored and danielmai committed May 8, 2019
1 parent 6c68a70 commit 9cd628f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 14 additions & 4 deletions conn/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,21 @@ func (n *Node) SetPeer(pid uint64, addr string) {
n.peers[pid] = addr
}

func (n *Node) Send(m raftpb.Message) {
x.AssertTruef(n.Id != m.To, "Sending message to itself")
data, err := m.Marshal()
func (n *Node) Send(msg raftpb.Message) {
x.AssertTruef(n.Id != msg.To, "Sending message to itself")
data, err := msg.Marshal()
x.Check(err)

if glog.V(2) {
switch msg.Type {
case raftpb.MsgHeartbeat, raftpb.MsgHeartbeatResp:
case raftpb.MsgReadIndex, raftpb.MsgReadIndexResp:
case raftpb.MsgApp, raftpb.MsgAppResp:
case raftpb.MsgProp:
default:
glog.Infof("RaftComm: [%#x] Sending message of type %s to %#x", msg.From, msg.Type, msg.To)
}
}
// As long as leadership is stable, any attempted Propose() calls should be reflected in the
// next raft.Ready.Messages. Leaders will send MsgApps to the followers; followers will send
// MsgProp to the leader. It is up to the transport layer to get those messages to their
Expand All @@ -243,7 +253,7 @@ func (n *Node) Send(m raftpb.Message) {
// node. But, we shouldn't take the liberty to do that here. It would take us more time to
// repropose these dropped messages anyway, than to block here a bit waiting for the messages
// channel to clear out.
n.messages <- sendmsg{to: m.To, data: data}
n.messages <- sendmsg{to: msg.To, data: data}
}

func (n *Node) Snapshot() (raftpb.Snapshot, error) {
Expand Down
10 changes: 10 additions & 0 deletions conn/raft_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ func (w *RaftServer) RaftMessage(server pb.Raft_RaftMessageServer) error {
// This should be done in order, and not via a goroutine.
// Step can block forever. See: https://github.com/etcd-io/etcd/issues/10585
// So, add a context with timeout to allow it to get out of the blockage.
if glog.V(2) {
switch msg.Type {
case raftpb.MsgHeartbeat, raftpb.MsgHeartbeatResp:
case raftpb.MsgReadIndex, raftpb.MsgReadIndexResp:
case raftpb.MsgApp, raftpb.MsgAppResp:
case raftpb.MsgProp:
default:
glog.Infof("RaftComm: [%#x] Received msg of type: %s from %#x", msg.To, msg.Type, msg.From)
}
}
if err := raft.Step(ctx, msg); err != nil {
glog.Warningf("Error while raft.Step from %#x: %v. Closing RaftMessage stream.",
rc.GetId(), err)
Expand Down

0 comments on commit 9cd628f

Please sign in to comment.