2020-12-17 16:13:34 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
objutil "github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/checksum"
|
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/storagegroup"
|
|
|
|
"github.com/TrueCloudLab/tzhash/tz"
|
2020-12-17 16:13:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CollectMembers creates new storage group structure and fills it
|
|
|
|
// with information about members collected via HeadReceiver.
|
|
|
|
//
|
|
|
|
// Resulting storage group consists of physically stored objects only.
|
2022-04-29 17:02:52 +00:00
|
|
|
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID, calcHomoHash bool) (*storagegroup.StorageGroup, error) {
|
2020-12-17 16:13:34 +00:00
|
|
|
var (
|
|
|
|
sumPhySize uint64
|
2022-05-31 17:00:41 +00:00
|
|
|
phyMembers []oid.ID
|
2020-12-17 16:13:34 +00:00
|
|
|
phyHashes [][]byte
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2022-05-13 09:25:13 +00:00
|
|
|
sg storagegroup.StorageGroup
|
2020-12-17 16:13:34 +00:00
|
|
|
)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.SetContainer(cnr)
|
2020-12-17 16:13:34 +00:00
|
|
|
|
|
|
|
for i := range members {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.SetObject(members[i])
|
2020-12-17 16:13:34 +00:00
|
|
|
|
|
|
|
if err := objutil.IterateAllSplitLeaves(r, addr, func(leaf *object.Object) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, ok := leaf.ID()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
phyMembers = append(phyMembers, id)
|
2020-12-17 16:13:34 +00:00
|
|
|
sumPhySize += leaf.PayloadSize()
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := leaf.PayloadHomomorphicHash()
|
2022-04-29 17:02:52 +00:00
|
|
|
|
|
|
|
if calcHomoHash {
|
|
|
|
phyHashes = append(phyHashes, cs.Value())
|
|
|
|
}
|
2020-12-17 16:13:34 +00:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sg.SetMembers(phyMembers)
|
|
|
|
sg.SetValidationDataSize(sumPhySize)
|
2022-04-29 17:02:52 +00:00
|
|
|
|
|
|
|
if calcHomoHash {
|
|
|
|
sumHash, err := tz.Concat(phyHashes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cs checksum.Checksum
|
|
|
|
tzHash := [64]byte{}
|
|
|
|
copy(tzHash[:], sumHash)
|
|
|
|
cs.SetTillichZemor(tzHash)
|
|
|
|
|
|
|
|
sg.SetValidationDataHash(cs)
|
|
|
|
}
|
2020-12-17 16:13:34 +00:00
|
|
|
|
2022-05-13 09:25:13 +00:00
|
|
|
return &sg, nil
|
2020-12-17 16:13:34 +00:00
|
|
|
}
|