diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index a7afaa6d51..7d095f1e16 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -657,27 +657,25 @@ func (c *cfg) LocalNodeInfo() (*netmapV2.NodeInfo, error) { return ni.ToV2(), nil } +// handleLocalNodeInfo rewrites local node info func (c *cfg) handleLocalNodeInfo(ni *netmap.NodeInfo) { c.cfgNodeInfo.infoMtx.Lock() - var nmState netmap.NodeState - if ni != nil { c.cfgNodeInfo.info = *ni - nmState = ni.State() - } else { - nmState = netmap.NodeStateOffline - c.cfgNodeInfo.info.SetState(nmState) } - switch nmState { - default: - c.setNetmapStatus(control.NetmapStatus_STATUS_UNDEFINED) - case netmap.NodeStateOnline: - c.setNetmapStatus(control.NetmapStatus_ONLINE) - case netmap.NodeStateOffline: - c.setNetmapStatus(control.NetmapStatus_OFFLINE) - } + c.updateStatusWithoutLock(ni) + + c.cfgNodeInfo.infoMtx.Unlock() +} + +// handleNodeInfoStatus updates node info status without rewriting whole local +// node info status +func (c *cfg) handleNodeInfoStatus(ni *netmap.NodeInfo) { + c.cfgNodeInfo.infoMtx.Lock() + + c.updateStatusWithoutLock(ni) c.cfgNodeInfo.infoMtx.Unlock() } @@ -695,3 +693,23 @@ func (c *cfg) toOnlineLocalNodeInfo() *netmap.NodeInfo { return &ni } + +func (c *cfg) updateStatusWithoutLock(ni *netmap.NodeInfo) { + var nmState netmap.NodeState + + if ni != nil { + nmState = ni.State() + } else { + nmState = netmap.NodeStateOffline + c.cfgNodeInfo.info.SetState(nmState) + } + + switch nmState { + default: + c.setNetmapStatus(control.NetmapStatus_STATUS_UNDEFINED) + case netmap.NodeStateOnline: + c.setNetmapStatus(control.NetmapStatus_ONLINE) + case netmap.NodeStateOffline: + c.setNetmapStatus(control.NetmapStatus_OFFLINE) + } +} diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 35e72310fd..4fe56f8928 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -127,7 +127,7 @@ func initState(c *cfg) { ni, err := c.netmapLocalNodeState(epoch) fatalOnErr(errors.Wrap(err, "could not init network state")) - c.handleLocalNodeInfo(ni) + c.handleNodeInfoStatus(ni) c.log.Info("initial network state", zap.Uint64("epoch", epoch),