[#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 763 additions and 206 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
}

View file

@ -7,11 +7,10 @@
package control package control
import ( import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

View file

@ -8,7 +8,6 @@ package control
import ( import (
context "context" context "context"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"

View file

@ -7,11 +7,10 @@
package control package control
import ( import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

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
}

File diff suppressed because it is too large Load diff

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

View file

@ -8,7 +8,6 @@ package control
import ( import (
context "context" context "context"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
@ -41,6 +40,8 @@ type ControlServiceClient interface {
SynchronizeTree(ctx context.Context, in *SynchronizeTreeRequest, opts ...grpc.CallOption) (*SynchronizeTreeResponse, error) SynchronizeTree(ctx context.Context, in *SynchronizeTreeRequest, opts ...grpc.CallOption) (*SynchronizeTreeResponse, error)
// EvacuateShard moves all data from one shard to the others. // EvacuateShard moves all data from one shard to the others.
EvacuateShard(ctx context.Context, in *EvacuateShardRequest, opts ...grpc.CallOption) (*EvacuateShardResponse, error) EvacuateShard(ctx context.Context, in *EvacuateShardRequest, opts ...grpc.CallOption) (*EvacuateShardResponse, error)
// FlushCache moves all data from one shard to the others.
FlushCache(ctx context.Context, in *FlushCacheRequest, opts ...grpc.CallOption) (*FlushCacheResponse, error)
} }
type controlServiceClient struct { type controlServiceClient struct {
@ -132,6 +133,15 @@ func (c *controlServiceClient) EvacuateShard(ctx context.Context, in *EvacuateSh
return out, nil return out, nil
} }
func (c *controlServiceClient) FlushCache(ctx context.Context, in *FlushCacheRequest, opts ...grpc.CallOption) (*FlushCacheResponse, error) {
out := new(FlushCacheResponse)
err := c.cc.Invoke(ctx, "/control.ControlService/FlushCache", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ControlServiceServer is the server API for ControlService service. // ControlServiceServer is the server API for ControlService service.
// All implementations should embed UnimplementedControlServiceServer // All implementations should embed UnimplementedControlServiceServer
// for forward compatibility // for forward compatibility
@ -154,6 +164,8 @@ type ControlServiceServer interface {
SynchronizeTree(context.Context, *SynchronizeTreeRequest) (*SynchronizeTreeResponse, error) SynchronizeTree(context.Context, *SynchronizeTreeRequest) (*SynchronizeTreeResponse, error)
// EvacuateShard moves all data from one shard to the others. // EvacuateShard moves all data from one shard to the others.
EvacuateShard(context.Context, *EvacuateShardRequest) (*EvacuateShardResponse, error) EvacuateShard(context.Context, *EvacuateShardRequest) (*EvacuateShardResponse, error)
// FlushCache moves all data from one shard to the others.
FlushCache(context.Context, *FlushCacheRequest) (*FlushCacheResponse, error)
} }
// UnimplementedControlServiceServer should be embedded to have forward compatible implementations. // UnimplementedControlServiceServer should be embedded to have forward compatible implementations.
@ -187,6 +199,9 @@ func (UnimplementedControlServiceServer) SynchronizeTree(context.Context, *Synch
func (UnimplementedControlServiceServer) EvacuateShard(context.Context, *EvacuateShardRequest) (*EvacuateShardResponse, error) { func (UnimplementedControlServiceServer) EvacuateShard(context.Context, *EvacuateShardRequest) (*EvacuateShardResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method EvacuateShard not implemented") return nil, status.Errorf(codes.Unimplemented, "method EvacuateShard not implemented")
} }
func (UnimplementedControlServiceServer) FlushCache(context.Context, *FlushCacheRequest) (*FlushCacheResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method FlushCache not implemented")
}
// UnsafeControlServiceServer may be embedded to opt out of forward compatibility for this service. // UnsafeControlServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ControlServiceServer will // Use of this interface is not recommended, as added methods to ControlServiceServer will
@ -361,6 +376,24 @@ func _ControlService_EvacuateShard_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _ControlService_FlushCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FlushCacheRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ControlServiceServer).FlushCache(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/control.ControlService/FlushCache",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ControlServiceServer).FlushCache(ctx, req.(*FlushCacheRequest))
}
return interceptor(ctx, in, info, handler)
}
// ControlService_ServiceDesc is the grpc.ServiceDesc for ControlService service. // ControlService_ServiceDesc is the grpc.ServiceDesc for ControlService service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -404,6 +437,10 @@ var ControlService_ServiceDesc = grpc.ServiceDesc{
MethodName: "EvacuateShard", MethodName: "EvacuateShard",
Handler: _ControlService_EvacuateShard_Handler, Handler: _ControlService_EvacuateShard_Handler,
}, },
{
MethodName: "FlushCache",
Handler: _ControlService_FlushCache_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "pkg/services/control/service.proto", Metadata: "pkg/services/control/service.proto",

View file

@ -1395,3 +1395,154 @@ func (x *EvacuateShardResponse) ReadSignedData(buf []byte) ([]byte, error) {
func (x *EvacuateShardResponse) SetSignature(sig *Signature) { func (x *EvacuateShardResponse) SetSignature(sig *Signature) {
x.Signature = sig x.Signature = sig
} }
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *FlushCacheRequest_Body) StableSize() (size int) {
size += proto.BytesSize(1, x.Shard_ID)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *FlushCacheRequest_Body) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.BytesMarshal(1, buf[offset:], x.Shard_ID)
return buf
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *FlushCacheRequest) StableSize() (size int) {
size += proto.NestedStructureSize(1, x.Body)
size += proto.NestedStructureSize(2, x.Signature)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *FlushCacheRequest) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(1, buf[offset:], x.Body)
offset += proto.NestedStructureMarshal(2, buf[offset:], x.Signature)
return buf
}
// ReadSignedData fills buf with signed data of x.
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *FlushCacheRequest) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SignedDataSize returns size of the request signed data in bytes.
//
// Structures with the same field values have the same signed data size.
func (x *FlushCacheRequest) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf), nil
}
func (x *FlushCacheRequest) SetSignature(sig *Signature) {
x.Signature = sig
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *FlushCacheResponse_Body) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *FlushCacheResponse_Body) StableMarshal(buf []byte) []byte {
return buf
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *FlushCacheResponse) StableSize() (size int) {
size += proto.NestedStructureSize(1, x.Body)
size += proto.NestedStructureSize(2, x.Signature)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *FlushCacheResponse) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(1, buf[offset:], x.Body)
offset += proto.NestedStructureMarshal(2, buf[offset:], x.Signature)
return buf
}
// ReadSignedData fills buf with signed data of x.
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *FlushCacheResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SignedDataSize returns size of the request signed data in bytes.
//
// Structures with the same field values have the same signed data size.
func (x *FlushCacheResponse) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf), nil
}
func (x *FlushCacheResponse) SetSignature(sig *Signature) {
x.Signature = sig
}

View file

@ -7,11 +7,10 @@
package control package control
import ( import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (