Skip to content

Commit

Permalink
node: use SDK funcs for get and set node attributes
Browse files Browse the repository at this point in the history
Use `GetAttributes` and `SetAttributes` from SDK instead of api-go
`netmap.Attribute`.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Nov 22, 2024
1 parent 9a7864d commit e44033d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
9 changes: 0 additions & 9 deletions cmd/neofs-node/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/nspcc-dev/locode-db/pkg/locodedb"
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"go.uber.org/zap"
Expand Down Expand Up @@ -118,11 +117,3 @@ func nodeAttrsEqual(arr1, arr2 [][2]string) bool {

return true
}

func nodeAttrsToSlice(attrs []netmapV2.Attribute) [][2]string {
res := make([][2]string, len(attrs))
for i := range attrs {
res[i] = [2]string{attrs[i].GetKey(), attrs[i].GetValue()}
}
return res
}
22 changes: 5 additions & 17 deletions cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"sync/atomic"

netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/metrics"
Expand Down Expand Up @@ -457,33 +456,22 @@ func (n *netInfo) Dump(ver version.Version) (*netmapSDK.NetworkInfo, error) {
func (c *cfg) reloadNodeAttributes() error {
c.cfgNodeInfo.localInfoLock.Lock()

// TODO(@End-rey): after updating SDK, rewrite with w/o api netmap. See #3005, neofs-sdk-go#635.
var ni2 netmapV2.NodeInfo
c.cfgNodeInfo.localInfo.WriteToV2(&ni2)
oldAttrs := c.cfgNodeInfo.localInfo.GetAttributes()

oldAttrs := ni2.GetAttributes()
c.cfgNodeInfo.localInfo.SetAttributes(nil)

ni2.SetAttributes(nil)

err := c.cfgNodeInfo.localInfo.ReadFromV2(ni2)
if err != nil {
c.cfgNodeInfo.localInfoLock.Unlock()
return err
}

err = writeSystemAttributes(c)
err := writeSystemAttributes(c)
if err != nil {
c.cfgNodeInfo.localInfoLock.Unlock()
return err
}
parseAttributes(c)

c.cfgNodeInfo.localInfo.WriteToV2(&ni2)
newAttrs := c.cfgNodeInfo.localInfo.GetAttributes()

newAttrs := ni2.GetAttributes()
c.cfgNodeInfo.localInfoLock.Unlock()

if nodeAttrsEqual(nodeAttrsToSlice(oldAttrs), nodeAttrsToSlice(newAttrs)) {
if nodeAttrsEqual(oldAttrs, newAttrs) {
return nil
}

Expand Down

0 comments on commit e44033d

Please sign in to comment.