Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit c8be9fe

Browse files
committed
Address comments, and actually check if the peers are being removed.
1 parent 03bb861 commit c8be9fe

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

partitions.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ func (p *partitions) updateLocalPartitions(local map[int]bool) {
113113
}
114114
}
115115

116-
func (p *partitions) deDupe(nodes []string) []string {
116+
func dedupe(nodes []string) []string {
117117
found := map[string]bool{}
118-
dedupedNodes := make([]string, len(nodes))
118+
dedupedNodes := make([]string, 0, len(nodes))
119119
for _, node := range nodes {
120120
if !found[node] {
121121
found[node] = true
@@ -144,12 +144,22 @@ func (p *partitions) updateRemotePartitions(nodes []string) {
144144
}
145145
}
146146

147-
for partitionId, partition := range remote {
148-
newPartition := make([]string, len(partition))
149-
copy(newPartition, partition)
147+
for partitionId, partition := range p.remote {
148+
disappearedPeers := make([]string, len(partition))
150149

151-
unDedupedPartition := append(newPartition, p.disappeared[partitionId]...)
152-
p.disappeared[partitionId] = p.deDupe(unDedupedPartition)
150+
for _, oldPeer := range partition {
151+
found := false
152+
for _, newPeer := range remote[partitionId] {
153+
if newPeer == oldPeer {
154+
found = true
155+
}
156+
}
157+
if !found {
158+
disappearedPeers = append(disappearedPeers, oldPeer)
159+
}
160+
}
161+
162+
p.disappeared[partitionId] = dedupe(append(disappearedPeers, p.disappeared[partitionId]...))
153163
if len(p.disappeared[partitionId]) >= 1024 {
154164
p.disappeared[partitionId] = p.disappeared[partitionId][:1024]
155165
}

0 commit comments

Comments
 (0)