forked from TrueCloudLab/frostfs-node
[#1809] node: Do not boot up if metabase is outdated
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
8b3b16fe62
commit
4eb0ed11f8
4 changed files with 14 additions and 1 deletions
|
@ -21,6 +21,7 @@ Changelog for NeoFS Node
|
|||
### Fixed
|
||||
- Description of command `netmap nodeinfo` (#1821)
|
||||
- Proper status for object.Delete if session token is missing (#1697)
|
||||
- Fail startup if metabase has an old version (#1809)
|
||||
|
||||
### Removed
|
||||
- Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128)
|
||||
|
|
|
@ -58,6 +58,8 @@ func (db *DB) Open(readOnly bool) error {
|
|||
|
||||
// Init initializes metabase. It creates static (CID-independent) buckets in underlying BoltDB instance.
|
||||
//
|
||||
// Returns ErrOutdatedVersion if a database at the provided path is outdated.
|
||||
//
|
||||
// Does nothing if metabase has already been initialized and filled. To roll back the database to its initial state,
|
||||
// use Reset.
|
||||
func (db *DB) Init() error {
|
||||
|
|
|
@ -2,6 +2,7 @@ package meta
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.etcd.io/bbolt"
|
||||
|
@ -12,6 +13,11 @@ const version = 2
|
|||
|
||||
var versionKey = []byte("version")
|
||||
|
||||
// ErrOutdatedVersion is returned on initializing
|
||||
// an existing metabase that is not compatible with
|
||||
// the current code version.
|
||||
var ErrOutdatedVersion = errors.New("invalid version")
|
||||
|
||||
func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
||||
b := tx.Bucket(shardInfoBucket)
|
||||
if b != nil {
|
||||
|
@ -19,7 +25,7 @@ func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
|||
if len(data) == 8 {
|
||||
stored := binary.LittleEndian.Uint64(data)
|
||||
if stored != version {
|
||||
return fmt.Errorf("invalid version: expected=%d, stored=%d", version, stored)
|
||||
return fmt.Errorf("%w: expected=%d, stored=%d", ErrOutdatedVersion, version, stored)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,10 @@ func (s *Shard) Init() error {
|
|||
for _, component := range components {
|
||||
if err := component.Init(); err != nil {
|
||||
if component == s.metaBase {
|
||||
if errors.Is(err, meta.ErrOutdatedVersion) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.handleMetabaseFailure("init", err)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue