From c8be9fe1e30f6c5e3d1f79f6bc76ec4e44c80d1e Mon Sep 17 00:00:00 2001 From: Jim Scott Date: Fri, 11 Nov 2016 10:09:44 -0800 Subject: [PATCH] Address comments, and actually check if the peers are being removed. --- partitions.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/partitions.go b/partitions.go index d9fe7daf..5e97a9bc 100644 --- a/partitions.go +++ b/partitions.go @@ -113,9 +113,9 @@ func (p *partitions) updateLocalPartitions(local map[int]bool) { } } -func (p *partitions) deDupe(nodes []string) []string { +func dedupe(nodes []string) []string { found := map[string]bool{} - dedupedNodes := make([]string, len(nodes)) + dedupedNodes := make([]string, 0, len(nodes)) for _, node := range nodes { if !found[node] { found[node] = true @@ -144,12 +144,22 @@ func (p *partitions) updateRemotePartitions(nodes []string) { } } - for partitionId, partition := range remote { - newPartition := make([]string, len(partition)) - copy(newPartition, partition) + for partitionId, partition := range p.remote { + disappearedPeers := make([]string, len(partition)) - unDedupedPartition := append(newPartition, p.disappeared[partitionId]...) - p.disappeared[partitionId] = p.deDupe(unDedupedPartition) + for _, oldPeer := range partition { + found := false + for _, newPeer := range remote[partitionId] { + if newPeer == oldPeer { + found = true + } + } + if !found { + disappearedPeers = append(disappearedPeers, oldPeer) + } + } + + p.disappeared[partitionId] = dedupe(append(disappearedPeers, p.disappeared[partitionId]...)) if len(p.disappeared[partitionId]) >= 1024 { p.disappeared[partitionId] = p.disappeared[partitionId][:1024] }