forked from TrueCloudLab/frostfs-node
[#216] blobovnicza: Implement main methods and logic
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
52b0c1f19a
commit
07e998d846
10 changed files with 627 additions and 0 deletions
78
pkg/local_object_storage/blobovnicza/get.go
Normal file
78
pkg/local_object_storage/blobovnicza/get.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
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"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// GetPrm groups the parameters of Get operation.
|
||||
type GetPrm struct {
|
||||
addr *objectSDK.Address
|
||||
}
|
||||
|
||||
// GetRes groups resulting values of Get operation.
|
||||
type GetRes struct {
|
||||
obj *object.Object
|
||||
}
|
||||
|
||||
// ErrObjectNotFound is returns on read operations requested on a missing object.
|
||||
var ErrObjectNotFound = errors.New("object not found")
|
||||
|
||||
// SetAddress sets address of the requested object.
|
||||
func (p *GetPrm) SetAddress(addr *objectSDK.Address) {
|
||||
p.addr = addr
|
||||
}
|
||||
|
||||
// Object returns the requested object.
|
||||
func (p *GetRes) Object() *object.Object {
|
||||
return p.obj
|
||||
}
|
||||
|
||||
// Get reads the object from Blobovnicza by address.
|
||||
//
|
||||
// Returns any error encountered that
|
||||
// did not allow to completely read the object.
|
||||
func (b *Blobovnicza) Get(prm *GetPrm) (*GetRes, error) {
|
||||
var (
|
||||
data []byte
|
||||
addrKey = addressKey(prm.addr)
|
||||
)
|
||||
|
||||
if err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
||||
return b.iterateBuckets(tx, func(lower, upper uint64, buck *bbolt.Bucket) (bool, error) {
|
||||
data = buck.Get(addrKey)
|
||||
|
||||
stop := data != nil
|
||||
|
||||
if stop {
|
||||
b.log.Debug("object is found in bucket",
|
||||
zap.String("binary size", stringifyByteSize(uint64(len(data)))),
|
||||
zap.String("range", stringifyBounds(lower, upper)),
|
||||
)
|
||||
}
|
||||
|
||||
return stop, nil
|
||||
})
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return nil, ErrObjectNotFound
|
||||
}
|
||||
|
||||
// TODO: add decompression step
|
||||
|
||||
// unmarshal the object
|
||||
obj := object.New()
|
||||
if err := obj.Unmarshal(data); err != nil {
|
||||
return nil, errors.Wrap(err, "could not unmarshal the object")
|
||||
}
|
||||
|
||||
return &GetRes{
|
||||
obj: obj,
|
||||
}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue