forked from TrueCloudLab/frostfs-s3-gw
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package layer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree"
|
|
)
|
|
|
|
func (n *Layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *data.ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, data.LockInfo, error) {
|
|
var err error
|
|
owner := n.BearerOwner(ctx)
|
|
|
|
tags := n.cache.GetTagging(owner, objectTaggingCacheKey(objVersion))
|
|
lockInfo := n.cache.GetLockInfo(owner, lockObjectKey(objVersion))
|
|
|
|
if tags != nil && lockInfo != nil {
|
|
return tags, *lockInfo, nil
|
|
}
|
|
|
|
if nodeVersion == nil {
|
|
nodeVersion, err = n.getNodeVersion(ctx, objVersion)
|
|
if err != nil {
|
|
return nil, data.LockInfo{}, err
|
|
}
|
|
}
|
|
|
|
tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, objVersion.BktInfo, nodeVersion)
|
|
if err != nil {
|
|
if errors.Is(err, tree.ErrNodeNotFound) {
|
|
return nil, data.LockInfo{}, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error())
|
|
}
|
|
return nil, data.LockInfo{}, err
|
|
}
|
|
|
|
n.cache.PutTagging(owner, objectTaggingCacheKey(objVersion), tags)
|
|
n.cache.PutLockInfo(owner, lockObjectKey(objVersion), lockInfo)
|
|
|
|
return tags, *lockInfo, nil
|
|
}
|