diff --git a/ipam/allocator.go b/ipam/allocator.go index 0159f0d2..93c81f21 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -767,7 +767,7 @@ func (alloc *Allocator) update(sender mesh.PeerName, msg []byte) error { // (if we did so on periodic gossip we would force consensus unnecessarily) // * If we are an elector (to avoid a broadcast storm of ring request messages) default: - if _, ok := alloc.paxos.(*paxos.Node); ok && sender != mesh.UnknownPeerName { + if alloc.paxos.IsElector() && sender != mesh.UnknownPeerName { alloc.establishRing() } } diff --git a/ipam/paxos/participant.go b/ipam/paxos/participant.go index 32162018..b15b8733 100644 --- a/ipam/paxos/participant.go +++ b/ipam/paxos/participant.go @@ -7,6 +7,7 @@ type Participant interface { Propose() Think() bool Consensus() (bool, AcceptedValue) + IsElector() bool } type Observer struct { @@ -37,3 +38,7 @@ func (observer *Observer) Think() bool { func (observer *Observer) Consensus() (bool, AcceptedValue) { return false, AcceptedValue{} } + +func (observer *Observer) IsElector() bool { + return false +} diff --git a/ipam/paxos/paxos.go b/ipam/paxos/paxos.go index 3a956269..6d157060 100644 --- a/ipam/paxos/paxos.go +++ b/ipam/paxos/paxos.go @@ -257,14 +257,15 @@ func (node *Node) Consensus() (bool, AcceptedValue) { return false, AcceptedValue{} } +func (node *Node) IsElector() bool { + return true +} + type Status struct { KnownNodes int Quorum uint } func NewStatus(node *Node) *Status { - if node == nil { - return nil - } return &Status{len(node.knows), node.quorum} } diff --git a/ipam/status.go b/ipam/status.go index f98f303d..c826b9b1 100644 --- a/ipam/status.go +++ b/ipam/status.go @@ -37,8 +37,10 @@ func NewStatus(allocator *Allocator, defaultSubnet address.CIDR) *Status { var paxosStatus *paxos.Status if allocator.awaitingConsensus && allocator.paxos != nil { - if node, ok := allocator.paxos.(*paxos.Node); ok { - paxosStatus = paxos.NewStatus(node) + if allocator.paxos.IsElector() { + if node, ok := allocator.paxos.(*paxos.Node); ok { + paxosStatus = paxos.NewStatus(node) + } } }