From eb5248621ac43daa73796eccb83691d1c4883b57 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 5 Oct 2023 10:57:58 +0300 Subject: [PATCH 1/2] [#723] netmap: Send bootstrap at each epoch tick Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/netmap.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cmd/frostfs-node/netmap.go b/cmd/frostfs-node/netmap.go index 7d4831bc..170a5844 100644 --- a/cmd/frostfs-node/netmap.go +++ b/cmd/frostfs-node/netmap.go @@ -179,15 +179,8 @@ func addNewEpochNotificationHandlers(c *cfg) { return } - n := ev.(netmapEvent.NewEpoch).EpochNumber() - - const reBootstrapInterval = 2 - - if (n-c.cfgNetmap.startEpoch)%reBootstrapInterval == 0 { - err := c.bootstrap() - if err != nil { - c.log.Warn(logs.FrostFSNodeCantSendRebootstrapTx, zap.Error(err)) - } + if err := c.bootstrap(); err != nil { + c.log.Warn(logs.FrostFSNodeCantSendRebootstrapTx, zap.Error(err)) } }) -- 2.40.1 From e0f0b93b5ec064bce15dcdff5d0a008a92fae279 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 5 Oct 2023 11:30:41 +0300 Subject: [PATCH 2/2] [#723] netmap: Drop already bootstraped check Because of this check, under certain conditions, the node could be removed from the network map, although the node was functioning normally. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/config.go | 3 +- cmd/frostfs-node/netmap.go | 76 +++----------------------------------- 2 files changed, 7 insertions(+), 72 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 8286bc7d..60e567c5 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -345,8 +345,7 @@ type internals struct { apiVersion version.Version healthStatus *atomic.Int32 // is node under maintenance - isMaintenance atomic.Bool - alreadyBootstraped bool + isMaintenance atomic.Bool } // starts node's maintenance. diff --git a/cmd/frostfs-node/netmap.go b/cmd/frostfs-node/netmap.go index 170a5844..ebe152e4 100644 --- a/cmd/frostfs-node/netmap.go +++ b/cmd/frostfs-node/netmap.go @@ -220,10 +220,6 @@ func bootstrapNode(c *cfg) { c.log.Info(logs.FrostFSNodeNodeIsUnderMaintenanceSkipInitialBootstrap) return } - if c.alreadyBootstraped { - c.log.Info(logs.NetmapNodeAlreadyInCandidateListOnlineSkipInitialBootstrap) - return - } err := c.bootstrap() fatalOnErrDetails("bootstrap error", err) } @@ -256,7 +252,7 @@ func initNetmapState(c *cfg) { fatalOnErrDetails("could not initialize current epoch number", err) var ni *netmapSDK.NodeInfo - ni, c.alreadyBootstraped, err = c.netmapInitLocalNodeState(epoch) + ni, err = c.netmapInitLocalNodeState(epoch) fatalOnErrDetails("could not init network state", err) stateWord := nodeState(ni) @@ -275,64 +271,6 @@ func initNetmapState(c *cfg) { c.handleLocalNodeInfo(ni) } -func needsUpdate(local, remote *netmapSDK.NodeInfo) bool { - return bytes.Equal(local.PublicKey(), remote.PublicKey()) && equalEndpoints(local, remote) && equalAttributes(local, remote) -} - -func equalAttributes(local, remote *netmapSDK.NodeInfo) bool { - asA := make(map[string]string) - local.IterateAttributes(func(k, v string) { - asA[k] = v - }) - - allMatched := true - count := 0 - remote.IterateAttributes(func(k, vb string) { - // IR adds new attributes derived from the locode, they should be skipped. - if isLocodeAttribute(k) { - return - } - if va, ok := asA[k]; !ok || va != vb { - allMatched = false - return - } - count++ - }) - return allMatched && count == len(asA) -} - -func isLocodeAttribute(k string) bool { - // See https://git.frostfs.info/TrueCloudLab/frostfs-api/src/branch/master/netmap/types.proto#L171 - switch k { - case "Continent", "Country", "CountryCode", "Location", "SubDiv", "SubDivCode": - return true - default: - return false - } -} - -func equalEndpoints(a, b *netmapSDK.NodeInfo) bool { - var esA, esB []string - a.IterateNetworkEndpoints(func(e string) bool { - esA = append(esA, e) - return false - }) - b.IterateNetworkEndpoints(func(e string) bool { - esB = append(esB, e) - return false - }) - - if len(esA) != len(esB) { - return false - } - for i := range esA { - if esA[i] != esB[i] { - return false - } - } - return true -} - func nodeState(ni *netmapSDK.NodeInfo) string { if ni != nil { switch { @@ -347,29 +285,27 @@ func nodeState(ni *netmapSDK.NodeInfo) string { return "undefined" } -func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, bool, error) { +func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) { nmNodes, err := c.cfgNetmap.wrapper.GetCandidates() if err != nil { - return nil, false, err + return nil, err } var candidate *netmapSDK.NodeInfo - alreadyBootstraped := false for i := range nmNodes { if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) { candidate = &nmNodes[i] - alreadyBootstraped = candidate.IsOnline() && needsUpdate(&c.cfgNodeInfo.localInfo, candidate) break } } node, err := c.netmapLocalNodeState(epoch) if err != nil { - return nil, false, err + return nil, err } if candidate == nil { - return node, false, nil + return node, nil } nmState := nodeState(node) @@ -381,7 +317,7 @@ func (c *cfg) netmapInitLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, bool, zap.String("netmap", nmState), zap.String("candidate", candidateState)) } - return candidate, alreadyBootstraped, nil + return candidate, nil } func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) { -- 2.40.1