Browse Source

[tm-monitor] fixed online status not changing issue. (#99)

* [tm-monitor] fixed online status not changing issue.

* Refactor UpdateNodeStatus.
pull/1943/head
rao yunkun 7 years ago
committed by Anton Kaliaev
parent
commit
a12785aa60
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      tm-monitor/monitor/monitor.go

+ 18
- 0
tm-monitor/monitor/monitor.go View File

@ -131,6 +131,21 @@ func (m *Monitor) NodeByName(name string) (index int, node *Node) {
return -1, nil
}
// NodeIsOnline is called when connection to the node is restored.
// Must be safe to call multiple times.
func (m *Monitor) NodeIsOnline(name string) {
_, node := m.NodeByName(name)
if nil != node {
if online, ok := m.Network.nodeStatusMap[name]; ok && online {
m.mtx.Lock()
node.Online = online
m.mtx.Unlock()
}
}
}
// Start starts the monitor's routines: recalculating network uptime and
// updating number of validators.
func (m *Monitor) Start() error {
@ -160,14 +175,17 @@ func (m *Monitor) listen(nodeName string, blockCh <-chan tmtypes.Header, blockLa
case b := <-blockCh:
m.Network.NewBlock(b)
m.Network.NodeIsOnline(nodeName)
m.NodeIsOnline(nodeName)
case l := <-blockLatencyCh:
m.Network.NewBlockLatency(l)
m.Network.NodeIsOnline(nodeName)
m.NodeIsOnline(nodeName)
case disconnected := <-disconnectCh:
if disconnected {
m.Network.NodeIsDown(nodeName)
} else {
m.Network.NodeIsOnline(nodeName)
m.NodeIsOnline(nodeName)
}
case <-time.After(nodeLivenessTimeout):
logger.Info("event", fmt.Sprintf("node was not responding for %v", nodeLivenessTimeout))


Loading…
Cancel
Save