[#1969] local_object_storage: Add a type for logical errors

All logic errors are wrapped in `logicerr.Logical` type and do not
affect shard error counter.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-26 15:23:12 +03:00 committed by fyrchik
parent 98034005f1
commit fcdbf5e509
42 changed files with 206 additions and 139 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"go.uber.org/zap"
)
@ -62,9 +63,7 @@ func (b *Blobovniczas) Delete(prm common.DeletePrm) (res common.DeleteRes, err e
if err == nil && !objectFound {
// not found in any blobovnicza
var errNotFound apistatus.ObjectNotFound
return common.DeleteRes{}, errNotFound
return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
return
@ -117,9 +116,7 @@ func (b *Blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
// and it's pointless to open them).
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound
return common.DeleteRes{}, errNotFound
return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
// open blobovnicza (cached inside)

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
"go.uber.org/zap"
@ -54,9 +55,7 @@ func (b *Blobovniczas) Get(prm common.GetPrm) (res common.GetRes, err error) {
if err == nil && res.Object == nil {
// not found in any blobovnicza
var errNotFound apistatus.ObjectNotFound
return res, errNotFound
return res, logicerr.Wrap(apistatus.ObjectNotFound{})
}
return
@ -110,9 +109,7 @@ func (b *Blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
// and it's pointless to open them).
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound
return common.GetRes{}, errNotFound
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
// open blobovnicza (cached inside)

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
"go.uber.org/zap"
@ -58,9 +59,7 @@ func (b *Blobovniczas) GetRange(prm common.GetRangePrm) (res common.GetRangeRes,
if err == nil && !objectFound {
// not found in any blobovnicza
var errNotFound apistatus.ObjectNotFound
return common.GetRangeRes{}, errNotFound
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
return
@ -125,9 +124,7 @@ func (b *Blobovniczas) getRangeFromLevel(prm common.GetRangePrm, blzPath string,
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
b.log.Debug("index is too big", zap.String("path", blzPath))
var errNotFound apistatus.ObjectNotFound
return common.GetRangeRes{}, errNotFound
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
// open blobovnicza (cached inside)
@ -170,7 +167,7 @@ func (b *Blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm common.G
payload := obj.Payload()
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
return common.GetRangeRes{}, apistatus.ObjectOutOfRange{}
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectOutOfRange{})
}
return common.GetRangeRes{

View file

@ -1,10 +1,14 @@
package common
import "errors"
import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
)
// ErrReadOnly MUST be returned for modifying operations when the storage was opened
// in readonly mode.
var ErrReadOnly = errors.New("opened as read-only")
var ErrReadOnly = logicerr.Wrap(errors.New("opened as read-only"))
// ErrNoSpace MUST be returned when there is no space to put an object on the device.
var ErrNoSpace = errors.New("no free space")
var ErrNoSpace = logicerr.Wrap(errors.New("no free space"))

View file

@ -12,6 +12,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
"github.com/nspcc-dev/neofs-node/pkg/util"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -192,15 +193,14 @@ func (t *FSTree) Delete(prm common.DeletePrm) (common.DeleteRes, error) {
p, err := t.getPath(prm.Address)
if err != nil {
if os.IsNotExist(err) {
var errNotFound apistatus.ObjectNotFound
err = errNotFound
err = logicerr.Wrap(apistatus.ObjectNotFound{})
}
return common.DeleteRes{}, err
}
err = os.Remove(p)
if err != nil && os.IsNotExist(err) {
err = apistatus.ObjectNotFound{}
err = logicerr.Wrap(apistatus.ObjectNotFound{})
}
return common.DeleteRes{}, err
}
@ -274,8 +274,7 @@ func (t *FSTree) Get(prm common.GetPrm) (common.GetRes, error) {
p := t.treePath(prm.Address)
if _, err := os.Stat(p); os.IsNotExist(err) {
var errNotFound apistatus.ObjectNotFound
return common.GetRes{}, errNotFound
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
data, err := os.ReadFile(p)
@ -308,7 +307,7 @@ func (t *FSTree) GetRange(prm common.GetRangePrm) (common.GetRangeRes, error) {
to := from + prm.Range.GetLength()
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
return common.GetRangeRes{}, apistatus.ObjectOutOfRange{}
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectOutOfRange{})
}
return common.GetRangeRes{

View file

@ -4,6 +4,7 @@ import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
)
@ -19,8 +20,7 @@ func (b *BlobStor) Get(prm common.GetPrm) (common.GetRes, error) {
}
}
var errNotFound apistatus.ObjectNotFound
return common.GetRes{}, errNotFound
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
if len(prm.StorageID) == 0 {
return b.storage[len(b.storage)-1].Storage.Get(prm)

View file

@ -4,6 +4,7 @@ import (
"errors"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
)
@ -19,8 +20,7 @@ func (b *BlobStor) GetRange(prm common.GetRangePrm) (common.GetRangeRes, error)
}
}
var errNotFound apistatus.ObjectNotFound
return common.GetRangeRes{}, errNotFound
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
}
if len(prm.StorageID) == 0 {
return b.storage[len(b.storage)-1].Storage.GetRange(prm)

View file

@ -6,12 +6,13 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
)
// ErrNoPlaceFound is returned when object can't be saved to any sub-storage component
// because of the policy.
var ErrNoPlaceFound = errors.New("couldn't find a place to store an object")
var ErrNoPlaceFound = logicerr.Wrap(errors.New("couldn't find a place to store an object"))
// Put saves the object in BLOB storage.
//