From b9054e2ee053fac9e0b45cb55998bad2c9605ec1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 26 Nov 2020 10:44:34 +0300 Subject: [PATCH] [#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 --- pkg/local_object_storage/blobstor/put.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 016cd57ef..d05c6e49b 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -6,6 +6,7 @@ import ( "path" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/pkg/errors" ) @@ -37,8 +38,16 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) { // compress object data data = b.compressor(data) - // save object in fs tree - return nil, b.fsTree.put(prm.obj.Address(), data) + if b.isBig(prm.obj) { + // save object in shallow dir + 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 { @@ -50,3 +59,14 @@ func (t *fsTree) put(addr *objectSDK.Address, data []byte) error { 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 +}