forked from TrueCloudLab/frostfs-node
Anton Nikiforov
d19ade23c8
Avoid opening database for `metabase` and `cache` in `Degraded` mode. Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
40 lines
810 B
Go
40 lines
810 B
Go
package meta
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
)
|
|
|
|
// SetMode sets the metabase mode of operation.
|
|
// If the mode assumes no operation metabase, the database is closed.
|
|
func (db *DB) SetMode(m mode.Mode) error {
|
|
db.modeMtx.Lock()
|
|
defer db.modeMtx.Unlock()
|
|
|
|
if db.mode == m {
|
|
return nil
|
|
}
|
|
|
|
if !db.mode.NoMetabase() {
|
|
if err := db.Close(); err != nil {
|
|
return fmt.Errorf("can't set metabase mode (old=%s, new=%s): %w", db.mode, m, err)
|
|
}
|
|
}
|
|
|
|
if m.NoMetabase() {
|
|
db.boltDB = nil
|
|
} else {
|
|
err := db.openDB(m)
|
|
if err == nil && !m.ReadOnly() {
|
|
err = db.Init()
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("can't set metabase mode (old=%s, new=%s): %w", db.mode, m, err)
|
|
}
|
|
}
|
|
|
|
db.mode = m
|
|
db.metrics.SetMode(m)
|
|
return nil
|
|
}
|