[#211] blobstor: Add a branch for processing objects by size in Put

Implement "big or small" property classifier (only the size of the payload
is temporarily considered). Save "big" objects in shallow dir. Save "small"
objects in shallow dir until the moment of implementation of blobovnicza.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-26 10:44:34 +03:00 committed by Alex Vanin
parent cfc770c3fe
commit b9054e2ee0

View file

@ -6,6 +6,7 @@ import (
"path" "path"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -37,8 +38,16 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) {
// compress object data // compress object data
data = b.compressor(data) data = b.compressor(data)
// save object in fs tree if b.isBig(prm.obj) {
// save object in shallow dir
return nil, b.fsTree.put(prm.obj.Address(), data) return nil, b.fsTree.put(prm.obj.Address(), data)
} else {
// save object in blobovnicza
// FIXME: use Blobovnicza when it becomes implemented.
// Temporary save in shallow dir.
return nil, b.fsTree.put(prm.obj.Address(), data)
}
} }
func (t *fsTree) put(addr *objectSDK.Address, data []byte) error { func (t *fsTree) put(addr *objectSDK.Address, data []byte) error {
@ -50,3 +59,14 @@ func (t *fsTree) put(addr *objectSDK.Address, data []byte) error {
return ioutil.WriteFile(p, data, t.Permissions) return ioutil.WriteFile(p, data, t.Permissions)
} }
// checks if object is "big".
func (b *BlobStor) isBig(obj *object.Object) bool {
// FIXME: headers are temporary ignored
// due to slight impact in size.
// In fact, we have to honestly calculate the size
// in binary format, which requires Size() method.
sz := obj.PayloadSize()
return sz > b.smallSizeLimit
}