From f058cead8f1716f9434665cb36dbd01045f7826b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 3 Mar 2022 18:09:24 +0300 Subject: [PATCH] [#1143] shard: Handle some errors in degraded mode If metabase is corrupted for some reason, failback to checking blobstor directly. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/shard/exists.go | 25 +++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 488214231..11b85356c 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -1,8 +1,10 @@ package shard import ( + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + "go.uber.org/zap" ) // ExistsPrm groups the parameters of Exists operation. @@ -36,13 +38,26 @@ func (p *ExistsRes) Exists() bool { // // Returns an error of type apistatus.ObjectAlreadyRemoved if object has been marked as removed. func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) { - exists, err := s.objectExists(prm.addr) + exists, err := meta.Exists(s.metaBase, prm.addr) + if err != nil { + // If the shard is in degraded mode, try to consult blobstor directly. + // Otherwise, just return an error. + if s.GetMode() == ModeDegraded { + p := new(blobstor.ExistsPrm) + p.SetAddress(prm.addr) + + res, bErr := s.blobStor.Exists(p) + if bErr == nil { + exists = res.Exists() + s.log.Warn("metabase existence check finished with error", + zap.Stringer("address", prm.addr), + zap.String("error", err.Error())) + err = nil + } + } + } return &ExistsRes{ ex: exists, }, err } - -func (s *Shard) objectExists(addr *addressSDK.Address) (bool, error) { - return meta.Exists(s.metaBase, addr) -}