From fb3ed9c1a684c05b73bb5fc7a399e162f45c559a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 3 May 2016 12:26:17 +0100 Subject: [PATCH] Re-organise checking of persisted data so the failure paths bail out of the function first. Also bail out if there is no persisted ring, since persisted 'owned' data isn't meaningful in that state. --- ipam/allocator.go | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index a8b14fe8..d708702a 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -901,28 +901,34 @@ func (alloc *Allocator) loadPersistedData() bool { alloc.fatalf("Error loading persisted address data: %s", err) } - if nameFound { - if checkPeerName == alloc.ourName { - if ringFound { - alloc.ring = persistedRing - alloc.space.UpdateRanges(alloc.ring.OwnedRanges()) - } - if ownedFound { - alloc.owned = persistedOwned - for _, d := range alloc.owned { - for _, cidr := range d.Cidrs { - alloc.space.Claim(cidr.Addr) - } - } - } - return true - } - alloc.infof("Deleting persisted data for peername %s", checkPeerName) + overwritePersisted := func(fmt string, args ...interface{}) { + alloc.infof(fmt, args...) alloc.persistRing() alloc.persistOwned() } - return false + if !nameFound || !ringFound { + overwritePersisted("No valid persisted data") + return false + } + + if checkPeerName != alloc.ourName { + overwritePersisted("Deleting persisted data for peername %s", checkPeerName) + return false + } + + alloc.ring = persistedRing + alloc.space.UpdateRanges(alloc.ring.OwnedRanges()) + + if ownedFound { + alloc.owned = persistedOwned + for _, d := range alloc.owned { + for _, cidr := range d.Cidrs { + alloc.space.Claim(cidr.Addr) + } + } + } + return true } func (alloc *Allocator) persistOwned() {