forked from TrueCloudLab/frostfs-s3-gw
[#669] Use object cache in PutLockInfo optimization
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
5ffe28a42f
commit
272c485706
2 changed files with 32 additions and 4 deletions
|
@ -34,13 +34,18 @@ func (n *layer) PutLockInfo(ctx context.Context, p *PutLockInfoParams) (err erro
|
||||||
|
|
||||||
versionNode := p.NodeVersion
|
versionNode := p.NodeVersion
|
||||||
// sometimes node version can be provided from executing context
|
// 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 {
|
if versionNode == nil {
|
||||||
|
// 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)
|
versionNode, err = n.getNodeVersion(ctx, p.ObjVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lockInfo, err := n.treeService.GetLock(ctx, cnrID, versionNode.ID)
|
lockInfo, err := n.treeService.GetLock(ctx, cnrID, versionNode.ID)
|
||||||
if err != nil && !errorsStd.Is(err, ErrNodeNotFound) {
|
if err != nil && !errorsStd.Is(err, ErrNodeNotFound) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api/errors"
|
"github.com/nspcc-dev/neofs-s3-gw/api/errors"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -169,3 +170,25 @@ func (n *layer) getNodeVersion(ctx context.Context, objVersion *ObjectVersion) (
|
||||||
|
|
||||||
return version, err
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue