From 87be4f16295eafc0b75ff72ca45c38af62837d5f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sun, 16 Oct 2022 16:11:29 +0300 Subject: [PATCH] [#1869] shard: Restore shard mode on failed reloads Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/metabase/control.go | 2 +- pkg/local_object_storage/shard/control.go | 14 +++++++++++--- pkg/local_object_storage/shard/reload_test.go | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index dc3e6e25e..750ecfdd5 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -171,7 +171,7 @@ func (db *DB) Reload(opts ...Option) (bool, error) { db.modeMtx.Lock() defer db.modeMtx.Unlock() - if c.info.Path != "" && filepath.Clean(db.info.Path) != filepath.Clean(c.info.Path) { + if db.mode.NoMetabase() || c.info.Path != "" && filepath.Clean(db.info.Path) != filepath.Clean(c.info.Path) { if err := db.Close(); err != nil { return false, err } diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 7abe8f4d2..cbb9b38e6 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -287,12 +287,20 @@ func (s *Shard) Reload(opts ...Option) error { return err } if ok { + var err error if c.refillMetabase { - return s.refillMetabase() + // Here we refill metabase only if a new instance was opened. This is a feature, + // we don't want to hang for some time just because we forgot to change + // config after the node was updated. + err = s.refillMetabase() } else { - return s.metaBase.Init() + err = s.metaBase.Init() + } + if err != nil { + _ = s.setMode(mode.DegradedReadOnly) + return err } } - return nil + return s.setMode(mode.ReadWrite) } diff --git a/pkg/local_object_storage/shard/reload_test.go b/pkg/local_object_storage/shard/reload_test.go index 2c5ad30b7..e6c52add6 100644 --- a/pkg/local_object_storage/shard/reload_test.go +++ b/pkg/local_object_storage/shard/reload_test.go @@ -113,6 +113,16 @@ func TestShardReload(t *testing.T) { // Old objects are still accessible. checkHasObjects(t, true) + + // Successive reload produces no undesired effects. + require.NoError(t, os.RemoveAll(badPath)) + require.NoError(t, sh.Reload(newOpts...)) + + obj = newObject() + require.NoError(t, putObject(sh, obj)) + + objects = append(objects, objAddr{obj: obj, addr: objectCore.AddressOf(obj)}) + checkHasObjects(t, true) }) }) }