[#577] Add IsDeleteMarker() to NodeVersion

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-08-09 16:10:04 +04:00 committed by Kira
parent 2a933f48be
commit f66e4a77cd
7 changed files with 12 additions and 8 deletions

View file

@ -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 {

View file

@ -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))
}

View file

@ -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
}

View file

@ -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

View file

@ -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)
}

View file

@ -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)

View file

@ -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)