[#273] service/audit: Add cache of head responses in PoR

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-23 16:39:51 +03:00 committed by Alex Vanin
parent 9212864f42
commit afb83c610c
2 changed files with 44 additions and 0 deletions

View file

@ -34,6 +34,8 @@ type Context struct {
} }
cnrNodesNum int cnrNodesNum int
headResponses map[string]shortHeader
} }
type pairMemberInfo struct { type pairMemberInfo struct {
@ -48,6 +50,12 @@ type gamePair struct {
id *object.ID id *object.ID
} }
type shortHeader struct {
tzhash []byte
objectSize uint64
}
// ContextPrm groups components required to conduct data audit checks. // ContextPrm groups components required to conduct data audit checks.
type ContextPrm struct { type ContextPrm struct {
log *logger.Logger log *logger.Logger
@ -114,6 +122,8 @@ func (c *Context) init() {
c.pairedNodes = make(map[uint64]pairMemberInfo) c.pairedNodes = make(map[uint64]pairMemberInfo)
c.headResponses = make(map[string]shortHeader)
c.log = c.log.With( c.log = c.log.With(
zap.Stringer("container ID", c.task.ContainerID()), zap.Stringer("container ID", c.task.ContainerID()),
) )
@ -166,3 +176,34 @@ func (c *Context) buildPlacement(id *object.ID) ([]netmap.Nodes, error) {
return nn, nil return nn, nil
} }
func (c *Context) objectSize(id *object.ID) uint64 {
strID := id.String()
if hdr, ok := c.headResponses[strID]; ok {
return hdr.objectSize
}
return 0
}
func (c *Context) objectHomoHash(id *object.ID) []byte {
strID := id.String()
if hdr, ok := c.headResponses[strID]; ok {
return hdr.tzhash
}
return nil
}
func (c *Context) updateHeadResponses(hdr *object.Object) {
strID := hdr.ID().String()
if _, ok := c.headResponses[strID]; !ok {
c.headResponses[strID] = shortHeader{
tzhash: hdr.PayloadHomomorphicHash().Sum(),
objectSize: hdr.PayloadSize(),
}
}
}

View file

@ -54,6 +54,9 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *object.ID) {
continue continue
} }
// update cache for PoR and PDP audit checks
c.updateHeadResponses(hdr)
if len(tzHash) == 0 { if len(tzHash) == 0 {
tzHash = hdr.PayloadHomomorphicHash().Sum() tzHash = hdr.PayloadHomomorphicHash().Sum()
} else { } else {