From afb83c610cf18ff7b18dd749b66d9ea7c5b35ef3 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 23 Dec 2020 16:39:51 +0300 Subject: [PATCH] [#273] service/audit: Add cache of head responses in PoR Signed-off-by: Alex Vanin --- pkg/services/audit/auditor/context.go | 41 +++++++++++++++++++++++++++ pkg/services/audit/auditor/por.go | 3 ++ 2 files changed, 44 insertions(+) diff --git a/pkg/services/audit/auditor/context.go b/pkg/services/audit/auditor/context.go index 4097537a..f0ebbf1b 100644 --- a/pkg/services/audit/auditor/context.go +++ b/pkg/services/audit/auditor/context.go @@ -34,6 +34,8 @@ type Context struct { } cnrNodesNum int + + headResponses map[string]shortHeader } type pairMemberInfo struct { @@ -48,6 +50,12 @@ type gamePair struct { id *object.ID } +type shortHeader struct { + tzhash []byte + + objectSize uint64 +} + // ContextPrm groups components required to conduct data audit checks. type ContextPrm struct { log *logger.Logger @@ -114,6 +122,8 @@ func (c *Context) init() { c.pairedNodes = make(map[uint64]pairMemberInfo) + c.headResponses = make(map[string]shortHeader) + c.log = c.log.With( zap.Stringer("container ID", c.task.ContainerID()), ) @@ -166,3 +176,34 @@ func (c *Context) buildPlacement(id *object.ID) ([]netmap.Nodes, error) { 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(), + } + } +} diff --git a/pkg/services/audit/auditor/por.go b/pkg/services/audit/auditor/por.go index acd9a064..82ade8e6 100644 --- a/pkg/services/audit/auditor/por.go +++ b/pkg/services/audit/auditor/por.go @@ -54,6 +54,9 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *object.ID) { continue } + // update cache for PoR and PDP audit checks + c.updateHeadResponses(hdr) + if len(tzHash) == 0 { tzHash = hdr.PayloadHomomorphicHash().Sum() } else {