From f66e4a77cd49bb7811500ed5791abba0831b43f5 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Tue, 9 Aug 2022 16:10:04 +0400 Subject: [PATCH] [#577] Add IsDeleteMarker() to NodeVersion Signed-off-by: Angira Kekteeva --- api/data/tree.go | 4 ++++ api/handler/attributes.go | 2 +- api/layer/layer.go | 2 +- api/layer/object.go | 4 ++-- api/layer/tagging.go | 2 +- api/layer/versioning.go | 2 +- internal/neofs/tree.go | 4 ++-- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/api/data/tree.go b/api/data/tree.go index 4dbbe2cb1..60ecf4cd7 100644 --- a/api/data/tree.go +++ b/api/data/tree.go @@ -20,6 +20,10 @@ type NodeVersion struct { IsUnversioned bool } +func (v NodeVersion) IsDeleteMarker() bool { + return v.DeleteMarker != nil +} + // DeleteMarkerInfo is used to save object info if node in the tree service is delete marker. // We need this information because the "delete marker" object is no longer stored in NeoFS. type DeleteMarkerInfo struct { diff --git a/api/handler/attributes.go b/api/handler/attributes.go index 069f160c9..4c57783b7 100644 --- a/api/handler/attributes.go +++ b/api/handler/attributes.go @@ -122,7 +122,7 @@ func writeAttributesHeaders(h http.Header, info *data.ExtendedObjectInfo, isBuck h.Set(api.AmzVersionID, info.Version()) } - if info.NodeVersion.DeleteMarker != nil { + if info.NodeVersion.IsDeleteMarker() { h.Set(api.AmzDeleteMarker, strconv.FormatBool(true)) } diff --git a/api/layer/layer.go b/api/layer/layer.go index 91ab72ad2..e33d24cd7 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -556,7 +556,7 @@ func (n *layer) getNodeVersionToDelete(ctx context.Context, bkt *data.BucketInfo } func (n *layer) removeOldVersion(ctx context.Context, bkt *data.BucketInfo, nodeVersion *data.NodeVersion, obj *VersionedObject) (string, error) { - if nodeVersion.DeleteMarker != nil { + if nodeVersion.IsDeleteMarker() { return obj.VersionID, nil } diff --git a/api/layer/object.go b/api/layer/object.go index 14971d470..80eb5427f 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -264,7 +264,7 @@ func (n *layer) headLastVersionIfNotDeleted(ctx context.Context, bkt *data.Bucke return nil, err } - if node.DeleteMarker != nil { + if node.IsDeleteMarker() { return nil, apiErrors.GetAPIError(apiErrors.ErrNoSuchKey) } @@ -596,7 +596,7 @@ func (n *layer) getAllObjectsVersions(ctx context.Context, bkt *data.BucketInfo, for _, nodeVersion := range nodeVersions { oi := &data.ObjectInfo{} - if nodeVersion.DeleteMarker != nil { // delete marker does not match any object in NeoFS + if nodeVersion.IsDeleteMarker() { // delete marker does not match any object in NeoFS oi.ID = nodeVersion.OID oi.Name = nodeVersion.FilePath oi.Owner = nodeVersion.DeleteMarker.Owner diff --git a/api/layer/tagging.go b/api/layer/tagging.go index 48136c331..5d6da64e1 100644 --- a/api/layer/tagging.go +++ b/api/layer/tagging.go @@ -163,7 +163,7 @@ func (n *layer) getNodeVersion(ctx context.Context, objVersion *ObjectVersion) ( } } - if err == nil && version.DeleteMarker != nil && !objVersion.NoErrorOnDeleteMarker || errorsStd.Is(err, ErrNodeNotFound) { + if err == nil && version.IsDeleteMarker() && !objVersion.NoErrorOnDeleteMarker || errorsStd.Is(err, ErrNodeNotFound) { return nil, errors.GetAPIError(errors.ErrNoSuchKey) } diff --git a/api/layer/versioning.go b/api/layer/versioning.go index 003821294..46df8a6dd 100644 --- a/api/layer/versioning.go +++ b/api/layer/versioning.go @@ -68,7 +68,7 @@ func triageVersions(objVersions []*data.ExtendedObjectInfo) ([]*data.ExtendedObj var resDelMarkVersions []*data.ExtendedObjectInfo for _, version := range objVersions { - if version.NodeVersion.DeleteMarker != nil { + if version.NodeVersion.IsDeleteMarker() { resDelMarkVersions = append(resDelMarkVersions, version) } else { resVersion = append(resVersion, version) diff --git a/internal/neofs/tree.go b/internal/neofs/tree.go index 6de807566..f1c932908 100644 --- a/internal/neofs/tree.go +++ b/internal/neofs/tree.go @@ -747,7 +747,7 @@ func (c *TreeClient) getSubTreeVersions(ctx context.Context, cnrID cid.ID, nodeI result := make([]*data.NodeVersion, 0, len(versions)) // consider use len(subTree) for _, version := range versions { - if latestOnly && version[0].DeleteMarker != nil { + if latestOnly && version[0].IsDeleteMarker() { continue } result = append(result, version...) @@ -1066,7 +1066,7 @@ func (c *TreeClient) addVersion(ctx context.Context, cnrID cid.ID, treeID string meta[etagKV] = version.ETag } - if version.DeleteMarker != nil { + if version.IsDeleteMarker() { meta[isDeleteMarkerKV] = "true" meta[ownerKV] = version.DeleteMarker.Owner.EncodeToString() meta[createdKV] = strconv.FormatInt(version.DeleteMarker.Created.UTC().UnixMilli(), 10)