object: Introduce new fields for v2 ECHeader #82

Merged
fyrchik merged 3 commits from aarifullin/frostfs-api-go:feat/ecHeader_parentSplit into master 2024-09-04 19:51:16 +00:00
7 changed files with 54 additions and 20 deletions
Showing only changes of commit bc7b49eed2 - Show all commits

View file

@ -269,6 +269,8 @@ func (h *ECHeader) ToGRPCMessage() grpc.Message {
m = new(object.Header_EC)
m.Parent = h.Parent.ToGRPCMessage().(*refsGRPC.ObjectID)
m.ParentSplitId = h.ParentSplitID
m.ParentSplitIndex = h.ParentSplitIndex
m.Index = h.Index
m.Total = h.Total
m.Header = h.Header
@ -300,6 +302,8 @@ func (h *ECHeader) FromGRPCMessage(m grpc.Message) error {
}
}
h.ParentSplitID = v.GetParentSplitId()
h.ParentSplitIndex = v.GetParentSplitIndex()
h.Index = v.GetIndex()
h.Total = v.GetTotal()
h.Header = v.GetHeader()

Binary file not shown.

BIN
object/grpc/types.pb.go generated

Binary file not shown.

View file

@ -31,6 +31,8 @@ const (
ecHdrTotalField = 3
ecHdrHeaderLengthField = 4
ecHdrHeaderField = 5
ecHdrParentSplitID = 6
ecHdrParentSplitIndex = 7
hdrVersionField = 1
hdrContainerIDField = 2
@ -260,7 +262,9 @@ func (h *ECHeader) StableMarshal(buf []byte) []byte {
offset += proto.UInt32Marshal(ecHdrIndexField, buf[offset:], h.Index)
offset += proto.UInt32Marshal(ecHdrTotalField, buf[offset:], h.Total)
offset += proto.UInt32Marshal(ecHdrHeaderLengthField, buf[offset:], h.HeaderLength)
proto.BytesMarshal(ecHdrHeaderField, buf[offset:], h.Header)
offset += proto.BytesMarshal(ecHdrHeaderField, buf[offset:], h.Header)
offset += proto.BytesMarshal(ecHdrParentSplitID, buf[offset:], h.ParentSplitID)
proto.UInt32Marshal(ecHdrParentSplitIndex, buf[offset:], h.ParentSplitIndex)
return buf
}
@ -274,6 +278,8 @@ func (h *ECHeader) StableSize() (size int) {
size += proto.UInt32Size(ecHdrTotalField, h.Total)
size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength)
size += proto.BytesSize(ecHdrHeaderField, h.Header)
size += proto.BytesSize(ecHdrParentSplitID, h.ParentSplitID)
size += proto.UInt32Size(ecHdrParentSplitIndex, h.ParentSplitIndex)
return size
}

View file

@ -13,7 +13,9 @@ func TestMessageConvert(t *testing.T) {
func(empty bool) message.Message { return objecttest.GenerateShortHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateAttribute(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeaderWithSplitHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeaderWithECHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateECHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateObject(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) },
func(empty bool) message.Message { return objecttest.GenerateECInfo(empty) },

View file

@ -68,17 +68,41 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m.SetParentSignature(refstest.GenerateSignature(empty))
if withPar {
m.SetParentHeader(generateHeader(empty, false))
m.SetParentHeader(GenerateHeaderWithSplitHeader(empty))
}
return m
}
func GenerateHeader(empty bool) *object.Header {
return generateHeader(empty, true)
func GenerateHeaderWithSplitHeader(empty bool) *object.Header {
m := generateHeader(empty)
m.SetSplit(generateSplitHeader(empty, false))
return m
}
func generateHeader(empty, withSplit bool) *object.Header {
func GenerateHeaderWithECHeader(empty bool) *object.Header {
m := generateHeader(empty)
m.SetEC(GenerateECHeader(empty))
return m
}
func GenerateECHeader(empty bool) *object.ECHeader {
ech := new(object.ECHeader)
if !empty {
ech.Parent = refstest.GenerateObjectID(empty)
ech.ParentSplitID = []byte{1, 2, 3}
ech.ParentSplitIndex = 1
ech.Index = 0
ech.Total = 2
ech.Header = []byte("chunk of ec-encoded parent header")
ech.HeaderLength = uint32(2 * len(ech.Header))
}
return ech
}
func generateHeader(empty bool) *object.Header {
m := new(object.Header)
if !empty {
@ -95,10 +119,6 @@ func generateHeader(empty, withSplit bool) *object.Header {
m.SetHomomorphicHash(refstest.GenerateChecksum(empty))
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
if withSplit {
m.SetSplit(generateSplitHeader(empty, false))
}
return m
}
@ -106,7 +126,7 @@ func GenerateHeaderWithSignature(empty bool) *object.HeaderWithSignature {
m := new(object.HeaderWithSignature)
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -120,7 +140,7 @@ func GenerateObject(empty bool) *object.Object {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -194,7 +214,7 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}
@ -248,7 +268,7 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit {
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetHeader(GenerateHeader(empty))
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
return m
}

View file

@ -41,6 +41,8 @@ type SplitHeader struct {
type ECHeader struct {
Parent *refs.ObjectID
ParentSplitID []byte
ParentSplitIndex uint32
Index uint32
Total uint32
Header []byte