object: Introduce parent attributes in EC-header #224

Merged
fyrchik merged 1 commit from aarifullin/frostfs-sdk-go:feat/ec_parent_attr into master 2024-05-31 16:41:36 +00:00
5 changed files with 57 additions and 11 deletions

2
go.mod
View file

@ -3,7 +3,7 @@ module git.frostfs.info/TrueCloudLab/frostfs-sdk-go
go 1.20 go 1.20
require ( 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-contract v0.0.0-20230307110621-19a8ef2d02fb
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/hrw v1.2.1

BIN
go.sum

Binary file not shown.

View file

@ -13,18 +13,34 @@ type ECHeader struct {
parent oid.ID parent oid.ID
parentSplitID *SplitID parentSplitID *SplitID
parentSplitParentID *oid.ID parentSplitParentID *oid.ID
parentAttributes []Attribute
index uint32 index uint32
total uint32 total uint32
header []byte header []byte
headerLength uint32 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. // 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{ return &ECHeader{
parent: parent, parent: ecParentInfo.ID,
parentSplitID: parentSplitID, parentSplitID: ecParentInfo.SplitID,
parentSplitParentID: parentSplitParentID, parentSplitParentID: ecParentInfo.SplitParentID,
parentAttributes: ecParentInfo.Attributes,
index: index, index: index,
total: total, total: total,
header: header, header: header,
@ -45,6 +61,13 @@ func (e *ECHeader) WriteToV2(h *object.ECHeader) {
} }
h.Parent = &parent 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.Index = e.index
h.Total = e.total h.Total = e.total
h.Header = e.header h.Header = e.header
@ -60,6 +83,12 @@ func (e *ECHeader) ReadFromV2(h *object.ECHeader) error {
return errors.New("empty parent") 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.parent.ReadFromV2(*h.Parent)
e.parentSplitID = NewSplitIDFromV2(h.ParentSplitID) e.parentSplitID = NewSplitIDFromV2(h.ParentSplitID)
if h.ParentSplitParentID != nil { if h.ParentSplitParentID != nil {
@ -123,6 +152,14 @@ func (e *ECHeader) SetParentSplitParentID(parentSplitParentID *oid.ID) {
e.parentSplitParentID = parentSplitParentID 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 { func (e *ECHeader) Index() uint32 {
return e.index return e.index
} }

View file

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