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

Commit

Permalink
Address comments, and actually check if the peers are being removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjab committed Nov 11, 2016
1 parent 03bb861 commit c8be9fe
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down

0 comments on commit c8be9fe

Please sign in to comment.