From 3c39c5a90c79fff56d921d622ddfb649067a1979 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 3 Nov 2020 17:09:59 +0300 Subject: [PATCH] [#142] metabase: Fix selection emptying due to deleted object Fix a bug in the selection when removed object that matches search query provoked the return of an empty result. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/select.go | 2 +- .../metabase/select_test.go | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index af5614ecc..c6c051011 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -97,7 +97,7 @@ func (db *DB) Select(fs object.SearchFilters) ([]*object.Address, error) { // check if object marked as deleted if objectRemoved(tx, []byte(a)) { - return nil + continue } addr := object.NewAddress() diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index 94dbdf185..ef3e574ea 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -5,6 +5,7 @@ import ( "testing" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/stretchr/testify/require" ) @@ -111,3 +112,43 @@ func TestMismatchAfterMatch(t *testing.T) { testSelect(t, db, fs) } + +func addCommonAttribute(objs ...*object.Object) *objectSDK.Attribute { + aCommon := objectSDK.NewAttribute() + aCommon.SetKey("common key") + aCommon.SetValue("common value") + + for _, o := range objs { + object.NewRawFromObject(o).SetAttributes( + append(o.GetAttributes(), aCommon)..., + ) + } + + return aCommon +} + +func TestSelectRemoved(t *testing.T) { + db := newDB(t) + defer releaseDB(db) + + // create 2 objects + obj1 := generateObject(t, testPrm{}) + obj2 := generateObject(t, testPrm{}) + + // add common attribute + a := addCommonAttribute(obj1, obj2) + + // add to DB + require.NoError(t, db.Put(obj1)) + require.NoError(t, db.Put(obj2)) + + fs := objectSDK.SearchFilters{} + fs.AddFilter(a.GetKey(), a.GetValue(), objectSDK.MatchStringEqual) + + testSelect(t, db, fs, obj1.Address(), obj2.Address()) + + // remote 1st object + require.NoError(t, db.Delete(obj1.Address())) + + testSelect(t, db, fs, obj2.Address()) +}