2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2021-04-08 13:53:25 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
2022-03-17 08:03:58 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2022-03-03 14:19:05 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2020-11-17 16:29:00 +00:00
|
|
|
)
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
// GetBig reads the object from shallow dir of BLOB storage by address.
|
2020-11-17 16:29:00 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
2020-11-24 13:29:55 +00:00
|
|
|
// did not allow to completely read the object.
|
2020-11-30 16:39:05 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if the requested object is not
|
2020-11-30 16:39:05 +00:00
|
|
|
// presented in shallow dir.
|
2022-07-05 14:07:40 +00:00
|
|
|
func (b *BlobStor) GetBig(prm common.GetPrm) (common.GetRes, error) {
|
2020-11-17 16:29:00 +00:00
|
|
|
// get compressed object data
|
2022-07-05 14:07:40 +00:00
|
|
|
data, err := b.fsTree.Get(prm)
|
2020-11-17 16:29:00 +00:00
|
|
|
if err != nil {
|
2021-04-08 13:53:25 +00:00
|
|
|
if errors.Is(err, fstree.ErrFileNotFound) {
|
2022-03-17 08:03:58 +00:00
|
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
return common.GetRes{}, errNotFound
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
return common.GetRes{}, fmt.Errorf("could not read object from fs tree: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
data, err = b.Decompress(data)
|
2020-11-17 16:29:00 +00:00
|
|
|
if err != nil {
|
2022-07-05 14:07:40 +00:00
|
|
|
return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the object
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := objectSDK.New()
|
2020-11-17 16:29:00 +00:00
|
|
|
if err := obj.Unmarshal(data); err != nil {
|
2022-07-05 14:07:40 +00:00
|
|
|
return common.GetRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
return common.GetRes{Object: obj}, nil
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
func (b *BlobStor) GetSmall(prm common.GetPrm) (common.GetRes, error) {
|
2022-07-05 13:47:39 +00:00
|
|
|
return b.blobovniczas.Get(prm)
|
|
|
|
}
|