From e904ed51c7c0615aeedba592c064f8bb43f7524b Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Thu, 2 Jun 2022 20:56:04 +0400 Subject: [PATCH] [#487] Optimize bucketInfo in initObjectPayloadReader Signed-off-by: Angira Kekteeva --- api/handler/copy.go | 1 + api/handler/get.go | 1 + api/handler/head.go | 1 + api/handler/multipart_upload.go | 2 ++ api/layer/layer.go | 4 ++++ api/layer/multipart_upload.go | 4 ++++ api/layer/object.go | 9 ++------- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/api/handler/copy.go b/api/handler/copy.go index 6f65d005..652abf27 100644 --- a/api/handler/copy.go +++ b/api/handler/copy.go @@ -102,6 +102,7 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { params := &layer.CopyObjectParams{ SrcObject: info, + ScrBktInfo: p.BktInfo, DstBktInfo: dstBktInfo, DstObject: reqInfo.ObjectName, SrcSize: info.Size, diff --git a/api/handler/get.go b/api/handler/get.go index cd7080ec..95804719 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -164,6 +164,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { ObjectInfo: info, Writer: w, Range: params, + BucketInfo: bktInfo, } if err = h.obj.GetObject(r.Context(), getParams); err != nil { h.logAndSendError(w, "could not get object", reqInfo, err) diff --git a/api/handler/head.go b/api/handler/head.go index 67c4a525..2e11696b 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -74,6 +74,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { ObjectInfo: info, Writer: buffer, Range: getRangeToDetectContentType(info.Size), + BucketInfo: bktInfo, } if err = h.obj.GetObject(r.Context(), getParams); err != nil { h.logAndSendError(w, "could not get object", reqInfo, err, zap.Stringer("oid", info.ID)) diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index 0aad7a08..222eda44 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -316,6 +316,7 @@ func (h *handler) UploadPartCopy(w http.ResponseWriter, r *http.Request) { Key: reqInfo.ObjectName, }, SrcObjInfo: srcInfo, + SrcBktInfo: srcBktInfo, PartNumber: partNumber, Range: srcRange, } @@ -380,6 +381,7 @@ func (h *handler) CompleteMultipartUploadHandler(w http.ResponseWriter, r *http. p := &layer.GetObjectParams{ ObjectInfo: initPart, Writer: initPartPayload, + BucketInfo: bktInfo, } if err = h.obj.GetObject(r.Context(), p); err != nil { h.logAndSendError(w, "could not get multipart upload acl and/or tagging", reqInfo, err, additional...) diff --git a/api/layer/layer.go b/api/layer/layer.go index e16e9f16..41d7200f 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -78,6 +78,7 @@ type ( GetObjectParams struct { Range *RangeParams ObjectInfo *data.ObjectInfo + BucketInfo *data.BucketInfo Writer io.Writer } @@ -125,6 +126,7 @@ type ( // CopyObjectParams stores object copy request parameters. CopyObjectParams struct { SrcObject *data.ObjectInfo + ScrBktInfo *data.BucketInfo DstBktInfo *data.BucketInfo DstObject string SrcSize int64 @@ -382,6 +384,7 @@ func (n *layer) GetObject(ctx context.Context, p *GetObjectParams) error { var params getParams params.objInfo = p.ObjectInfo + params.bktInfo = p.BucketInfo if p.Range != nil { if p.Range.Start > p.Range.End { @@ -517,6 +520,7 @@ func (n *layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*data.Obje ObjectInfo: p.SrcObject, Writer: pw, Range: p.Range, + BucketInfo: p.ScrBktInfo, }) if err = pw.CloseWithError(err); err != nil { diff --git a/api/layer/multipart_upload.go b/api/layer/multipart_upload.go index 1eae6577..ba7538c4 100644 --- a/api/layer/multipart_upload.go +++ b/api/layer/multipart_upload.go @@ -52,6 +52,7 @@ type ( UploadCopyParams struct { Info *UploadInfoParams SrcObjInfo *data.ObjectInfo + SrcBktInfo *data.BucketInfo PartNumber int Range *RangeParams } @@ -167,6 +168,7 @@ func (n *layer) UploadPartCopy(ctx context.Context, p *UploadCopyParams) (*data. ObjectInfo: p.SrcObjInfo, Writer: pw, Range: p.Range, + BucketInfo: p.SrcBktInfo, }) if err = pw.CloseWithError(err); err != nil { @@ -307,6 +309,8 @@ func (n *layer) CompleteMultipartUpload(ctx context.Context, p *CompleteMultipar parts: parts, } + r.prm.bktInfo = p.Info.Bkt + obj, err = n.PutObject(ctx, &PutObjectParams{ BktInfo: p.Info.Bkt, Object: p.Info.Key, diff --git a/api/layer/object.go b/api/layer/object.go index ab71784c..7714d7bc 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -36,6 +36,7 @@ type ( off, ln uint64 objInfo *data.ObjectInfo + bktInfo *data.BucketInfo } // ListObjectsParamsCommon contains common parameters for ListObjectsV1 and ListObjectsV2. @@ -126,13 +127,7 @@ func (n *layer) initObjectPayloadReader(ctx context.Context, p getParams) (io.Re PayloadRange: [2]uint64{p.off, p.ln}, } - // should be taken from cache - bktInfo, err := n.GetBucketInfo(ctx, p.objInfo.Bucket) - if err != nil { - return nil, err - } - - n.prepareAuthParameters(ctx, &prm.PrmAuth, bktInfo.Owner) + n.prepareAuthParameters(ctx, &prm.PrmAuth, p.bktInfo.Owner) res, err := n.neoFS.ReadObject(ctx, prm) if err != nil {