From 5ffe28a42fb5a32282341ff2112d3a5ba850b088 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 29 Aug 2022 14:30:38 +0300 Subject: [PATCH] [#669] Optimize PutLockInfo Signed-off-by: Alex Vanin --- api/layer/object.go | 5 +++-- api/layer/system_object.go | 15 +++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api/layer/object.go b/api/layer/object.go index a96e07eb3..f7d1585a5 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -255,7 +255,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object } if p.Lock != nil && (p.Lock.Retention != nil || p.Lock.LegalHold != nil) { - prm := &PutLockInfoParams{ + putLockInfoPrms := &PutLockInfoParams{ ObjVersion: &ObjectVersion{ BktInfo: p.BktInfo, ObjectName: p.Object, @@ -263,9 +263,10 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object }, NewLock: p.Lock, CopiesNumber: p.CopiesNumber, + NodeVersion: newVersion, // provide new version to make one less tree service call in PutLockInfo } - if err = n.PutLockInfo(ctx, prm); err != nil { + if err = n.PutLockInfo(ctx, putLockInfoPrms); err != nil { return nil, err } } diff --git a/api/layer/system_object.go b/api/layer/system_object.go index 019397a40..3c1068ed3 100644 --- a/api/layer/system_object.go +++ b/api/layer/system_object.go @@ -23,16 +23,23 @@ type PutLockInfoParams struct { ObjVersion *ObjectVersion NewLock *data.ObjectLock CopiesNumber uint32 + NodeVersion *data.NodeVersion // optional } -func (n *layer) PutLockInfo(ctx context.Context, p *PutLockInfoParams) error { +func (n *layer) PutLockInfo(ctx context.Context, p *PutLockInfoParams) (err error) { var ( cnrID = p.ObjVersion.BktInfo.CID newLock = p.NewLock ) - versionNode, err := n.getNodeVersion(ctx, p.ObjVersion) - if err != nil { - return err + + versionNode := p.NodeVersion + // sometimes node version can be provided from executing context + // if value is not provided, make a tree service call + if versionNode == nil { + versionNode, err = n.getNodeVersion(ctx, p.ObjVersion) + if err != nil { + return err + } } lockInfo, err := n.treeService.GetLock(ctx, cnrID, versionNode.ID)