From 8731dcfd3c5fe1a7c8708a3a87505844faba41c7 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 31 May 2022 17:28:06 +0300 Subject: [PATCH] [#477] Use tags and lock aggregation in handler Reduce amount of tree service RPCs by using new method in layer package. Signed-off-by: Alex Vanin --- api/handler/get.go | 6 +++--- api/handler/head.go | 34 ++++++++++------------------------ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/api/handler/get.go b/api/handler/get.go index a4cb8bd62..04a7ab983 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -144,9 +144,9 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { VersionID: info.Version(), } - tagSet, err := h.obj.GetObjectTagging(r.Context(), t) + tagSet, lockInfo, err := h.obj.GetObjectTaggingAndLock(r.Context(), t) if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) { - h.logAndSendError(w, "could not get object tag set", reqInfo, err) + h.logAndSendError(w, "could not get object meta data", reqInfo, err) return } @@ -154,7 +154,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { overrideResponseHeaders(w.Header(), reqInfo.URL.Query()) } - if err = h.setLockingHeaders(r.Context(), bktInfo, info, w.Header()); err != nil { + if err = h.setLockingHeaders(bktInfo, lockInfo, w.Header()); err != nil { h.logAndSendError(w, "could not get locking info", reqInfo, err) return } diff --git a/api/handler/head.go b/api/handler/head.go index 0f2cdc3e4..12a62024c 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -2,7 +2,6 @@ package handler import ( "bytes" - "context" "net/http" "github.com/nspcc-dev/neofs-s3-gw/api" @@ -68,9 +67,9 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { VersionID: info.Version(), } - tagSet, err := h.obj.GetObjectTagging(r.Context(), t) + tagSet, lockInfo, err := h.obj.GetObjectTaggingAndLock(r.Context(), t) if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) { - h.logAndSendError(w, "could not get object tag set", reqInfo, err) + h.logAndSendError(w, "could not get object meta data", reqInfo, err) return } @@ -91,7 +90,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { } } - if err = h.setLockingHeaders(r.Context(), bktInfo, info, w.Header()); err != nil { + if err = h.setLockingHeaders(bktInfo, lockInfo, w.Header()); err != nil { h.logAndSendError(w, "could not get locking info", reqInfo, err) return } @@ -113,7 +112,7 @@ func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) { api.WriteResponse(w, http.StatusOK, nil, api.MimeNone) } -func (h *handler) setLockingHeaders(ctx context.Context, bktInfo *data.BucketInfo, objInfo *data.ObjectInfo, header http.Header) error { +func (h *handler) setLockingHeaders(bktInfo *data.BucketInfo, lockInfo *data.LockInfo, header http.Header) error { if !bktInfo.ObjectLockEnabled { return nil } @@ -121,26 +120,13 @@ func (h *handler) setLockingHeaders(ctx context.Context, bktInfo *data.BucketInf legalHold := &data.LegalHold{Status: legalHoldOff} retention := &data.Retention{Mode: governanceMode} - p := &layer.ObjectVersion{ - BktInfo: bktInfo, - ObjectName: objInfo.Name, - VersionID: objInfo.Version(), + if lockInfo.LegalHoldOID != nil { + legalHold.Status = legalHoldOn } - - lockInfo, err := h.obj.GetLockInfo(ctx, p) - if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) { - return err - } - - if lockInfo != nil { - if lockInfo.LegalHoldOID != nil { - legalHold.Status = legalHoldOn - } - if lockInfo.RetentionOID != nil { - retention.RetainUntilDate = lockInfo.UntilDate - if lockInfo.IsCompliance { - retention.Mode = complianceMode - } + if lockInfo.RetentionOID != nil { + retention.RetainUntilDate = lockInfo.UntilDate + if lockInfo.IsCompliance { + retention.Mode = complianceMode } }