forked from TrueCloudLab/frostfs-node
[#1365] cli: Calculate homomorphic hash flexibly
Do not use homomorphic hash in storage group for containers that have `homomorphic_hashing_disabled` set to `true`. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
a455f4e3a7
commit
ab749460cd
2 changed files with 31 additions and 18 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
objectCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/object"
|
||||
sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
|
@ -71,8 +72,16 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
var (
|
||||
headPrm internalclient.HeadObjectPrm
|
||||
putPrm internalclient.PutObjectPrm
|
||||
getCnrPrm internalclient.GetContainerPrm
|
||||
)
|
||||
|
||||
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
||||
getCnrPrm.SetClient(cli)
|
||||
getCnrPrm.SetContainer(cnr)
|
||||
|
||||
resGetCnr, err := internalclient.GetContainer(getCnrPrm)
|
||||
common.ExitOnErr(cmd, "get container RPC call: %w", err)
|
||||
|
||||
sessionCli.Prepare(cmd, cnr, nil, pk, &putPrm)
|
||||
objectCli.Prepare(cmd, &headPrm, &putPrm)
|
||||
|
||||
|
@ -83,11 +92,9 @@ func putSG(cmd *cobra.Command, _ []string) {
|
|||
key: pk,
|
||||
ownerID: &ownerID,
|
||||
prm: headPrm,
|
||||
}, cnr, members)
|
||||
}, cnr, members, !container.IsHomomorphicHashingDisabled(resGetCnr.Container()))
|
||||
common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
|
||||
|
||||
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
||||
|
||||
var netInfoPrm internalclient.NetworkInfoPrm
|
||||
netInfoPrm.SetClient(cli)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// with information about members collected via HeadReceiver.
|
||||
//
|
||||
// Resulting storage group consists of physically stored objects only.
|
||||
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*storagegroup.StorageGroup, error) {
|
||||
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID, calcHomoHash bool) (*storagegroup.StorageGroup, error) {
|
||||
var (
|
||||
sumPhySize uint64
|
||||
phyMembers []oid.ID
|
||||
|
@ -37,12 +37,19 @@ func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*stor
|
|||
phyMembers = append(phyMembers, id)
|
||||
sumPhySize += leaf.PayloadSize()
|
||||
cs, _ := leaf.PayloadHomomorphicHash()
|
||||
|
||||
if calcHomoHash {
|
||||
phyHashes = append(phyHashes, cs.Value())
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
sg.SetMembers(phyMembers)
|
||||
sg.SetValidationDataSize(sumPhySize)
|
||||
|
||||
if calcHomoHash {
|
||||
sumHash, err := tz.Concat(phyHashes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -53,9 +60,8 @@ func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*stor
|
|||
copy(tzHash[:], sumHash)
|
||||
cs.SetTillichZemor(tzHash)
|
||||
|
||||
sg.SetMembers(phyMembers)
|
||||
sg.SetValidationDataSize(sumPhySize)
|
||||
sg.SetValidationDataHash(cs)
|
||||
}
|
||||
|
||||
return &sg, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue