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
|
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 {
|
||||||
versionNode, err = n.getNodeVersion(ctx, p.ObjVersion)
|
// check cache if node version is stored inside extendedObjectVersion
|
||||||
if err != nil {
|
versionNode = n.getNodeVersionFromCache(p.ObjVersion)
|
||||||
return err
|
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/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