2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2020-11-17 16:29:00 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2021-04-08 13:53:25 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
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
|
|
|
}
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
// GetBigRes groups resulting values of GetBig operation.
|
|
|
|
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
|
|
|
//
|
|
|
|
// Returns ErrNotFound if requested object is not
|
|
|
|
// presented in shallow dir.
|
2020-11-24 13:29:55 +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) {
|
2020-11-30 16:39:05 +00:00
|
|
|
return nil, object.ErrNotFound
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not read object from fs tree: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err = b.decompressor(data)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, 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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 13:29:55 +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
|
|
|
|
}
|