frostfs-node/pkg/local_object_storage/metabase/mode.go
Evgenii Stratonikov 58668e6bc3
storage: Remove "could not/can't/failed to" from error messages
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-18 09:38:14 +03:00

41 lines
878 B
Go

package meta
import (
"context"
"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(ctx context.Context, 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(ctx); err != nil {
return fmt.Errorf("set metabase mode (old=%s, new=%s): %w", db.mode, m, err)
}
}
if m.NoMetabase() {
db.boltDB = nil
} else {
err := db.openDB(ctx, m)
if err == nil && !m.ReadOnly() {
err = db.Init(ctx)
}
if err != nil {
return fmt.Errorf("set metabase mode (old=%s, new=%s): %w", db.mode, m, err)
}
}
db.mode = m
db.metrics.SetMode(mode.ConvertToComponentModeDegraded(m))
return nil
}