feature/frostfs_system_attribute #10

Merged
fyrchik merged 1 commit from dkirillov/frostfs-api-go:feature/frostfs_system_attribute into master 2023-07-26 21:08:03 +00:00
5 changed files with 71 additions and 14 deletions

View file

@ -1,7 +1,7 @@
package container package container
// SysAttributePrefix is a prefix of key to system attribute. // SysAttributePrefix is a prefix of key to system attribute.
const SysAttributePrefix = "__NEOFS__" const SysAttributePrefix = "__FROSTFS__"
const ( const (
// SysAttributeSubnet is a string ID of container's storage subnet. // SysAttributeSubnet is a string ID of container's storage subnet.
@ -17,6 +17,23 @@ const (
SysAttributeHomomorphicHashing = SysAttributePrefix + "DISABLE_HOMOMORPHIC_HASHING" 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. // SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
const SysAttributeZoneDefault = "container" const SysAttributeZoneDefault = "container"
@ -33,7 +50,7 @@ const disabledHomomorphicHashingValue = "true"
// See also SetHomomorphicHashingState. // See also SetHomomorphicHashingState.
func (c Container) HomomorphicHashingState() bool { func (c Container) HomomorphicHashingState() bool {
for i := range c.attr { 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 return c.attr[i].GetValue() != disabledHomomorphicHashingValue
} }
} }
@ -50,7 +67,7 @@ func (c Container) HomomorphicHashingState() bool {
// See also HomomorphicHashingState. // See also HomomorphicHashingState.
func (c *Container) SetHomomorphicHashingState(enable bool) { func (c *Container) SetHomomorphicHashingState(enable bool) {
for i := range c.attr { for i := range c.attr {
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing { if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
if enable { if enable {
// approach without allocation/waste // approach without allocation/waste
// coping works since the attributes // coping works since the attributes

View file

@ -9,7 +9,10 @@ import (
) )
// prefix of keys to subnet attributes. // 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 ( const (
// subnet attribute's value denoting subnet entry // subnet attribute's value denoting subnet entry
@ -62,7 +65,7 @@ func subnetAttributeKey(id *refs.SubnetID) string {
// - disables non-zero subnet; // - disables non-zero subnet;
// - enables 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: // Attribute Value is:
// - `True` if node enters the subnet; // - `True` if node enters the subnet;
// - `False`, otherwise. // - `False`, otherwise.
@ -143,8 +146,11 @@ func IterateSubnets(node *NodeInfo, f func(refs.SubnetID) error) error {
// cut subnet ID string // cut subnet ID string
idTxt := strings.TrimPrefix(key, attrSubnetPrefix) idTxt := strings.TrimPrefix(key, attrSubnetPrefix)
if len(idTxt) == len(key) { if len(idTxt) == len(key) {
// not a subnet attribute idTxt = strings.TrimPrefix(key, attrSubnetPrefixNeoFS)
continue if len(idTxt) == len(key) {
// not a subnet attribute
continue
}
} }
// check value // check value

View file

@ -11,7 +11,7 @@ import (
) )
func subnetAttrKey(val string) string { func subnetAttrKey(val string) string {
return "__NEOFS__SUBNET_" + val return "__FROSTFS__SUBNET_" + val
} }
func assertSubnetAttrKey(t *testing.T, attr *netmap.Attribute, num uint32) { func assertSubnetAttrKey(t *testing.T, attr *netmap.Attribute, num uint32) {

View file

@ -7,7 +7,7 @@ import (
) )
// SysAttributePrefix is a prefix of key to system attribute. // SysAttributePrefix is a prefix of key to system attribute.
const SysAttributePrefix = "__NEOFS__" const SysAttributePrefix = "__FROSTFS__"
const ( const (
// SysAttributeUploadID marks smaller parts of a split bigger object. // SysAttributeUploadID marks smaller parts of a split bigger object.
@ -25,6 +25,25 @@ const (
SysAttributeTickTopic = SysAttributePrefix + "TICK_TOPIC" 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 // NotificationInfo groups information about object notification
// that can be written to object. // that can be written to object.
// //
@ -81,10 +100,10 @@ func WriteNotificationInfo(o *Object, ni NotificationInfo) {
for i := range attrs { for i := range attrs {
switch attrs[i].GetKey() { switch attrs[i].GetKey() {
case SysAttributeTickEpoch: case SysAttributeTickEpoch, SysAttributeTickEpochNeoFS:
attrs[i].SetValue(epoch) attrs[i].SetValue(epoch)
changedEpoch = true changedEpoch = true
case SysAttributeTickTopic: case SysAttributeTickTopic, SysAttributeTickTopicNeoFS:
changedTopic = true changedTopic = true
if topic == "" { if topic == "" {
@ -141,7 +160,7 @@ func GetNotificationInfo(o *Object) (*NotificationInfo, error) {
for _, attr := range o.GetHeader().GetAttributes() { for _, attr := range o.GetHeader().GetAttributes() {
switch key := attr.GetKey(); key { switch key := attr.GetKey(); key {
case SysAttributeTickEpoch: case SysAttributeTickEpoch, SysAttributeTickEpochNeoFS:
epoch, err := strconv.ParseUint(attr.GetValue(), 10, 64) epoch, err := strconv.ParseUint(attr.GetValue(), 10, 64)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not parse epoch: %w", err) return nil, fmt.Errorf("could not parse epoch: %w", err)
@ -150,7 +169,7 @@ func GetNotificationInfo(o *Object) (*NotificationInfo, error) {
ni.SetEpoch(epoch) ni.SetEpoch(epoch)
foundEpoch = true foundEpoch = true
case SysAttributeTickTopic: case SysAttributeTickTopic, SysAttributeTickTopicNeoFS:
ni.SetTopic(attr.GetValue()) ni.SetTopic(attr.GetValue())
} }
} }

View file

@ -1,7 +1,7 @@
package session package session
// ReservedXHeaderPrefix is a prefix of keys to "well-known" X-headers. // ReservedXHeaderPrefix is a prefix of keys to "well-known" X-headers.
const ReservedXHeaderPrefix = "__NEOFS__" const ReservedXHeaderPrefix = "__FROSTFS__"
const ( const (
// XHeaderNetmapEpoch is a key to the reserved X-header that specifies netmap epoch // 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. // set, the current epoch only will be used.
XHeaderNetmapLookupDepth = ReservedXHeaderPrefix + "NETMAP_LOOKUP_DEPTH" 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"
)