Browse Source

Add ReportUnreachable and ReportSnapshot to MultiNode.

Add ReportSnapshot requirement to doc.go.
Ben Darnell 10 years ago
parent
commit
725c411346
2 changed files with 28 additions and 1 deletions
  1. 2 1
      raft/doc.go
  2. 26 0
      raft/multinode.go

+ 2 - 1
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
 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,
 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
 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.
 3. Apply Snapshot (if any) and CommittedEntries to the state machine.
 If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange()
 If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange()

+ 26 - 0
raft/multinode.go

@@ -38,6 +38,10 @@ type MultiNode interface {
 	Advance(map[uint64]Ready)
 	Advance(map[uint64]Ready)
 	// Status returns the current status of the given group.
 	// Status returns the current status of the given group.
 	Status(group uint64) Status
 	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 performs any necessary termination of the MultiNode.
 	Stop()
 	Stop()
 }
 }
@@ -447,3 +451,25 @@ func (mn *multiNode) Status(group uint64) Status {
 	mn.status <- ms
 	mn.status <- ms
 	return <-ms.ch
 	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:
+	}
+}