Skip to content

Commit 5edec33

Browse files
committed
Keep methods addPeer and removePeer close to each other
Signed-off-by: Daniele Sciascia <daniele@nats.io>
1 parent a1e9ba7 commit 5edec33

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

server/raft.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -951,21 +951,6 @@ func (n *raft) ProposeAddPeer(peer string) error {
951951
return nil
952952
}
953953

954-
// Remove the peer with the given id from our membership,
955-
// and adjusts cluster size and quorum accordingly.
956-
// Lock should be held.
957-
func (n *raft) removePeer(peer string) {
958-
if n.removed == nil {
959-
n.removed = map[string]time.Time{}
960-
}
961-
n.removed[peer] = time.Now()
962-
if _, ok := n.peers[peer]; ok {
963-
delete(n.peers, peer)
964-
n.adjustClusterSizeAndQuorum()
965-
n.writePeerState(&peerState{n.peerNames(), n.csz, n.extSt})
966-
}
967-
}
968-
969954
// ProposeRemovePeer is called to remove a peer from the group.
970955
func (n *raft) ProposeRemovePeer(peer string) error {
971956
n.Lock()
@@ -2683,6 +2668,21 @@ func (n *raft) addPeer(peer string) {
26832668
n.writePeerState(&peerState{n.peerNames(), n.csz, n.extSt})
26842669
}
26852670

2671+
// Remove the peer with the given id from our membership,
2672+
// and adjusts cluster size and quorum accordingly.
2673+
// Lock should be held.
2674+
func (n *raft) removePeer(peer string) {
2675+
if n.removed == nil {
2676+
n.removed = map[string]time.Time{}
2677+
}
2678+
n.removed[peer] = time.Now()
2679+
if _, ok := n.peers[peer]; ok {
2680+
delete(n.peers, peer)
2681+
n.adjustClusterSizeAndQuorum()
2682+
n.writePeerState(&peerState{n.peerNames(), n.csz, n.extSt})
2683+
}
2684+
}
2685+
26862686
// Build and send appendEntry request for the given entry that changes
26872687
// membership (EntryAddPeer / EntryRemovePeer).
26882688
// Returns true if the entry made it to the WAL and was sent to the followers

0 commit comments

Comments
 (0)