[#250] v2/container: Add epoch field to size announce body

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-01-26 21:32:33 +03:00 committed by Alex Vanin
parent 5566081d2d
commit e27d76e804
7 changed files with 41 additions and 2 deletions

View file

@ -857,6 +857,8 @@ func UsedSpaceAnnouncementToGRPCMessage(a *UsedSpaceAnnouncement) *container.Ann
m := new(container.AnnounceUsedSpaceRequest_Body_Announcement)
m.SetEpoch(a.GetEpoch())
m.SetContainerId(
refs.ContainerIDToGRPCMessage(a.GetContainerID()),
)
@ -873,6 +875,8 @@ func UsedSpaceAnnouncementFromGRPCMessage(m *container.AnnounceUsedSpaceRequest_
a := new(UsedSpaceAnnouncement)
a.SetEpoch(m.GetEpoch())
a.SetContainerID(
refs.ContainerIDFromGRPCMessage(m.GetContainerId()),
)

View file

@ -354,6 +354,13 @@ func (m *GetExtendedACLResponse) SetVerifyHeader(v *session.ResponseVerification
}
}
// SetEpoch sets epoch of the size estimation.
func (m *AnnounceUsedSpaceRequest_Body_Announcement) SetEpoch(v uint64) {
if m != nil {
m.Epoch = v
}
}
// SetContainerId sets identifier of the container.
func (m *AnnounceUsedSpaceRequest_Body_Announcement) SetContainerId(v *refs.ContainerID) {
if m != nil {

Binary file not shown.

View file

@ -41,8 +41,9 @@ const (
getEACLRespBodyTableField = 1
getEACLRespBodySignatureField = 2
usedSpaceAnnounceCIDField = 1
usedSpaceAnnounceUsedSpaceField = 2
usedSpaceAnnounceEpochField = 1
usedSpaceAnnounceCIDField = 2
usedSpaceAnnounceUsedSpaceField = 3
usedSpaceReqBodyAnnouncementsField = 1
)
@ -554,6 +555,13 @@ func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) ([]byte, error) {
err error
)
n, err = protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
if err != nil {
return nil, err
@ -574,6 +582,7 @@ func (a *UsedSpaceAnnouncement) StableSize() (size int) {
return 0
}
size += protoutil.UInt64Size(usedSpaceAnnounceEpochField, a.epoch)
size += protoutil.NestedStructureSize(usedSpaceAnnounceCIDField, a.cid)
size += protoutil.UInt64Size(usedSpaceAnnounceUsedSpaceField, a.usedSpace)

View file

@ -455,6 +455,7 @@ func generateAnnounceRequestBody(n int) *container.AnnounceUsedSpaceRequestBody
cid.SetValue(buf)
a := new(container.UsedSpaceAnnouncement)
a.SetEpoch(rand.Uint64())
a.SetContainerID(cid)
a.SetUsedSpace(rand.Uint64())
}

View file

@ -418,10 +418,12 @@ func testAnnounceRequest() *container.AnnounceUsedSpaceRequest {
cid2.SetValue([]byte{4, 5, 6})
a1 := new(container.UsedSpaceAnnouncement)
a1.SetEpoch(20)
a1.SetUsedSpace(10)
a1.SetContainerID(cid1)
a2 := new(container.UsedSpaceAnnouncement)
a2.SetEpoch(20)
a2.SetUsedSpace(20)
a2.SetContainerID(cid2)

View file

@ -94,6 +94,8 @@ type GetExtendedACLResponseBody struct {
}
type UsedSpaceAnnouncement struct {
epoch uint64
cid *refs.ContainerID
usedSpace uint64
@ -917,6 +919,20 @@ func (r *GetExtendedACLResponse) SetVerificationHeader(v *session.ResponseVerifi
}
}
func (a *UsedSpaceAnnouncement) GetEpoch() uint64 {
if a != nil {
return a.epoch
}
return 0
}
func (a *UsedSpaceAnnouncement) SetEpoch(v uint64) {
if a != nil {
a.epoch = v
}
}
func (a *UsedSpaceAnnouncement) GetUsedSpace() uint64 {
if a != nil {
return a.usedSpace