From 13c55f5340523e4211cdf184142581f6b67780a0 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 14 Jul 2023 16:22:38 +0300 Subject: [PATCH] [#516] node: Do not bootstrap if node is online candidate Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/config.go | 3 ++- cmd/frostfs-node/netmap.go | 19 +++++++++++++------ internal/logs/logs.go | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 5d7adab29..d22d68ba0 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -337,7 +337,8 @@ type internals struct { apiVersion version.Version healthStatus *atomic.Int32 // is node under maintenance - isMaintenance atomic.Bool + isMaintenance atomic.Bool + isOnlineCandidate bool } // starts node's maintenance. diff --git a/cmd/frostfs-node/netmap.go b/cmd/frostfs-node/netmap.go index b7b09a00b..96b866b11 100644 --- a/cmd/frostfs-node/netmap.go +++ b/cmd/frostfs-node/netmap.go @@ -227,6 +227,10 @@ func bootstrapNode(c *cfg) { c.log.Info(logs.FrostFSNodeNodeIsUnderMaintenanceSkipInitialBootstrap) return } + if c.isOnlineCandidate { + c.log.Info(logs.NetmapNodeAlreadyInCandidateListOnlineSkipInitialBootstrap) + return + } err := c.bootstrap() fatalOnErrDetails("bootstrap error", err) } @@ -258,7 +262,8 @@ func initNetmapState(c *cfg) { epoch, err := c.cfgNetmap.wrapper.Epoch() fatalOnErrDetails("could not initialize current epoch number", err) - ni, err := c.netmapInitLocalNodeState(epoch) + var ni *netmapSDK.NodeInfo + ni, c.isOnlineCandidate, err = c.netmapInitLocalNodeState(epoch) fatalOnErrDetails("could not init network state", err) stateWord := nodeState(ni) @@ -291,27 +296,29 @@ func nodeState(ni *netmapSDK.NodeInfo) string { return "undefined" } -func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) { +func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, bool, error) { nmNodes, err := c.cfgNetmap.wrapper.GetCandidates() if err != nil { - return nil, err + return nil, false, err } var candidate *netmapSDK.NodeInfo + isOnlineCandidate := false for i := range nmNodes { if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) { candidate = &nmNodes[i] + isOnlineCandidate = candidate.IsOnline() break } } node, err := c.netmapLocalNodeState(epoch) if err != nil { - return nil, err + return nil, false, err } if candidate == nil { - return node, nil + return node, false, nil } nmState := nodeState(node) @@ -323,7 +330,7 @@ func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error zap.String("netmap", nmState), zap.String("candidate", candidateState)) } - return candidate, nil + return candidate, isOnlineCandidate, nil } func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) { diff --git a/internal/logs/logs.go b/internal/logs/logs.go index 2ba9e6e4b..82e04a16d 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -493,4 +493,5 @@ const ( ShardDeleteCantDeleteFromWriteCache = "can't delete object from write cache" FrostFSNodeNodeIsUnderMaintenanceSkipInitialBootstrap = "the node is under maintenance, skip initial bootstrap" EngineCouldNotChangeShardModeToDisabled = "could not change shard mode to disabled" + NetmapNodeAlreadyInCandidateListOnlineSkipInitialBootstrap = "the node is already in candidate list with online state, skip initial bootstrap" ) -- 2.45.2