From 115b8b0fc8ac6421d134be9c8fe1a7cf33c99e8e Mon Sep 17 00:00:00 2001 From: Fadila Date: Wed, 18 Dec 2019 16:33:12 +0100 Subject: [PATCH] storagenode/piecestore: delete several pieces in a single request This is part of the deletion performance improvement. See https://storjlabs.atlassian.net/browse/V3-3349 Change-Id: Idcd83a302f2bd5cc3299e1a4195a7e177f452599 --- pkg/pb/piecestore2.pb.go | 252 ++++++++++++++++++------ pkg/pb/piecestore2.proto | 13 +- private/testplanet/uplink_test.go | 6 + proto.lock | 37 +++- storagenode/piecestore/endpoint.go | 51 ++++- storagenode/piecestore/endpoint_test.go | 90 +++++++++ uplink/piecestore/client.go | 17 ++ 7 files changed, 404 insertions(+), 62 deletions(-) diff --git a/pkg/pb/piecestore2.pb.go b/pkg/pb/piecestore2.pb.go index bb55d120c..e56a9c6d3 100644 --- a/pkg/pb/piecestore2.pb.go +++ b/pkg/pb/piecestore2.pb.go @@ -49,7 +49,7 @@ func (x PieceHeader_FormatVersion) String() string { } func (PieceHeader_FormatVersion) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{12, 0} + return fileDescriptor_23ff32dd550c2439, []int{14, 0} } // Expected order of messages from uplink: @@ -550,6 +550,67 @@ func (m *PieceDeletePieceResponse) XXX_DiscardUnknown() { var xxx_messageInfo_PieceDeletePieceResponse proto.InternalMessageInfo +type DeletePiecesRequest struct { + PieceIds []PieceID `protobuf:"bytes,1,rep,name=piece_ids,json=pieceIds,proto3,customtype=PieceID" json:"piece_ids"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeletePiecesRequest) Reset() { *m = DeletePiecesRequest{} } +func (m *DeletePiecesRequest) String() string { return proto.CompactTextString(m) } +func (*DeletePiecesRequest) ProtoMessage() {} +func (*DeletePiecesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_23ff32dd550c2439, []int{8} +} +func (m *DeletePiecesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeletePiecesRequest.Unmarshal(m, b) +} +func (m *DeletePiecesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeletePiecesRequest.Marshal(b, m, deterministic) +} +func (m *DeletePiecesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeletePiecesRequest.Merge(m, src) +} +func (m *DeletePiecesRequest) XXX_Size() int { + return xxx_messageInfo_DeletePiecesRequest.Size(m) +} +func (m *DeletePiecesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeletePiecesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeletePiecesRequest proto.InternalMessageInfo + +type DeletePiecesResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeletePiecesResponse) Reset() { *m = DeletePiecesResponse{} } +func (m *DeletePiecesResponse) String() string { return proto.CompactTextString(m) } +func (*DeletePiecesResponse) ProtoMessage() {} +func (*DeletePiecesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_23ff32dd550c2439, []int{9} +} +func (m *DeletePiecesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeletePiecesResponse.Unmarshal(m, b) +} +func (m *DeletePiecesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeletePiecesResponse.Marshal(b, m, deterministic) +} +func (m *DeletePiecesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeletePiecesResponse.Merge(m, src) +} +func (m *DeletePiecesResponse) XXX_Size() int { + return xxx_messageInfo_DeletePiecesResponse.Size(m) +} +func (m *DeletePiecesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeletePiecesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeletePiecesResponse proto.InternalMessageInfo + type RetainRequest struct { CreationDate time.Time `protobuf:"bytes,1,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date"` Filter []byte `protobuf:"bytes,2,opt,name=filter,proto3" json:"filter,omitempty"` @@ -562,7 +623,7 @@ func (m *RetainRequest) Reset() { *m = RetainRequest{} } func (m *RetainRequest) String() string { return proto.CompactTextString(m) } func (*RetainRequest) ProtoMessage() {} func (*RetainRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{8} + return fileDescriptor_23ff32dd550c2439, []int{10} } func (m *RetainRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RetainRequest.Unmarshal(m, b) @@ -606,7 +667,7 @@ func (m *RetainResponse) Reset() { *m = RetainResponse{} } func (m *RetainResponse) String() string { return proto.CompactTextString(m) } func (*RetainResponse) ProtoMessage() {} func (*RetainResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{9} + return fileDescriptor_23ff32dd550c2439, []int{11} } func (m *RetainResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RetainResponse.Unmarshal(m, b) @@ -636,7 +697,7 @@ func (m *RestoreTrashRequest) Reset() { *m = RestoreTrashRequest{} } func (m *RestoreTrashRequest) String() string { return proto.CompactTextString(m) } func (*RestoreTrashRequest) ProtoMessage() {} func (*RestoreTrashRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{10} + return fileDescriptor_23ff32dd550c2439, []int{12} } func (m *RestoreTrashRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RestoreTrashRequest.Unmarshal(m, b) @@ -666,7 +727,7 @@ func (m *RestoreTrashResponse) Reset() { *m = RestoreTrashResponse{} } func (m *RestoreTrashResponse) String() string { return proto.CompactTextString(m) } func (*RestoreTrashResponse) ProtoMessage() {} func (*RestoreTrashResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{11} + return fileDescriptor_23ff32dd550c2439, []int{13} } func (m *RestoreTrashResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RestoreTrashResponse.Unmarshal(m, b) @@ -711,7 +772,7 @@ func (m *PieceHeader) Reset() { *m = PieceHeader{} } func (m *PieceHeader) String() string { return proto.CompactTextString(m) } func (*PieceHeader) ProtoMessage() {} func (*PieceHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_23ff32dd550c2439, []int{12} + return fileDescriptor_23ff32dd550c2439, []int{14} } func (m *PieceHeader) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PieceHeader.Unmarshal(m, b) @@ -779,6 +840,8 @@ func init() { proto.RegisterType((*PieceDeleteResponse)(nil), "piecestore.PieceDeleteResponse") proto.RegisterType((*PieceDeletePieceRequest)(nil), "piecestore.PieceDeletePieceRequest") proto.RegisterType((*PieceDeletePieceResponse)(nil), "piecestore.PieceDeletePieceResponse") + proto.RegisterType((*DeletePiecesRequest)(nil), "piecestore.DeletePiecesRequest") + proto.RegisterType((*DeletePiecesResponse)(nil), "piecestore.DeletePiecesResponse") proto.RegisterType((*RetainRequest)(nil), "piecestore.RetainRequest") proto.RegisterType((*RetainResponse)(nil), "piecestore.RetainResponse") proto.RegisterType((*RestoreTrashRequest)(nil), "piecestore.RestoreTrashRequest") @@ -789,54 +852,57 @@ func init() { func init() { proto.RegisterFile("piecestore2.proto", fileDescriptor_23ff32dd550c2439) } var fileDescriptor_23ff32dd550c2439 = []byte{ - // 747 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4b, 0x4f, 0x13, 0x51, - 0x14, 0x66, 0xfa, 0x02, 0x4e, 0xa7, 0x08, 0x97, 0x87, 0x75, 0xa2, 0x16, 0x07, 0x50, 0x62, 0xe2, - 0x80, 0x65, 0xa5, 0x41, 0x8c, 0xb5, 0x12, 0x49, 0x40, 0xc8, 0xe5, 0x11, 0xe3, 0xa6, 0x19, 0x98, - 0xdb, 0x76, 0x62, 0x3b, 0xb7, 0xce, 0xdc, 0x6a, 0xc2, 0x2f, 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x95, 0xb3, 0xcd, 0xd9, 0x89, - 0xe8, 0xf3, 0xf1, 0xac, 0x56, 0xfc, 0x9d, 0x04, 0x38, 0xea, 0xd0, 0x83, 0x0e, 0x20, 0x23, 0x0f, - 0x18, 0xba, 0x3b, 0xfa, 0xb0, 0x1a, 0x85, 0xa1, 0x7e, 0x35, 0x9e, 0x89, 0x75, 0x0d, 0x9d, 0xc2, - 0x54, 0xb8, 0xb8, 0x68, 0x79, 0xdc, 0xad, 0x31, 0xee, 0x8d, 0xdd, 0x7a, 0x9e, 0x74, 0x53, 0x43, - 0x6f, 0x20, 0x23, 0x55, 0x3c, 0xa0, 0xcb, 0xd8, 0xf2, 0x0d, 0xe8, 0xb2, 0x67, 0xb9, 0x92, 0x9f, - 0x13, 0x1a, 0x7a, 0x0b, 0xd9, 0xc8, 0x56, 0xa0, 0x95, 0x21, 0x41, 0xd1, 0xd5, 0x33, 0x56, 0x47, - 0x83, 0xd4, 0x5d, 0x7b, 0x0e, 0x19, 0x29, 0x72, 0x74, 0x2b, 0x8a, 0x8f, 0x2d, 0x9b, 0x61, 0x0c, - 0x72, 0xa9, 0x04, 0xc7, 0xa0, 0x47, 0xc5, 0x8f, 0x0a, 0x71, 0x6c, 0xdf, 0xb6, 0x18, 0xcb, 0xc3, - 0x01, 0x21, 0x87, 0xa5, 0xd4, 0xbb, 0x44, 0xeb, 0xfc, 0x3c, 0x23, 0xe4, 0xba, 0xf5, 0x37, 0x00, - 0x00, 0xff, 0xff, 0xfb, 0xe1, 0x1b, 0xbe, 0x12, 0x08, 0x00, 0x00, + // 793 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcb, 0x6e, 0xd3, 0x4c, + 0x14, 0x8e, 0x73, 0x6b, 0x72, 0xe2, 0xf4, 0x6f, 0xa7, 0x97, 0x3f, 0x58, 0x40, 0x82, 0xdb, 0x42, + 0x85, 0xc0, 0x2d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8, 0x79, 0x8c, + 0x55, 0x92, 0x6f, 0xe2, 0xdd, 0xb3, 0xb3, 0x34, 0x1f, 0x83, 0x8d, 0x3f, 0x01, 0x00, 0x00, 0xff, + 0xff, 0x87, 0xd0, 0x1d, 0xa6, 0xc7, 0x08, 0x00, 0x00, } type DRPCPiecestoreClient interface { @@ -847,6 +913,8 @@ type DRPCPiecestoreClient interface { Delete(ctx context.Context, in *PieceDeleteRequest) (*PieceDeleteResponse, error) // DeletePiece deletes a piece from a satellite request DeletePiece(ctx context.Context, in *PieceDeletePieceRequest) (*PieceDeletePieceResponse, error) + // DeletePieces deletes a set of pieces on satellite request + DeletePieces(ctx context.Context, in *DeletePiecesRequest) (*DeletePiecesResponse, error) Retain(ctx context.Context, in *RetainRequest) (*RetainResponse, error) RestoreTrash(ctx context.Context, in *RestoreTrashRequest) (*RestoreTrashResponse, error) } @@ -944,6 +1012,15 @@ func (c *drpcPiecestoreClient) DeletePiece(ctx context.Context, in *PieceDeleteP return out, nil } +func (c *drpcPiecestoreClient) DeletePieces(ctx context.Context, in *DeletePiecesRequest) (*DeletePiecesResponse, error) { + out := new(DeletePiecesResponse) + err := c.cc.Invoke(ctx, "/piecestore.Piecestore/DeletePieces", in, out) + if err != nil { + return nil, err + } + return out, nil +} + func (c *drpcPiecestoreClient) Retain(ctx context.Context, in *RetainRequest) (*RetainResponse, error) { out := new(RetainResponse) err := c.cc.Invoke(ctx, "/piecestore.Piecestore/Retain", in, out) @@ -968,13 +1045,15 @@ type DRPCPiecestoreServer interface { Delete(context.Context, *PieceDeleteRequest) (*PieceDeleteResponse, error) // DeletePiece deletes a piece from a satellite request DeletePiece(context.Context, *PieceDeletePieceRequest) (*PieceDeletePieceResponse, error) + // DeletePieces deletes a set of pieces on satellite request + DeletePieces(context.Context, *DeletePiecesRequest) (*DeletePiecesResponse, error) Retain(context.Context, *RetainRequest) (*RetainResponse, error) RestoreTrash(context.Context, *RestoreTrashRequest) (*RestoreTrashResponse, error) } type DRPCPiecestoreDescription struct{} -func (DRPCPiecestoreDescription) NumMethods() int { return 6 } +func (DRPCPiecestoreDescription) NumMethods() int { return 7 } func (DRPCPiecestoreDescription) Method(n int) (string, drpc.Handler, interface{}, bool) { switch n { @@ -1013,6 +1092,15 @@ func (DRPCPiecestoreDescription) Method(n int) (string, drpc.Handler, interface{ ) }, DRPCPiecestoreServer.DeletePiece, true case 4: + return "/piecestore.Piecestore/DeletePieces", + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCPiecestoreServer). + DeletePieces( + ctx, + in1.(*DeletePiecesRequest), + ) + }, DRPCPiecestoreServer.DeletePieces, true + case 5: return "/piecestore.Piecestore/Retain", func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { return srv.(DRPCPiecestoreServer). @@ -1021,7 +1109,7 @@ func (DRPCPiecestoreDescription) Method(n int) (string, drpc.Handler, interface{ in1.(*RetainRequest), ) }, DRPCPiecestoreServer.Retain, true - case 5: + case 6: return "/piecestore.Piecestore/RestoreTrash", func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { return srv.(DRPCPiecestoreServer). @@ -1118,6 +1206,22 @@ func (x *drpcPiecestoreDeletePieceStream) SendAndClose(m *PieceDeletePieceRespon return x.CloseSend() } +type DRPCPiecestore_DeletePiecesStream interface { + drpc.Stream + SendAndClose(*DeletePiecesResponse) error +} + +type drpcPiecestoreDeletePiecesStream struct { + drpc.Stream +} + +func (x *drpcPiecestoreDeletePiecesStream) SendAndClose(m *DeletePiecesResponse) error { + if err := x.MsgSend(m); err != nil { + return err + } + return x.CloseSend() +} + type DRPCPiecestore_RetainStream interface { drpc.Stream SendAndClose(*RetainResponse) error @@ -1167,6 +1271,8 @@ type PiecestoreClient interface { Delete(ctx context.Context, in *PieceDeleteRequest, opts ...grpc.CallOption) (*PieceDeleteResponse, error) // DeletePiece deletes a piece from a satellite request DeletePiece(ctx context.Context, in *PieceDeletePieceRequest, opts ...grpc.CallOption) (*PieceDeletePieceResponse, error) + // DeletePieces deletes a set of pieces on satellite request + DeletePieces(ctx context.Context, in *DeletePiecesRequest, opts ...grpc.CallOption) (*DeletePiecesResponse, error) Retain(ctx context.Context, in *RetainRequest, opts ...grpc.CallOption) (*RetainResponse, error) RestoreTrash(ctx context.Context, in *RestoreTrashRequest, opts ...grpc.CallOption) (*RestoreTrashResponse, error) } @@ -1254,6 +1360,7 @@ func (c *piecestoreClient) Delete(ctx context.Context, in *PieceDeleteRequest, o return out, nil } +// Deprecated: Do not use. func (c *piecestoreClient) DeletePiece(ctx context.Context, in *PieceDeletePieceRequest, opts ...grpc.CallOption) (*PieceDeletePieceResponse, error) { out := new(PieceDeletePieceResponse) err := c.cc.Invoke(ctx, "/piecestore.Piecestore/DeletePiece", in, out, opts...) @@ -1263,6 +1370,15 @@ func (c *piecestoreClient) DeletePiece(ctx context.Context, in *PieceDeletePiece return out, nil } +func (c *piecestoreClient) DeletePieces(ctx context.Context, in *DeletePiecesRequest, opts ...grpc.CallOption) (*DeletePiecesResponse, error) { + out := new(DeletePiecesResponse) + err := c.cc.Invoke(ctx, "/piecestore.Piecestore/DeletePieces", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *piecestoreClient) Retain(ctx context.Context, in *RetainRequest, opts ...grpc.CallOption) (*RetainResponse, error) { out := new(RetainResponse) err := c.cc.Invoke(ctx, "/piecestore.Piecestore/Retain", in, out, opts...) @@ -1288,6 +1404,8 @@ type PiecestoreServer interface { Delete(context.Context, *PieceDeleteRequest) (*PieceDeleteResponse, error) // DeletePiece deletes a piece from a satellite request DeletePiece(context.Context, *PieceDeletePieceRequest) (*PieceDeletePieceResponse, error) + // DeletePieces deletes a set of pieces on satellite request + DeletePieces(context.Context, *DeletePiecesRequest) (*DeletePiecesResponse, error) Retain(context.Context, *RetainRequest) (*RetainResponse, error) RestoreTrash(context.Context, *RestoreTrashRequest) (*RestoreTrashResponse, error) } @@ -1384,6 +1502,24 @@ func _Piecestore_DeletePiece_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +func _Piecestore_DeletePieces_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeletePiecesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PiecestoreServer).DeletePieces(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/piecestore.Piecestore/DeletePieces", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PiecestoreServer).DeletePieces(ctx, req.(*DeletePiecesRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Piecestore_Retain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(RetainRequest) if err := dec(in); err != nil { @@ -1432,6 +1568,10 @@ var _Piecestore_serviceDesc = grpc.ServiceDesc{ MethodName: "DeletePiece", Handler: _Piecestore_DeletePiece_Handler, }, + { + MethodName: "DeletePieces", + Handler: _Piecestore_DeletePieces_Handler, + }, { MethodName: "Retain", Handler: _Piecestore_Retain_Handler, diff --git a/pkg/pb/piecestore2.proto b/pkg/pb/piecestore2.proto index 3bf06bde8..470bddd16 100644 --- a/pkg/pb/piecestore2.proto +++ b/pkg/pb/piecestore2.proto @@ -17,7 +17,11 @@ service Piecestore { option deprecated = true; } // DeletePiece deletes a piece from a satellite request - rpc DeletePiece(PieceDeletePieceRequest) returns (PieceDeletePieceResponse); + rpc DeletePiece(PieceDeletePieceRequest) returns (PieceDeletePieceResponse) { + option deprecated = true; + } + // DeletePieces deletes a set of pieces on satellite request + rpc DeletePieces(DeletePiecesRequest) returns (DeletePiecesResponse); rpc Retain(RetainRequest) returns (RetainResponse); rpc RestoreTrash(RestoreTrashRequest) returns (RestoreTrashResponse) {} } @@ -97,6 +101,13 @@ message PieceDeletePieceRequest { message PieceDeletePieceResponse { } +message DeletePiecesRequest { + repeated bytes piece_ids = 1 [(gogoproto.customtype) = "PieceID", (gogoproto.nullable) = false]; +} + +message DeletePiecesResponse { +} + message RetainRequest { google.protobuf.Timestamp creation_date = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; bytes filter = 2; diff --git a/private/testplanet/uplink_test.go b/private/testplanet/uplink_test.go index ce03b4195..e538738a1 100644 --- a/private/testplanet/uplink_test.go +++ b/private/testplanet/uplink_test.go @@ -176,9 +176,15 @@ func (mock *piecestoreMock) Download(server pb.Piecestore_DownloadServer) error func (mock *piecestoreMock) Delete(ctx context.Context, delete *pb.PieceDeleteRequest) (_ *pb.PieceDeleteResponse, err error) { return nil, nil } + func (mock *piecestoreMock) DeletePiece(ctx context.Context, delete *pb.PieceDeletePieceRequest) (_ *pb.PieceDeletePieceResponse, err error) { return nil, nil } + +func (mock *piecestoreMock) DeletePieces(ctx context.Context, delete *pb.DeletePiecesRequest) (_ *pb.DeletePiecesResponse, err error) { + return nil, nil +} + func (mock *piecestoreMock) Retain(ctx context.Context, retain *pb.RetainRequest) (_ *pb.RetainResponse, err error) { return nil, nil } diff --git a/proto.lock b/proto.lock index 937443a84..4a47bd0e4 100644 --- a/proto.lock +++ b/proto.lock @@ -5593,6 +5593,30 @@ { "name": "PieceDeletePieceResponse" }, + { + "name": "DeletePiecesRequest", + "fields": [ + { + "id": 1, + "name": "piece_ids", + "type": "bytes", + "is_repeated": true, + "options": [ + { + "name": "(gogoproto.customtype)", + "value": "PieceID" + }, + { + "name": "(gogoproto.nullable)", + "value": "false" + } + ] + } + ] + }, + { + "name": "DeletePiecesResponse" + }, { "name": "RetainRequest", "fields": [ @@ -5705,7 +5729,18 @@ { "name": "DeletePiece", "in_type": "PieceDeletePieceRequest", - "out_type": "PieceDeletePieceResponse" + "out_type": "PieceDeletePieceResponse", + "options": [ + { + "name": "deprecated", + "value": "true" + } + ] + }, + { + "name": "DeletePieces", + "in_type": "DeletePiecesRequest", + "out_type": "DeletePiecesResponse" }, { "name": "Retain", diff --git a/storagenode/piecestore/endpoint.go b/storagenode/piecestore/endpoint.go index 8c740c467..1f890a092 100644 --- a/storagenode/piecestore/endpoint.go +++ b/storagenode/piecestore/endpoint.go @@ -139,7 +139,7 @@ var monLiveRequests = mon.TaskNamed("live-request") // Delete handles deleting a piece on piece store requested by uplink. // -// DEPRECATED in favor of DeletePiece. +// DEPRECATED in favor of DeletePieces. func (endpoint *Endpoint) Delete(ctx context.Context, delete *pb.PieceDeleteRequest) (_ *pb.PieceDeleteResponse, err error) { defer monLiveRequests(&ctx)(&err) defer mon.Task()(&ctx)(&err) @@ -173,9 +173,47 @@ func (endpoint *Endpoint) Delete(ctx context.Context, delete *pb.PieceDeleteRequ return &pb.PieceDeleteResponse{}, nil } +// DeletePieces delete a list of pieces on satellite request. +func (endpoint *Endpoint) DeletePieces( + ctx context.Context, req *pb.DeletePiecesRequest, +) (_ *pb.DeletePiecesResponse, err error) { + defer mon.Task()(&ctx, req.PieceIds)(&err) + + peer, err := identity.PeerIdentityFromContext(ctx) + if err != nil { + return nil, rpcstatus.Error(rpcstatus.Unauthenticated, Error.Wrap(err).Error()) + } + + err = endpoint.trust.VerifySatelliteID(ctx, peer.ID) + if err != nil { + return nil, rpcstatus.Error(rpcstatus.PermissionDenied, + Error.New("%s", "delete pieces called with untrusted ID").Error(), + ) + } + + for _, pieceID := range req.PieceIds { + err = endpoint.store.Delete(ctx, peer.ID, pieceID) + if err != nil { + // If a piece cannot be deleted, we just log the error. + // No error is returned to the caller. + endpoint.log.Error("delete failed", + zap.Stringer("Satellite ID", peer.ID), + zap.Stringer("Piece ID", pieceID), + zap.Error(Error.Wrap(err)), + ) + } else { + endpoint.log.Info("deleted", + zap.Stringer("Satellite ID", peer.ID), + zap.Stringer("Piece ID", pieceID), + ) + } + } + return &pb.DeletePiecesResponse{}, nil +} + // DeletePiece handles deleting a piece on piece store requested by satellite. // -// It doesn't return an error if the piece isn't found by any reason. +// DEPRECATED in favor of DeletePieces. func (endpoint *Endpoint) DeletePiece( ctx context.Context, req *pb.PieceDeletePieceRequest, ) (_ *pb.PieceDeletePieceResponse, err error) { @@ -201,17 +239,22 @@ func (endpoint *Endpoint) DeletePiece( return nil, rpcstatus.Error(rpcstatus.NotFound, "piece not found") } - endpoint.log.Error("delete piece failed", + endpoint.log.Error("delete failed", zap.Error(Error.Wrap(err)), zap.Stringer("Satellite ID", peer.ID), zap.Stringer("Piece ID", req.PieceId), ) return nil, rpcstatus.Error(rpcstatus.Internal, - Error.New("%s", "delete piece failed").Error(), + Error.New("%s", "delete failed").Error(), ) } + endpoint.log.Info("deleted", + zap.Stringer("Satellite ID", peer.ID), + zap.Stringer("Piece ID", req.PieceId), + ) + return &pb.PieceDeletePieceResponse{}, nil } diff --git a/storagenode/piecestore/endpoint_test.go b/storagenode/piecestore/endpoint_test.go index 1a46652ee..3f2ff1114 100644 --- a/storagenode/piecestore/endpoint_test.go +++ b/storagenode/piecestore/endpoint_test.go @@ -362,6 +362,96 @@ func TestDelete(t *testing.T) { }) } +func TestDeletePieces(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + var ( + planetSat = planet.Satellites[0] + planetSN = planet.StorageNodes[0] + ) + + var client *piecestore.Client + { + dossier, err := planetSat.Overlay.DB.Get(ctx.Context, planetSN.ID()) + require.NoError(t, err) + + client, err = piecestore.Dial( + ctx.Context, planetSat.Dialer, &dossier.Node, zaptest.NewLogger(t), piecestore.Config{}, + ) + require.NoError(t, err) + } + + t.Run("Ok", func(t *testing.T) { + pieceIDs := []storj.PieceID{{1}, {2}, {3}, {4}} + dataArray := make([][]byte, len(pieceIDs)) + for i, pieceID := range pieceIDs { + dataArray[i], _, _ = uploadPiece(t, ctx, pieceID, planetSN, planet.Uplinks[0], planetSat) + } + + err := client.DeletePieces(ctx.Context, pieceIDs...) + require.NoError(t, err) + + for i, pieceID := range pieceIDs { + _, err = downloadPiece(t, ctx, pieceID, int64(len(dataArray[i])), planetSN, planet.Uplinks[0], planetSat) + require.Error(t, err) + } + require.Condition(t, func() bool { + return strings.Contains(err.Error(), "file does not exist") || + strings.Contains(err.Error(), "The system cannot find the path specified") + }, "unexpected error message") + }) + + t.Run("Ok: one piece to delete is missing", func(t *testing.T) { + missingPieceID := storj.PieceID{12} + pieceIDs := []storj.PieceID{{1}, {2}, {3}, {4}} + dataArray := make([][]byte, len(pieceIDs)) + for i, pieceID := range pieceIDs { + dataArray[i], _, _ = uploadPiece(t, ctx, pieceID, planetSN, planet.Uplinks[0], planetSat) + } + + err := client.DeletePieces(ctx.Context, append(pieceIDs, missingPieceID)...) + require.NoError(t, err) + + for i, pieceID := range pieceIDs { + _, err = downloadPiece(t, ctx, pieceID, int64(len(dataArray[i])), planetSN, planet.Uplinks[0], planetSat) + require.Error(t, err) + } + require.Condition(t, func() bool { + return strings.Contains(err.Error(), "file does not exist") || + strings.Contains(err.Error(), "The system cannot find the path specified") + }, "unexpected error message") + }) + + t.Run("Ok: no piece deleted", func(t *testing.T) { + pieceID := storj.PieceID{10} + data, _, _ := uploadPiece(t, ctx, pieceID, planetSN, planet.Uplinks[0], planetSat) + + err := client.DeletePieces(ctx.Context) + require.NoError(t, err) + + downloaded, err := downloadPiece(t, ctx, pieceID, int64(len(data)), planetSN, planet.Uplinks[0], planetSat) + require.NoError(t, err) + require.Equal(t, data, downloaded) + }) + + t.Run("error: permission denied", func(t *testing.T) { + pieceID := storj.PieceID{11} + data, _, _ := uploadPiece(t, ctx, pieceID, planetSN, planet.Uplinks[0], planetSat) + + client, err := planet.Uplinks[0].DialPiecestore(ctx, planetSN) + require.NoError(t, err) + + err = client.DeletePieces(ctx.Context, pieceID) + require.Error(t, err) + require.Equal(t, rpcstatus.PermissionDenied, rpcstatus.Code(err)) + + downloaded, err := downloadPiece(t, ctx, pieceID, int64(len(data)), planetSN, planet.Uplinks[0], planetSat) + require.NoError(t, err) + require.Equal(t, data, downloaded) + }) + }) +} func TestDeletePiece(t *testing.T) { testplanet.Run(t, testplanet.Config{ SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1, diff --git a/uplink/piecestore/client.go b/uplink/piecestore/client.go index b1efa919a..55270a8e8 100644 --- a/uplink/piecestore/client.go +++ b/uplink/piecestore/client.go @@ -62,6 +62,8 @@ func Dial(ctx context.Context, dialer rpc.Dialer, target *pb.Node, log *zap.Logg } // Delete uses delete order limit to delete a piece on piece store. +// +// DEPRECATED in favor of DeletePieces. func (client *Client) Delete(ctx context.Context, limit *pb.OrderLimit, privateKey storj.PiecePrivateKey) (err error) { defer mon.Task()(&ctx)(&err) _, err = client.client.Delete(ctx, &pb.PieceDeleteRequest{ @@ -71,6 +73,8 @@ func (client *Client) Delete(ctx context.Context, limit *pb.OrderLimit, privateK } // DeletePiece deletes a piece. +// +// DEPRECATED in favor of DeletePieces. func (client *Client) DeletePiece(ctx context.Context, id storj.PieceID) (err error) { defer mon.Task()(&ctx, id.String())(&err) _, err = client.client.DeletePiece(ctx, &pb.PieceDeletePieceRequest{ @@ -79,6 +83,19 @@ func (client *Client) DeletePiece(ctx context.Context, id storj.PieceID) (err er return Error.Wrap(err) } +// DeletePieces deletes a set of pieces. +func (client *Client) DeletePieces(ctx context.Context, ids ...storj.PieceID) (err error) { + defer mon.Task()(&ctx)(&err) + if len(ids) == 0 { + // Avoid RPC calls if no pieces to delete. + return nil + } + _, err = client.client.DeletePieces(ctx, &pb.DeletePiecesRequest{ + PieceIds: ids, + }) + return Error.Wrap(err) +} + // Retain uses a bloom filter to tell the piece store which pieces to keep. func (client *Client) Retain(ctx context.Context, req *pb.RetainRequest) (err error) { defer mon.Task()(&ctx)(&err)