frostfs-node/pkg/services/netmap/executor.go
Alexander Chuprov 9b113c3156
Some checks failed
DCO action / DCO (pull_request) Successful in 59s
Vulncheck / Vulncheck (pull_request) Successful in 1m4s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m4s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m16s
Tests and linters / Run gofumpt (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Successful in 4m12s
Tests and linters / gopls check (pull_request) Successful in 4m31s
Tests and linters / Tests with -race (pull_request) Successful in 4m38s
OCI image / Build container images (push) Failing after 18s
Vulncheck / Vulncheck (push) Successful in 1m2s
Pre-commit hooks / Pre-commit (push) Successful in 1m39s
Build / Build Components (push) Successful in 1m45s
Tests and linters / Staticcheck (push) Successful in 2m18s
Tests and linters / Run gofumpt (push) Successful in 2m46s
Tests and linters / Lint (push) Successful in 3m5s
Tests and linters / Tests with -race (push) Successful in 3m23s
Tests and linters / Tests (push) Successful in 3m52s
Tests and linters / gopls check (push) Successful in 4m18s
[#1613] morph: Add tracing for morph queries to neo-go
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2025-02-05 16:38:20 +03:00

132 lines
3.3 KiB
Go

package netmap
import (
"context"
"errors"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/version"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
netmapSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
versionsdk "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
)
type executorSvc struct {
version refs.Version
state NodeState
netInfo NetworkInfo
respSvc *response.Service
}
// NodeState encapsulates information
// about current node state.
type NodeState interface {
// LocalNodeInfo must return current node state
// in FrostFS API v2 NodeInfo structure.
LocalNodeInfo() *netmapSDK.NodeInfo
// ReadCurrentNetMap reads current local network map of the storage node
// into the given parameter. Returns any error encountered which prevented
// the network map to be read.
ReadCurrentNetMap(*netmap.NetMap) error
}
// NetworkInfo encapsulates source of the
// recent information about the FrostFS network.
type NetworkInfo interface {
// Dump must return recent network information in FrostFS API v2 NetworkInfo structure.
//
// If protocol version is <=2.9, MillisecondsPerBlock and network config should be unset.
Dump(context.Context, versionsdk.Version) (*netmapSDK.NetworkInfo, error)
}
func NewExecutionService(s NodeState, v versionsdk.Version, netInfo NetworkInfo, respSvc *response.Service) Server {
if s == nil || netInfo == nil || !version.IsValid(v) || respSvc == nil {
// this should never happen, otherwise it programmers bug
panic("can't create netmap execution service")
}
res := &executorSvc{
state: s,
netInfo: netInfo,
respSvc: respSvc,
}
v.WriteToV2(&res.version)
return res
}
func (s *executorSvc) LocalNodeInfo(
_ context.Context,
_ *netmap.LocalNodeInfoRequest,
) (*netmap.LocalNodeInfoResponse, error) {
ni := s.state.LocalNodeInfo()
var nodeInfo netmap.NodeInfo
ni.WriteToV2(&nodeInfo)
body := new(netmap.LocalNodeInfoResponseBody)
body.SetVersion(&s.version)
body.SetNodeInfo(&nodeInfo)
resp := new(netmap.LocalNodeInfoResponse)
resp.SetBody(body)
s.respSvc.SetMeta(resp)
return resp, nil
}
func (s *executorSvc) NetworkInfo(
ctx context.Context,
req *netmap.NetworkInfoRequest,
) (*netmap.NetworkInfoResponse, error) {
verV2 := req.GetMetaHeader().GetVersion()
if verV2 == nil {
return nil, errors.New("missing protocol version in meta header")
}
var ver versionsdk.Version
if err := ver.ReadFromV2(*verV2); err != nil {
return nil, fmt.Errorf("can't read version: %w", err)
}
ni, err := s.netInfo.Dump(ctx, ver)
if err != nil {
return nil, err
}
var niV2 netmap.NetworkInfo
ni.WriteToV2(&niV2)
body := new(netmap.NetworkInfoResponseBody)
body.SetNetworkInfo(&niV2)
resp := new(netmap.NetworkInfoResponse)
resp.SetBody(body)
s.respSvc.SetMeta(resp)
return resp, nil
}
func (s *executorSvc) Snapshot(_ context.Context, _ *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
var nm netmap.NetMap
err := s.state.ReadCurrentNetMap(&nm)
if err != nil {
return nil, fmt.Errorf("read current local network map: %w", err)
}
body := new(netmap.SnapshotResponseBody)
body.SetNetMap(&nm)
resp := new(netmap.SnapshotResponse)
resp.SetBody(body)
s.respSvc.SetMeta(resp)
return resp, nil
}