forked from TrueCloudLab/frostfs-api-go
[#356] netmap: Improve docs and slightly optimize the code
API changes: * Rename `Enters` method of the `NodeSubnetInfo` to `Enabled`. * Declare undefined behavior of `WriteSubnetInfo` with non-unique attributes. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
abc494b2bc
commit
50ab22c19c
1 changed files with 9 additions and 6 deletions
|
@ -28,8 +28,8 @@ type NodeSubnetInfo struct {
|
||||||
id *refs.SubnetID
|
id *refs.SubnetID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enters returns true iff node enters the subnet.
|
// Enabled returns true iff subnet membership is enabled for the node.
|
||||||
func (x NodeSubnetInfo) Enters() bool {
|
func (x NodeSubnetInfo) Enabled() bool {
|
||||||
return !x.exit
|
return !x.exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,11 @@ func subnetAttributeKey(id *refs.SubnetID) string {
|
||||||
|
|
||||||
// WriteSubnetInfo writes NodeSubnetInfo to NodeInfo via attributes. NodeInfo must not be nil.
|
// WriteSubnetInfo writes NodeSubnetInfo to NodeInfo via attributes. NodeInfo must not be nil.
|
||||||
//
|
//
|
||||||
|
// Existing subnet attributes are expected to be key-unique, otherwise undefined behavior.
|
||||||
|
//
|
||||||
// Does not add (removes existing) attribute if node:
|
// Does not add (removes existing) attribute if node:
|
||||||
// * exists non-zero subnet;
|
// * disables non-zero subnet;
|
||||||
// * enters zero subnet.
|
// * enables zero subnet.
|
||||||
//
|
//
|
||||||
// Attribute key is calculated from ID using format `__NEOFS__SUBNET_%s`.
|
// Attribute key is calculated from ID using format `__NEOFS__SUBNET_%s`.
|
||||||
// Attribute Value is:
|
// Attribute Value is:
|
||||||
|
@ -68,7 +70,7 @@ func WriteSubnetInfo(node *NodeInfo, info NodeSubnetInfo) {
|
||||||
attrs := node.GetAttributes()
|
attrs := node.GetAttributes()
|
||||||
|
|
||||||
id := info.ID()
|
id := info.ID()
|
||||||
enters := info.Enters()
|
enters := info.Enabled()
|
||||||
|
|
||||||
// calculate attribute key
|
// calculate attribute key
|
||||||
key := subnetAttributeKey(id)
|
key := subnetAttributeKey(id)
|
||||||
|
@ -77,6 +79,7 @@ func WriteSubnetInfo(node *NodeInfo, info NodeSubnetInfo) {
|
||||||
for i := range attrs {
|
for i := range attrs {
|
||||||
if attrs[i].GetKey() == key {
|
if attrs[i].GetKey() == key {
|
||||||
attrs = append(attrs[:i], attrs[i+1:]...)
|
attrs = append(attrs[:i], attrs[i+1:]...)
|
||||||
|
break // attributes are expected to be key-unique
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,7 +144,7 @@ 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 idTxt == key {
|
if len(idTxt) == len(key) {
|
||||||
// not a subnet attribute
|
// not a subnet attribute
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue