[#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:
parent
98034005f1
commit
fcdbf5e509
42 changed files with 206 additions and 139 deletions
|
@ -1,8 +1,12 @@
|
||||||
package object
|
package object
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
|
)
|
||||||
|
|
||||||
// ErrObjectIsExpired is returned when the requested object's
|
// ErrObjectIsExpired is returned when the requested object's
|
||||||
// epoch is less than the current one. Such objects are considered
|
// epoch is less than the current one. Such objects are considered
|
||||||
// as removed and should not be returned from the Storage Engine.
|
// as removed and should not be returned from the Storage Engine.
|
||||||
var ErrObjectIsExpired = errors.New("object is expired")
|
var ErrObjectIsExpired = logicerr.Wrap(errors.New("object is expired"))
|
||||||
|
|
|
@ -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/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -62,9 +63,7 @@ func (b *Blobovniczas) Delete(prm common.DeletePrm) (res common.DeleteRes, err e
|
||||||
|
|
||||||
if err == nil && !objectFound {
|
if err == nil && !objectFound {
|
||||||
// not found in any blobovnicza
|
// not found in any blobovnicza
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return common.DeleteRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -117,9 +116,7 @@ func (b *Blobovniczas) deleteObjectFromLevel(prm blobovnicza.DeletePrm, blzPath
|
||||||
// and it's pointless to open them).
|
// and it's pointless to open them).
|
||||||
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
||||||
b.log.Debug("index is too big", zap.String("path", blzPath))
|
b.log.Debug("index is too big", zap.String("path", blzPath))
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.DeleteRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return common.DeleteRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open blobovnicza (cached inside)
|
// open blobovnicza (cached inside)
|
||||||
|
|
|
@ -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/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"go.uber.org/zap"
|
"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 {
|
if err == nil && res.Object == nil {
|
||||||
// not found in any blobovnicza
|
// not found in any blobovnicza
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return res, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return res, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -110,9 +109,7 @@ func (b *Blobovniczas) getObjectFromLevel(prm blobovnicza.GetPrm, blzPath string
|
||||||
// and it's pointless to open them).
|
// and it's pointless to open them).
|
||||||
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
||||||
b.log.Debug("index is too big", zap.String("path", blzPath))
|
b.log.Debug("index is too big", zap.String("path", blzPath))
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return common.GetRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open blobovnicza (cached inside)
|
// open blobovnicza (cached inside)
|
||||||
|
|
|
@ -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/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -58,9 +59,7 @@ func (b *Blobovniczas) GetRange(prm common.GetRangePrm) (res common.GetRangeRes,
|
||||||
|
|
||||||
if err == nil && !objectFound {
|
if err == nil && !objectFound {
|
||||||
// not found in any blobovnicza
|
// not found in any blobovnicza
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return common.GetRangeRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -125,9 +124,7 @@ func (b *Blobovniczas) getRangeFromLevel(prm common.GetRangePrm, blzPath string,
|
||||||
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
if u64FromHexString(filepath.Base(blzPath)) > active.ind {
|
||||||
b.log.Debug("index is too big", zap.String("path", blzPath))
|
b.log.Debug("index is too big", zap.String("path", blzPath))
|
||||||
|
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.GetRangeRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return common.GetRangeRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open blobovnicza (cached inside)
|
// open blobovnicza (cached inside)
|
||||||
|
@ -170,7 +167,7 @@ func (b *Blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm common.G
|
||||||
payload := obj.Payload()
|
payload := obj.Payload()
|
||||||
|
|
||||||
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
|
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{
|
return common.GetRangeRes{
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package common
|
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
|
// ErrReadOnly MUST be returned for modifying operations when the storage was opened
|
||||||
// in readonly mode.
|
// 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.
|
// 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"))
|
||||||
|
|
|
@ -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/common"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
|
"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"
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
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)
|
p, err := t.getPath(prm.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
err = logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
err = errNotFound
|
|
||||||
}
|
}
|
||||||
return common.DeleteRes{}, err
|
return common.DeleteRes{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(p)
|
err = os.Remove(p)
|
||||||
if err != nil && os.IsNotExist(err) {
|
if err != nil && os.IsNotExist(err) {
|
||||||
err = apistatus.ObjectNotFound{}
|
err = logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
}
|
}
|
||||||
return common.DeleteRes{}, err
|
return common.DeleteRes{}, err
|
||||||
}
|
}
|
||||||
|
@ -274,8 +274,7 @@ func (t *FSTree) Get(prm common.GetPrm) (common.GetRes, error) {
|
||||||
p := t.treePath(prm.Address)
|
p := t.treePath(prm.Address)
|
||||||
|
|
||||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return common.GetRes{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
return common.GetRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := os.ReadFile(p)
|
data, err := os.ReadFile(p)
|
||||||
|
@ -308,7 +307,7 @@ func (t *FSTree) GetRange(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
||||||
to := from + prm.Range.GetLength()
|
to := from + prm.Range.GetLength()
|
||||||
|
|
||||||
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
|
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{
|
return common.GetRangeRes{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
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{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
return common.GetRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
if len(prm.StorageID) == 0 {
|
if len(prm.StorageID) == 0 {
|
||||||
return b.storage[len(b.storage)-1].Storage.Get(prm)
|
return b.storage[len(b.storage)-1].Storage.Get(prm)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
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{}, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
return common.GetRangeRes{}, errNotFound
|
|
||||||
}
|
}
|
||||||
if len(prm.StorageID) == 0 {
|
if len(prm.StorageID) == 0 {
|
||||||
return b.storage[len(b.storage)-1].Storage.GetRange(prm)
|
return b.storage[len(b.storage)-1].Storage.GetRange(prm)
|
||||||
|
|
|
@ -6,12 +6,13 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"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/blobstor/common"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNoPlaceFound is returned when object can't be saved to any sub-storage component
|
// ErrNoPlaceFound is returned when object can't be saved to any sub-storage component
|
||||||
// because of the policy.
|
// 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.
|
// Put saves the object in BLOB storage.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -77,10 +75,9 @@ func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRe
|
||||||
csPrm.SetContainerID(prm.cnr)
|
csPrm.SetContainerID(prm.cnr)
|
||||||
|
|
||||||
csRes, err := sh.Shard.ContainerSize(csPrm)
|
csRes, err := sh.Shard.ContainerSize(csPrm)
|
||||||
if err != nil && !errors.Is(err, shard.ErrDegradedMode) {
|
if err != nil {
|
||||||
e.reportShardError(sh, "can't get container size", err,
|
e.reportShardError(sh, "can't get container size", err,
|
||||||
zap.Stringer("container_id", prm.cnr),
|
zap.Stringer("container_id", prm.cnr))
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +123,7 @@ func (e *StorageEngine) listContainers() (ListContainersRes, error) {
|
||||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||||
res, err := sh.Shard.ListContainers(shard.ListContainersPrm{})
|
res, err := sh.Shard.ListContainers(shard.ListContainersPrm{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, shard.ErrDegradedMode) {
|
e.reportShardError(sh, "can't get list of containers", err)
|
||||||
e.reportShardError(sh, "can't get list of containers", err)
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
splitErr, ok := err.(*objectSDK.SplitInfoError)
|
var splitErr *objectSDK.SplitInfoError
|
||||||
if !ok {
|
if !errors.As(err, &splitErr) {
|
||||||
if !shard.IsErrNotFound(err) {
|
if !shard.IsErrNotFound(err) {
|
||||||
e.reportShardError(sh, "could not check object existence", err)
|
e.reportShardError(sh, "could not check object existence", err)
|
||||||
}
|
}
|
||||||
|
@ -97,13 +97,7 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
|
||||||
|
|
||||||
_, err = sh.Inhume(shPrm)
|
_, err = sh.Inhume(shPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, shard.ErrReadOnlyMode) || errors.Is(err, shard.ErrDegradedMode) {
|
e.reportShardError(sh, "could not inhume object in shard", err)
|
||||||
e.log.Warn("could not inhume object in shard",
|
|
||||||
zap.Stringer("shard_id", sh.ID()),
|
|
||||||
zap.String("error", err.Error()))
|
|
||||||
} else {
|
|
||||||
e.reportShardError(sh, "could not inhume object in shard", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
locked.is = errors.As(err, &locked.err)
|
locked.is = errors.As(err, &locked.err)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util"
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
@ -40,6 +42,13 @@ func (e *StorageEngine) reportShardError(
|
||||||
msg string,
|
msg string,
|
||||||
err error,
|
err error,
|
||||||
fields ...zap.Field) {
|
fields ...zap.Field) {
|
||||||
|
if isLogical(err) {
|
||||||
|
e.log.Warn(msg,
|
||||||
|
zap.Stringer("shard_id", sh.ID()),
|
||||||
|
zap.String("error", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sid := sh.ID()
|
sid := sh.ID()
|
||||||
errCount := sh.errorCount.Inc()
|
errCount := sh.errorCount.Inc()
|
||||||
e.log.Warn(msg, append([]zap.Field{
|
e.log.Warn(msg, append([]zap.Field{
|
||||||
|
@ -77,6 +86,10 @@ func (e *StorageEngine) reportShardError(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isLogical(err error) bool {
|
||||||
|
return errors.As(err, &logicerr.Logical{})
|
||||||
|
}
|
||||||
|
|
||||||
// Option represents StorageEngine's constructor option.
|
// Option represents StorageEngine's constructor option.
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -22,8 +24,8 @@ func (e *StorageEngine) exists(addr oid.Address) (bool, error) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := err.(*objectSDK.SplitInfoError)
|
var siErr *objectSDK.SplitInfoError
|
||||||
if ok {
|
if errors.As(err, &siErr) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -90,8 +91,6 @@ func (e *StorageEngine) get(prm GetPrm) (GetRes, error) {
|
||||||
case shard.IsErrNotFound(err):
|
case shard.IsErrNotFound(err):
|
||||||
return false // ignore, go to next shard
|
return false // ignore, go to next shard
|
||||||
case errors.As(err, &siErr):
|
case errors.As(err, &siErr):
|
||||||
siErr = err.(*objectSDK.SplitInfoError)
|
|
||||||
|
|
||||||
if outSI == nil {
|
if outSI == nil {
|
||||||
outSI = objectSDK.NewSplitInfo()
|
outSI = objectSDK.NewSplitInfo()
|
||||||
}
|
}
|
||||||
|
@ -128,7 +127,7 @@ func (e *StorageEngine) get(prm GetPrm) (GetRes, error) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if outSI != nil {
|
if outSI != nil {
|
||||||
return GetRes{}, objectSDK.NewSplitInfoError(outSI)
|
return GetRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -86,8 +87,6 @@ func (e *StorageEngine) head(prm HeadPrm) (HeadRes, error) {
|
||||||
case shard.IsErrNotFound(err):
|
case shard.IsErrNotFound(err):
|
||||||
return false // ignore, go to next shard
|
return false // ignore, go to next shard
|
||||||
case errors.As(err, &siErr):
|
case errors.As(err, &siErr):
|
||||||
siErr = err.(*objectSDK.SplitInfoError)
|
|
||||||
|
|
||||||
if outSI == nil {
|
if outSI == nil {
|
||||||
outSI = objectSDK.NewSplitInfo()
|
outSI = objectSDK.NewSplitInfo()
|
||||||
}
|
}
|
||||||
|
@ -127,7 +126,7 @@ func (e *StorageEngine) head(prm HeadPrm) (HeadRes, error) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if outSI != nil {
|
if outSI != nil {
|
||||||
return HeadRes{}, objectSDK.NewSplitInfoError(outSI)
|
return HeadRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
||||||
}
|
}
|
||||||
|
|
||||||
if head == nil {
|
if head == nil {
|
||||||
|
|
|
@ -68,8 +68,8 @@ func TestHeadRaw(t *testing.T) {
|
||||||
_, err = e.Head(headPrm)
|
_, err = e.Head(headPrm)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*object.SplitInfoError)
|
var si *object.SplitInfoError
|
||||||
require.True(t, ok)
|
require.ErrorAs(t, err, &si)
|
||||||
|
|
||||||
// SplitInfoError should contain info from both shards
|
// SplitInfoError should contain info from both shards
|
||||||
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -28,13 +29,13 @@ func (e *StorageEngine) lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error
|
||||||
for i := range locked {
|
for i := range locked {
|
||||||
switch e.lockSingle(idCnr, locker, locked[i], true) {
|
switch e.lockSingle(idCnr, locker, locked[i], true) {
|
||||||
case 1:
|
case 1:
|
||||||
return apistatus.LockNonRegularObject{}
|
return logicerr.Wrap(apistatus.LockNonRegularObject{})
|
||||||
case 0:
|
case 0:
|
||||||
switch e.lockSingle(idCnr, locker, locked[i], false) {
|
switch e.lockSingle(idCnr, locker, locked[i], false) {
|
||||||
case 1:
|
case 1:
|
||||||
return apistatus.LockNonRegularObject{}
|
return logicerr.Wrap(apistatus.LockNonRegularObject{})
|
||||||
case 0:
|
case 0:
|
||||||
return errLockFailed
|
return logicerr.Wrap(errLockFailed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -103,8 +104,6 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) {
|
||||||
case shard.IsErrNotFound(err):
|
case shard.IsErrNotFound(err):
|
||||||
return false // ignore, go to next shard
|
return false // ignore, go to next shard
|
||||||
case errors.As(err, &siErr):
|
case errors.As(err, &siErr):
|
||||||
siErr = err.(*objectSDK.SplitInfoError)
|
|
||||||
|
|
||||||
if outSI == nil {
|
if outSI == nil {
|
||||||
outSI = objectSDK.NewSplitInfo()
|
outSI = objectSDK.NewSplitInfo()
|
||||||
}
|
}
|
||||||
|
@ -138,7 +137,7 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if outSI != nil {
|
if outSI != nil {
|
||||||
return RngRes{}, objectSDK.NewSplitInfoError(outSI)
|
return RngRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -111,9 +109,7 @@ func (e *StorageEngine) list(limit uint64) (SelectRes, error) {
|
||||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||||
res, err := sh.List() // consider limit result of shard iterator
|
res, err := sh.List() // consider limit result of shard iterator
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, shard.ErrDegradedMode) {
|
e.reportShardError(sh, "could not select objects from shard", err)
|
||||||
e.reportShardError(sh, "could not select objects from shard", err)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for _, addr := range res.AddressList() { // save only unique values
|
for _, addr := range res.AddressList() { // save only unique values
|
||||||
if _, ok := uniqueMap[addr.EncodeToString()]; !ok {
|
if _, ok := uniqueMap[addr.EncodeToString()]; !ok {
|
||||||
|
|
|
@ -8,13 +8,14 @@ import (
|
||||||
"github.com/nspcc-dev/hrw"
|
"github.com/nspcc-dev/hrw"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errShardNotFound = errors.New("shard not found")
|
var errShardNotFound = logicerr.Wrap(errors.New("shard not found"))
|
||||||
|
|
||||||
type hashedShard shardWrapper
|
type hashedShard shardWrapper
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util"
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrDegradedMode is returned when metabase is in a degraded mode.
|
// ErrDegradedMode is returned when metabase is in a degraded mode.
|
||||||
var ErrDegradedMode = errors.New("metabase is in a degraded mode")
|
var ErrDegradedMode = logicerr.Wrap(errors.New("metabase is in a degraded mode"))
|
||||||
|
|
||||||
// Open boltDB instance for metabase.
|
// Open boltDB instance for metabase.
|
||||||
func (db *DB) Open(readOnly bool) error {
|
func (db *DB) Open(readOnly bool) error {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -24,7 +25,7 @@ type ExistsRes struct {
|
||||||
exists bool
|
exists bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrLackSplitInfo = errors.New("no split info on parent object")
|
var ErrLackSplitInfo = logicerr.Wrap(errors.New("no split info on parent object"))
|
||||||
|
|
||||||
// SetAddress is an Exists option to set object checked for existence.
|
// SetAddress is an Exists option to set object checked for existence.
|
||||||
func (p *ExistsPrm) SetAddress(addr oid.Address) {
|
func (p *ExistsPrm) SetAddress(addr oid.Address) {
|
||||||
|
@ -60,13 +61,9 @@ func (db *DB) exists(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) (exists b
|
||||||
// check graveyard and object expiration first
|
// check graveyard and object expiration first
|
||||||
switch objectStatus(tx, addr, currEpoch) {
|
switch objectStatus(tx, addr, currEpoch) {
|
||||||
case 1:
|
case 1:
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return false, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return false, errNotFound
|
|
||||||
case 2:
|
case 2:
|
||||||
var errRemoved apistatus.ObjectAlreadyRemoved
|
return false, logicerr.Wrap(apistatus.ObjectAlreadyRemoved{})
|
||||||
|
|
||||||
return false, errRemoved
|
|
||||||
case 3:
|
case 3:
|
||||||
return false, object.ErrObjectIsExpired
|
return false, object.ErrObjectIsExpired
|
||||||
}
|
}
|
||||||
|
@ -88,7 +85,7 @@ func (db *DB) exists(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) (exists b
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, objectSDK.NewSplitInfoError(splitInfo)
|
return false, logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
// if parent bucket is empty, then check if object exists in typed buckets
|
// if parent bucket is empty, then check if object exists in typed buckets
|
||||||
|
|
|
@ -128,9 +128,8 @@ func TestDB_Exists(t *testing.T) {
|
||||||
_, err = metaExists(db, object.AddressOf(parent))
|
_, err = metaExists(db, object.AddressOf(parent))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
var si *objectSDK.SplitInfoError
|
||||||
require.True(t, ok)
|
require.ErrorAs(t, err, &si)
|
||||||
|
|
||||||
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
||||||
|
|
||||||
id1, _ := child.ID()
|
id1, _ := child.ID()
|
||||||
|
@ -152,9 +151,8 @@ func TestDB_Exists(t *testing.T) {
|
||||||
_, err = metaExists(db, object.AddressOf(parent))
|
_, err = metaExists(db, object.AddressOf(parent))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
var si *objectSDK.SplitInfoError
|
||||||
require.True(t, ok)
|
require.ErrorAs(t, err, &si)
|
||||||
|
|
||||||
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
||||||
|
|
||||||
id1, _ := child.ID()
|
id1, _ := child.ID()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -66,13 +67,9 @@ func (db *DB) get(tx *bbolt.Tx, addr oid.Address, key []byte, checkStatus, raw b
|
||||||
if checkStatus {
|
if checkStatus {
|
||||||
switch objectStatus(tx, addr, currEpoch) {
|
switch objectStatus(tx, addr, currEpoch) {
|
||||||
case 1:
|
case 1:
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, errNotFound
|
|
||||||
case 2:
|
case 2:
|
||||||
var errRemoved apistatus.ObjectAlreadyRemoved
|
return nil, logicerr.Wrap(apistatus.ObjectAlreadyRemoved{})
|
||||||
|
|
||||||
return nil, errRemoved
|
|
||||||
case 3:
|
case 3:
|
||||||
return nil, object.ErrObjectIsExpired
|
return nil, object.ErrObjectIsExpired
|
||||||
}
|
}
|
||||||
|
@ -128,9 +125,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD
|
||||||
bucketName := make([]byte, bucketKeySize)
|
bucketName := make([]byte, bucketKeySize)
|
||||||
parentBucket := tx.Bucket(parentBucketName(cnr, bucketName))
|
parentBucket := tx.Bucket(parentBucketName(cnr, bucketName))
|
||||||
if parentBucket == nil {
|
if parentBucket == nil {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
relativeLst, err := decodeList(parentBucket.Get(key))
|
relativeLst, err := decodeList(parentBucket.Get(key))
|
||||||
|
@ -139,9 +134,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(relativeLst) == 0 { // this should never happen though
|
if len(relativeLst) == 0 { // this should never happen though
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pick last item, for now there is not difference which address to pick
|
// pick last item, for now there is not difference which address to pick
|
||||||
|
@ -160,9 +153,7 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD
|
||||||
par := child.Parent()
|
par := child.Parent()
|
||||||
|
|
||||||
if par == nil { // this should never happen though
|
if par == nil { // this should never happen though
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return par, nil
|
return par, nil
|
||||||
|
@ -171,10 +162,8 @@ func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSD
|
||||||
func getSplitInfoError(tx *bbolt.Tx, cnr cid.ID, key []byte) error {
|
func getSplitInfoError(tx *bbolt.Tx, cnr cid.ID, key []byte) error {
|
||||||
splitInfo, err := getSplitInfo(tx, cnr, key)
|
splitInfo, err := getSplitInfo(tx, cnr, key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return objectSDK.NewSplitInfoError(splitInfo)
|
return logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,16 +95,15 @@ func TestDB_Get(t *testing.T) {
|
||||||
_, err = metaGet(db, object.AddressOf(parent), true)
|
_, err = metaGet(db, object.AddressOf(parent), true)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
siErr, ok := err.(*objectSDK.SplitInfoError)
|
var siErr *objectSDK.SplitInfoError
|
||||||
require.True(t, ok)
|
require.ErrorAs(t, err, &siErr)
|
||||||
|
|
||||||
require.Equal(t, splitID, siErr.SplitInfo().SplitID())
|
require.Equal(t, splitID, siErr.SplitInfo().SplitID())
|
||||||
|
|
||||||
id1, _ := child.ID()
|
id1, _ := child.ID()
|
||||||
id2, _ := siErr.SplitInfo().LastPart()
|
id2, _ := siErr.SplitInfo().LastPart()
|
||||||
require.Equal(t, id1, id2)
|
require.Equal(t, id1, id2)
|
||||||
|
|
||||||
_, ok = siErr.SplitInfo().Link()
|
_, ok := siErr.SplitInfo().Link()
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -78,7 +79,7 @@ var errBreakBucketForEach = errors.New("bucket ForEach break")
|
||||||
|
|
||||||
// ErrLockObjectRemoval is returned when inhume operation is being
|
// ErrLockObjectRemoval is returned when inhume operation is being
|
||||||
// performed on lock object, and it is not a forced object removal.
|
// performed on lock object, and it is not a forced object removal.
|
||||||
var ErrLockObjectRemoval = errors.New("lock object removal")
|
var ErrLockObjectRemoval = logicerr.Wrap(errors.New("lock object removal"))
|
||||||
|
|
||||||
// Inhume marks objects as removed but not removes it from metabase.
|
// Inhume marks objects as removed but not removes it from metabase.
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -34,7 +35,7 @@ type ExpiredObjectHandler func(*ExpiredObject) error
|
||||||
|
|
||||||
// ErrInterruptIterator is returned by iteration handlers
|
// ErrInterruptIterator is returned by iteration handlers
|
||||||
// as a "break" keyword.
|
// as a "break" keyword.
|
||||||
var ErrInterruptIterator = errors.New("iterator is interrupted")
|
var ErrInterruptIterator = logicerr.Wrap(errors.New("iterator is interrupted"))
|
||||||
|
|
||||||
// IterateExpired iterates over all objects in DB which are out of date
|
// IterateExpired iterates over all objects in DB which are out of date
|
||||||
// relative to epoch. Locked objects are not included (do not confuse
|
// relative to epoch. Locked objects are not included (do not confuse
|
||||||
|
|
|
@ -3,6 +3,7 @@ package meta
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
|
@ -11,7 +12,7 @@ import (
|
||||||
// ErrEndOfListing is returned from object listing with cursor
|
// ErrEndOfListing is returned from object listing with cursor
|
||||||
// when storage can't return any more objects after provided
|
// when storage can't return any more objects after provided
|
||||||
// cursor. Use nil cursor object to start listing again.
|
// cursor. Use nil cursor object to start listing again.
|
||||||
var ErrEndOfListing = errors.New("end of object listing")
|
var ErrEndOfListing = logicerr.Wrap(errors.New("end of object listing"))
|
||||||
|
|
||||||
// Cursor is a type for continuous object listing.
|
// Cursor is a type for continuous object listing.
|
||||||
type Cursor struct {
|
type Cursor struct {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -41,7 +42,7 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error {
|
||||||
|
|
||||||
return db.boltDB.Update(func(tx *bbolt.Tx) error {
|
return db.boltDB.Update(func(tx *bbolt.Tx) error {
|
||||||
if firstIrregularObjectType(tx, cnr, bucketKeysLocked...) != object.TypeRegular {
|
if firstIrregularObjectType(tx, cnr, bucketKeysLocked...) != object.TypeRegular {
|
||||||
return apistatus.LockNonRegularObject{}
|
return logicerr.Wrap(apistatus.LockNonRegularObject{})
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketLocked := tx.Bucket(bucketNameLocked)
|
bucketLocked := tx.Bucket(bucketNameLocked)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ var versionKey = []byte("version")
|
||||||
// ErrOutdatedVersion is returned on initializing
|
// ErrOutdatedVersion is returned on initializing
|
||||||
// an existing metabase that is not compatible with
|
// an existing metabase that is not compatible with
|
||||||
// the current code version.
|
// the current code version.
|
||||||
var ErrOutdatedVersion = errors.New("invalid version, resynchronization is required")
|
var ErrOutdatedVersion = logicerr.Wrap(errors.New("invalid version, resynchronization is required"))
|
||||||
|
|
||||||
func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
||||||
var knownVersion bool
|
var knownVersion bool
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ type CIDDescriptor struct {
|
||||||
|
|
||||||
// ErrInvalidCIDDescriptor is returned when info about tne node position
|
// ErrInvalidCIDDescriptor is returned when info about tne node position
|
||||||
// in the container is invalid.
|
// in the container is invalid.
|
||||||
var ErrInvalidCIDDescriptor = errors.New("cid descriptor is invalid")
|
var ErrInvalidCIDDescriptor = logicerr.Wrap(errors.New("cid descriptor is invalid"))
|
||||||
|
|
||||||
func (d CIDDescriptor) checkValid() bool {
|
func (d CIDDescriptor) checkValid() bool {
|
||||||
return 0 <= d.Position && d.Position < d.Size
|
return 0 <= d.Position && d.Position < d.Size
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ func (r DumpRes) Count() int {
|
||||||
return r.count
|
return r.count
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrMustBeReadOnly = errors.New("shard must be in read-only mode")
|
var ErrMustBeReadOnly = logicerr.Wrap(errors.New("shard must be in read-only mode"))
|
||||||
|
|
||||||
// Dump dumps all objects from the shard to a file or stream.
|
// Dump dumps all objects from the shard to a file or stream.
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -125,9 +126,7 @@ func (s *Shard) fetchObjectData(addr oid.Address, skipMeta bool, cb storFetcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, false, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, false, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var mPrm meta.StorageIDPrm
|
var mPrm meta.StorageIDPrm
|
||||||
|
|
|
@ -97,12 +97,10 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
|
||||||
|
|
||||||
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
||||||
|
|
||||||
var expectedErr *objectSDK.SplitInfoError
|
var si *objectSDK.SplitInfoError
|
||||||
require.True(t, errors.As(err, &expectedErr))
|
require.True(t, errors.As(err, &si))
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
_, ok := si.SplitInfo().Link()
|
||||||
require.True(t, ok)
|
|
||||||
_, ok = si.SplitInfo().Link()
|
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
id1, _ := child.ID()
|
id1, _ := child.ID()
|
||||||
id2, _ := si.SplitInfo().LastPart()
|
id2, _ := si.SplitInfo().LastPart()
|
||||||
|
|
|
@ -4,14 +4,15 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrReadOnlyMode is returned when it is impossible to apply operation
|
// ErrReadOnlyMode is returned when it is impossible to apply operation
|
||||||
// that changes shard's memory due to the "read-only" shard's mode.
|
// that changes shard's memory due to the "read-only" shard's mode.
|
||||||
var ErrReadOnlyMode = errors.New("shard is in read-only mode")
|
var ErrReadOnlyMode = logicerr.Wrap(errors.New("shard is in read-only mode"))
|
||||||
|
|
||||||
// ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode.
|
// ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode.
|
||||||
var ErrDegradedMode = errors.New("shard is in degraded mode")
|
var ErrDegradedMode = logicerr.Wrap(errors.New("shard is in degraded mode"))
|
||||||
|
|
||||||
// SetMode sets mode of the shard.
|
// SetMode sets mode of the shard.
|
||||||
//
|
//
|
||||||
|
|
|
@ -3,6 +3,7 @@ package shard
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -94,7 +95,7 @@ func (s *Shard) GetRange(prm RngPrm) (RngRes, error) {
|
||||||
from := prm.off
|
from := prm.off
|
||||||
to := from + prm.ln
|
to := from + prm.ln
|
||||||
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
|
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
|
||||||
return nil, apistatus.ObjectOutOfRange{}
|
return nil, logicerr.Wrap(apistatus.ObjectOutOfRange{})
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := object.New()
|
obj := object.New()
|
||||||
|
|
|
@ -7,11 +7,12 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrInvalidMagic is returned when dump format is invalid.
|
// ErrInvalidMagic is returned when dump format is invalid.
|
||||||
var ErrInvalidMagic = errors.New("invalid magic")
|
var ErrInvalidMagic = logicerr.Wrap(errors.New("invalid magic"))
|
||||||
|
|
||||||
// RestorePrm groups the parameters of Restore operation.
|
// RestorePrm groups the parameters of Restore operation.
|
||||||
type RestorePrm struct {
|
type RestorePrm struct {
|
||||||
|
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ pilorama.Forest = (*Shard)(nil)
|
var _ pilorama.Forest = (*Shard)(nil)
|
||||||
|
|
||||||
// ErrPiloramaDisabled is returned when pilorama was disabled in the configuration.
|
// ErrPiloramaDisabled is returned when pilorama was disabled in the configuration.
|
||||||
var ErrPiloramaDisabled = errors.New("pilorama is disabled")
|
var ErrPiloramaDisabled = logicerr.Wrap(errors.New("pilorama is disabled"))
|
||||||
|
|
||||||
// TreeMove implements the pilorama.Forest interface.
|
// TreeMove implements the pilorama.Forest interface.
|
||||||
func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) {
|
func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) {
|
||||||
|
|
21
pkg/local_object_storage/util/logicerr/error.go
Normal file
21
pkg/local_object_storage/util/logicerr/error.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package logicerr
|
||||||
|
|
||||||
|
// Logical is a wrapper for logical errors.
|
||||||
|
type Logical struct {
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e Logical) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap wraps arbitrary error into a logical one.
|
||||||
|
func Wrap(err error) Logical {
|
||||||
|
return Logical{err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap returns underlying error.
|
||||||
|
func (e Logical) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
58
pkg/local_object_storage/util/logicerr/error_test.go
Normal file
58
pkg/local_object_storage/util/logicerr/error_test.go
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
package logicerr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestError(t *testing.T) {
|
||||||
|
t.Run("errors.Is", func(t *testing.T) {
|
||||||
|
e1 := errors.New("some error")
|
||||||
|
ee := Wrap(e1)
|
||||||
|
require.ErrorIs(t, ee, e1)
|
||||||
|
|
||||||
|
e2 := fmt.Errorf("wrap: %w", e1)
|
||||||
|
ee = Wrap(e2)
|
||||||
|
require.ErrorIs(t, ee, e1)
|
||||||
|
require.ErrorIs(t, ee, e2)
|
||||||
|
|
||||||
|
require.Equal(t, errors.Unwrap(ee), e2)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("errors.As", func(t *testing.T) {
|
||||||
|
e1 := testError{42}
|
||||||
|
ee := Wrap(e1)
|
||||||
|
|
||||||
|
{
|
||||||
|
var actual testError
|
||||||
|
require.ErrorAs(t, ee, &actual)
|
||||||
|
require.Equal(t, e1.data, actual.data)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var actual Logical
|
||||||
|
require.ErrorAs(t, ee, &actual)
|
||||||
|
require.Equal(t, e1, actual.err)
|
||||||
|
}
|
||||||
|
|
||||||
|
e2 := fmt.Errorf("wrap: %w", e1)
|
||||||
|
ee = Wrap(e2)
|
||||||
|
|
||||||
|
{
|
||||||
|
var actual testError
|
||||||
|
require.ErrorAs(t, ee, &actual)
|
||||||
|
require.Equal(t, e1.data, actual.data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type testError struct {
|
||||||
|
data uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e testError) Error() string {
|
||||||
|
return strconv.FormatUint(e.data, 10)
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package writecache
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
@ -24,9 +25,7 @@ func (c *cache) Get(addr oid.Address) (*objectSDK.Object, error) {
|
||||||
|
|
||||||
res, err := c.fsTree.Get(common.GetPrm{Address: addr})
|
res, err := c.fsTree.Get(common.GetPrm{Address: addr})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return nil, logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return nil, errNotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.flushed.Get(saddr)
|
c.flushed.Get(saddr)
|
||||||
|
@ -58,9 +57,7 @@ func Get(db *bbolt.DB, key []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
value = b.Get(key)
|
value = b.Get(key)
|
||||||
if value == nil {
|
if value == nil {
|
||||||
var errNotFound apistatus.ObjectNotFound
|
return logicerr.Wrap(apistatus.ObjectNotFound{})
|
||||||
|
|
||||||
return errNotFound
|
|
||||||
}
|
}
|
||||||
value = slice.Copy(value)
|
value = slice.Copy(value)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,10 +6,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrReadOnly is returned when Put/Write is performed in a read-only mode.
|
// ErrReadOnly is returned when Put/Write is performed in a read-only mode.
|
||||||
var ErrReadOnly = errors.New("write-cache is in read-only mode")
|
var ErrReadOnly = logicerr.Wrap(errors.New("write-cache is in read-only mode"))
|
||||||
|
|
||||||
// SetMode sets write-cache mode of operation.
|
// SetMode sets write-cache mode of operation.
|
||||||
// When shard is put in read-only mode all objects in memory are flushed to disk
|
// When shard is put in read-only mode all objects in memory are flushed to disk
|
||||||
|
|
Loading…
Reference in a new issue