frostfs-node/pkg/local_object_storage/metabase/mode.go
Evgenii Stratonikov 4944490ffb [] local_object_storage: Move shard to the DegradedReadOnly mode
`Degraded` mode can be set by the administrator if needed.
Modifying operations in this mode can lead node into an inconsistent state
because metabase checks such as lock checking are not performed.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-07-21 17:56:06 +03:00

44 lines
859 B
Go

package meta
import (
"fmt"
"github.com/nspcc-dev/neofs-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)
}
}
var err error
switch {
case m.NoMetabase():
db.boltDB = nil
case m.ReadOnly():
err = db.Open(true)
default:
err = db.Open(false)
}
if err == nil && !m.NoMetabase() && !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
return nil
}