From 6b2ddcadd0f72a92da06c00ce462bc183b461810 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 24 May 2022 16:27:15 +0300 Subject: [PATCH] [#417] Abort multipart upload using tree service Signed-off-by: Denis Kirillov --- api/handler/multipart_upload.go | 17 +++++++---------- api/layer/multipart_upload.go | 4 ++-- api/layer/tree_service.go | 1 + internal/neofs/tree.go | 4 ++++ internal/neofstest/tree/tree_mock.go | 4 ++++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index d92a9ccef..05a6ceccc 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -584,17 +584,14 @@ func (h *handler) AbortMultipartUploadHandler(w http.ResponseWriter, r *http.Req return } - var ( - queryValues = reqInfo.URL.Query() - uploadID = queryValues.Get(uploadIDHeaderName) - additional = []zap.Field{zap.String("uploadID", uploadID), zap.String("Key", reqInfo.ObjectName)} + uploadID := reqInfo.URL.Query().Get(uploadIDHeaderName) + additional := []zap.Field{zap.String("uploadID", uploadID), zap.String("Key", reqInfo.ObjectName)} - p = &layer.UploadInfoParams{ - UploadID: uploadID, - Bkt: bktInfo, - Key: reqInfo.ObjectName, - } - ) + p := &layer.UploadInfoParams{ + UploadID: uploadID, + Bkt: bktInfo, + Key: reqInfo.ObjectName, + } if err = h.obj.AbortMultipartUpload(r.Context(), p); err != nil { h.logAndSendError(w, "could not abort multipart upload", reqInfo, err, additional...) diff --git a/api/layer/multipart_upload.go b/api/layer/multipart_upload.go index 0c847852f..1a55cd04a 100644 --- a/api/layer/multipart_upload.go +++ b/api/layer/multipart_upload.go @@ -488,7 +488,7 @@ func (n *layer) ListMultipartUploads(ctx context.Context, p *ListMultipartUpload } func (n *layer) AbortMultipartUpload(ctx context.Context, p *UploadInfoParams) error { - _, objects, err := n.getUploadParts(ctx, p) + multipartInfo, objects, err := n.getUploadParts(ctx, p) if err != nil { return err } @@ -499,7 +499,7 @@ func (n *layer) AbortMultipartUpload(ctx context.Context, p *UploadInfoParams) e } } - return nil + return n.treeService.DeleteMultipartUpload(ctx, &p.Bkt.CID, multipartInfo.ID) } func (n *layer) ListParts(ctx context.Context, p *ListPartsParams) (*ListPartsInfo, error) { diff --git a/api/layer/tree_service.go b/api/layer/tree_service.go index 52edc9406..b98c1e0ae 100644 --- a/api/layer/tree_service.go +++ b/api/layer/tree_service.go @@ -51,6 +51,7 @@ type TreeService interface { RemoveSystemVersion(ctx context.Context, cnrID *cid.ID, nodeID uint64) error CreateMultipartUpload(ctx context.Context, cnrID *cid.ID, info *data.MultipartInfo) error + DeleteMultipartUpload(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64) error GetMultipartUploadsByPrefix(ctx context.Context, cnrID *cid.ID, prefix string) ([]*data.MultipartInfo, error) GetMultipartUpload(ctx context.Context, cnrID *cid.ID, objectName, uploadID string) (*data.MultipartInfo, error) diff --git a/internal/neofs/tree.go b/internal/neofs/tree.go index 71fe767e8..27f90f521 100644 --- a/internal/neofs/tree.go +++ b/internal/neofs/tree.go @@ -869,6 +869,10 @@ func (c *TreeClient) GetParts(ctx context.Context, cnrID *cid.ID, multipartNodeI return result, nil } +func (c *TreeClient) DeleteMultipartUpload(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64) error { + return c.removeNode(ctx, cnrID, systemTree, multipartNodeID) +} + func (c *TreeClient) Close() error { if c.conn != nil { return c.conn.Close() diff --git a/internal/neofstest/tree/tree_mock.go b/internal/neofstest/tree/tree_mock.go index ead70912b..e4870224e 100644 --- a/internal/neofstest/tree/tree_mock.go +++ b/internal/neofstest/tree/tree_mock.go @@ -255,3 +255,7 @@ func (t *TreeServiceMock) AddPart(ctx context.Context, cnrID *cid.ID, multipartN func (t *TreeServiceMock) GetParts(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64) ([]*data.PartInfo, error) { panic("implement me") } + +func (t *TreeServiceMock) DeleteMultipartUpload(ctx context.Context, cnrID *cid.ID, multipartNodeID uint64) error { + panic("implement me") +}