From 342e571d89ed6d0049f2f975a0decf35af27924c Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 6 Mar 2023 16:11:42 +0300 Subject: [PATCH] [#159] Add handle __SYSTEM__ sys attributes Signed-off-by: Denis Kirillov --- CHANGELOG.md | 4 ++ cmd/frostfs-cli/docs/storage-node-xheaders.md | 10 ++--- cmd/frostfs-cli/modules/container/list.go | 2 +- .../modules/container/list_objects.go | 2 +- go.mod | 4 +- go.sum | Bin 90897 -> 90897 bytes pkg/core/object/fmt.go | 2 +- pkg/local_object_storage/metabase/exists.go | 35 +++++++++++------- .../metabase/iterators.go | 5 ++- .../object_manager/tombstone/checker.go | 2 +- 10 files changed, 40 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1ba8aaf9..d8082adc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Changelog for FrostFS Node - `neofs-cli` buffer for object put increased from 4 KiB to 3 MiB (#2243) - Expired locked object is available for reading (#56) - Initialize write-cache asynchronously (#32) +- Update system attribute names (#159) ### Fixed - Increase payload size metric on shards' `put` operation (#1794) @@ -70,6 +71,9 @@ You need to change configuration environment variables to `FROSTFS_*` if you use New config field `object.delete.tombstone_lifetime` allows to set tombstone lifetime more appropriate for a specific deployment. +Use `__SYSTEM__` prefix for system attributes instead of `__NEOFS__` +(existed objects with old attributes will be treated as before, but for new objects new attributes will be used). + ## [0.35.0] - 2022-12-28 - Sindo (신도, 信島) ### Added diff --git a/cmd/frostfs-cli/docs/storage-node-xheaders.md b/cmd/frostfs-cli/docs/storage-node-xheaders.md index db759dcfd..15bce457a 100644 --- a/cmd/frostfs-cli/docs/storage-node-xheaders.md +++ b/cmd/frostfs-cli/docs/storage-node-xheaders.md @@ -9,16 +9,16 @@ duplicated header names or headers with empty values are considered invalid. ## Existing headers -There are some "well-known" headers starting with `__FROSTFS__` prefix that +There are some "well-known" headers starting with `__SYSTEM__` prefix that affect system behaviour. For backward compatibility, the same set of "well-known" headers may also use `__NEOFS__` prefix: -* `__FROSTFS__NETMAP_EPOCH` - netmap epoch to use for object placement calculation. The `value` is string +* `__SYSTEM__NETMAP_EPOCH` - netmap epoch to use for object placement calculation. The `value` is string encoded `uint64` in decimal presentation. If set to '0' or omitted, the current epoch only will be used. -* `__FROSTFS__NETMAP_LOOKUP_DEPTH` - if object can't be found using current epoch's netmap, this header limits +* `__SYSTEM__NETMAP_LOOKUP_DEPTH` - if object can't be found using current epoch's netmap, this header limits how many past epochs the node can look up through. Depth is applied to a current epoch or the value -of `__FROSTFS__NETMAP_EPOCH` attribute. The `value` is string encoded `uint64` in decimal presentation. +of `__SYSTEM__NETMAP_EPOCH` attribute. The `value` is string encoded `uint64` in decimal presentation. If set to '0' or not set, only the current epoch is used. ## `frostfs-cli` commands with `--xhdr` @@ -30,5 +30,5 @@ List of commands with support of extended headers: Example: ```shell -$ frostfs-cli object put -r s01.frostfs.devenv:8080 -w wallet.json --cid CID --file FILE --xhdr "__FROSTFS__NETMAP_EPOCH=777" +$ frostfs-cli object put -r s01.frostfs.devenv:8080 -w wallet.json --cid CID --file FILE --xhdr "__SYSTEM__NETMAP_EPOCH=777" ``` diff --git a/cmd/frostfs-cli/modules/container/list.go b/cmd/frostfs-cli/modules/container/list.go index 1dd0fe8cd..9565748c3 100644 --- a/cmd/frostfs-cli/modules/container/list.go +++ b/cmd/frostfs-cli/modules/container/list.go @@ -62,7 +62,7 @@ var listContainersCmd = &cobra.Command{ res, err := internalclient.GetContainer(prmGet) if err == nil { res.Container().IterateAttributes(func(key, val string) { - if !strings.HasPrefix(key, container.SysAttributePrefix) { + if !strings.HasPrefix(key, container.SysAttributePrefix) && !strings.HasPrefix(key, container.SysAttributePrefixNeoFS) { // FIXME(@cthulhu-rider): neofs-sdk-go#314 use dedicated method to skip system attributes cmd.Printf(" %s: %s\n", key, val) } diff --git a/cmd/frostfs-cli/modules/container/list_objects.go b/cmd/frostfs-cli/modules/container/list_objects.go index 35649a08c..aef4a1f80 100644 --- a/cmd/frostfs-cli/modules/container/list_objects.go +++ b/cmd/frostfs-cli/modules/container/list_objects.go @@ -70,7 +70,7 @@ var listContainerObjectsCmd = &cobra.Command{ attrs := resHead.Header().Attributes() for i := range attrs { attrKey := attrs[i].Key() - if !strings.HasPrefix(attrKey, v2object.SysAttributePrefix) { + if !strings.HasPrefix(attrKey, v2object.SysAttributePrefix) && !strings.HasPrefix(attrKey, v2object.SysAttributePrefixNeoFS) { // FIXME(@cthulhu-rider): neofs-sdk-go#226 use dedicated method to skip system attributes cmd.Printf(" %s: %s\n", attrKey, attrs[i].Value()) } diff --git a/go.mod b/go.mod index bb5a53b22..e3cfab207 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module git.frostfs.info/TrueCloudLab/frostfs-node go 1.18 require ( - git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.11.2-0.20230307104236-f69d2ad83c51 + git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.11.2-0.20230315095236-9dc375346703 git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230307124721-94476f905599 + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230316081442-bec77f280a85 git.frostfs.info/TrueCloudLab/hrw v1.2.0 git.frostfs.info/TrueCloudLab/tzhash v1.8.0 github.com/cheggaaa/pb v1.0.29 diff --git a/go.sum b/go.sum index 93f805d21f46b9e4cd524f20e5a2587fe12c04a9..724d51efe5b82a56527dcb3251964ef4fa53fcd0 100644 GIT binary patch delta 337 zcmZwC-A;l~0KoCN=B1Qd58!1RGY%XMAFZ2%7>Oc^3dU7@2?R!^0(#Zf6F6U_tqUKZ z&F3n+>cSWJ?f>5%s@p^L^R_0_2#AP*TvPNt$Ro&dJb;aezDdgf$V>Z`THV>Ey%L?5 zlGDA;w52YRp``hgVg?UN7sCSY-fL3#Bt(VT^*r;BUTF9zZX+zPc^s!}4tsrRF-pfJ zGYvEAtuW*bzX6)FmWRLI)oxFaUysChMW#6*&@9U|-N57d86yBkKu2*r@l=FCiw>hjyOQp!9m`7apkHQx;`zm8_ayeOl7X{{lD2cIGk5eD=3c_(_7li~ d%SOvUk9xhqvuWLrhQaZ=@j=x0M7?rm`~W2mWo7^X delta 337 zcmZwBOKQSE002;=xHPTM1Gp>%o5^G*lay|%(Nq$m4z>BLsw1glG%?ADaaHIE#ETTV z@BjtRRnt|Wy};w`Pu2aY`f*<~0FeQLirNfSeG11@O<`DW%;dWWiIzNbM2EXh9tA=C ztQC|Flo2O`d1wR77oD}mCcw%LZ?%^7FC@Ljx6621dMjXTEuTjmKBPpUYM(h>1=(|3 z^2Xxapu`OLxZj>l?9SP{IUEJ?^F{coltYLJl$$z2L=AO-v96cma%XywdK%RprF^tb zM_hhl{sIlD(PFKhYx)@*tXOFGhd<)w)pfc2i~U;e$c`nZFDAT)6J8WJF1nKtf{mMK a$j!5;y=AE?EjE~)&BnV>KMM8A1^ou+HDy5n diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 217c04664..053306356 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -353,7 +353,7 @@ func (v *FormatValidator) checkExpiration(obj *object.Object) error { func expirationEpochAttribute(obj *object.Object) (uint64, error) { for _, a := range obj.Attributes() { - if a.Key() != objectV2.SysAttributeExpEpoch { + if a.Key() != objectV2.SysAttributeExpEpoch && a.Key() != objectV2.SysAttributeExpEpochNeoFS { continue } diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index 59bd9f4f2..6ad65c735 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -110,20 +110,9 @@ func objectStatus(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) uint8 { // GC is expected to collect all the objects that have // expired previously for less than the one epoch duration - var expired bool - - // bucket with objects that have expiration attr - attrKey := make([]byte, bucketKeySize+len(objectV2.SysAttributeExpEpoch)) - expirationBucket := tx.Bucket(attributeBucketName(addr.Container(), objectV2.SysAttributeExpEpoch, attrKey)) - if expirationBucket != nil { - // bucket that contains objects that expire in the current epoch - prevEpochBkt := expirationBucket.Bucket([]byte(strconv.FormatUint(currEpoch-1, 10))) - if prevEpochBkt != nil { - rawOID := objectKey(addr.Object(), make([]byte, objectKeySize)) - if prevEpochBkt.Get(rawOID) != nil { - expired = true - } - } + expired := isExpiredWithAttribute(tx, objectV2.SysAttributeExpEpoch, addr, currEpoch) + if !expired { + expired = isExpiredWithAttribute(tx, objectV2.SysAttributeExpEpochNeoFS, addr, currEpoch) } if expired { @@ -136,6 +125,24 @@ func objectStatus(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) uint8 { return inGraveyardWithKey(addrKey, graveyardBkt, garbageBkt) } +func isExpiredWithAttribute(tx *bbolt.Tx, attr string, addr oid.Address, currEpoch uint64) bool { + // bucket with objects that have expiration attr + attrKey := make([]byte, bucketKeySize+len(attr)) + expirationBucket := tx.Bucket(attributeBucketName(addr.Container(), attr, attrKey)) + if expirationBucket != nil { + // bucket that contains objects that expire in the current epoch + prevEpochBkt := expirationBucket.Bucket([]byte(strconv.FormatUint(currEpoch-1, 10))) + if prevEpochBkt != nil { + rawOID := objectKey(addr.Object(), make([]byte, objectKeySize)) + if prevEpochBkt.Get(rawOID) != nil { + return true + } + } + } + + return false +} + func inGraveyardWithKey(addrKey []byte, graveyard, garbageBCK *bbolt.Bucket) uint8 { if graveyard == nil { // incorrect metabase state, does not make diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 9741225df..3c5888e1c 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -60,7 +60,10 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) err := tx.ForEach(func(name []byte, b *bbolt.Bucket) error { cidBytes := cidFromAttributeBucket(name, objectV2.SysAttributeExpEpoch) if cidBytes == nil { - return nil + cidBytes = cidFromAttributeBucket(name, objectV2.SysAttributeExpEpochNeoFS) + if cidBytes == nil { + return nil + } } var cnrID cid.ID diff --git a/pkg/services/object_manager/tombstone/checker.go b/pkg/services/object_manager/tombstone/checker.go index 379dad0f5..4097f22bf 100644 --- a/pkg/services/object_manager/tombstone/checker.go +++ b/pkg/services/object_manager/tombstone/checker.go @@ -73,7 +73,7 @@ func (g *ExpirationChecker) IsTombstoneAvailable(ctx context.Context, a oid.Addr func (g *ExpirationChecker) handleTS(addr string, ts *object.Object, reqEpoch uint64) bool { for _, atr := range ts.Attributes() { - if atr.Key() == objectV2.SysAttributeExpEpoch { + if atr.Key() == objectV2.SysAttributeExpEpoch || atr.Key() == objectV2.SysAttributeExpEpochNeoFS { epoch, err := strconv.ParseUint(atr.Value(), 10, 64) if err != nil { g.log.Warn(