2022-07-05 04:55:46 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
2024-10-21 08:56:38 +00:00
|
|
|
"context"
|
2022-07-05 04:55:46 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2022-07-05 04:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetMode sets the metabase mode of operation.
|
|
|
|
// If the mode assumes no operation metabase, the database is closed.
|
2024-10-21 08:56:38 +00:00
|
|
|
func (db *DB) SetMode(ctx context.Context, m mode.Mode) error {
|
2022-07-05 04:55:46 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 06:17:17 +00:00
|
|
|
if m.NoMetabase() {
|
2022-07-05 04:55:46 +00:00
|
|
|
db.boltDB = nil
|
2024-02-09 06:17:17 +00:00
|
|
|
} else {
|
2024-10-21 08:56:38 +00:00
|
|
|
err := db.openDB(ctx, m)
|
2024-02-09 06:17:17 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-07-05 04:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db.mode = m
|
2024-06-04 13:28:47 +00:00
|
|
|
db.metrics.SetMode(mode.ConvertToComponentModeDegraded(m))
|
2022-07-05 04:55:46 +00:00
|
|
|
return nil
|
|
|
|
}
|