forked from TrueCloudLab/frostfs-node
[#142] metabase: Fix false-positive select
Fix a bug in the selection when an object could be added to the result after a mismatch in the previous filter. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
77e80f517f
commit
7a8f322d59
2 changed files with 34 additions and 5 deletions
|
@ -45,8 +45,8 @@ func (db *DB) Select(fs object.SearchFilters) ([]*object.Address, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep processed addresses
|
// keep processed addresses (false if address was added and excluded later)
|
||||||
mAddr := make(map[string]struct{})
|
mAddr := make(map[string]bool)
|
||||||
|
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
matchFunc, ok := db.matchers[f.Operation()]
|
matchFunc, ok := db.matchers[f.Operation()]
|
||||||
|
@ -76,9 +76,11 @@ func (db *DB) Select(fs object.SearchFilters) ([]*object.Address, error) {
|
||||||
|
|
||||||
for i := range strs {
|
for i := range strs {
|
||||||
if include {
|
if include {
|
||||||
mAddr[strs[i]] = struct{}{}
|
if _, ok := mAddr[strs[i]]; !ok {
|
||||||
|
mAddr[strs[i]] = true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
delete(mAddr, strs[i])
|
mAddr[strs[i]] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +90,11 @@ func (db *DB) Select(fs object.SearchFilters) ([]*object.Address, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for a := range mAddr {
|
for a, inc := range mAddr {
|
||||||
|
if !inc {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// check if object marked as deleted
|
// check if object marked as deleted
|
||||||
if objectRemoved(tx, []byte(a)) {
|
if objectRemoved(tx, []byte(a)) {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -88,3 +88,26 @@ func BenchmarkDB_Select(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMismatchAfterMatch(t *testing.T) {
|
||||||
|
db := newDB(t)
|
||||||
|
defer releaseDB(db)
|
||||||
|
|
||||||
|
obj := generateObject(t, testPrm{
|
||||||
|
attrNum: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
require.NoError(t, db.Put(obj))
|
||||||
|
|
||||||
|
a := obj.GetAttributes()[0]
|
||||||
|
|
||||||
|
fs := objectSDK.SearchFilters{}
|
||||||
|
|
||||||
|
// 1st - mismatching filter
|
||||||
|
fs.AddFilter(a.GetKey(), a.GetValue()+"1", objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
|
// 2nd - matching filter
|
||||||
|
fs.AddFilter(a.GetKey(), a.GetValue(), objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
|
testSelect(t, db, fs)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue