[#9999] metabase: Fix db engine to pebble in version.go

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-07-02 15:15:33 +03:00
parent 586a971b90
commit b7bd21b412

View file

@ -5,7 +5,7 @@ import (
"fmt"
"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.
@ -18,25 +18,25 @@ var versionKey = []byte("version")
// the current code version.
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
b := tx.Bucket(shardInfoBucket)
if b != nil {
data := b.Get(versionKey)
if len(data) == 8 {
knownVersion = true
data, err := valueSafe(b, shardInfoKey(versionKey))
if err != nil {
return err
}
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)
}
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
return updateVersion(tx, version)
return updateVersion(b, version)
} else if !knownVersion {
// db is initialized but no version
// has been found; that could happen
@ -49,13 +49,8 @@ func checkVersion(tx *bbolt.Tx, initialized bool) error {
return nil
}
func updateVersion(tx *bbolt.Tx, version uint64) error {
func updateVersion(b *pebble.Batch, version uint64) error {
data := make([]byte, 8)
binary.LittleEndian.PutUint64(data, version)
b, err := tx.CreateBucketIfNotExists(shardInfoBucket)
if err != nil {
return fmt.Errorf("can't create auxiliary bucket: %w", err)
}
return b.Put(versionKey, data)
return b.Set(shardInfoKey(versionKey), data, pebble.Sync)
}