2022-05-31 14:27:08 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-30 09:03:55 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-05-31 14:27:08 +00:00
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2023-06-30 09:03:55 +00:00
|
|
|
s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2024-09-27 08:13:13 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/tree"
|
2022-05-31 14:27:08 +00:00
|
|
|
)
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *data.ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, data.LockInfo, error) {
|
2022-10-06 08:46:53 +00:00
|
|
|
var err error
|
2023-08-03 12:08:22 +00:00
|
|
|
owner := n.BearerOwner(ctx)
|
2022-05-31 14:27:08 +00:00
|
|
|
|
2022-10-06 08:46:53 +00:00
|
|
|
tags := n.cache.GetTagging(owner, objectTaggingCacheKey(objVersion))
|
|
|
|
lockInfo := n.cache.GetLockInfo(owner, lockObjectKey(objVersion))
|
2022-05-31 14:27:08 +00:00
|
|
|
|
|
|
|
if tags != nil && lockInfo != nil {
|
2024-02-29 14:47:36 +00:00
|
|
|
return tags, *lockInfo, nil
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 13:35:05 +00:00
|
|
|
if nodeVersion == nil {
|
|
|
|
nodeVersion, err = n.getNodeVersion(ctx, objVersion)
|
|
|
|
if err != nil {
|
2024-02-29 14:47:36 +00:00
|
|
|
return nil, data.LockInfo{}, err
|
2022-06-28 13:35:05 +00:00
|
|
|
}
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, objVersion.BktInfo, nodeVersion)
|
2022-05-31 14:27:08 +00:00
|
|
|
if err != nil {
|
2024-09-27 08:13:13 +00:00
|
|
|
if errors.Is(err, tree.ErrNodeNotFound) {
|
2024-02-29 14:47:36 +00:00
|
|
|
return nil, data.LockInfo{}, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error())
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|
2024-02-29 14:47:36 +00:00
|
|
|
return nil, data.LockInfo{}, err
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 08:46:53 +00:00
|
|
|
n.cache.PutTagging(owner, objectTaggingCacheKey(objVersion), tags)
|
|
|
|
n.cache.PutLockInfo(owner, lockObjectKey(objVersion), lockInfo)
|
2022-05-31 14:27:08 +00:00
|
|
|
|
2024-02-29 14:47:36 +00:00
|
|
|
return tags, *lockInfo, nil
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|