From 9618c3e268dce0e75667b8b6540123d1ebc8986b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 3 Feb 2021 17:59:57 +0300 Subject: [PATCH] [#367] cmd/neofs-node: Don't update local node info for bootstrap At startup, update only node info status. Leave all other attributes from node configuration, so user can update them. Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 46 ++++++++++++++++++++++++++++------------ cmd/neofs-node/netmap.go | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index a7afaa6d5..7d095f1e1 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 35e72310f..4fe56f892 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),