Tweak naming to be closer to code changes in nameserver
This commit is contained in:
1 parent
ace372cfc6
commit
8742957f75
2 files changed
+15
-15
No files matched your search
+13
-13
@@ -56,20 +56,20 @@ type Allocator struct {
|
|||||||
paxosTicker *time.Ticker
|
paxosTicker *time.Ticker
|
||||||
shuttingDown bool // to avoid doing any requests while trying to shut down
|
shuttingDown bool // to avoid doing any requests while trying to shut down
|
||||||
now func() time.Time
|
now func() time.Time
|
||||||
peerValidFunc func(router.PeerName) bool
|
isKnownPeer func(router.PeerName) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAllocator creates and initialises a new Allocator
|
// NewAllocator creates and initialises a new Allocator
|
||||||
func NewAllocator(ourName router.PeerName, ourUID router.PeerUID, ourNickname string, universe address.Range, quorum uint, validPeer func(name router.PeerName) bool) *Allocator {
|
func NewAllocator(ourName router.PeerName, ourUID router.PeerUID, ourNickname string, universe address.Range, quorum uint, isKnownPeer func(name router.PeerName) bool) *Allocator {
|
||||||
return &Allocator{
|
return &Allocator{
|
||||||
ourName: ourName,
|
ourName: ourName,
|
||||||
universe: universe,
|
universe: universe,
|
||||||
ring: ring.New(universe.Start, universe.End, ourName),
|
ring: ring.New(universe.Start, universe.End, ourName),
|
||||||
owned: make(map[string][]address.Address),
|
owned: make(map[string][]address.Address),
|
||||||
paxos: paxos.NewNode(ourName, ourUID, quorum),
|
paxos: paxos.NewNode(ourName, ourUID, quorum),
|
||||||
nicknames: map[router.PeerName]string{ourName: ourNickname},
|
nicknames: map[router.PeerName]string{ourName: ourNickname},
|
||||||
now: time.Now,
|
now: time.Now,
|
||||||
peerValidFunc: validPeer,
|
isKnownPeer: isKnownPeer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,11 +287,11 @@ func (alloc *Allocator) pickPeerFromNicknames(isValid func(router.PeerName) bool
|
|||||||
|
|
||||||
func (alloc *Allocator) pickPeerForTransfer() router.PeerName {
|
func (alloc *Allocator) pickPeerForTransfer() router.PeerName {
|
||||||
// first try alive peers that actively participate in IPAM (i.e. have entries)
|
// first try alive peers that actively participate in IPAM (i.e. have entries)
|
||||||
if heir := alloc.ring.PickPeerForTransfer(alloc.peerValidFunc); heir != router.UnknownPeerName {
|
if heir := alloc.ring.PickPeerForTransfer(alloc.isKnownPeer); heir != router.UnknownPeerName {
|
||||||
return heir
|
return heir
|
||||||
}
|
}
|
||||||
// next try alive peers that have IPAM enabled but have no entries
|
// next try alive peers that have IPAM enabled but have no entries
|
||||||
if heir := alloc.pickPeerFromNicknames(alloc.peerValidFunc); heir != router.UnknownPeerName {
|
if heir := alloc.pickPeerFromNicknames(alloc.isKnownPeer); heir != router.UnknownPeerName {
|
||||||
return heir
|
return heir
|
||||||
}
|
}
|
||||||
// next try disappeared peers that still have entries
|
// next try disappeared peers that still have entries
|
||||||
@@ -365,7 +365,7 @@ func (alloc *Allocator) lookupPeername(name string) (router.PeerName, error) {
|
|||||||
func (alloc *Allocator) pruneNicknames() {
|
func (alloc *Allocator) pruneNicknames() {
|
||||||
ringPeers := alloc.ring.PeerNames()
|
ringPeers := alloc.ring.PeerNames()
|
||||||
for name := range alloc.nicknames {
|
for name := range alloc.nicknames {
|
||||||
if _, ok := ringPeers[name]; !ok && !alloc.peerValidFunc(name) {
|
if _, ok := ringPeers[name]; !ok && !alloc.isKnownPeer(name) {
|
||||||
delete(alloc.nicknames, name)
|
delete(alloc.nicknames, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -368,8 +368,8 @@ func createAllocator(router *weave.Router, ipRangeStr string, defaultSubnetStr s
|
|||||||
Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange)
|
Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isValidFunc := func(name weave.PeerName) bool { return router.Peers.Fetch(name) != nil }
|
isKnownPeer := func(name weave.PeerName) bool { return router.Peers.Fetch(name) != nil }
|
||||||
allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum, isValidFunc)
|
allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum, isKnownPeer)
|
||||||
|
|
||||||
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
||||||
allocator.Start()
|
allocator.Start()
|
||||||
|
|||||||
Reference in new issue
Block a user