WIP: Change metabase engine to pebble #1221

Closed
dstepanov-yadro wants to merge 28 commits from dstepanov-yadro/frostfs-node:feat/pebble_metabase into master
Showing only changes of commit c229b08f46 - Show all commits

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)
}