[#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:
Pavel Karpy 2022-04-29 20:02:52 +03:00 committed by fyrchik
parent 68e583f143
commit ae86d2907c
2 changed files with 31 additions and 18 deletions

View file

@ -14,6 +14,7 @@ import (
objectCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/object" objectCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/object"
sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session" 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-node/pkg/services/object_manager/storagegroup"
"github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
@ -78,8 +79,16 @@ func putSG(cmd *cobra.Command, _ []string) {
var ( var (
headPrm internalclient.HeadObjectPrm headPrm internalclient.HeadObjectPrm
putPrm internalclient.PutObjectPrm 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) sessionCli.Prepare(cmd, cnr, nil, pk, &putPrm)
objectCli.Prepare(cmd, &headPrm, &putPrm) objectCli.Prepare(cmd, &headPrm, &putPrm)
@ -90,11 +99,9 @@ func putSG(cmd *cobra.Command, _ []string) {
key: pk, key: pk,
ownerID: &ownerID, ownerID: &ownerID,
prm: headPrm, prm: headPrm,
}, cnr, members) }, cnr, members, !container.IsHomomorphicHashingDisabled(resGetCnr.Container()))
common.ExitOnErr(cmd, "could not collect storage group members: %w", err) common.ExitOnErr(cmd, "could not collect storage group members: %w", err)
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
var netInfoPrm internalclient.NetworkInfoPrm var netInfoPrm internalclient.NetworkInfoPrm
netInfoPrm.SetClient(cli) netInfoPrm.SetClient(cli)

View file

@ -14,7 +14,7 @@ import (
// with information about members collected via HeadReceiver. // with information about members collected via HeadReceiver.
// //
// Resulting storage group consists of physically stored objects only. // 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 ( var (
sumPhySize uint64 sumPhySize uint64
phyMembers []oid.ID phyMembers []oid.ID
@ -37,12 +37,19 @@ func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*stor
phyMembers = append(phyMembers, id) phyMembers = append(phyMembers, id)
sumPhySize += leaf.PayloadSize() sumPhySize += leaf.PayloadSize()
cs, _ := leaf.PayloadHomomorphicHash() cs, _ := leaf.PayloadHomomorphicHash()
if calcHomoHash {
phyHashes = append(phyHashes, cs.Value()) phyHashes = append(phyHashes, cs.Value())
}
}); err != nil { }); err != nil {
return nil, err return nil, err
} }
} }
sg.SetMembers(phyMembers)
sg.SetValidationDataSize(sumPhySize)
if calcHomoHash {
sumHash, err := tz.Concat(phyHashes) sumHash, err := tz.Concat(phyHashes)
if err != nil { if err != nil {
return nil, err return nil, err
@ -53,9 +60,8 @@ func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*stor
copy(tzHash[:], sumHash) copy(tzHash[:], sumHash)
cs.SetTillichZemor(tzHash) cs.SetTillichZemor(tzHash)
sg.SetMembers(phyMembers)
sg.SetValidationDataSize(sumPhySize)
sg.SetValidationDataHash(cs) sg.SetValidationDataHash(cs)
}
return &sg, nil return &sg, nil
} }