From f76516a88347ab63d1b3e6732f9345be11dda405 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 12 Oct 2022 22:45:05 +0300 Subject: [PATCH] [#1860] meta: Fix 0,1 -> 2+ version migration In the 2nd version, there was a database format change: buckets have changed their keys, so it becomes impossible to check the version in the 1 -> 2+ migrations because of different buckets that store info about the version. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/local_object_storage/metabase/version.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33b93d406..6f3655065 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 5d1d9d84f..55e420ed9 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 {