forked from TrueCloudLab/frostfs-api-go
[#82] object: Introduce new fields for EC header
* Regenerate protobufs as frostfs-api introduced `parent_split_id` and `parent_split_index` fields. * Fix marshaller and converter for EC header. * Extend v2 type `ECHeader` with `ParentSplitID` and `ParentSplitIndex` fields. * Fix message_test for `Object`. Also generate EC headers and check it. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
b171364079
commit
bc7b49eed2
7 changed files with 54 additions and 20 deletions
|
@ -269,6 +269,8 @@ func (h *ECHeader) ToGRPCMessage() grpc.Message {
|
||||||
m = new(object.Header_EC)
|
m = new(object.Header_EC)
|
||||||
|
|
||||||
m.Parent = h.Parent.ToGRPCMessage().(*refsGRPC.ObjectID)
|
m.Parent = h.Parent.ToGRPCMessage().(*refsGRPC.ObjectID)
|
||||||
|
m.ParentSplitId = h.ParentSplitID
|
||||||
|
m.ParentSplitIndex = h.ParentSplitIndex
|
||||||
m.Index = h.Index
|
m.Index = h.Index
|
||||||
m.Total = h.Total
|
m.Total = h.Total
|
||||||
m.Header = h.Header
|
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.Index = v.GetIndex()
|
||||||
h.Total = v.GetTotal()
|
h.Total = v.GetTotal()
|
||||||
h.Header = v.GetHeader()
|
h.Header = v.GetHeader()
|
||||||
|
|
BIN
object/grpc/service.pb.go
generated
BIN
object/grpc/service.pb.go
generated
Binary file not shown.
BIN
object/grpc/types.pb.go
generated
BIN
object/grpc/types.pb.go
generated
Binary file not shown.
|
@ -31,6 +31,8 @@ const (
|
||||||
ecHdrTotalField = 3
|
ecHdrTotalField = 3
|
||||||
ecHdrHeaderLengthField = 4
|
ecHdrHeaderLengthField = 4
|
||||||
ecHdrHeaderField = 5
|
ecHdrHeaderField = 5
|
||||||
|
ecHdrParentSplitID = 6
|
||||||
|
ecHdrParentSplitIndex = 7
|
||||||
|
|
||||||
hdrVersionField = 1
|
hdrVersionField = 1
|
||||||
hdrContainerIDField = 2
|
hdrContainerIDField = 2
|
||||||
|
@ -260,7 +262,9 @@ func (h *ECHeader) StableMarshal(buf []byte) []byte {
|
||||||
offset += proto.UInt32Marshal(ecHdrIndexField, buf[offset:], h.Index)
|
offset += proto.UInt32Marshal(ecHdrIndexField, buf[offset:], h.Index)
|
||||||
offset += proto.UInt32Marshal(ecHdrTotalField, buf[offset:], h.Total)
|
offset += proto.UInt32Marshal(ecHdrTotalField, buf[offset:], h.Total)
|
||||||
offset += proto.UInt32Marshal(ecHdrHeaderLengthField, buf[offset:], h.HeaderLength)
|
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
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +278,8 @@ func (h *ECHeader) StableSize() (size int) {
|
||||||
size += proto.UInt32Size(ecHdrTotalField, h.Total)
|
size += proto.UInt32Size(ecHdrTotalField, h.Total)
|
||||||
size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength)
|
size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength)
|
||||||
size += proto.BytesSize(ecHdrHeaderField, h.Header)
|
size += proto.BytesSize(ecHdrHeaderField, h.Header)
|
||||||
|
size += proto.BytesSize(ecHdrParentSplitID, h.ParentSplitID)
|
||||||
|
size += proto.UInt32Size(ecHdrParentSplitIndex, h.ParentSplitIndex)
|
||||||
|
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.GenerateShortHeader(empty) },
|
||||||
func(empty bool) message.Message { return objecttest.GenerateAttribute(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.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.GenerateObject(empty) },
|
||||||
func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) },
|
func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) },
|
||||||
func(empty bool) message.Message { return objecttest.GenerateECInfo(empty) },
|
func(empty bool) message.Message { return objecttest.GenerateECInfo(empty) },
|
||||||
|
|
|
@ -68,17 +68,41 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
|
||||||
m.SetParentSignature(refstest.GenerateSignature(empty))
|
m.SetParentSignature(refstest.GenerateSignature(empty))
|
||||||
|
|
||||||
if withPar {
|
if withPar {
|
||||||
m.SetParentHeader(generateHeader(empty, false))
|
m.SetParentHeader(GenerateHeaderWithSplitHeader(empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateHeader(empty bool) *object.Header {
|
func GenerateHeaderWithSplitHeader(empty bool) *object.Header {
|
||||||
return generateHeader(empty, true)
|
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)
|
m := new(object.Header)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
|
@ -95,10 +119,6 @@ func generateHeader(empty, withSplit bool) *object.Header {
|
||||||
m.SetHomomorphicHash(refstest.GenerateChecksum(empty))
|
m.SetHomomorphicHash(refstest.GenerateChecksum(empty))
|
||||||
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
|
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
|
||||||
|
|
||||||
if withSplit {
|
|
||||||
m.SetSplit(generateSplitHeader(empty, false))
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +126,7 @@ func GenerateHeaderWithSignature(empty bool) *object.HeaderWithSignature {
|
||||||
m := new(object.HeaderWithSignature)
|
m := new(object.HeaderWithSignature)
|
||||||
|
|
||||||
m.SetSignature(refstest.GenerateSignature(empty))
|
m.SetSignature(refstest.GenerateSignature(empty))
|
||||||
m.SetHeader(GenerateHeader(empty))
|
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -120,7 +140,7 @@ func GenerateObject(empty bool) *object.Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetSignature(refstest.GenerateSignature(empty))
|
m.SetSignature(refstest.GenerateSignature(empty))
|
||||||
m.SetHeader(GenerateHeader(empty))
|
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -194,7 +214,7 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetSignature(refstest.GenerateSignature(empty))
|
m.SetSignature(refstest.GenerateSignature(empty))
|
||||||
m.SetHeader(GenerateHeader(empty))
|
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -248,7 +268,7 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetSignature(refstest.GenerateSignature(empty))
|
m.SetSignature(refstest.GenerateSignature(empty))
|
||||||
m.SetHeader(GenerateHeader(empty))
|
m.SetHeader(GenerateHeaderWithSplitHeader(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ type SplitHeader struct {
|
||||||
|
|
||||||
type ECHeader struct {
|
type ECHeader struct {
|
||||||
Parent *refs.ObjectID
|
Parent *refs.ObjectID
|
||||||
|
ParentSplitID []byte
|
||||||
|
ParentSplitIndex uint32
|
||||||
Index uint32
|
Index uint32
|
||||||
Total uint32
|
Total uint32
|
||||||
Header []byte
|
Header []byte
|
||||||
|
|
Loading…
Reference in a new issue