diff --git a/go.mod b/go.mod index 96ef020..4ec6eca 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6e302d0..f2a2799 100644 Binary files a/go.sum and b/go.sum differ diff --git a/object/erasure_code.go b/object/erasure_code.go index 625f161..bb55fe4 100644 --- a/object/erasure_code.go +++ b/object/erasure_code.go @@ -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 } diff --git a/object/erasurecode/reconstruct.go b/object/erasurecode/reconstruct.go index 4561a7c..ca9767b 100644 --- a/object/erasurecode/reconstruct.go +++ b/object/erasurecode/reconstruct.go @@ -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 diff --git a/object/erasurecode/split.go b/object/erasurecode/split.go index 63895da..bd173a7 100644 --- a/object/erasurecode/split.go +++ b/object/erasurecode/split.go @@ -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