Refactor Paxos status call to remove type assertion
This commit is contained in:
1 parent
768e2a31fa
commit
0c59de40e7
4 files changed
+14
-6
No files matched your search
+1
-1
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+4
-3
@@ -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}
|
||||
}
|
||||
+4
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user