From 56de2f1363590b9b3ba6733ab905f263dafefc07 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 31 Oct 2022 10:02:30 +0300 Subject: [PATCH] [#1969] local_object_storage: Simplify logic error construction Signed-off-by: Evgenii Stratonikov --- pkg/core/object/errors.go | 4 +--- pkg/local_object_storage/blobstor/common/errors.go | 6 ++---- pkg/local_object_storage/blobstor/put.go | 3 +-- pkg/local_object_storage/engine/shards.go | 3 +-- pkg/local_object_storage/metabase/control.go | 2 +- pkg/local_object_storage/metabase/exists.go | 3 +-- pkg/local_object_storage/metabase/inhume.go | 2 +- pkg/local_object_storage/metabase/iterators.go | 2 +- pkg/local_object_storage/metabase/list.go | 4 +--- pkg/local_object_storage/metabase/version.go | 3 +-- pkg/local_object_storage/pilorama/interface.go | 4 +--- pkg/local_object_storage/shard/dump.go | 3 +-- pkg/local_object_storage/shard/mode.go | 6 ++---- pkg/local_object_storage/shard/restore.go | 2 +- pkg/local_object_storage/shard/tree.go | 4 +--- pkg/local_object_storage/util/logicerr/error.go | 7 +++++++ pkg/local_object_storage/writecache/mode.go | 3 +-- 17 files changed, 25 insertions(+), 36 deletions(-) diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index d8c9a182c..c4c99c65e 100644 --- a/pkg/core/object/errors.go +++ b/pkg/core/object/errors.go @@ -1,12 +1,10 @@ package object import ( - "errors" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" ) // ErrObjectIsExpired is returned when the requested object's // epoch is less than the current one. Such objects are considered // as removed and should not be returned from the Storage Engine. -var ErrObjectIsExpired = logicerr.Wrap(errors.New("object is expired")) +var ErrObjectIsExpired = logicerr.New("object is expired") diff --git a/pkg/local_object_storage/blobstor/common/errors.go b/pkg/local_object_storage/blobstor/common/errors.go index c26d4ddea..149393488 100644 --- a/pkg/local_object_storage/blobstor/common/errors.go +++ b/pkg/local_object_storage/blobstor/common/errors.go @@ -1,14 +1,12 @@ package common 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 = logicerr.Wrap(errors.New("opened as read-only")) +var ErrReadOnly = logicerr.New("opened as read-only") // ErrNoSpace MUST be returned when there is no space to put an object on the device. -var ErrNoSpace = logicerr.Wrap(errors.New("no free space")) +var ErrNoSpace = logicerr.New("no free space") diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 978c5d93f..4ace6e1b1 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -1,7 +1,6 @@ package blobstor import ( - "errors" "fmt" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -12,7 +11,7 @@ import ( // ErrNoPlaceFound is returned when object can't be saved to any sub-storage component // because of the policy. -var ErrNoPlaceFound = logicerr.Wrap(errors.New("couldn't find a place to store an object")) +var ErrNoPlaceFound = logicerr.New("couldn't find a place to store an object") // Put saves the object in BLOB storage. // diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index 7b1d61f20..4f275ac05 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -1,7 +1,6 @@ package engine import ( - "errors" "fmt" "github.com/google/uuid" @@ -15,7 +14,7 @@ import ( "go.uber.org/zap" ) -var errShardNotFound = logicerr.Wrap(errors.New("shard not found")) +var errShardNotFound = logicerr.New("shard not found") type hashedShard shardWrapper diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index 877a82377..018fe075b 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -13,7 +13,7 @@ import ( ) // ErrDegradedMode is returned when metabase is in a degraded mode. -var ErrDegradedMode = logicerr.Wrap(errors.New("metabase is in a degraded mode")) +var ErrDegradedMode = logicerr.New("metabase is in a degraded mode") // Open boltDB instance for metabase. func (db *DB) Open(readOnly bool) error { diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index 33ff196f3..825ec5118 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -1,7 +1,6 @@ package meta import ( - "errors" "fmt" "strconv" @@ -25,7 +24,7 @@ type ExistsRes struct { exists bool } -var ErrLackSplitInfo = logicerr.Wrap(errors.New("no split info on parent object")) +var ErrLackSplitInfo = logicerr.New("no split info on parent object") // SetAddress is an Exists option to set object checked for existence. func (p *ExistsPrm) SetAddress(addr oid.Address) { diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 6596f8ee2..7e6ec0914 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -79,7 +79,7 @@ var errBreakBucketForEach = errors.New("bucket ForEach break") // ErrLockObjectRemoval is returned when inhume operation is being // performed on lock object, and it is not a forced object removal. -var ErrLockObjectRemoval = logicerr.Wrap(errors.New("lock object removal")) +var ErrLockObjectRemoval = logicerr.New("lock object removal") // Inhume marks objects as removed but not removes it from metabase. // diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 3ecbc7898..d5c8173ee 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -35,7 +35,7 @@ type ExpiredObjectHandler func(*ExpiredObject) error // ErrInterruptIterator is returned by iteration handlers // as a "break" keyword. -var ErrInterruptIterator = logicerr.Wrap(errors.New("iterator is interrupted")) +var ErrInterruptIterator = logicerr.New("iterator is interrupted") // IterateExpired iterates over all objects in DB which are out of date // relative to epoch. Locked objects are not included (do not confuse diff --git a/pkg/local_object_storage/metabase/list.go b/pkg/local_object_storage/metabase/list.go index 3e3266f9d..21701fc64 100644 --- a/pkg/local_object_storage/metabase/list.go +++ b/pkg/local_object_storage/metabase/list.go @@ -1,8 +1,6 @@ package meta import ( - "errors" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -12,7 +10,7 @@ import ( // ErrEndOfListing is returned from object listing with cursor // when storage can't return any more objects after provided // cursor. Use nil cursor object to start listing again. -var ErrEndOfListing = logicerr.Wrap(errors.New("end of object listing")) +var ErrEndOfListing = logicerr.New("end of object listing") // Cursor is a type for continuous object listing. type Cursor struct { diff --git a/pkg/local_object_storage/metabase/version.go b/pkg/local_object_storage/metabase/version.go index 53cc95cac..155beedc1 100644 --- a/pkg/local_object_storage/metabase/version.go +++ b/pkg/local_object_storage/metabase/version.go @@ -2,7 +2,6 @@ package meta import ( "encoding/binary" - "errors" "fmt" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr" @@ -17,7 +16,7 @@ var versionKey = []byte("version") // ErrOutdatedVersion is returned on initializing // an existing metabase that is not compatible with // the current code version. -var ErrOutdatedVersion = logicerr.Wrap(errors.New("invalid version, resynchronization is required")) +var ErrOutdatedVersion = logicerr.New("invalid version, resynchronization is required") func checkVersion(tx *bbolt.Tx, initialized bool) error { var knownVersion bool diff --git a/pkg/local_object_storage/pilorama/interface.go b/pkg/local_object_storage/pilorama/interface.go index f70465ba9..087761f39 100644 --- a/pkg/local_object_storage/pilorama/interface.go +++ b/pkg/local_object_storage/pilorama/interface.go @@ -1,8 +1,6 @@ package pilorama import ( - "errors" - "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" @@ -68,7 +66,7 @@ type CIDDescriptor struct { // ErrInvalidCIDDescriptor is returned when info about tne node position // in the container is invalid. -var ErrInvalidCIDDescriptor = logicerr.Wrap(errors.New("cid descriptor is invalid")) +var ErrInvalidCIDDescriptor = logicerr.New("cid descriptor is invalid") func (d CIDDescriptor) checkValid() bool { return 0 <= d.Position && d.Position < d.Size diff --git a/pkg/local_object_storage/shard/dump.go b/pkg/local_object_storage/shard/dump.go index 322554fcf..53033232c 100644 --- a/pkg/local_object_storage/shard/dump.go +++ b/pkg/local_object_storage/shard/dump.go @@ -2,7 +2,6 @@ package shard import ( "encoding/binary" - "errors" "io" "os" @@ -47,7 +46,7 @@ func (r DumpRes) Count() int { return r.count } -var ErrMustBeReadOnly = logicerr.Wrap(errors.New("shard must be in read-only mode")) +var ErrMustBeReadOnly = logicerr.New("shard must be in read-only mode") // Dump dumps all objects from the shard to a file or stream. // diff --git a/pkg/local_object_storage/shard/mode.go b/pkg/local_object_storage/shard/mode.go index c716ef2c9..7fc719166 100644 --- a/pkg/local_object_storage/shard/mode.go +++ b/pkg/local_object_storage/shard/mode.go @@ -1,18 +1,16 @@ package shard import ( - "errors" - "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 // that changes shard's memory due to the "read-only" shard's mode. -var ErrReadOnlyMode = logicerr.Wrap(errors.New("shard is in read-only mode")) +var ErrReadOnlyMode = logicerr.New("shard is in read-only mode") // ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode. -var ErrDegradedMode = logicerr.Wrap(errors.New("shard is in degraded mode")) +var ErrDegradedMode = logicerr.New("shard is in degraded mode") // SetMode sets mode of the shard. // diff --git a/pkg/local_object_storage/shard/restore.go b/pkg/local_object_storage/shard/restore.go index bfb3b8b86..349d3ae29 100644 --- a/pkg/local_object_storage/shard/restore.go +++ b/pkg/local_object_storage/shard/restore.go @@ -12,7 +12,7 @@ import ( ) // ErrInvalidMagic is returned when dump format is invalid. -var ErrInvalidMagic = logicerr.Wrap(errors.New("invalid magic")) +var ErrInvalidMagic = logicerr.New("invalid magic") // RestorePrm groups the parameters of Restore operation. type RestorePrm struct { diff --git a/pkg/local_object_storage/shard/tree.go b/pkg/local_object_storage/shard/tree.go index bfc456dbf..25300314c 100644 --- a/pkg/local_object_storage/shard/tree.go +++ b/pkg/local_object_storage/shard/tree.go @@ -1,8 +1,6 @@ package shard import ( - "errors" - "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" @@ -11,7 +9,7 @@ import ( var _ pilorama.Forest = (*Shard)(nil) // ErrPiloramaDisabled is returned when pilorama was disabled in the configuration. -var ErrPiloramaDisabled = logicerr.Wrap(errors.New("pilorama is disabled")) +var ErrPiloramaDisabled = logicerr.New("pilorama is disabled") // TreeMove implements the pilorama.Forest interface. func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) { diff --git a/pkg/local_object_storage/util/logicerr/error.go b/pkg/local_object_storage/util/logicerr/error.go index 7f1c3c159..6b78cb073 100644 --- a/pkg/local_object_storage/util/logicerr/error.go +++ b/pkg/local_object_storage/util/logicerr/error.go @@ -1,10 +1,17 @@ package logicerr +import "errors" + // Logical is a wrapper for logical errors. type Logical struct { err error } +// New returns simple error with a provided error message. +func New(msg string) Logical { + return Wrap(errors.New(msg)) +} + // Error implements the error interface. func (e Logical) Error() string { return e.err.Error() diff --git a/pkg/local_object_storage/writecache/mode.go b/pkg/local_object_storage/writecache/mode.go index 5d5532498..0da8391ae 100644 --- a/pkg/local_object_storage/writecache/mode.go +++ b/pkg/local_object_storage/writecache/mode.go @@ -1,7 +1,6 @@ package writecache import ( - "errors" "fmt" "time" @@ -10,7 +9,7 @@ import ( ) // ErrReadOnly is returned when Put/Write is performed in a read-only mode. -var ErrReadOnly = logicerr.Wrap(errors.New("write-cache is in read-only mode")) +var ErrReadOnly = logicerr.New("write-cache is in read-only mode") // SetMode sets write-cache mode of operation. // When shard is put in read-only mode all objects in memory are flushed to disk