[#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 <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2020-11-03 17:09:59 +03:00 committed by Alex Vanin
parent 7a8f322d59
commit 3c39c5a90c
2 changed files with 42 additions and 1 deletions

View File

@ -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()

View File

@ -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())
}