From 5b33d841809c836c97121da1ad622c3836d42668 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 1 Jul 2024 19:24:00 +0300 Subject: [PATCH] [#9999] metabase: Fix db engine to pebble in children.go Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/metabase/children.go | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/pkg/local_object_storage/metabase/children.go b/pkg/local_object_storage/metabase/children.go index a1889d911..304d6e3a8 100644 --- a/pkg/local_object_storage/metabase/children.go +++ b/pkg/local_object_storage/metabase/children.go @@ -7,7 +7,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" - "go.etcd.io/bbolt" + "github.com/cockroachdb/pebble" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -37,34 +37,30 @@ func (db *DB) GetChildren(ctx context.Context, addresses []oid.Address) (map[oid } result := make(map[oid.Address][]oid.Address, len(addresses)) - - buffer := make([]byte, bucketKeySize) - err := db.database.View(func(tx *bbolt.Tx) error { + err := db.snapshot(func(s *pebble.Snapshot) error { for _, addr := range addresses { if _, found := result[addr]; found { continue } result[addr] = []oid.Address{} - bkt := tx.Bucket(parentBucketName(addr.Container(), buffer)) - if bkt == nil { - continue - } - binObjIDs, err := decodeList(bkt.Get(objectKey(addr.Object(), buffer))) - if err != nil { - return err - } - - for _, binObjID := range binObjIDs { - var id oid.ID - if err = id.Decode(binObjID); err != nil { + for { + keys, err := selectByPrefixBatch(ctx, s, parentKeyLongPrefix(addr.Container(), addr.Object()), batchSize) + if err != nil { return err } - var resultAddress oid.Address - resultAddress.SetContainer(addr.Container()) - resultAddress.SetObject(id) - result[addr] = append(result[addr], resultAddress) + + for _, key := range keys { + resultAddress, err := addressOfTargetFromParentKey(key) + if err != nil { + return err + } + result[addr] = append(result[addr], resultAddress) + } + if len(keys) < batchSize { + break + } } } return nil