[#9999] metabase: Fix db engine to pebble in shard_id.go
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
435589bb4d
commit
e9e2741a30
2 changed files with 16 additions and 15 deletions
|
@ -8,13 +8,10 @@ import (
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
|
"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"
|
metamode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
||||||
"go.etcd.io/bbolt"
|
"github.com/cockroachdb/pebble"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var shardIDKey = []byte("id")
|
||||||
shardInfoBucket = []byte{shardInfoPrefix}
|
|
||||||
shardIDKey = []byte("id")
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetShardID sets metabase operation mode
|
// GetShardID sets metabase operation mode
|
||||||
// and reads shard id from db.
|
// 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.
|
// If id is missing, returns nil, nil.
|
||||||
func (db *DB) readShardID() ([]byte, error) {
|
func (db *DB) readShardID() ([]byte, error) {
|
||||||
var id []byte
|
var id []byte
|
||||||
err := db.database.View(func(tx *bbolt.Tx) error {
|
err := db.snapshot(func(s *pebble.Snapshot) error {
|
||||||
b := tx.Bucket(shardInfoBucket)
|
v, err := valueSafe(s, shardInfoKey(shardIDKey))
|
||||||
if b != nil {
|
if err != nil {
|
||||||
id = bytes.Clone(b.Get(shardIDKey))
|
return err
|
||||||
}
|
}
|
||||||
|
id = bytes.Clone(v)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return id, metaerr.Wrap(err)
|
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.
|
// writeShardID writes shard id to db.
|
||||||
func (db *DB) writeShardID(id []byte) error {
|
func (db *DB) writeShardID(id []byte) error {
|
||||||
return metaerr.Wrap(db.database.Update(func(tx *bbolt.Tx) error {
|
return metaerr.Wrap(db.batch(func(b *pebble.Batch) error {
|
||||||
b, err := tx.CreateBucketIfNotExists(shardInfoBucket)
|
return b.Set(shardInfoKey(shardIDKey), id, pebble.Sync)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return b.Put(shardIDKey, id)
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,3 +669,10 @@ func addressFromExpiredKey(key []byte) (oid.Address, error) {
|
||||||
result.SetContainer(cnr)
|
result.SetContainer(cnr)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shardInfoKey(key []byte) []byte {
|
||||||
|
result := make([]byte, len(key))
|
||||||
|
result[0] = shardInfoPrefix
|
||||||
|
copy(result[1:], key)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue