[#1806] services/control: Allow to flush write-cache

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-21 13:51:51 +03:00 committed by fyrchik
parent 3d882e9f47
commit 51b8f26a31
11 changed files with 93 additions and 0 deletions

View file

@ -182,3 +182,21 @@ func (w *evacuateShardResponseWrapper) FromGRPCMessage(m grpc.Message) error {
w.EvacuateShardResponse = r w.EvacuateShardResponse = r
return nil 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
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -17,6 +17,7 @@ const (
rpcRestoreShard = "RestoreShard" rpcRestoreShard = "RestoreShard"
rpcSynchronizeTree = "SynchronizeTree" rpcSynchronizeTree = "SynchronizeTree"
rpcEvacuateShard = "EvacuateShard" rpcEvacuateShard = "EvacuateShard"
rpcFlushCache = "FlushCache"
) )
// HealthCheck executes ControlService.HealthCheck RPC. // HealthCheck executes ControlService.HealthCheck RPC.
@ -177,3 +178,16 @@ func EvacuateShard(cli *client.Client, req *EvacuateShardRequest, opts ...client
return wResp.EvacuateShardResponse, nil 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
}

View file

@ -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
}

Binary file not shown.

View file

@ -34,6 +34,9 @@ service ControlService {
// EvacuateShard moves all data from one shard to the others. // EvacuateShard moves all data from one shard to the others.
rpc EvacuateShard (EvacuateShardRequest) returns (EvacuateShardResponse); rpc EvacuateShard (EvacuateShardRequest) returns (EvacuateShardResponse);
// FlushCache moves all data from one shard to the others.
rpc FlushCache (FlushCacheRequest) returns (FlushCacheResponse);
} }
// Health check request. // Health check request.
@ -311,3 +314,25 @@ message EvacuateShardResponse {
Body body = 1; Body body = 1;
Signature signature = 2; 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;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.