Handle range wrap-around when checking for allocations

Ring wraps around at zero but Space doesn't know about this, so we
have to normalise ranges coming out of Ring.  In turn we may need to
split one range into two, across the end of the Ring.
This commit is contained in:
Bryan Boreham committed 2019-10-10 11:14:41 +00:00
1 parent 9c09e36135
commit d2f0287fa3
3 files changed
+26 -18

No files matched your search

+9 -3
View File
@@ -814,8 +814,14 @@ func (alloc *Allocator) sendRingUpdate(dest mesh.PeerName) {
alloc.gossip.GossipUnicast(dest, msg)
}
func (alloc *Allocator) checkRangeHasAllocations(r address.Range) bool {
return alloc.space.NumFreeAddressesInRange(r) != r.Size()
func (alloc *Allocator) hasAllocations(rs []address.Range) bool {
for _, r := range rs {
alloc.debugf("hasAllocations: %v %v vs %v", r, alloc.space.NumFreeAddressesInRange(r), r.Size())
if alloc.space.NumFreeAddressesInRange(r) != r.Size() {
return true
}
}
return false
}
func (alloc *Allocator) update(sender mesh.PeerName, msg []byte) error {
@@ -836,7 +842,7 @@ func (alloc *Allocator) update(sender mesh.PeerName, msg []byte) error {
// If someone sent us a ring, merge it into ours. Note this will move us
// out of the awaiting-consensus state if we didn't have a ring already.
case data.Ring != nil:
updated, err := alloc.ring.Merge(*data.Ring, alloc.checkRangeHasAllocations)
updated, err := alloc.ring.Merge(*data.Ring, alloc.hasAllocations)
switch err {
case nil:
if updated {