forked from TrueCloudLab/frostfs-api-go
[#399] container: Support homomorphic hash disabling
Container could now have "__NEOFS__DISABLE_HOMOMORPHIC_HASHING" well-known attribute. Setting that to "true" means disabling homomorphic hashing for objects that belong to that container, any other cases mean that homomorphic hashing is enabled. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
417fd3a08b
commit
c6f7ab3ef1
2 changed files with 116 additions and 0 deletions
|
@ -12,7 +12,64 @@ const (
|
|||
|
||||
// SysAttributeZone is a string of zone for container name.
|
||||
SysAttributeZone = SysAttributePrefix + "ZONE"
|
||||
|
||||
// SysAttributeHomomorphicHashing is a container's homomorphic hashing state.
|
||||
SysAttributeHomomorphicHashing = SysAttributePrefix + "DISABLE_HOMOMORPHIC_HASHING"
|
||||
)
|
||||
|
||||
// SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
|
||||
const SysAttributeZoneDefault = "container"
|
||||
|
||||
const disabledHomomorphicHashingValue = "true"
|
||||
|
||||
// HomomorphicHashingState returns container's homomorphic
|
||||
// hashing state:
|
||||
// * true if hashing is enabled;
|
||||
// * false if hashing is disabled.
|
||||
//
|
||||
// All container's attributes must be unique, otherwise behavior
|
||||
// is undefined.
|
||||
//
|
||||
// See also SetHomomorphicHashingState.
|
||||
func (c Container) HomomorphicHashingState() bool {
|
||||
for i := range c.attr {
|
||||
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing {
|
||||
return c.attr[i].GetValue() != disabledHomomorphicHashingValue
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// SetHomomorphicHashingState sets homomorphic hashing state for
|
||||
// container.
|
||||
//
|
||||
// All container's attributes must be unique, otherwise behavior
|
||||
// is undefined.
|
||||
//
|
||||
// See also HomomorphicHashingState.
|
||||
func (c *Container) SetHomomorphicHashingState(enable bool) {
|
||||
for i := range c.attr {
|
||||
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing {
|
||||
if enable {
|
||||
// approach without allocation/waste
|
||||
// coping works since the attributes
|
||||
// order is not important
|
||||
c.attr[i] = c.attr[len(c.attr)-1]
|
||||
c.attr = c.attr[:len(c.attr)-1]
|
||||
} else {
|
||||
c.attr[i].SetValue(disabledHomomorphicHashingValue)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !enable {
|
||||
attr := Attribute{}
|
||||
attr.SetKey(SysAttributeHomomorphicHashing)
|
||||
attr.SetValue(disabledHomomorphicHashingValue)
|
||||
|
||||
c.attr = append(c.attr, attr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue