From 272c4857062eeba8728333c16f3c88e51e7d8d3a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 30 Aug 2022 15:19:28 +0300 Subject: [PATCH] [#669] Use object cache in PutLockInfo optimization Signed-off-by: Alex Vanin --- api/layer/system_object.go | 13 +++++++++---- api/layer/tagging.go | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/api/layer/system_object.go b/api/layer/system_object.go index 3c1068ed..5783ee75 100644 --- a/api/layer/system_object.go +++ b/api/layer/system_object.go @@ -34,11 +34,16 @@ func (n *layer) PutLockInfo(ctx context.Context, p *PutLockInfoParams) (err erro versionNode := p.NodeVersion // sometimes node version can be provided from executing context - // if value is not provided, make a tree service call + // if not, then receive node version from tree service if versionNode == nil { - versionNode, err = n.getNodeVersion(ctx, p.ObjVersion) - if err != nil { - return err + // check cache if node version is stored inside extendedObjectVersion + versionNode = n.getNodeVersionFromCache(p.ObjVersion) + if versionNode == nil { + // else get node version from tree service + versionNode, err = n.getNodeVersion(ctx, p.ObjVersion) + if err != nil { + return err + } } } diff --git a/api/layer/tagging.go b/api/layer/tagging.go index 5d6da64e..001ff5e6 100644 --- a/api/layer/tagging.go +++ b/api/layer/tagging.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/errors" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -169,3 +170,25 @@ func (n *layer) getNodeVersion(ctx context.Context, objVersion *ObjectVersion) ( return version, err } + +func (n *layer) getNodeVersionFromCache(o *ObjectVersion) *data.NodeVersion { + if len(o.VersionID) == 0 || o.VersionID == data.UnversionedObjectVersionID { + return nil + } + + var objID oid.ID + if objID.DecodeString(o.VersionID) != nil { + return nil + } + + var addr oid.Address + addr.SetContainer(o.BktInfo.CID) + addr.SetObject(objID) + + extObjectInfo := n.objCache.GetObject(addr) + if extObjectInfo == nil { + return nil + } + + return extObjectInfo.NodeVersion +}