[#669] Optimize PutLockInfo

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
Alexey Vanin 2022-08-29 14:30:38 +03:00 committed by Alex Vanin
parent e06f6f1c2a
commit 5ffe28a42f
2 changed files with 14 additions and 6 deletions

View file

@ -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) { if p.Lock != nil && (p.Lock.Retention != nil || p.Lock.LegalHold != nil) {
prm := &PutLockInfoParams{ putLockInfoPrms := &PutLockInfoParams{
ObjVersion: &ObjectVersion{ ObjVersion: &ObjectVersion{
BktInfo: p.BktInfo, BktInfo: p.BktInfo,
ObjectName: p.Object, ObjectName: p.Object,
@ -263,9 +263,10 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object
}, },
NewLock: p.Lock, NewLock: p.Lock,
CopiesNumber: p.CopiesNumber, 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 return nil, err
} }
} }

View file

@ -23,16 +23,23 @@ type PutLockInfoParams struct {
ObjVersion *ObjectVersion ObjVersion *ObjectVersion
NewLock *data.ObjectLock NewLock *data.ObjectLock
CopiesNumber uint32 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 ( var (
cnrID = p.ObjVersion.BktInfo.CID cnrID = p.ObjVersion.BktInfo.CID
newLock = p.NewLock newLock = p.NewLock
) )
versionNode, err := n.getNodeVersion(ctx, p.ObjVersion)
if err != nil { versionNode := p.NodeVersion
return err // 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) lockInfo, err := n.treeService.GetLock(ctx, cnrID, versionNode.ID)