From cd2e46a17cd739a99a39ff14ab9e036d5e48fee7 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 6 Mar 2023 15:24:58 +0300 Subject: [PATCH] [#10] Add __FROSTFS__ system attributes Signed-off-by: Denis Kirillov --- container/attributes.go | 23 ++++++++++++++++++++--- netmap/attributes.go | 14 ++++++++++---- netmap/attributes_test.go | 2 +- object/attributes.go | 29 ++++++++++++++++++++++++----- session/xheaders.go | 17 ++++++++++++++++- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/container/attributes.go b/container/attributes.go index eb4b0782..356a6b9a 100644 --- a/container/attributes.go +++ b/container/attributes.go @@ -1,7 +1,7 @@ package container // SysAttributePrefix is a prefix of key to system attribute. -const SysAttributePrefix = "__NEOFS__" +const SysAttributePrefix = "__FROSTFS__" const ( // SysAttributeSubnet is a string ID of container's storage subnet. @@ -17,6 +17,23 @@ const ( SysAttributeHomomorphicHashing = SysAttributePrefix + "DISABLE_HOMOMORPHIC_HASHING" ) +// SysAttributePrefixNeoFS is a prefix of key to system attribute. +const SysAttributePrefixNeoFS = "__NEOFS__" + +const ( + // SysAttributeSubnetNeoFS is a string ID of container's storage subnet. + SysAttributeSubnetNeoFS = SysAttributePrefixNeoFS + "SUBNET" + + // SysAttributeNameNeoFS is a string of human-friendly container name registered as the domain in NNS contract. + SysAttributeNameNeoFS = SysAttributePrefixNeoFS + "NAME" + + // SysAttributeZoneNeoFS is a string of zone for container name. + SysAttributeZoneNeoFS = SysAttributePrefixNeoFS + "ZONE" + + // SysAttributeHomomorphicHashingNeoFS is a container's homomorphic hashing state. + SysAttributeHomomorphicHashingNeoFS = SysAttributePrefixNeoFS + "DISABLE_HOMOMORPHIC_HASHING" +) + // SysAttributeZoneDefault is a default value for SysAttributeZone attribute. const SysAttributeZoneDefault = "container" @@ -33,7 +50,7 @@ const disabledHomomorphicHashingValue = "true" // See also SetHomomorphicHashingState. func (c Container) HomomorphicHashingState() bool { for i := range c.attr { - if c.attr[i].GetKey() == SysAttributeHomomorphicHashing { + if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS { return c.attr[i].GetValue() != disabledHomomorphicHashingValue } } @@ -50,7 +67,7 @@ func (c Container) HomomorphicHashingState() bool { // See also HomomorphicHashingState. func (c *Container) SetHomomorphicHashingState(enable bool) { for i := range c.attr { - if c.attr[i].GetKey() == SysAttributeHomomorphicHashing { + if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS { if enable { // approach without allocation/waste // coping works since the attributes diff --git a/netmap/attributes.go b/netmap/attributes.go index 719d8828..3ebec576 100644 --- a/netmap/attributes.go +++ b/netmap/attributes.go @@ -9,7 +9,10 @@ import ( ) // prefix of keys to subnet attributes. -const attrSubnetPrefix = "__NEOFS__SUBNET_" +const attrSubnetPrefix = "__FROSTFS__SUBNET_" + +// prefix of keys to subnet attributes. +const attrSubnetPrefixNeoFS = "__NEOFS__SUBNET_" const ( // subnet attribute's value denoting subnet entry @@ -62,7 +65,7 @@ func subnetAttributeKey(id *refs.SubnetID) string { // - disables non-zero subnet; // - enables zero subnet. // -// Attribute key is calculated from ID using format `__NEOFS__SUBNET_%s`. +// Attribute key is calculated from ID using format `__FROSTFS__SUBNET_%s`. // Attribute Value is: // - `True` if node enters the subnet; // - `False`, otherwise. @@ -143,8 +146,11 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error { // cut subnet ID string idTxt := strings.TrimPrefix(key, attrSubnetPrefix) if len(idTxt) == len(key) { - // not a subnet attribute - continue + idTxt = strings.TrimPrefix(key, attrSubnetPrefixNeoFS) + if len(idTxt) == len(key) { + // not a subnet attribute + continue + } } // check value diff --git a/netmap/attributes_test.go b/netmap/attributes_test.go index 6d5b9ea4..a2b3be90 100644 --- a/netmap/attributes_test.go +++ b/netmap/attributes_test.go @@ -11,7 +11,7 @@ import ( ) func subnetAttrKey(val string) string { - return "__NEOFS__SUBNET_" + val + return "__FROSTFS__SUBNET_" + val } func assertSubnetAttrKey(t *testing.T, attr *netmap.Attribute, num uint32) { diff --git a/object/attributes.go b/object/attributes.go index cc828738..32936825 100644 --- a/object/attributes.go +++ b/object/attributes.go @@ -7,7 +7,7 @@ import ( ) // SysAttributePrefix is a prefix of key to system attribute. -const SysAttributePrefix = "__NEOFS__" +const SysAttributePrefix = "__FROSTFS__" const ( // SysAttributeUploadID marks smaller parts of a split bigger object. @@ -25,6 +25,25 @@ const ( SysAttributeTickTopic = SysAttributePrefix + "TICK_TOPIC" ) +// SysAttributePrefixNeoFS is a prefix of key to system attribute. +const SysAttributePrefixNeoFS = "__NEOFS__" + +const ( + // SysAttributeUploadIDNeoFS marks smaller parts of a split bigger object. + SysAttributeUploadIDNeoFS = SysAttributePrefixNeoFS + "UPLOAD_ID" + + // SysAttributeExpEpochNeoFS tells GC to delete object after that epoch. + SysAttributeExpEpochNeoFS = SysAttributePrefixNeoFS + "EXPIRATION_EPOCH" + + // SysAttributeTickEpochNeoFS defines what epoch must produce object + // notification. + SysAttributeTickEpochNeoFS = SysAttributePrefixNeoFS + "TICK_EPOCH" + + // SysAttributeTickTopicNeoFS defines what topic object notification + // must be sent to. + SysAttributeTickTopicNeoFS = SysAttributePrefixNeoFS + "TICK_TOPIC" +) + // NotificationInfo groups information about object notification // that can be written to object. // @@ -81,10 +100,10 @@ func WriteNotificationInfo(o *Object, ni NotificationInfo) { for i := range attrs { switch attrs[i].GetKey() { - case SysAttributeTickEpoch: + case SysAttributeTickEpoch, SysAttributeTickEpochNeoFS: attrs[i].SetValue(epoch) changedEpoch = true - case SysAttributeTickTopic: + case SysAttributeTickTopic, SysAttributeTickTopicNeoFS: changedTopic = true if topic == "" { @@ -141,7 +160,7 @@ func GetNotificationInfo(o *Object) (*NotificationInfo, error) { for _, attr := range o.GetHeader().GetAttributes() { switch key := attr.GetKey(); key { - case SysAttributeTickEpoch: + case SysAttributeTickEpoch, SysAttributeTickEpochNeoFS: epoch, err := strconv.ParseUint(attr.GetValue(), 10, 64) if err != nil { return nil, fmt.Errorf("could not parse epoch: %w", err) @@ -150,7 +169,7 @@ func GetNotificationInfo(o *Object) (*NotificationInfo, error) { ni.SetEpoch(epoch) foundEpoch = true - case SysAttributeTickTopic: + case SysAttributeTickTopic, SysAttributeTickTopicNeoFS: ni.SetTopic(attr.GetValue()) } } diff --git a/session/xheaders.go b/session/xheaders.go index 64b16dee..ba3ac8d4 100644 --- a/session/xheaders.go +++ b/session/xheaders.go @@ -1,7 +1,7 @@ package session // ReservedXHeaderPrefix is a prefix of keys to "well-known" X-headers. -const ReservedXHeaderPrefix = "__NEOFS__" +const ReservedXHeaderPrefix = "__FROSTFS__" const ( // XHeaderNetmapEpoch is a key to the reserved X-header that specifies netmap epoch @@ -14,3 +14,18 @@ const ( // set, the current epoch only will be used. XHeaderNetmapLookupDepth = ReservedXHeaderPrefix + "NETMAP_LOOKUP_DEPTH" ) + +// ReservedXHeaderPrefixNeoFS is a prefix of keys to "well-known" X-headers. +const ReservedXHeaderPrefixNeoFS = "__NEOFS__" + +const ( + // XHeaderNetmapEpochNeoFS is a key to the reserved X-header that specifies netmap epoch + // to use for object placement calculation. If set to '0' or not set, the current + // epoch only will be used. + XHeaderNetmapEpochNeoFS = ReservedXHeaderPrefixNeoFS + "NETMAP_EPOCH" + + // XHeaderNetmapLookupDepthNeoFS is a key to the reserved X-header that limits + // how many past epochs back the node will can lookup. If set to '0' or not + // set, the current epoch only will be used. + XHeaderNetmapLookupDepthNeoFS = ReservedXHeaderPrefixNeoFS + "NETMAP_LOOKUP_DEPTH" +)