From 725c411346e04dcc72934329345ef5607f912608 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Thu, 5 Mar 2015 12:39:52 -0500 Subject: [PATCH] Add ReportUnreachable and ReportSnapshot to MultiNode. Add ReportSnapshot requirement to doc.go. --- raft/doc.go | 3 ++- raft/multinode.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/raft/doc.go b/raft/doc.go index 72bb4077a..81e157c18 100644 --- a/raft/doc.go +++ b/raft/doc.go @@ -35,7 +35,8 @@ previously-persisted entries with Index >= i must be discarded. 2. Send all Messages to the nodes named in the To field. It is important that no messages be sent until after the latest HardState has been persisted to disk, and all Entries written by any previous Ready batch (Messages may be sent while -entries from the same batch are being persisted). +entries from the same batch are being persisted). If any Message has type MsgSnap, +call Node.ReportSnapshot() after it has been sent (these messages may be large). 3. Apply Snapshot (if any) and CommittedEntries to the state machine. If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange() diff --git a/raft/multinode.go b/raft/multinode.go index 1d3a05362..ad1184947 100644 --- a/raft/multinode.go +++ b/raft/multinode.go @@ -38,6 +38,10 @@ type MultiNode interface { Advance(map[uint64]Ready) // Status returns the current status of the given group. Status(group uint64) Status + // Report reports the given node is not reachable for the last send. + ReportUnreachable(id, groupID uint64) + // ReportSnapshot reports the stutus of the sent snapshot. + ReportSnapshot(id, groupID uint64, status SnapshotStatus) // Stop performs any necessary termination of the MultiNode. Stop() } @@ -447,3 +451,25 @@ func (mn *multiNode) Status(group uint64) Status { mn.status <- ms return <-ms.ch } + +func (mn *multiNode) ReportUnreachable(id, groupID uint64) { + select { + case mn.recvc <- multiMessage{ + group: groupID, + msg: pb.Message{Type: pb.MsgUnreachable, From: id}, + }: + case <-mn.done: + } +} + +func (mn *multiNode) ReportSnapshot(id, groupID uint64, status SnapshotStatus) { + rej := status == SnapshotFailure + + select { + case mn.recvc <- multiMessage{ + group: groupID, + msg: pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}, + }: + case <-mn.done: + } +}