From 5a45471c6855fcfb331c2d4986552b7c82fbef8f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 6 Oct 2015 14:20:42 +0100 Subject: [PATCH] more readable errors on ring.Merge There are three significant changes here: - rewrite ring.ErrDifferentSeeds errors - remove the pre-checking of ranges and instead rewrite ring.ErrDifferentRange errors - don't pruneNicknames() and signal ringUpdated() when there was an error We don't rewrite other errors since our current belief is that only ErrDifferentSeeds and ErrDifferentRange can arise from user error. --- ipam/allocator.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index d3c0e0e2..a6d17eaf 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -618,16 +618,20 @@ func (alloc *Allocator) update(sender router.PeerName, msg []byte) error { // shouldn't get updates for a empty Ring. But tolerate // them just in case. if data.Ring != nil { - if data.Ring.Range() != alloc.universe { - return fmt.Errorf("Incompatible IP allocation range %s; ours is %s", - data.Ring.Range().AsCIDRString(), alloc.universe.AsCIDRString()) + switch err = alloc.ring.Merge(*data.Ring); err { + case ring.ErrDifferentSeeds: + return fmt.Errorf("IP allocation was seeded by different peers (received: %v, ours: %v)", + data.Ring.Seeds, alloc.ring.Seeds) + case ring.ErrDifferentRange: + return fmt.Errorf("Incompatible IP allocation ranges (received: %s, ours: %s)", + data.Ring.Range().AsCIDRString(), alloc.ring.Range().AsCIDRString()) + default: + if err == nil && !alloc.ring.Empty() { + alloc.pruneNicknames() + alloc.ringUpdated() + } + return err } - err = alloc.ring.Merge(*data.Ring) - if !alloc.ring.Empty() { - alloc.pruneNicknames() - alloc.ringUpdated() - } - return err } if data.Paxos != nil {