From 3db4112366d35cc415608038d5b0e17afb534429 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 2 Jul 2024 15:13:28 +0300 Subject: [PATCH] [#9999] metabase: Fix db engine to pebble in shard_id.go Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/metabase/shard_id.go | 24 +++++++------------ pkg/local_object_storage/metabase/util.go | 7 ++++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/local_object_storage/metabase/shard_id.go b/pkg/local_object_storage/metabase/shard_id.go index 7d9c8b98e..408a49e82 100644 --- a/pkg/local_object_storage/metabase/shard_id.go +++ b/pkg/local_object_storage/metabase/shard_id.go @@ -8,13 +8,10 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" metamode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" - "go.etcd.io/bbolt" + "github.com/cockroachdb/pebble" ) -var ( - shardInfoBucket = []byte{shardInfoPrefix} - shardIDKey = []byte("id") -) +var shardIDKey = []byte("id") // GetShardID sets metabase operation mode // and reads shard id from db. @@ -47,11 +44,12 @@ func (db *DB) GetShardID(mode metamode.Mode) ([]byte, error) { // If id is missing, returns nil, nil. func (db *DB) readShardID() ([]byte, error) { var id []byte - err := db.database.View(func(tx *bbolt.Tx) error { - b := tx.Bucket(shardInfoBucket) - if b != nil { - id = bytes.Clone(b.Get(shardIDKey)) + err := db.snapshot(func(s *pebble.Snapshot) error { + v, err := valueSafe(s, shardInfoKey(shardIDKey)) + if err != nil { + return err } + id = bytes.Clone(v) return nil }) return id, metaerr.Wrap(err) @@ -86,11 +84,7 @@ func (db *DB) SetShardID(id []byte, mode metamode.Mode) error { // writeShardID writes shard id to db. func (db *DB) writeShardID(id []byte) error { - return metaerr.Wrap(db.database.Update(func(tx *bbolt.Tx) error { - b, err := tx.CreateBucketIfNotExists(shardInfoBucket) - if err != nil { - return err - } - return b.Put(shardIDKey, id) + return metaerr.Wrap(db.batch(func(b *pebble.Batch) error { + return b.Set(shardInfoKey(shardIDKey), id, pebble.Sync) })) } diff --git a/pkg/local_object_storage/metabase/util.go b/pkg/local_object_storage/metabase/util.go index cb7f03ddc..a2c4c781b 100644 --- a/pkg/local_object_storage/metabase/util.go +++ b/pkg/local_object_storage/metabase/util.go @@ -669,3 +669,10 @@ func addressFromExpiredKey(key []byte) (oid.Address, error) { result.SetContainer(cnr) return result, nil } + +func shardInfoKey(key []byte) []byte { + result := make([]byte, len(key)) + result[0] = shardInfoPrefix + copy(result[1:], key) + return result +}