From bce16de72ad6780dea5371ed384c50603e041391 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 26 Nov 2020 17:17:24 +0300 Subject: [PATCH] [#216] blobstor: Classify objects by size according to binary format In previous implementation objects were classified by size according to payload size. From now they are classified by the size of their binary representation. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/blobstor/put.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index d05c6e49..59069d87 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -6,7 +6,6 @@ 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" ) @@ -35,10 +34,10 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) { return nil, errors.Wrap(err, "could not marshal the object") } - // compress object data - data = b.compressor(data) + if b.isBig(data) { + // compress object data + data = b.compressor(data) - if b.isBig(prm.obj) { // save object in shallow dir return nil, b.fsTree.put(prm.obj.Address(), data) } else { @@ -46,7 +45,7 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) { // FIXME: use Blobovnicza when it becomes implemented. // Temporary save in shallow dir. - return nil, b.fsTree.put(prm.obj.Address(), data) + return nil, b.fsTree.put(prm.obj.Address(), b.compressor(data)) } } @@ -61,12 +60,6 @@ func (t *fsTree) put(addr *objectSDK.Address, data []byte) error { } // 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 +func (b *BlobStor) isBig(data []byte) bool { + return uint64(len(data)) > b.smallSizeLimit }