Skip to content

Commit

Permalink
[nspcc-dev#1809] node: Do not boot up if metabase is outdated
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell authored and fyrchik committed Oct 4, 2022
1 parent 8b3b16f commit 4eb0ed1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/local_object_storage/metabase/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/local_object_storage/metabase/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meta

import (
"encoding/binary"
"errors"
"fmt"

"go.etcd.io/bbolt"
Expand All @@ -12,14 +13,19 @@ 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 {
data := b.Get(versionKey)
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)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/local_object_storage/shard/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4eb0ed1

Please sign in to comment.