2021-08-25 11:41:52 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
2021-08-28 10:12:00 +08:00
|
|
|
"encoding/binary"
|
|
|
|
"errors"
|
2021-08-25 11:41:52 +08:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
)
|
|
|
|
|
2021-09-22 20:02:09 +08:00
|
|
|
// DeleteNode is to process delete msg, flush delete info into storage.
|
2021-08-25 11:41:52 +08:00
|
|
|
type deleteNode struct {
|
|
|
|
BaseNode
|
|
|
|
|
2021-09-27 14:38:00 +08:00
|
|
|
channelName string
|
|
|
|
replica Replica
|
2021-08-25 11:41:52 +08:00
|
|
|
}
|
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
func (dn *deleteNode) Name() string {
|
|
|
|
return "deleteNode"
|
2021-08-25 11:41:52 +08:00
|
|
|
}
|
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
func (dn *deleteNode) Close() {
|
|
|
|
log.Info("Flowgraph Delete Node closing")
|
|
|
|
}
|
2021-08-25 11:41:52 +08:00
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
func (dn *deleteNode) Operate(in []Msg) []Msg {
|
2021-09-22 20:02:09 +08:00
|
|
|
log.Debug("deleteNode Operating")
|
2021-08-25 11:41:52 +08:00
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
if len(in) != 1 {
|
|
|
|
log.Warn("Invalid operate message input in deleteNode", zap.Int("input length", len(in)))
|
2021-08-25 11:41:52 +08:00
|
|
|
return []Msg{}
|
|
|
|
}
|
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
_, ok := in[0].(*MsgStreamMsg)
|
2021-08-25 11:41:52 +08:00
|
|
|
if !ok {
|
2021-09-08 10:41:59 +08:00
|
|
|
log.Warn("type assertion failed for MsgStreamMsg")
|
2021-08-25 11:41:52 +08:00
|
|
|
return []Msg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return []Msg{}
|
|
|
|
}
|
|
|
|
|
2021-09-27 14:38:00 +08:00
|
|
|
// filterSegmentByPK returns the bloom filter check result.
|
2021-09-22 20:02:09 +08:00
|
|
|
// 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.
|
2021-09-27 14:38:00 +08:00
|
|
|
func (dn *deleteNode) filterSegmentByPK(pks []int64) (map[int64][]int64, error) {
|
2021-08-28 10:12:00 +08:00
|
|
|
if pks == nil {
|
2021-09-08 10:41:59 +08:00
|
|
|
return nil, errors.New("pks is nil")
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
|
|
|
results := make(map[int64][]int64)
|
|
|
|
buf := make([]byte, 8)
|
2021-09-27 14:38:00 +08:00
|
|
|
segments := dn.replica.getSegments(dn.channelName)
|
2021-08-28 10:12:00 +08:00
|
|
|
for _, segment := range segments {
|
|
|
|
for _, pk := range pks {
|
|
|
|
binary.BigEndian.PutUint64(buf, uint64(pk))
|
|
|
|
exist := segment.pkFilter.Test(buf)
|
|
|
|
if exist {
|
2021-09-27 14:38:00 +08:00
|
|
|
results[pk] = append(results[pk], segment.segmentID)
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results, nil
|
|
|
|
}
|
|
|
|
|
2021-09-27 14:38:00 +08:00
|
|
|
func newDeleteNode(replica Replica, channelName string) *deleteNode {
|
2021-08-25 11:41:52 +08:00
|
|
|
baseNode := BaseNode{}
|
|
|
|
baseNode.SetMaxParallelism(Params.FlowGraphMaxQueueLength)
|
|
|
|
|
|
|
|
return &deleteNode{
|
|
|
|
BaseNode: baseNode,
|
2021-09-27 14:38:00 +08:00
|
|
|
|
|
|
|
channelName: channelName,
|
|
|
|
replica: replica,
|
2021-09-09 15:36:01 +08:00
|
|
|
}
|
2021-08-25 11:41:52 +08:00
|
|
|
}
|