[#229] blobovnicza: Store objects in a binary format

In previous implementation Blobovnicza's stored objects in protocol format
which did not allow working with externally compressed objects. To achieve
this goal, operations Get and Put no longer work with the structure of the
object, but only with abstract binary data. Operation GetRange has become
incorrect in its original purpose to receive the payload range. In this
regard, BlobStor receives the payload range of the object through Get
operation. In the future either Blobovnicza will learn to compress objects
by itself, or the GetRange operation will be eliminated.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-02 12:58:42 +03:00 committed by Alex Vanin
parent 3d77fdb347
commit eaae5a5dd7
6 changed files with 73 additions and 58 deletions

View file

@ -2,7 +2,6 @@ package blobovnicza
import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors"
"go.etcd.io/bbolt"
)
@ -11,8 +10,6 @@ import (
type PutPrm struct {
addr *objectSDK.Address
obj *object.Object
objData []byte
}
@ -31,11 +28,6 @@ func (p *PutPrm) SetAddress(addr *objectSDK.Address) {
p.addr = addr
}
// SetObject sets the object.
func (p *PutPrm) SetObject(obj *object.Object) {
p.obj = obj
}
// SetMarshaledObject sets binary representation of the object.
func (p *PutPrm) SetMarshaledObject(data []byte) {
p.objData = data
@ -56,9 +48,7 @@ func (p *PutPrm) SetMarshaledObject(data []byte) {
func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) {
addr := prm.addr
if addr == nil {
if addr = prm.obj.Address(); addr == nil {
return nil, errNilAddress
}
return nil, errNilAddress
}
err := b.boltDB.Update(func(tx *bbolt.Tx) error {
@ -66,19 +56,8 @@ func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) {
return ErrFull
}
// marshal the object
data := prm.objData
if data == nil {
var err error
if data, err = prm.obj.Marshal(); err != nil {
return errors.Wrapf(err, "(%T) could not marshal the object", b)
}
}
// TODO: add compression step
// calculate size
sz := uint64(len(data))
sz := uint64(len(prm.objData))
// get bucket for size
buck := tx.Bucket(bucketForSize(sz))
@ -90,7 +69,7 @@ func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) {
}
// save the object in bucket
if err := buck.Put(addressKey(addr), data); err != nil {
if err := buck.Put(addressKey(addr), prm.objData); err != nil {
return errors.Wrapf(err, "(%T) could not save object in bucket", b)
}