From 658d8af96df35c875dbde87e6af8330a625401b9 Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Sat, 4 May 2019 11:49:57 -0400 Subject: [PATCH] adds peer changes to observations. allows for reactions to peers changing. --- observer.go | 11 ++++++++++- raft.go | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/observer.go b/observer.go index bce17ef19a4..2d4f37db12d 100644 --- a/observer.go +++ b/observer.go @@ -9,7 +9,10 @@ type Observation struct { // Raft holds the Raft instance generating the observation. Raft *Raft // Data holds observation-specific data. Possible types are - // *RequestVoteRequest and RaftState. + // *RequestVoteRequest + // RaftState + // PeerObservation + // LeaderObservation Data interface{} } @@ -18,6 +21,12 @@ type LeaderObservation struct { leader ServerAddress } +// PeerObservation is sent to observers when peers change. +type PeerObservation struct { + Removed bool + Peer Server +} + // nextObserverId is used to provide a unique ID for each observer to aid in // deregistration. var nextObserverID uint64 diff --git a/raft.go b/raft.go index 67b2ece85d3..a759230bc98 100644 --- a/raft.go +++ b/raft.go @@ -450,6 +450,7 @@ func (r *Raft) startStopReplication() { r.leaderState.replState[server.ID] = s r.goFunc(func() { r.replicate(s) }) asyncNotifyCh(s.triggerCh) + r.observe(PeerObservation{Peer: server, Removed: false}) } } @@ -463,6 +464,7 @@ func (r *Raft) startStopReplication() { repl.stopCh <- lastIdx close(repl.stopCh) delete(r.leaderState.replState, serverID) + r.observe(PeerObservation{Peer: repl.peer, Removed: true}) } }