[#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 <carpawell@nspcc.ru>
This commit is contained in:
parent
6eb82c4cbf
commit
f76516a883
2 changed files with 17 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue