[#224] object: Introduce parent attributes in EC-header

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-05-27 13:16:18 +03:00
parent 717a7d00ef
commit ebd8fcd168
5 changed files with 59 additions and 13 deletions

2
go.mod
View file

@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go
go 1.20
require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240529164544-9e825239ac5f
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240530152826-2f6d3209e1d3
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
git.frostfs.info/TrueCloudLab/hrw v1.2.1

4
go.sum
View file

@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240529164544-9e825239ac5f h1:/BC1Aq7WcfZ/g9Y3t2UfZ44/w1Z8s367MYrBSzno0cQ=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240529164544-9e825239ac5f/go.mod h1:OBDSr+DqV1z4VDouoX3YMleNc4DPBVBWTG3WDT2PK1o=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240530152826-2f6d3209e1d3 h1:H5GvrVlowIMWfzqQkhY0p0myooJxQ1sMRVSFfXawwWg=
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240530152826-2f6d3209e1d3/go.mod h1:OBDSr+DqV1z4VDouoX3YMleNc4DPBVBWTG3WDT2PK1o=
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb h1:S/TrbOOu9qEXZRZ9/Ddw7crnxbBUQLo68PSzQWYrc9M=
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o=
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk=

View file

@ -13,18 +13,34 @@ type ECHeader struct {
parent oid.ID
parentSplitID *SplitID
parentSplitParentID *oid.ID
parentAttributes []Attribute
index uint32
total uint32
header []byte
headerLength uint32
}
type ECParentInfo struct {
// EC-parent's ID.
ID oid.ID
// EC-parent's split ID if the parent is a part of Split itself.
SplitID *SplitID
// EC-parent's parent split ID if the parent is a part of Split itself.
SplitParentID *oid.ID
// EC-parent's attributes.
Attributes []Attribute
}
// NewECHeader constructs new erasure coding header.
func NewECHeader(parent oid.ID, parentSplitID *SplitID, parentSplitParentID *oid.ID, index, total uint32, header []byte, headerLength uint32) *ECHeader {
func NewECHeader(ecParentInfo ECParentInfo, index, total uint32, header []byte, headerLength uint32) *ECHeader {
return &ECHeader{
parent: parent,
parentSplitID: parentSplitID,
parentSplitParentID: parentSplitParentID,
parent: ecParentInfo.ID,
parentSplitID: ecParentInfo.SplitID,
parentSplitParentID: ecParentInfo.SplitParentID,
parentAttributes: ecParentInfo.Attributes,
index: index,
total: total,
header: header,
@ -45,6 +61,13 @@ func (e *ECHeader) WriteToV2(h *object.ECHeader) {
}
h.Parent = &parent
attrs := make([]object.Attribute, len(e.parentAttributes))
for i := range e.parentAttributes {
attrs[i] = *e.parentAttributes[i].ToV2()
}
h.ParentAttributes = attrs
h.Index = e.index
h.Total = e.total
h.Header = e.header
@ -60,6 +83,12 @@ func (e *ECHeader) ReadFromV2(h *object.ECHeader) error {
return errors.New("empty parent")
}
attrs := make([]Attribute, len(h.ParentAttributes))
for i := range h.ParentAttributes {
attrs[i] = *NewAttributeFromV2(&h.ParentAttributes[i])
}
e.parentAttributes = attrs
_ = e.parent.ReadFromV2(*h.Parent)
e.parentSplitID = NewSplitIDFromV2(h.ParentSplitID)
if h.ParentSplitParentID != nil {
@ -123,6 +152,14 @@ func (e *ECHeader) SetParentSplitParentID(parentSplitParentID *oid.ID) {
e.parentSplitParentID = parentSplitParentID
}
func (e *ECHeader) ParentAttributes() []Attribute {
return e.parentAttributes
}
func (e *ECHeader) SetParentAttributes(attrs []Attribute) {
e.parentAttributes = attrs
}
func (e *ECHeader) Index() uint32 {
return e.index
}

View file

@ -85,10 +85,13 @@ func (c *Constructor) ReconstructParts(parts []*objectSDK.Object, required []boo
}
ec := parts[nonNilPart].GetECHeader()
parent := ec.Parent()
ecParentInfo := objectSDK.ECParentInfo{
ID: ec.Parent(),
SplitID: ec.ParentSplitID(),
SplitParentID: ec.ParentSplitParentID(),
Attributes: ec.ParentAttributes(),
}
total := ec.Total()
splitID := ec.ParentSplitID()
parSplitParID := ec.ParentSplitParentID()
for i := range required {
if parts[i] != nil || !required[i] {
@ -99,8 +102,7 @@ func (c *Constructor) ReconstructParts(parts []*objectSDK.Object, required []boo
copyRequiredFields(part, parts[nonNilPart])
part.SetPayload(c.payloadShards[i])
part.SetPayloadSize(uint64(len(c.payloadShards[i])))
part.SetECHeader(objectSDK.NewECHeader(parent, splitID, parSplitParID, uint32(i), total,
c.headerShards[i], c.headerLength))
part.SetECHeader(objectSDK.NewECHeader(ecParentInfo, uint32(i), total, c.headerShards[i], c.headerLength))
if err := setIDWithSignature(part, key); err != nil {
return err

View file

@ -41,7 +41,14 @@ func (c *Constructor) Split(obj *objectSDK.Object, key *ecdsa.PrivateKey) ([]*ob
}
}
ec := objectSDK.NewECHeader(parent, obj.SplitID(), parentSplitParentID, uint32(i), uint32(len(payloadShards)), headerShards[i], uint32(len(header)))
ecParentInfo := objectSDK.ECParentInfo{
ID: parent,
SplitID: obj.SplitID(),
SplitParentID: parentSplitParentID,
Attributes: obj.Attributes(),
}
ec := objectSDK.NewECHeader(ecParentInfo, uint32(i), uint32(len(payloadShards)), headerShards[i], uint32(len(header)))
chunk.SetECHeader(ec)
if err := setIDWithSignature(chunk, key); err != nil {
return nil, err