[#9999] metabase: Fix db engine to pebble in version.go
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
586a971b90
commit
b7bd21b412
1 changed files with 14 additions and 19 deletions
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"go.etcd.io/bbolt"
|
"github.com/cockroachdb/pebble"
|
||||||
)
|
)
|
||||||
|
|
||||||
// version contains current metabase version.
|
// version contains current metabase version.
|
||||||
|
@ -18,25 +18,25 @@ var versionKey = []byte("version")
|
||||||
// the current code version.
|
// the current code version.
|
||||||
var ErrOutdatedVersion = logicerr.New("invalid version, resynchronization is required")
|
var ErrOutdatedVersion = logicerr.New("invalid version, resynchronization is required")
|
||||||
|
|
||||||
func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
func checkVersion(b *pebble.Batch, initialized bool) error {
|
||||||
var knownVersion bool
|
var knownVersion bool
|
||||||
|
|
||||||
b := tx.Bucket(shardInfoBucket)
|
data, err := valueSafe(b, shardInfoKey(versionKey))
|
||||||
if b != nil {
|
if err != nil {
|
||||||
data := b.Get(versionKey)
|
return err
|
||||||
if len(data) == 8 {
|
}
|
||||||
knownVersion = true
|
if len(data) == 8 {
|
||||||
|
knownVersion = true
|
||||||
|
|
||||||
stored := binary.LittleEndian.Uint64(data)
|
stored := binary.LittleEndian.Uint64(data)
|
||||||
if stored != version {
|
if stored != version {
|
||||||
return fmt.Errorf("%w: expected=%d, stored=%d", ErrOutdatedVersion, version, stored)
|
return fmt.Errorf("%w: expected=%d, stored=%d", ErrOutdatedVersion, version, stored)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initialized {
|
if !initialized {
|
||||||
// new database, write version
|
// new database, write version
|
||||||
return updateVersion(tx, version)
|
return updateVersion(b, version)
|
||||||
} else if !knownVersion {
|
} else if !knownVersion {
|
||||||
// db is initialized but no version
|
// db is initialized but no version
|
||||||
// has been found; that could happen
|
// has been found; that could happen
|
||||||
|
@ -49,13 +49,8 @@ func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateVersion(tx *bbolt.Tx, version uint64) error {
|
func updateVersion(b *pebble.Batch, version uint64) error {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, version)
|
binary.LittleEndian.PutUint64(data, version)
|
||||||
|
return b.Set(shardInfoKey(versionKey), data, pebble.Sync)
|
||||||
b, err := tx.CreateBucketIfNotExists(shardInfoBucket)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't create auxiliary bucket: %w", err)
|
|
||||||
}
|
|
||||||
return b.Put(versionKey, data)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue