Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
Add RemovePeer().
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Jun 7, 2013
1 parent 77c63cc commit bb7caaf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ func (l *Log) ContainsEntry(index uint64, term uint64) bool {
// Retrieves a list of entries after a given index. This function also returns
// the term of the index provided.
func (l *Log) GetEntriesAfter(index uint64) ([]*LogEntry, uint64) {
l.mutex.Lock()
defer l.mutex.Unlock()

// Return an error if the index doesn't exist.
if index > uint64(len(l.entries)) {
panic(fmt.Sprintf("raft.Log: Index is beyond end of log: %v", index))
Expand Down
9 changes: 8 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,17 @@ func (s *Server) RemovePeer(name string) error {
}
// Return error if peer doesn't exist.
peer := s.peers[name]
if peer != nil {
if peer == nil {
return fmt.Errorf("raft: Peer not found: %s", name)
}

// Flush entries to the peer first.
if s.state == Leader {
if _, _, err := peer.internalFlush(); err != nil {
warn("raft: Unable to notify peer of removal: %v", err)
}
}

// Stop peer and remove it.
peer.stop()
delete(s.peers, name)
Expand Down

0 comments on commit bb7caaf

Please sign in to comment.