2016-03-29 00:28:57 +00:00
|
|
|
package networkdb
|
|
|
|
|
|
|
|
import "github.com/hashicorp/memberlist"
|
|
|
|
|
|
|
|
type eventDelegate struct {
|
|
|
|
nDB *NetworkDB
|
|
|
|
}
|
|
|
|
|
2016-09-15 05:24:14 +00:00
|
|
|
func (e *eventDelegate) NotifyJoin(mn *memberlist.Node) {
|
2016-03-29 00:28:57 +00:00
|
|
|
e.nDB.Lock()
|
2016-09-15 05:24:14 +00:00
|
|
|
// In case the node is rejoining after a failure or leave,
|
|
|
|
// wait until an explicit join message arrives before adding
|
|
|
|
// it to the nodes just to make sure this is not a stale
|
|
|
|
// join. If you don't know about this node add it immediately.
|
|
|
|
_, fOk := e.nDB.failedNodes[mn.Name]
|
|
|
|
_, lOk := e.nDB.leftNodes[mn.Name]
|
|
|
|
if fOk || lOk {
|
|
|
|
e.nDB.Unlock()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
e.nDB.nodes[mn.Name] = &node{Node: *mn}
|
2016-03-29 00:28:57 +00:00
|
|
|
e.nDB.Unlock()
|
|
|
|
}
|
|
|
|
|
2016-09-15 05:24:14 +00:00
|
|
|
func (e *eventDelegate) NotifyLeave(mn *memberlist.Node) {
|
|
|
|
e.nDB.deleteNodeTableEntries(mn.Name)
|
|
|
|
e.nDB.deleteNetworkEntriesForNode(mn.Name)
|
2016-03-29 00:28:57 +00:00
|
|
|
e.nDB.Lock()
|
2016-09-15 05:24:14 +00:00
|
|
|
if n, ok := e.nDB.nodes[mn.Name]; ok {
|
|
|
|
delete(e.nDB.nodes, mn.Name)
|
|
|
|
e.nDB.failedNodes[mn.Name] = n
|
|
|
|
}
|
2016-03-29 00:28:57 +00:00
|
|
|
e.nDB.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *eventDelegate) NotifyUpdate(n *memberlist.Node) {
|
|
|
|
}
|