frostfs-node/pkg/local_object_storage/blobstor/get_big.go
Leonard Lyubich 70ffdf3478 [#1247] object: Return NOT_FOUND and ALREADY_REMOVED statuses
Replace `ErrNotFound`/`ErrAlreadyRemoved` error from
`pkg/core/object` package with `ObjectNotFound`/`ObjectAlreadyRemoved`
one from `apistatus` package. These errors are returned by storage
node's server as NeoFS API statuses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-03-17 16:34:00 +03:00

58 lines
1.4 KiB
Go

package blobstor
import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
)
// GetBigPrm groups the parameters of GetBig operation.
type GetBigPrm struct {
address
}
// GetBigRes groups resulting values of GetBig operation.
type GetBigRes struct {
roObject
}
// GetBig reads the object from shallow dir of BLOB storage by address.
//
// Returns any error encountered that
// did not allow to completely read the object.
//
// Returns apistatus.ObjectNotFound if requested object is not
// presented in shallow dir.
func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) {
// get compressed object data
data, err := b.fsTree.Get(prm.addr)
if err != nil {
if errors.Is(err, fstree.ErrFileNotFound) {
var errNotFound apistatus.ObjectNotFound
return nil, errNotFound
}
return nil, fmt.Errorf("could not read object from fs tree: %w", err)
}
data, err = b.decompressor(data)
if err != nil {
return nil, fmt.Errorf("could not decompress object data: %w", err)
}
// unmarshal the object
obj := objectSDK.New()
if err := obj.Unmarshal(data); err != nil {
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
}
return &GetBigRes{
roObject: roObject{
obj: obj,
},
}, nil
}