diff --git a/pkg/local_object_storage/metabase/version.go b/pkg/local_object_storage/metabase/version.go index 2f93800650..17dbefb267 100644 --- a/pkg/local_object_storage/metabase/version.go +++ b/pkg/local_object_storage/metabase/version.go @@ -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 { @@ -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 { diff --git a/pkg/local_object_storage/metabase/version_test.go b/pkg/local_object_storage/metabase/version_test.go index 568017d931..be949cdb9a 100644 --- a/pkg/local_object_storage/metabase/version_test.go +++ b/pkg/local_object_storage/metabase/version_test.go @@ -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) }