From 7fd27e04fe971626f5dfb2a33daa229fc5492ece Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 31 May 2022 17:27:08 +0300 Subject: [PATCH] [#477] Provide aggregation of tags and locks in layer.Client Adopts GetObjectTaggingAndLock method from TreeClient in layer.Client with caching. Signed-off-by: Alex Vanin --- api/layer/compound.go | 47 +++++++++++++++++++++++++++++++++++++++++++ api/layer/layer.go | 5 +++++ 2 files changed, 52 insertions(+) create mode 100644 api/layer/compound.go diff --git a/api/layer/compound.go b/api/layer/compound.go new file mode 100644 index 00000000..fb8e37a1 --- /dev/null +++ b/api/layer/compound.go @@ -0,0 +1,47 @@ +package layer + +import ( + "context" + errorsStd "errors" + + "github.com/nspcc-dev/neofs-s3-gw/api/data" + "github.com/nspcc-dev/neofs-s3-gw/api/errors" + "go.uber.org/zap" +) + +func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectVersion) (map[string]string, *data.LockInfo, error) { + var ( + err error + tags map[string]string + ) + + tags = n.systemCache.GetTagging(objectTaggingCacheKey(objVersion)) + lockInfo := n.systemCache.GetLockInfo(lockObjectKey(objVersion)) + + if tags != nil && lockInfo != nil { + return tags, lockInfo, nil + } + + version, err := n.getNodeVersion(ctx, objVersion) + if err != nil { + return nil, nil, err + } + + tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, &objVersion.BktInfo.CID, version) + if err != nil { + if errorsStd.Is(err, ErrNodeNotFound) { + return nil, nil, errors.GetAPIError(errors.ErrNoSuchKey) + } + return nil, nil, err + } + + if err = n.systemCache.PutTagging(objectTaggingCacheKey(objVersion), tags); err != nil { + n.log.Error("couldn't cache system object", zap.Error(err)) + } + + if err = n.systemCache.PutLockInfo(lockObjectKey(objVersion), lockInfo); err != nil { + n.log.Error("couldn't cache system object", zap.Error(err)) + } + + return tags, lockInfo, nil +} diff --git a/api/layer/layer.go b/api/layer/layer.go index 8722791b..6d14ebde 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -248,6 +248,11 @@ type ( PutBucketNotificationConfiguration(ctx context.Context, p *PutBucketNotificationConfigurationParams) error GetBucketNotificationConfiguration(ctx context.Context, bktInfo *data.BucketInfo) (*data.NotificationConfiguration, error) + + // Compound methods for optimizations + + // GetObjectTaggingAndLock unifies GetObjectTagging and GetLock methods in single tree service invocation. + GetObjectTaggingAndLock(ctx context.Context, p *ObjectVersion) (map[string]string, *data.LockInfo, error) } )