[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-03 17:59:57 +03:00 committed by Alex Vanin
parent 3775d61ccb
commit 9618c3e268
2 changed files with 33 additions and 15 deletions

View file

@ -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)
}
}

View file

@ -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),