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,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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue