Merge pull request #2070 from weaveworks/issues/1721-quorum-callback
Use current target list to compute quorum
This commit is contained in:
commit
436dc01f52
6 files changed
+40
-27
No files matched your search
+12
-2
@@ -64,6 +64,7 @@ type Allocator struct {
|
||||
ticker *time.Ticker
|
||||
shuttingDown bool // to avoid doing any requests while trying to shut down
|
||||
isKnownPeer func(mesh.PeerName) bool
|
||||
quorum func() uint
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
@@ -73,13 +74,20 @@ type Config struct {
|
||||
OurNickname string
|
||||
Seed []mesh.PeerName
|
||||
Universe address.Range
|
||||
Quorum uint
|
||||
IsObserver bool
|
||||
Quorum func() uint
|
||||
Db db.DB
|
||||
IsKnownPeer func(name mesh.PeerName) bool
|
||||
}
|
||||
|
||||
// NewAllocator creates and initialises a new Allocator
|
||||
func NewAllocator(config Config) *Allocator {
|
||||
var participant paxos.Participant
|
||||
if config.IsObserver {
|
||||
participant = paxos.NewObserver()
|
||||
} else {
|
||||
participant = paxos.NewNode(config.OurName, config.OurUID, 1)
|
||||
}
|
||||
return &Allocator{
|
||||
ourName: config.OurName,
|
||||
seed: config.Seed,
|
||||
@@ -87,9 +95,10 @@ func NewAllocator(config Config) *Allocator {
|
||||
ring: ring.New(config.Universe.Start, config.Universe.End, config.OurName),
|
||||
owned: make(map[string][]address.CIDR),
|
||||
db: config.Db,
|
||||
paxos: paxos.NewParticipant(config.OurName, config.OurUID, config.Quorum),
|
||||
paxos: participant,
|
||||
nicknames: map[mesh.PeerName]string{config.OurName: config.OurNickname},
|
||||
isKnownPeer: config.IsKnownPeer,
|
||||
quorum: config.Quorum,
|
||||
dead: make(map[string]time.Time),
|
||||
now: time.Now,
|
||||
}
|
||||
@@ -603,6 +612,7 @@ func (alloc *Allocator) establishRing() {
|
||||
}
|
||||
|
||||
alloc.awaitingConsensus = true
|
||||
alloc.paxos.SetQuorum(alloc.quorum())
|
||||
alloc.propose()
|
||||
if ok, cons := alloc.paxos.Consensus(); ok {
|
||||
// If the quorum was 1, then proposing immediately
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
package paxos
|
||||
|
||||
import "github.com/weaveworks/mesh"
|
||||
|
||||
type Participant interface {
|
||||
GossipState() GossipState
|
||||
Update(from GossipState) bool
|
||||
SetQuorum(uint)
|
||||
Propose()
|
||||
Think() bool
|
||||
Consensus() (bool, AcceptedValue)
|
||||
}
|
||||
|
||||
func NewParticipant(name mesh.PeerName, uid mesh.PeerUID, quorum uint) Participant {
|
||||
switch quorum {
|
||||
case 0:
|
||||
return &Observer{}
|
||||
default:
|
||||
return NewNode(name, uid, quorum)
|
||||
}
|
||||
type Observer struct {
|
||||
}
|
||||
|
||||
type Observer struct {
|
||||
func NewObserver() Participant {
|
||||
return &Observer{}
|
||||
}
|
||||
|
||||
func (observer *Observer) GossipState() GossipState {
|
||||
@@ -33,6 +27,9 @@ func (observer *Observer) Update(from GossipState) bool {
|
||||
func (observer *Observer) Propose() {
|
||||
}
|
||||
|
||||
func (observer *Observer) SetQuorum(uint) {
|
||||
}
|
||||
|
||||
func (observer *Observer) Think() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -80,6 +80,10 @@ func NewNode(name mesh.PeerName, uid mesh.PeerUID, quorum uint) *Node {
|
||||
}
|
||||
}
|
||||
|
||||
func (node *Node) SetQuorum(quorum uint) {
|
||||
node.quorum = quorum
|
||||
}
|
||||
|
||||
func (node *Node) GossipState() GossipState {
|
||||
return node.knows
|
||||
}
|
||||
@@ -124,6 +128,9 @@ func max(a uint, b uint) uint {
|
||||
// simply a matter of gossipping a new proposal that supersedes all
|
||||
// others.
|
||||
func (node *Node) Propose() {
|
||||
if node.quorum == 0 {
|
||||
panic("Paxos node.Propose() called with no quorum set")
|
||||
}
|
||||
// Find the highest round number around
|
||||
round := uint(0)
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, addres
|
||||
OurUID: mesh.PeerUID(rand.Int63()),
|
||||
OurNickname: "nick-" + name,
|
||||
Universe: cidr.Range(),
|
||||
Quorum: quorum,
|
||||
IsObserver: quorum == 0,
|
||||
Quorum: func() uint { return quorum },
|
||||
Db: new(mockDB),
|
||||
IsKnownPeer: func(mesh.PeerName) bool { return true },
|
||||
}), cidr
|
||||
|
||||
Reference in new issue
Block a user