Remove syncNodes/syncPeers not Ready special case

First the comment "so remove it from the mesh" is wrong / missleading as
since 034c27ab78 the delete in that if is
not in there anymore.

Second the m.nodes map is not updated so setting `diff = true` will call `applyTopology` without any changes... which seams useless.

Third the rest of the code already checks for Ready so this special case
here should not be needed.
This commit is contained in:
Julien Viard de Galbert 2021-04-19 17:04:36 +02:00
parent 863628ffaa
commit 81f592de74

View File

@ -274,28 +274,23 @@ func (m *Mesh) syncNodes(e *NodeEvent) {
var diff bool var diff bool
m.mu.Lock() m.mu.Lock()
if !e.Node.Ready() { if !e.Node.Ready() {
level.Debug(logger).Log("msg", "received incomplete node", "node", e.Node) // Trace non ready nodes with their presence in the mesh.
// An existing node is no longer valid _, ok := m.nodes[e.Node.Name]
// so remove it from the mesh. level.Debug(logger).Log("msg", "received non ready node", "node", e.Node, "in-mesh", ok)
if _, ok := m.nodes[e.Node.Name]; ok { }
level.Info(logger).Log("msg", "node is no longer ready", "node", e.Node) switch e.Type {
diff = true case AddEvent:
} fallthrough
} else { case UpdateEvent:
switch e.Type { if !nodesAreEqual(m.nodes[e.Node.Name], e.Node) {
case AddEvent:
fallthrough
case UpdateEvent:
if !nodesAreEqual(m.nodes[e.Node.Name], e.Node) {
diff = true
}
// Even if the nodes are the same,
// overwrite the old node to update the timestamp.
m.nodes[e.Node.Name] = e.Node
case DeleteEvent:
delete(m.nodes, e.Node.Name)
diff = true diff = true
} }
// Even if the nodes are the same,
// overwrite the old node to update the timestamp.
m.nodes[e.Node.Name] = e.Node
case DeleteEvent:
delete(m.nodes, e.Node.Name)
diff = true
} }
m.mu.Unlock() m.mu.Unlock()
if diff { if diff {
@ -312,30 +307,25 @@ func (m *Mesh) syncPeers(e *PeerEvent) {
// Peers are indexed by public key. // Peers are indexed by public key.
key := string(e.Peer.PublicKey) key := string(e.Peer.PublicKey)
if !e.Peer.Ready() { if !e.Peer.Ready() {
level.Debug(logger).Log("msg", "received incomplete peer", "peer", e.Peer) // Trace non ready peer with their presence in the mesh.
// An existing peer is no longer valid _, ok := m.peers[key]
// so remove it from the mesh. level.Debug(logger).Log("msg", "received non ready peer", "peer", e.Peer, "in-mesh", ok)
if _, ok := m.peers[key]; ok { }
level.Info(logger).Log("msg", "peer is no longer ready", "peer", e.Peer) switch e.Type {
case AddEvent:
fallthrough
case UpdateEvent:
if e.Old != nil && key != string(e.Old.PublicKey) {
delete(m.peers, string(e.Old.PublicKey))
diff = true diff = true
} }
} else { if !peersAreEqual(m.peers[key], e.Peer) {
switch e.Type { m.peers[key] = e.Peer
case AddEvent:
fallthrough
case UpdateEvent:
if e.Old != nil && key != string(e.Old.PublicKey) {
delete(m.peers, string(e.Old.PublicKey))
diff = true
}
if !peersAreEqual(m.peers[key], e.Peer) {
m.peers[key] = e.Peer
diff = true
}
case DeleteEvent:
delete(m.peers, key)
diff = true diff = true
} }
case DeleteEvent:
delete(m.peers, key)
diff = true
} }
m.mu.Unlock() m.mu.Unlock()
if diff { if diff {