diff --git a/pkg/services/control/convert.go b/pkg/services/control/convert.go index 39cad6af..041af61e 100644 --- a/pkg/services/control/convert.go +++ b/pkg/services/control/convert.go @@ -182,3 +182,21 @@ func (w *evacuateShardResponseWrapper) FromGRPCMessage(m grpc.Message) error { w.EvacuateShardResponse = r return nil } + +type flushCacheResponseWrapper struct { + *FlushCacheResponse +} + +func (w *flushCacheResponseWrapper) ToGRPCMessage() grpc.Message { + return w.FlushCacheResponse +} + +func (w *flushCacheResponseWrapper) FromGRPCMessage(m grpc.Message) error { + r, ok := m.(*FlushCacheResponse) + if !ok { + return message.NewUnexpectedMessageType(m, (*FlushCacheResponse)(nil)) + } + + w.FlushCacheResponse = r + return nil +} diff --git a/pkg/services/control/ir/service.pb.go b/pkg/services/control/ir/service.pb.go index 7e1f7d9e..dd8fa736 100644 Binary files a/pkg/services/control/ir/service.pb.go and b/pkg/services/control/ir/service.pb.go differ diff --git a/pkg/services/control/ir/service_grpc.pb.go b/pkg/services/control/ir/service_grpc.pb.go index 7a053876..bd98e881 100644 Binary files a/pkg/services/control/ir/service_grpc.pb.go and b/pkg/services/control/ir/service_grpc.pb.go differ diff --git a/pkg/services/control/ir/types.pb.go b/pkg/services/control/ir/types.pb.go index d76fcc77..9f00354c 100644 Binary files a/pkg/services/control/ir/types.pb.go and b/pkg/services/control/ir/types.pb.go differ diff --git a/pkg/services/control/rpc.go b/pkg/services/control/rpc.go index 6c70d9e6..b0be2a7f 100644 --- a/pkg/services/control/rpc.go +++ b/pkg/services/control/rpc.go @@ -17,6 +17,7 @@ const ( rpcRestoreShard = "RestoreShard" rpcSynchronizeTree = "SynchronizeTree" rpcEvacuateShard = "EvacuateShard" + rpcFlushCache = "FlushCache" ) // HealthCheck executes ControlService.HealthCheck RPC. @@ -177,3 +178,16 @@ func EvacuateShard(cli *client.Client, req *EvacuateShardRequest, opts ...client return wResp.EvacuateShardResponse, nil } + +// FlushCache executes ControlService.FlushCache RPC. +func FlushCache(cli *client.Client, req *FlushCacheRequest, opts ...client.CallOption) (*FlushCacheResponse, error) { + wResp := &flushCacheResponseWrapper{new(FlushCacheResponse)} + wReq := &requestWrapper{m: req} + + err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcFlushCache), wReq, wResp, opts...) + if err != nil { + return nil, err + } + + return wResp.FlushCacheResponse, nil +} diff --git a/pkg/services/control/server/flush_cache.go b/pkg/services/control/server/flush_cache.go new file mode 100644 index 00000000..baf1eb62 --- /dev/null +++ b/pkg/services/control/server/flush_cache.go @@ -0,0 +1,36 @@ +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) FlushCache(_ context.Context, req *control.FlushCacheRequest) (*control.FlushCacheResponse, 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.FlushWriteCachePrm + prm.SetShardID(shardID) + + _, err = s.s.FlushWriteCache(prm) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + resp := &control.FlushCacheResponse{Body: &control.FlushCacheResponse_Body{}} + + err = SignMessage(s.key, resp) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return resp, nil +} diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index 0bef278b..104d511b 100644 Binary files a/pkg/services/control/service.pb.go and b/pkg/services/control/service.pb.go differ diff --git a/pkg/services/control/service.proto b/pkg/services/control/service.proto index 3f55d3cc..fba8ee99 100644 --- a/pkg/services/control/service.proto +++ b/pkg/services/control/service.proto @@ -34,6 +34,9 @@ service ControlService { // EvacuateShard moves all data from one shard to the others. rpc EvacuateShard (EvacuateShardRequest) returns (EvacuateShardResponse); + + // FlushCache moves all data from one shard to the others. + rpc FlushCache (FlushCacheRequest) returns (FlushCacheResponse); } // Health check request. @@ -311,3 +314,25 @@ message EvacuateShardResponse { Body body = 1; Signature signature = 2; } + +// FlushCache request. +message FlushCacheRequest { + // Request body structure. + message Body { + // ID of the shard. + bytes shard_ID = 1; + } + + Body body = 1; + Signature signature = 2; +} + +// FlushCache response. +message FlushCacheResponse { + // Response body structure. + message Body { + } + + Body body = 1; + Signature signature = 2; +} diff --git a/pkg/services/control/service_grpc.pb.go b/pkg/services/control/service_grpc.pb.go index f7523b98..1978deb6 100644 Binary files a/pkg/services/control/service_grpc.pb.go and b/pkg/services/control/service_grpc.pb.go differ diff --git a/pkg/services/control/service_neofs.pb.go b/pkg/services/control/service_neofs.pb.go index 70616a79..00979f01 100644 Binary files a/pkg/services/control/service_neofs.pb.go and b/pkg/services/control/service_neofs.pb.go differ diff --git a/pkg/services/control/types.pb.go b/pkg/services/control/types.pb.go index 4f95fa12..7056a225 100644 Binary files a/pkg/services/control/types.pb.go and b/pkg/services/control/types.pb.go differ