[#514] Missed version id in tags

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-06-07 12:12:07 +03:00 committed by Alex Vanin
parent 64931c77f4
commit 93a7c2eaeb
4 changed files with 22 additions and 11 deletions

View file

@ -66,7 +66,6 @@ func (h *handler) PutObjectTaggingHandler(w http.ResponseWriter, r *http.Request
func (h *handler) GetObjectTaggingHandler(w http.ResponseWriter, r *http.Request) { func (h *handler) GetObjectTaggingHandler(w http.ResponseWriter, r *http.Request) {
reqInfo := api.GetReqInfo(r.Context()) reqInfo := api.GetReqInfo(r.Context())
versionID := reqInfo.URL.Query().Get("versionId")
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName) bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
if err != nil { if err != nil {
@ -74,19 +73,27 @@ func (h *handler) GetObjectTaggingHandler(w http.ResponseWriter, r *http.Request
return return
} }
settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
if err != nil {
h.logAndSendError(w, "could not get bucket settings", reqInfo, err)
return
}
p := &layer.ObjectVersion{ p := &layer.ObjectVersion{
BktInfo: bktInfo, BktInfo: bktInfo,
ObjectName: reqInfo.ObjectName, ObjectName: reqInfo.ObjectName,
VersionID: versionID, VersionID: reqInfo.URL.Query().Get("versionId"),
} }
tagSet, err := h.obj.GetObjectTagging(r.Context(), p) versionID, tagSet, err := h.obj.GetObjectTagging(r.Context(), p)
if err != nil { if err != nil {
h.logAndSendError(w, "could not get object tagging", reqInfo, err) h.logAndSendError(w, "could not get object tagging", reqInfo, err)
return return
} }
if settings.VersioningEnabled {
w.Header().Set(api.AmzVersionID, versionID) w.Header().Set(api.AmzVersionID, versionID)
}
if err = api.EncodeToResponse(w, encodeTagging(tagSet)); err != nil { if err = api.EncodeToResponse(w, encodeTagging(tagSet)); err != nil {
h.logAndSendError(w, "something went wrong", reqInfo, err) h.logAndSendError(w, "something went wrong", reqInfo, err)
} }

View file

@ -26,6 +26,7 @@ func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectV
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
objVersion.VersionID = version.OID.EncodeToString()
tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, &objVersion.BktInfo.CID, version) tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, &objVersion.BktInfo.CID, version)
if err != nil { if err != nil {

View file

@ -224,7 +224,7 @@ type (
PutBucketTagging(ctx context.Context, cnrID *cid.ID, tagSet map[string]string) error PutBucketTagging(ctx context.Context, cnrID *cid.ID, tagSet map[string]string) error
DeleteBucketTagging(ctx context.Context, cnrID *cid.ID) error DeleteBucketTagging(ctx context.Context, cnrID *cid.ID) error
GetObjectTagging(ctx context.Context, p *ObjectVersion) (map[string]string, error) GetObjectTagging(ctx context.Context, p *ObjectVersion) (string, map[string]string, error)
PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error
DeleteObjectTagging(ctx context.Context, p *ObjectVersion) error DeleteObjectTagging(ctx context.Context, p *ObjectVersion) error

View file

@ -10,34 +10,36 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (map[string]string, error) { func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (string, map[string]string, error) {
var ( var (
err error err error
tags map[string]string tags map[string]string
) )
tags = n.systemCache.GetTagging(objectTaggingCacheKey(p)) tags = n.systemCache.GetTagging(objectTaggingCacheKey(p))
if tags != nil { if tags != nil {
return tags, nil return p.VersionID, tags, nil
} }
version, err := n.getNodeVersion(ctx, p) version, err := n.getNodeVersion(ctx, p)
if err != nil { if err != nil {
return nil, err return "", nil, err
} }
p.VersionID = version.OID.EncodeToString()
tags, err = n.treeService.GetObjectTagging(ctx, &p.BktInfo.CID, version) tags, err = n.treeService.GetObjectTagging(ctx, &p.BktInfo.CID, version)
if err != nil { if err != nil {
if errorsStd.Is(err, ErrNodeNotFound) { if errorsStd.Is(err, ErrNodeNotFound) {
return nil, errors.GetAPIError(errors.ErrNoSuchKey) return "", nil, errors.GetAPIError(errors.ErrNoSuchKey)
} }
return nil, err return "", nil, err
} }
if err = n.systemCache.PutTagging(objectTaggingCacheKey(p), tags); err != nil { if err = n.systemCache.PutTagging(objectTaggingCacheKey(p), tags); err != nil {
n.log.Error("couldn't cache system object", zap.Error(err)) n.log.Error("couldn't cache system object", zap.Error(err))
} }
return tags, nil return p.VersionID, tags, nil
} }
func (n *layer) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error { func (n *layer) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error {
@ -45,6 +47,7 @@ func (n *layer) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet m
if err != nil { if err != nil {
return err return err
} }
p.VersionID = version.OID.EncodeToString()
err = n.treeService.PutObjectTagging(ctx, &p.BktInfo.CID, version, tagSet) err = n.treeService.PutObjectTagging(ctx, &p.BktInfo.CID, version, tagSet)
if err != nil { if err != nil {