[#959] node: Set mode to shard's components when open it

Avoid opening database for `metabase` and `cache` in `Degraded` mode.

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2024-02-09 09:17:17 +03:00 committed by Evgenii Stratonikov
parent 60527abb65
commit d19ade23c8
25 changed files with 219 additions and 74 deletions

View file

@ -99,7 +99,7 @@ func (t *boltForest) SetMode(m mode.Mode) error {
err := t.Close()
if err == nil && !m.NoMetabase() {
if err = t.Open(context.TODO(), m.ReadOnly()); err == nil {
if err = t.openBolt(m); err == nil {
err = t.Init()
}
}
@ -112,7 +112,18 @@ func (t *boltForest) SetMode(m mode.Mode) error {
return nil
}
func (t *boltForest) Open(_ context.Context, readOnly bool) error {
func (t *boltForest) Open(_ context.Context, mode mode.Mode) error {
t.modeMtx.Lock()
defer t.modeMtx.Unlock()
t.mode = mode
if mode.NoMetabase() {
return nil
}
return t.openBolt(mode)
}
func (t *boltForest) openBolt(mode mode.Mode) error {
readOnly := mode.ReadOnly()
err := util.MkdirAllX(filepath.Dir(t.path), t.perm)
if err != nil {
return metaerr.Wrap(fmt.Errorf("can't create dir %s for the pilorama: %w", t.path, err))
@ -131,11 +142,7 @@ func (t *boltForest) Open(_ context.Context, readOnly bool) error {
t.db.MaxBatchSize = t.maxBatchSize
t.db.MaxBatchDelay = t.maxBatchDelay
m := mode.ReadWrite
if readOnly {
m = mode.ReadOnly
}
t.metrics.SetMode(m)
t.metrics.SetMode(mode)
return nil
}