[#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
3db4112366
commit
c229b08f46
1 changed files with 14 additions and 19 deletions
|
@ -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,12 +18,13 @@ 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)
|
||||
data, err := valueSafe(b, shardInfoKey(versionKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(data) == 8 {
|
||||
knownVersion = true
|
||||
|
||||
|
@ -32,11 +33,10 @@ func checkVersion(tx *bbolt.Tx, initialized bool) error {
|
|||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue