Skip to content

Commit

Permalink
meta: actually upgrade version during meta migration
Browse files Browse the repository at this point in the history
It wasn't updated previously leading to attempts to upgrade the DB on every
start. Which then leads to

    error        shard/control.go:17        metabase failure, switching mode        {"shard_id": "XxhmeQZZRSQfDGfiCYo9mB", "stage": "init", "mode": "READ_ONLY", "error": "migrating from 2 to 3 version failed, consider database resync: graveyard value with unexpected 72 length"}

on 0.44.0/0.44.1.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Dec 12, 2024
1 parent 562817d commit 2addebf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/local_object_storage/metabase/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ var versionKey = []byte("version")
var ErrOutdatedVersion = logicerr.New("invalid version, resynchronization is required")

func (db *DB) checkVersion(tx *bbolt.Tx) error {
var knownVersion bool
var (
knownVersion bool
migrated bool
)

b := tx.Bucket(shardInfoBucket)
if b != nil {
Expand All @@ -40,11 +43,12 @@ func (db *DB) checkVersion(tx *bbolt.Tx) error {
if err != nil {
return fmt.Errorf("migrating from %d to %d version failed, consider database resync: %w", stored, version, err)
}
migrated = true
}
}
}

if !db.initialized {
if !db.initialized || migrated {
// new database, write version
return updateVersion(tx, version)
} else if !knownVersion {
Expand Down
7 changes: 7 additions & 0 deletions pkg/local_object_storage/metabase/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,11 @@ func TestMigrate2to3(t *testing.T) {
})
})
require.NoError(t, err)
err = db.boltDB.View(func(tx *bbolt.Tx) error {
if getVersion(tx) != version {
return errors.New("version was not updated")
}
return nil
})
require.NoError(t, err)
}

0 comments on commit 2addebf

Please sign in to comment.