From f0edebea1820d96b9219917d34c7649f31db3782 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 21 May 2024 14:19:22 +0300 Subject: [PATCH] [#1144] metabase: Support ec parent filter for `Search` Signed-off-by: Airat Arifullin --- pkg/local_object_storage/metabase/db.go | 2 +- pkg/local_object_storage/metabase/put.go | 11 +++++++++++ pkg/local_object_storage/metabase/select.go | 3 +++ pkg/local_object_storage/metabase/util.go | 11 +++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index f5341ff2e..f2203f4d9 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -262,7 +262,7 @@ func unknownMatcherBucket(_ *bbolt.Bucket, _ string, _ string, _ func([]byte, [] // in boltDB. Useful for getting filter values from unique and list indexes. func bucketKeyHelper(hdr string, val string) []byte { switch hdr { - case v2object.FilterHeaderParent: + case v2object.FilterHeaderParent, v2object.FilterHeaderECParent: v, err := base58.Decode(val) if err != nil { return nil diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 94e68d85a..bb5976ec4 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -323,6 +323,17 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun } } + if ech := obj.ECHeader(); ech != nil { + err := f(tx, namedBucketItem{ + name: ecParentToChunksBucketName(cnr, bucketName), + key: objectKey(ech.Parent(), make([]byte, objectKeySize)), + val: objKey, + }) + if err != nil { + return err + } + } + return nil } diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index 65d0111c4..f544f95e2 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -211,6 +211,9 @@ func (db *DB) selectFastFilter( case v2object.FilterHeaderSplitID: bucketName := splitBucketName(cnr, bucketName) db.selectFromList(tx, bucketName, f, to, fNum) + case v2object.FilterHeaderECParent: + bucketName := ecParentToChunksBucketName(cnr, bucketName) + db.selectFromList(tx, bucketName, f, to, fNum) case v2object.FilterPropertyRoot: selectAllFromBucket(tx, rootBucketName(cnr, bucketName), to, fNum) case v2object.FilterPropertyPhy: diff --git a/pkg/local_object_storage/metabase/util.go b/pkg/local_object_storage/metabase/util.go index 9249ae49b..cfccff394 100644 --- a/pkg/local_object_storage/metabase/util.go +++ b/pkg/local_object_storage/metabase/util.go @@ -124,6 +124,12 @@ const ( // Key: container ID + type // Value: Object id ecInfoPrefix + + // ecParentToChunksPrefix is used to store a relation between EC parent ID and chunks, + // but unlike for ecInfoPrefix the list of chunk IDs is encoded with encodeList. + // Key: EC parent ID + // Value: list of EC chunk IDs + ecParentToChunksPrefix ) const ( @@ -200,6 +206,11 @@ func ecInfoBucketName(cnr cid.ID, key []byte) []byte { return bucketName(cnr, ecInfoPrefix, key) } +// ecParentToChunksBucketName returns _ecParentToChunks. +func ecParentToChunksBucketName(cnr cid.ID, key []byte) []byte { + return bucketName(cnr, ecParentToChunksPrefix, key) +} + // addressKey returns key for K-V tables when key is a whole address. func addressKey(addr oid.Address, key []byte) []byte { addr.Container().Encode(key)