From 596d877a44757cc3445dda53c4f3bee078cf7538 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 27 Jun 2022 11:36:32 +0300 Subject: [PATCH] [#1549] engine: Disable shard on blobovnicza init failure There is a need to support working w/o shard if it has problems with blobovnicza tree. Make `BlobStor.Init` to return new `ErrInitBlobovniczas` error. Remove shard from storage engine's shard set if it returned this error from `Init` call. So if some of the shards (but not all) return this error, the node will be able to continue working without them. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/blobstor/control.go | 17 ++++++++++++++++- pkg/local_object_storage/engine/control.go | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/blobstor/control.go b/pkg/local_object_storage/blobstor/control.go index 151e35600..048935adb 100644 --- a/pkg/local_object_storage/blobstor/control.go +++ b/pkg/local_object_storage/blobstor/control.go @@ -1,5 +1,10 @@ package blobstor +import ( + "errors" + "fmt" +) + // Open opens BlobStor. func (b *BlobStor) Open() error { b.log.Debug("opening...") @@ -7,13 +12,23 @@ func (b *BlobStor) Open() error { return nil } +// ErrInitBlobovniczas is returned when blobovnicza initialization fails. +var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stage") + // Init initializes internal data structures and system resources. // // If BlobStor is already initialized, no action is taken. +// +// Returns wrapped ErrInitBlobovniczas on blobovnicza tree's initializaiton failure. func (b *BlobStor) Init() error { b.log.Debug("initializing...") - return b.blobovniczas.init() + err := b.blobovniczas.init() + if err != nil { + return fmt.Errorf("%w: %v", ErrInitBlobovniczas, err) + } + + return nil } // Close releases all internal resources of BlobStor. diff --git a/pkg/local_object_storage/engine/control.go b/pkg/local_object_storage/engine/control.go index f2ea266c2..ac1b6afdf 100644 --- a/pkg/local_object_storage/engine/control.go +++ b/pkg/local_object_storage/engine/control.go @@ -5,6 +5,7 @@ import ( "fmt" "sync" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "go.uber.org/zap" ) @@ -48,10 +49,25 @@ func (e *StorageEngine) Init() error { for id, sh := range e.shards { if err := sh.Init(); err != nil { + if errors.Is(err, blobstor.ErrInitBlobovniczas) { + delete(e.shards, id) + + e.log.Error("shard initialization failure, skipping", + zap.String("id", id), + zap.Error(err), + ) + + continue + } + return fmt.Errorf("could not initialize shard %s: %w", id, err) } } + if len(e.shards) == 0 { + return errors.New("failed initialization on all shards") + } + return nil }