From f958eef2b368e74f79de8a26ec225cdc085bce90 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 29 Feb 2024 17:47:36 +0300 Subject: [PATCH] [#325] Use default empty data.LockInfo in get/head in case of error Signed-off-by: Denis Kirillov --- api/handler/head.go | 2 +- api/layer/compound.go | 12 ++++++------ api/layer/layer.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/handler/head.go b/api/handler/head.go index 93cc4e15..8a52c3e5 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -143,7 +143,7 @@ func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) { middleware.WriteResponse(w, http.StatusOK, nil, middleware.MimeNone) } -func (h *handler) setLockingHeaders(bktInfo *data.BucketInfo, lockInfo *data.LockInfo, header http.Header) error { +func (h *handler) setLockingHeaders(bktInfo *data.BucketInfo, lockInfo data.LockInfo, header http.Header) error { if !bktInfo.ObjectLockEnabled { return nil } diff --git a/api/layer/compound.go b/api/layer/compound.go index dd012748..c17c95b4 100644 --- a/api/layer/compound.go +++ b/api/layer/compound.go @@ -9,7 +9,7 @@ import ( s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors" ) -func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) { +func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, data.LockInfo, error) { var err error owner := n.BearerOwner(ctx) @@ -17,26 +17,26 @@ func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectV lockInfo := n.cache.GetLockInfo(owner, lockObjectKey(objVersion)) if tags != nil && lockInfo != nil { - return tags, lockInfo, nil + return tags, *lockInfo, nil } if nodeVersion == nil { nodeVersion, err = n.getNodeVersion(ctx, objVersion) if err != nil { - return nil, nil, err + return nil, data.LockInfo{}, err } } tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, objVersion.BktInfo, nodeVersion) if err != nil { if errors.Is(err, ErrNodeNotFound) { - return nil, nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) + return nil, data.LockInfo{}, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error()) } - return nil, nil, err + return nil, data.LockInfo{}, err } n.cache.PutTagging(owner, objectTaggingCacheKey(objVersion), tags) n.cache.PutLockInfo(owner, lockObjectKey(objVersion), lockInfo) - return tags, lockInfo, nil + return tags, *lockInfo, nil } diff --git a/api/layer/layer.go b/api/layer/layer.go index b23b0f56..a1d82829 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -279,7 +279,7 @@ type ( // Compound methods for optimizations // GetObjectTaggingAndLock unifies GetObjectTagging and GetLock methods in single tree service invocation. - GetObjectTaggingAndLock(ctx context.Context, p *ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) + GetObjectTaggingAndLock(ctx context.Context, p *ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, data.LockInfo, error) } )