frostfs-node/pkg/local_object_storage/blobstor/mode.go
Anton Nikiforov d19ade23c8 [#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>
2024-02-09 14:04:01 +00:00

35 lines
614 B
Go

package blobstor
import (
"context"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
)
// SetMode sets the blobstor mode of operation.
func (b *BlobStor) SetMode(m mode.Mode) error {
b.modeMtx.Lock()
defer b.modeMtx.Unlock()
if b.mode == m {
return nil
}
if b.mode.ReadOnly() == m.ReadOnly() {
return nil
}
err := b.Close()
if err == nil {
if err = b.openBlobStor(context.TODO(), m); err == nil {
err = b.Init()
}
}
if err != nil {
return fmt.Errorf("can't set blobstor mode (old=%s, new=%s): %w", b.mode, m, err)
}
b.mode = m
return nil
}