From 5f78a18a4f43de0fbe0f58904b00e08868611616 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 29 Oct 2020 14:38:50 +0300 Subject: [PATCH] [#128] metabase: Do not create leaves in indexed header bucket Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/put.go | 9 ++------- pkg/local_object_storage/metabase/select.go | 14 ++++++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index d067b936..ffe7fe98 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -61,11 +61,6 @@ func (db *DB) Put(obj *object.Object) error { // 1. add prefix byte (0 if empty); v := []byte(indices[i].val) - // put value to key bucket (it is needed for iteration over all values (Select)) - if err := keyBucket.Put(keyWithPrefix(v, false), nil); err != nil { - return errors.Wrapf(err, "(%T) could not put header value", db) - } - // create address bucket for the value valBucket, err := keyBucket.CreateBucketIfNotExists(keyWithPrefix(v, true)) if err != nil { @@ -91,8 +86,8 @@ func keyWithPrefix(key []byte, bucket bool) []byte { return append([]byte{b}, key...) } -func keyWithoutPrefix(key []byte) ([]byte, bool) { - return key[1:], key[0] == 1 +func cutKeyBytes(key []byte) []byte { + return key[1:] } func addressKey(addr *objectSDK.Address) []byte { diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index ac8cf116..227f483c 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -39,15 +39,13 @@ func (db *DB) Select(fs object.SearchFilters) ([]*object.Address, error) { // iterate over all existing values for the key if err := keyBucket.ForEach(func(k, _ []byte) error { - if k, bucket := keyWithoutPrefix(k); !bucket { - if !matchFunc(string(k), fVal) { - // exclude all addresses with this value - return keyBucket.Bucket(keyWithPrefix(k, true)).ForEach(func(k, _ []byte) error { - mAddr[string(k)] = struct{}{} + if !matchFunc(string(cutKeyBytes(k)), fVal) { + // exclude all addresses with this value + return keyBucket.Bucket(k).ForEach(func(k, _ []byte) error { + mAddr[string(k)] = struct{}{} - return nil - }) - } + return nil + }) } return nil