From bc20851cd14ef52450f92ae12ed5424ba3c00a46 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 22 Aug 2022 15:25:26 +0300 Subject: [PATCH] [#1686] shard: Open all components in case metabase has failed All components must be opened first, before any other operation is performed. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/shard/control.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 76e582dc19..e1dfd779db 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -50,9 +50,17 @@ func (s *Shard) Open() error { components = append(components, s.pilorama) } - for _, component := range components { + for i, component := range components { if err := component.Open(false); err != nil { if component == s.metaBase { + // We must first open all other components to avoid + // opening non-existent DB in read-only mode. + for j := i + 1; j < len(components); j++ { + if err := components[j].Open(false); err != nil { + // Other components must be opened, fail. + return fmt.Errorf("could not open %T: %w", components[j], err) + } + } err = s.handleMetabaseFailure("open", err) if err != nil { return err