[#490] cmd/neofs-node: Do not send rebootstrap after node went offline

Control service turns storage node to online and offline modes. We can't
reuse `cfgNetmap.reBootstrapEnabled` because it represents configuration
value while control service manages state in runtime.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-21 16:26:04 +03:00 committed by Alex Vanin
parent de74fcc38f
commit e9b3488aab
2 changed files with 10 additions and 1 deletions

View file

@ -262,7 +262,8 @@ type cfgNetmap struct {
state *networkState state *networkState
reBootstrapEnabled bool reBootstrapEnabled bool
reBootstrapInterval uint64 // in epochs reBoostrapTurnedOff *atomic.Bool // managed by control service in runtime
reBootstrapInterval uint64 // in epochs
goOfflineEnabled bool // send `UpdateState(offline)` tx at shutdown goOfflineEnabled bool // send `UpdateState(offline)` tx at shutdown
} }
@ -377,6 +378,7 @@ func initCfg(path string) *cfg {
workerPool: netmapWorkerPool, workerPool: netmapWorkerPool,
reBootstrapInterval: viperCfg.GetUint64(cfgReBootstrapInterval), reBootstrapInterval: viperCfg.GetUint64(cfgReBootstrapInterval),
reBootstrapEnabled: viperCfg.GetBool(cfgReBootstrapEnabled), reBootstrapEnabled: viperCfg.GetBool(cfgReBootstrapEnabled),
reBoostrapTurnedOff: atomic.NewBool(false),
goOfflineEnabled: viperCfg.GetBool(cfgShutdownOfflineEnabled), goOfflineEnabled: viperCfg.GetBool(cfgShutdownOfflineEnabled),
}, },
cfgNodeInfo: cfgNodeInfo{ cfgNodeInfo: cfgNodeInfo{

View file

@ -75,6 +75,10 @@ func initNetmapService(c *cfg) {
if c.cfgNetmap.reBootstrapEnabled { if c.cfgNetmap.reBootstrapEnabled {
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) { addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
if c.cfgNetmap.reBoostrapTurnedOff.Load() { // fixes #470
return
}
n := ev.(netmapEvent.NewEpoch).EpochNumber() n := ev.(netmapEvent.NewEpoch).EpochNumber()
if n%c.cfgNetmap.reBootstrapInterval == 0 { if n%c.cfgNetmap.reBootstrapInterval == 0 {
@ -202,6 +206,7 @@ func goOffline(c *cfg) {
func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
if st == control.NetmapStatus_ONLINE { if st == control.NetmapStatus_ONLINE {
c.cfgNetmap.reBoostrapTurnedOff.Store(false)
return c.cfgNetmap.wrapper.AddPeer(c.toOnlineLocalNodeInfo()) return c.cfgNetmap.wrapper.AddPeer(c.toOnlineLocalNodeInfo())
} }
@ -211,6 +216,8 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
apiState = netmapSDK.NodeStateOffline apiState = netmapSDK.NodeStateOffline
} }
c.cfgNetmap.reBoostrapTurnedOff.Store(true)
return c.cfgNetmap.wrapper.UpdatePeerState( return c.cfgNetmap.wrapper.UpdatePeerState(
crypto.MarshalPublicKey(&c.key.PublicKey), crypto.MarshalPublicKey(&c.key.PublicKey),
apiState, apiState,