diff --git a/CHANGELOG.md b/CHANGELOG.md index 33b93d40..6f365506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Changelog for NeoFS Node - Node's status in `neofs-cli netmap nodeinfo` command (#1833) - Child check in object assembly process of `ObjectService.Get` handler (#1878) - Shard ID in the object counter metrics (#1863) +- Metabase migration from the first version (#1860) ### Removed - Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128) diff --git a/pkg/local_object_storage/metabase/version.go b/pkg/local_object_storage/metabase/version.go index 5d1d9d84..55e420ed 100644 --- a/pkg/local_object_storage/metabase/version.go +++ b/pkg/local_object_storage/metabase/version.go @@ -19,20 +19,34 @@ var versionKey = []byte("version") var ErrOutdatedVersion = errors.New("invalid version") func checkVersion(tx *bbolt.Tx, initialized bool) error { + var knownVersion bool + b := tx.Bucket(shardInfoBucket) if b != nil { data := b.Get(versionKey) if len(data) == 8 { + knownVersion = true + stored := binary.LittleEndian.Uint64(data) if stored != version { return fmt.Errorf("%w: expected=%d, stored=%d", ErrOutdatedVersion, version, stored) } } } - if !initialized { // new database, write version + + if !initialized { + // new database, write version return updateVersion(tx, version) + } else if !knownVersion { + // db is initialized but no version + // has been found; that could happen + // if the db is corrupted or the version + // is <2 (is outdated and requires resync + // anyway) + return ErrOutdatedVersion } - return nil // return error here after the first version increase + + return nil } func updateVersion(tx *bbolt.Tx, version uint64) error {