Skip to content

Commit

Permalink
node/control: add object list control command
Browse files Browse the repository at this point in the history
Includes API definition extending; server side implementation; protoc version
update.
The command requests server's storage engine list of objects, that are known by
node.

Signed-off-by: Andrey Butusov <andrey@nspcc.io>
  • Loading branch information
End-rey committed Sep 10, 2024
1 parent 80111f9 commit bfef2e2
Show file tree
Hide file tree
Showing 12 changed files with 1,289 additions and 544 deletions.
19 changes: 19 additions & 0 deletions pkg/services/control/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ func (w *listShardsResponseWrapper) FromGRPCMessage(m grpc.Message) error {
return nil
}

type listObjectsResponseWrapper struct {
m *ListObjectsResponse
}

func (w *listObjectsResponseWrapper) ToGRPCMessage() grpc.Message {
return w.m
}

func (w *listObjectsResponseWrapper) FromGRPCMessage(m grpc.Message) error {
var ok bool

w.m, ok = m.(*ListObjectsResponse)
if !ok {
return message.NewUnexpectedMessageType(m, w.m)
}

return nil
}

type setShardModeResponseWrapper struct {
m *SetShardModeResponse
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/services/control/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
rpcSetNetmapStatus = "SetNetmapStatus"
rpcDropObjects = "DropObjects"
rpcListShards = "ListShards"
rpcListObjects = "ListObjects"
rpcSetShardMode = "SetShardMode"
rpcDumpShard = "DumpShard"
rpcRestoreShard = "RestoreShard"
Expand Down Expand Up @@ -107,6 +108,27 @@ func ListShards(
return wResp.m, nil
}

// ListObjects executes ControlService.ListObjects RPC.
func ListObjects(
cli *client.Client,
req *ListObjectsRequest,
opts ...client.CallOption,
) (*ListObjectsResponse, error) {
wResp := &listObjectsResponseWrapper{
m: new(ListObjectsResponse),
}

wReq := &requestWrapper{
m: req,
}
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcListObjects), wReq, wResp, opts...)
if err != nil {
return nil, err
}

return wResp.m, nil
}

// SetShardMode executes ControlService.SetShardMode RPC.
func SetShardMode(
cli *client.Client,
Expand Down
50 changes: 50 additions & 0 deletions pkg/services/control/server/list_objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package control

import (
"context"

"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s *Server) ListObjects(_ context.Context, req *control.ListObjectsRequest) (*control.ListObjectsResponse, error) {
// verify request
if err := s.isValidRequest(req); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}

// check availability
err := s.ready()
if err != nil {
return nil, err
}
// create and fill response
resp := new(control.ListObjectsResponse)

body := new(control.ListObjectsResponse_Body)
resp.SetBody(body)

objectsIds, err := engine.List(s.storage, 0)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

objects := make([]*control.ObjectInfo, 0, len(objectsIds))
for _, objectId := range objectsIds {
objectInfo := &control.ObjectInfo{
Address: objectId.EncodeToString(),
}
objects = append(objects, objectInfo)
}

body.SetObjects(objects)

// sign the response
if err := SignMessage(s.key, resp); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return resp, nil
}
14 changes: 14 additions & 0 deletions pkg/services/control/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ func (x *ListShardsResponse) SetBody(v *ListShardsResponse_Body) {
}
}

// SetBody sets list object response body.
func (x *ListObjectsResponse) SetBody(v *ListObjectsResponse_Body) {
if x != nil {
x.Body = v
}
}

// SetObjects sets shards of the storage node.
func (x *ListObjectsResponse_Body) SetObjects(v []*ObjectInfo) {
if x != nil {
x.Objects = v
}
}

// SetShardIDList sets shard ID whose mode is requested to be set.
func (x *SetShardModeRequest_Body) SetShardIDList(v [][]byte) {
if v != nil {
Expand Down
Loading

0 comments on commit bfef2e2

Please sign in to comment.