move code to reset the entry free space from entries.merge() to Ring.Merge()

This commit is contained in:
Murali Reddy committed 2019-05-10 17:23:45 +05:30
1 parent 89db74338e
commit 51d7f455c9
1 file changed
+10 -10
+10 -10
View File
@@ -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
}