Skip to content

Commit

Permalink
[nspcc-dev#1731] services/control: Allow to evacuate data from shard
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
  • Loading branch information
fyrchik authored and aprasolova committed Oct 19, 2022
1 parent 5e28909 commit 4a1ac2f
Show file tree
Hide file tree
Showing 11 changed files with 812 additions and 211 deletions.
18 changes: 18 additions & 0 deletions pkg/services/control/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,21 @@ func (w *synchronizeTreeResponseWrapper) FromGRPCMessage(m grpc.Message) error {
w.SynchronizeTreeResponse = r
return nil
}

type evacuateShardResponseWrapper struct {
*EvacuateShardResponse
}

func (w *evacuateShardResponseWrapper) ToGRPCMessage() grpc.Message {
return w.EvacuateShardResponse
}

func (w *evacuateShardResponseWrapper) FromGRPCMessage(m grpc.Message) error {
r, ok := m.(*EvacuateShardResponse)
if !ok {
return message.NewUnexpectedMessageType(m, (*EvacuateShardResponse)(nil))
}

w.EvacuateShardResponse = r
return nil
}
7 changes: 3 additions & 4 deletions pkg/services/control/ir/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/services/control/ir/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pkg/services/control/ir/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkg/services/control/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
rpcDumpShard = "DumpShard"
rpcRestoreShard = "RestoreShard"
rpcSynchronizeTree = "SynchronizeTree"
rpcEvacuateShard = "EvacuateShard"
)

// HealthCheck executes ControlService.HealthCheck RPC.
Expand Down Expand Up @@ -186,3 +187,16 @@ func SynchronizeTree(cli *client.Client, req *SynchronizeTreeRequest, opts ...cl

return wResp.SynchronizeTreeResponse, nil
}

// EvacuateShard executes ControlService.EvacuateShard RPC.
func EvacuateShard(cli *client.Client, req *EvacuateShardRequest, opts ...client.CallOption) (*EvacuateShardResponse, error) {
wResp := &evacuateShardResponseWrapper{new(EvacuateShardResponse)}
wReq := &requestWrapper{m: req}

err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcEvacuateShard), wReq, wResp, opts...)
if err != nil {
return nil, err
}

return wResp.EvacuateShardResponse, nil
}
41 changes: 41 additions & 0 deletions pkg/services/control/server/evacuate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package control

import (
"context"

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

func (s *Server) EvacuateShard(_ context.Context, req *control.EvacuateShardRequest) (*control.EvacuateShardResponse, error) {
err := s.isValidRequest(req)
if err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}

shardID := shard.NewIDFromBytes(req.GetBody().GetShard_ID())

var prm engine.EvacuateShardPrm
prm.WithShardID(shardID)
prm.WithIgnoreErrors(req.GetBody().GetIgnoreErrors())

res, err := s.s.Evacuate(prm)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

resp := &control.EvacuateShardResponse{
Body: &control.EvacuateShardResponse_Body{
Count: uint32(res.Count()),
},
}

err = SignMessage(s.key, resp)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return resp, nil
}
Loading

0 comments on commit 4a1ac2f

Please sign in to comment.