Update filterSegmentByPK (#9450)

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
This commit is contained in:
Cai Yudong 2021-10-08 12:04:56 +08:00 committed by GitHub
parent e52586a052
commit 12d640a023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -13,7 +13,6 @@ package datanode
import (
"encoding/binary"
"errors"
"go.uber.org/zap"
@ -68,23 +67,20 @@ func (dn *deleteNode) Operate(in []Msg) []Msg {
// filterSegmentByPK returns the bloom filter check result.
// If the key may exists in the segment, returns it in map.
// If the key not exists in the segment, the segment is filter out.
func (dn *deleteNode) filterSegmentByPK(partID UniqueID, pks []int64) (map[int64][]int64, error) {
if pks == nil {
return nil, errors.New("pks is nil")
}
results := make(map[int64][]int64)
func (dn *deleteNode) filterSegmentByPK(partID UniqueID, pks []int64) map[int64][]int64 {
result := make(map[int64][]int64)
buf := make([]byte, 8)
segments := dn.replica.filterSegments(dn.channelName, partID)
for _, segment := range segments {
for _, pk := range pks {
for _, pk := range pks {
for _, segment := range segments {
binary.BigEndian.PutUint64(buf, uint64(pk))
exist := segment.pkFilter.Test(buf)
if exist {
results[pk] = append(results[pk], segment.segmentID)
result[pk] = append(result[pk], segment.segmentID)
}
}
}
return results, nil
return result
}
func newDeleteNode(replica Replica, channelName string, flushCh <-chan *flushMsg) *deleteNode {

View File

@ -148,8 +148,7 @@ func Test_GetSegmentsByPKs(t *testing.T) {
mockReplica.flushedSegments[segment5.segmentID] = segment5
mockReplica.flushedSegments[segment6.segmentID] = segment6
dn := newDeleteNode(mockReplica, "test", make(chan *flushMsg))
results, err := dn.filterSegmentByPK(0, []int64{0, 1, 2, 3, 4})
assert.Nil(t, err)
results := dn.filterSegmentByPK(0, []int64{0, 1, 2, 3, 4})
expected := map[int64][]int64{
0: {1, 2, 3},
1: {1, 2, 3},