2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
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
|
|
|
// GetBigPrm groups the parameters of GetBig operation.
|
|
|
|
type GetBigPrm struct {
|
2020-11-24 13:40:50 +00:00
|
|
|
address
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetBigRes groups the resulting values of GetBig operation.
|
2020-11-24 13:29:55 +00:00
|
|
|
type GetBigRes struct {
|
2020-11-24 13:40:50 +00:00
|
|
|
roObject
|
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-05-31 12:18:32 +00:00
|
|
|
func (b *BlobStor) GetBig(prm GetBigPrm) (GetBigRes, error) {
|
2020-11-17 16:29:00 +00:00
|
|
|
// get compressed object data
|
2021-04-08 13:53:25 +00:00
|
|
|
data, err := b.fsTree.Get(prm.addr)
|
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-05-31 12:18:32 +00:00
|
|
|
return GetBigRes{}, errNotFound
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 12:18:32 +00:00
|
|
|
return GetBigRes{}, 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-05-31 12:18:32 +00:00
|
|
|
return GetBigRes{}, 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-05-31 12:18:32 +00:00
|
|
|
return GetBigRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 12:18:32 +00:00
|
|
|
return GetBigRes{
|
2020-11-24 13:40:50 +00:00
|
|
|
roObject: roObject{
|
|
|
|
obj: obj,
|
|
|
|
},
|
2020-11-17 16:29:00 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
func (b *BlobStor) GetSmall(prm blobovniczatree.GetSmallPrm) (blobovniczatree.GetSmallRes, error) {
|
|
|
|
return b.blobovniczas.Get(prm)
|
|
|
|
}
|