Add allocator.PeerGone
The function is registered within the mesh gc and it is responsible for removing gone nicknames (#2057).
This commit is contained in:
1 parent
2f5a3f4513
commit
849edb1768
2 files changed
+19
No files matched your search
@@ -90,11 +90,13 @@ type Config struct {
|
|||||||
// NewAllocator creates and initialises a new Allocator
|
// NewAllocator creates and initialises a new Allocator
|
||||||
func NewAllocator(config Config) *Allocator {
|
func NewAllocator(config Config) *Allocator {
|
||||||
var participant paxos.Participant
|
var participant paxos.Participant
|
||||||
|
|
||||||
if config.IsObserver {
|
if config.IsObserver {
|
||||||
participant = paxos.NewObserver()
|
participant = paxos.NewObserver()
|
||||||
} else {
|
} else {
|
||||||
participant = paxos.NewNode(config.OurName, config.OurUID, 0)
|
participant = paxos.NewNode(config.OurName, config.OurUID, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Allocator{
|
return &Allocator{
|
||||||
ourName: config.OurName,
|
ourName: config.OurName,
|
||||||
seed: config.Seed,
|
seed: config.Seed,
|
||||||
@@ -485,6 +487,22 @@ func (alloc *Allocator) annotatePeernames(names []mesh.PeerName) []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PeerGone removes nicknames of peers which are no longer mentioned
|
||||||
|
// in the ring. Async.
|
||||||
|
//
|
||||||
|
// NB: the function is invoked by the gossip library routines and should be
|
||||||
|
// registered manually.
|
||||||
|
func (alloc *Allocator) PeerGone(peerName mesh.PeerName) {
|
||||||
|
alloc.debugln("PeerGone: peer %s", peerName)
|
||||||
|
|
||||||
|
alloc.actionChan <- func() {
|
||||||
|
ringPeers := alloc.ring.PeerNames()
|
||||||
|
if _, ok := ringPeers[peerName]; !ok {
|
||||||
|
delete(alloc.nicknames, peerName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func decodeRange(msg []byte) (r address.Range, err error) {
|
func decodeRange(msg []byte) (r address.Range, err error) {
|
||||||
decoder := gob.NewDecoder(bytes.NewReader(msg))
|
decoder := gob.NewDecoder(bytes.NewReader(msg))
|
||||||
return r, decoder.Decode(&r)
|
return r, decoder.Decode(&r)
|
||||||
|
|||||||
@@ -452,6 +452,7 @@ func createAllocator(router *weave.NetworkRouter, config ipamConfig, db db.DB, i
|
|||||||
|
|
||||||
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
||||||
allocator.Start()
|
allocator.Start()
|
||||||
|
router.Peers.OnGC(func(peer *mesh.Peer) { allocator.PeerGone(peer.Name) })
|
||||||
|
|
||||||
return allocator, defaultSubnet
|
return allocator, defaultSubnet
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user