From 06f3793f0525b6571dd1282d6ceb69189fb347ee Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 12 Feb 2016 10:19:07 +0000 Subject: [PATCH] Remove persisted IPAM ring data on peerName change --- ipam/allocator.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ipam/allocator.go b/ipam/allocator.go index 7d4d4096..4d758f36 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -768,15 +768,31 @@ func (alloc *Allocator) reportFreeSpace() { // Persisting the Ring const ( ringIdent = "ring" + nameIdent = "peername" ) func (alloc *Allocator) persistRing() { + // It would be better if these two Save operations happened in the same transaction + if err := alloc.db.Save(nameIdent, alloc.ourName); err != nil { + common.Log.Errorf("Error persisting ring data: %s", err) + return + } if err := alloc.db.Save(ringIdent, alloc.ring); err != nil { common.Log.Errorf("Error persisting ring data: %s", err) } } func (alloc *Allocator) loadPersistedRing() { + var checkPeerName mesh.PeerName + if err := alloc.db.Load(nameIdent, &checkPeerName); err != nil { + common.Log.Errorf("Error loading persisted peer name: %s", err) + return + } + if checkPeerName != alloc.ourName { + alloc.infof("Deleting persisted data for peername %s", checkPeerName) + alloc.persistRing() + return + } if err := alloc.db.Load(ringIdent, &alloc.ring); err != nil { common.Log.Errorf("Error loading persisted ring data: %s", err) }