From d3a52ec73a3c2052a121ec95549ddae9b1cd6f51 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 4 Aug 2023 11:58:25 +0300 Subject: [PATCH] [#516] node: Send bootstrap request if attributes were updated Consider following situation: 1. Epoch tick. 2. Update node attributes in the config. 3. Restart node. Because we already sent bootstrap query after (1) and we are still online, new bootstrap query won't be sent. This leads to the node attributes being updated after another epoch. Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-node/config.go | 4 ++-- cmd/frostfs-node/netmap.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 31b1a793..47f84827 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -343,8 +343,8 @@ type internals struct { apiVersion version.Version healthStatus *atomic.Int32 // is node under maintenance - isMaintenance atomic.Bool - isOnlineCandidate bool + isMaintenance atomic.Bool + alreadyBootstraped bool } // starts node's maintenance. diff --git a/cmd/frostfs-node/netmap.go b/cmd/frostfs-node/netmap.go index 96b866b1..60a59940 100644 --- a/cmd/frostfs-node/netmap.go +++ b/cmd/frostfs-node/netmap.go @@ -227,7 +227,7 @@ func bootstrapNode(c *cfg) { c.log.Info(logs.FrostFSNodeNodeIsUnderMaintenanceSkipInitialBootstrap) return } - if c.isOnlineCandidate { + if c.alreadyBootstraped { c.log.Info(logs.NetmapNodeAlreadyInCandidateListOnlineSkipInitialBootstrap) return } @@ -263,7 +263,7 @@ func initNetmapState(c *cfg) { fatalOnErrDetails("could not initialize current epoch number", err) var ni *netmapSDK.NodeInfo - ni, c.isOnlineCandidate, err = c.netmapInitLocalNodeState(epoch) + ni, c.alreadyBootstraped, err = c.netmapInitLocalNodeState(epoch) fatalOnErrDetails("could not init network state", err) stateWord := nodeState(ni) @@ -282,6 +282,13 @@ func initNetmapState(c *cfg) { c.handleLocalNodeInfo(ni) } +func sameNodeInfo(a, b *netmapSDK.NodeInfo) bool { + // Suboptimal, but we do this once on the node startup. + rawA := a.Marshal() + rawB := b.Marshal() + return bytes.Equal(rawA, rawB) +} + func nodeState(ni *netmapSDK.NodeInfo) string { if ni != nil { switch { @@ -303,11 +310,11 @@ func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, bool, } var candidate *netmapSDK.NodeInfo - isOnlineCandidate := false + alreadyBootstraped := false for i := range nmNodes { if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) { candidate = &nmNodes[i] - isOnlineCandidate = candidate.IsOnline() + alreadyBootstraped = candidate.IsOnline() && sameNodeInfo(&c.cfgNodeInfo.localInfo, candidate) break } } @@ -330,7 +337,7 @@ func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, bool, zap.String("netmap", nmState), zap.String("candidate", candidateState)) } - return candidate, isOnlineCandidate, nil + return candidate, alreadyBootstraped, nil } func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) {