Skip to content

Commit

Permalink
Merge pull request hashicorp#326 from james-lawrence/observations/pee…
Browse files Browse the repository at this point in the history
…r-changes

adds peer changes to observations.
  • Loading branch information
Robbie McKinstry authored May 11, 2019
2 parents 773bcaa + 658d8af commit e50ea72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}

Expand All @@ -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})
}
}

Expand Down

0 comments on commit e50ea72

Please sign in to comment.