diff --git a/ipam/allocator.go b/ipam/allocator.go index c33fe920..ae8af51b 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -911,7 +911,9 @@ func (alloc *Allocator) reportFreeSpace() { for _, r := range ranges { freespace[r.Start] = alloc.space.NumFreeAddressesInRange(r) } - alloc.ring.ReportFree(freespace) + if alloc.ring.ReportFree(freespace) { + alloc.persistRing() + } } // Persistent data diff --git a/ipam/ring/ring.go b/ipam/ring/ring.go index 01010f24..67d1188c 100644 --- a/ipam/ring/ring.go +++ b/ipam/ring/ring.go @@ -449,8 +449,8 @@ func (r *Ring) String() string { // ReportFree is used by the allocator to tell the ring how many free // ips are in a given range, so that ChoosePeersToAskForSpace can make -// more intelligent decisions. -func (r *Ring) ReportFree(freespace map[address.Address]address.Count) { +// more intelligent decisions. Returns true if any changes made. +func (r *Ring) ReportFree(freespace map[address.Address]address.Count) (updated bool) { r.assertInvariants() defer r.assertInvariants() defer r.updateExportedVariables() @@ -483,12 +483,14 @@ func (r *Ring) ReportFree(freespace map[address.Address]address.Count) { common.Assert(free <= address.Count(maxSize)) if entries[i].Free == free { - return + continue } entries[i].Free = free entries[i].Version++ + updated = true } + return } type weightedPeer struct {