From 51d7f455c98b5689850658db0ec12ff3d00f5c59 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Fri, 10 May 2019 17:23:45 +0530 Subject: [PATCH] move code to reset the entry free space from entries.merge() to Ring.Merge() --- ipam/ring/ring.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ipam/ring/ring.go b/ipam/ring/ring.go index 945074af..2ab8291b 100644 --- a/ipam/ring/ring.go +++ b/ipam/ring/ring.go @@ -244,6 +244,16 @@ func (r *Ring) Merge(gossip Ring) (bool, error) { return false, err } + // reset the free space for entries if there is invalid free space + // due to accepting an unexpected update from the peers + for i := 0; i < len(result); i++ { + distance := r.distance(result.entry(i).Token, result.entry(i+1).Token) + if result.entry(i).Peer == r.Peer && result.entry(i).Free > distance { + // case that can arise when a range that we own that got split and had no allocations + result.entry(i).Free = distance + } + } + if err := r.checkEntries(result); err != nil { return false, fmt.Errorf("Merge of incoming data causes: %s", err) } @@ -364,16 +374,6 @@ func (es entries) merge(other entries, ourPeer mesh.PeerName, r *Ring) (result e addTheirs(*theirs) } - // reset the free space for entries if there is invalid free space - // due to accepting an unexpected update from the peers - for i := 0; i < len(result); i++ { - distance := r.distance(result.entry(i).Token, result.entry(i+1).Token) - if result.entry(i).Peer == r.Peer && result.entry(i).Free > distance { - // case that can arise when a range that we own that got split and had no allocations - result.entry(i).Free = distance - } - } - return }