2021-12-01 18:43:32 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-01 18:43:32 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-12-01 18:43:32 +08:00
|
|
|
// 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.
|
2021-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
import (
|
2021-10-19 20:18:47 +08:00
|
|
|
"bytes"
|
2021-10-18 20:08:42 +08:00
|
|
|
"encoding/binary"
|
2021-11-29 22:01:41 +08:00
|
|
|
"errors"
|
2021-10-18 20:08:42 +08:00
|
|
|
"fmt"
|
2021-10-19 20:18:47 +08:00
|
|
|
"io"
|
|
|
|
"strconv"
|
2020-11-09 16:27:11 +08:00
|
|
|
"sync"
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2021-06-09 11:37:55 +08:00
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-11-02 18:16:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-10-19 20:18:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-10-19 20:18:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/trace"
|
2020-11-09 16:27:11 +08:00
|
|
|
)
|
|
|
|
|
2021-12-06 21:15:48 +08:00
|
|
|
// insertNode is one of the nodes in query flow graph
|
2020-11-09 16:27:11 +08:00
|
|
|
type insertNode struct {
|
2021-01-15 15:28:54 +08:00
|
|
|
baseNode
|
2021-11-09 09:27:04 +08:00
|
|
|
streamingReplica ReplicaInterface
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
type insertData struct {
|
2021-09-14 10:25:26 +08:00
|
|
|
insertIDs map[UniqueID][]int64
|
2020-11-09 16:27:11 +08:00
|
|
|
insertTimestamps map[UniqueID][]Timestamp
|
|
|
|
insertRecords map[UniqueID][]*commonpb.Blob
|
|
|
|
insertOffset map[UniqueID]int64
|
2021-10-19 20:18:47 +08:00
|
|
|
insertPKs map[UniqueID][]int64
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-12-07 21:29:21 +08:00
|
|
|
// deleteData stores the valid delete data
|
2021-10-15 11:02:32 +08:00
|
|
|
type deleteData struct {
|
|
|
|
deleteIDs map[UniqueID][]int64
|
|
|
|
deleteTimestamps map[UniqueID][]Timestamp
|
|
|
|
deleteOffset map[UniqueID]int64
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func (iNode *insertNode) Name() string {
|
|
|
|
return "iNode"
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:41:46 +08:00
|
|
|
func (iNode *insertNode) Operate(in []flowgraph.Msg) []flowgraph.Msg {
|
2021-03-05 09:21:35 +08:00
|
|
|
//log.Debug("Do insertNode operation")
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
if len(in) != 1 {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("Invalid operate message input in insertNode", zap.Int("input length", len(in)))
|
2020-11-09 16:27:11 +08:00
|
|
|
// TODO: add error handling
|
|
|
|
}
|
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
iMsg, ok := in[0].(*insertMsg)
|
2020-11-09 16:27:11 +08:00
|
|
|
if !ok {
|
2021-07-23 20:09:33 +08:00
|
|
|
log.Warn("type assertion failed for insertMsg")
|
2020-11-09 16:27:11 +08:00
|
|
|
// TODO: add error handling
|
|
|
|
}
|
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
iData := insertData{
|
2021-09-14 10:25:26 +08:00
|
|
|
insertIDs: make(map[UniqueID][]int64),
|
|
|
|
insertTimestamps: make(map[UniqueID][]Timestamp),
|
|
|
|
insertRecords: make(map[UniqueID][]*commonpb.Blob),
|
|
|
|
insertOffset: make(map[UniqueID]int64),
|
2021-10-19 20:18:47 +08:00
|
|
|
insertPKs: make(map[UniqueID][]int64),
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
if iMsg == nil {
|
2021-03-25 14:41:46 +08:00
|
|
|
return []Msg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var spans []opentracing.Span
|
|
|
|
for _, msg := range iMsg.insertMessages {
|
|
|
|
sp, ctx := trace.StartSpanFromContext(msg.TraceCtx())
|
|
|
|
spans = append(spans, sp)
|
|
|
|
msg.SetTraceCtx(ctx)
|
2021-03-22 16:36:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
// 1. hash insertMessages to insertData
|
|
|
|
for _, task := range iMsg.insertMessages {
|
2021-06-15 12:41:40 +08:00
|
|
|
// check if partition exists, if not, create partition
|
2021-10-26 14:46:19 +08:00
|
|
|
if hasPartition := iNode.streamingReplica.hasPartition(task.PartitionID); !hasPartition {
|
|
|
|
err := iNode.streamingReplica.addPartition(task.CollectionID, task.PartitionID)
|
2021-06-15 12:41:40 +08:00
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2021-06-15 12:41:40 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 17:01:10 +08:00
|
|
|
// check if segment exists, if not, create this segment
|
2021-10-26 14:46:19 +08:00
|
|
|
if !iNode.streamingReplica.hasSegment(task.SegmentID) {
|
|
|
|
err := iNode.streamingReplica.addSegment(task.SegmentID, task.PartitionID, task.CollectionID, task.ShardName, segmentTypeGrowing, true)
|
2020-11-16 17:01:10 +08:00
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2020-11-16 17:01:10 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 19:23:06 +08:00
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
iData.insertIDs[task.SegmentID] = append(iData.insertIDs[task.SegmentID], task.RowIDs...)
|
|
|
|
iData.insertTimestamps[task.SegmentID] = append(iData.insertTimestamps[task.SegmentID], task.Timestamps...)
|
|
|
|
iData.insertRecords[task.SegmentID] = append(iData.insertRecords[task.SegmentID], task.RowData...)
|
2021-11-29 22:01:41 +08:00
|
|
|
pks, err := getPrimaryKeys(task, iNode.streamingReplica)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
iData.insertPKs[task.SegmentID] = append(iData.insertPKs[task.SegmentID], pks...)
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2. do preInsert
|
2021-10-09 22:52:59 +08:00
|
|
|
for segmentID := range iData.insertRecords {
|
2021-10-26 14:46:19 +08:00
|
|
|
var targetSegment, err = iNode.streamingReplica.getSegmentByID(segmentID)
|
2020-11-09 16:27:11 +08:00
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2021-11-09 09:27:04 +08:00
|
|
|
continue
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
var numOfRecords = len(iData.insertRecords[segmentID])
|
2020-11-09 16:27:11 +08:00
|
|
|
if targetSegment != nil {
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := targetSegment.segmentPreInsert(numOfRecords)
|
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2021-11-09 09:27:04 +08:00
|
|
|
continue
|
2021-03-12 19:23:06 +08:00
|
|
|
}
|
2021-10-09 22:52:59 +08:00
|
|
|
iData.insertOffset[segmentID] = offset
|
2021-03-31 16:16:58 +08:00
|
|
|
log.Debug("insertNode operator", zap.Int("insert size", numOfRecords), zap.Int64("insert offset", offset), zap.Int64("segment id", segmentID))
|
2021-10-19 20:18:47 +08:00
|
|
|
targetSegment.updateBloomFilter(iData.insertPKs[segmentID])
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. do insert
|
|
|
|
wg := sync.WaitGroup{}
|
2021-10-09 22:52:59 +08:00
|
|
|
for segmentID := range iData.insertRecords {
|
2020-11-09 16:27:11 +08:00
|
|
|
wg.Add(1)
|
2021-10-09 22:52:59 +08:00
|
|
|
go iNode.insert(&iData, segmentID, &wg)
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2021-10-18 20:08:42 +08:00
|
|
|
delData := &deleteData{
|
|
|
|
deleteIDs: make(map[UniqueID][]int64),
|
|
|
|
deleteTimestamps: make(map[UniqueID][]Timestamp),
|
|
|
|
deleteOffset: make(map[UniqueID]int64),
|
|
|
|
}
|
|
|
|
// 1. filter segment by bloom filter
|
|
|
|
for _, delMsg := range iMsg.deleteMessages {
|
2021-10-27 14:36:23 +08:00
|
|
|
if iNode.streamingReplica.getSegmentNum() != 0 {
|
2021-11-09 09:27:04 +08:00
|
|
|
log.Debug("delete in streaming replica",
|
|
|
|
zap.Any("collectionID", delMsg.CollectionID),
|
|
|
|
zap.Any("collectionName", delMsg.CollectionName),
|
|
|
|
zap.Any("pks", delMsg.PrimaryKeys),
|
|
|
|
zap.Any("timestamp", delMsg.Timestamps))
|
2021-10-26 14:46:19 +08:00
|
|
|
processDeleteMessages(iNode.streamingReplica, delMsg, delData)
|
2021-10-18 20:08:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 18:01:15 +08:00
|
|
|
// 2. do preDelete
|
2021-10-27 14:36:23 +08:00
|
|
|
for segmentID, pks := range delData.deleteIDs {
|
2021-11-09 09:27:04 +08:00
|
|
|
segment, err := iNode.streamingReplica.getSegmentByID(segmentID)
|
|
|
|
if err != nil {
|
|
|
|
log.Debug(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
2021-10-27 14:36:23 +08:00
|
|
|
offset := segment.segmentPreDelete(len(pks))
|
|
|
|
delData.deleteOffset[segmentID] = offset
|
|
|
|
}
|
|
|
|
|
2021-10-27 18:01:15 +08:00
|
|
|
// 3. do delete
|
2021-11-09 09:27:04 +08:00
|
|
|
for segmentID := range delData.deleteOffset {
|
2021-10-18 20:08:42 +08:00
|
|
|
wg.Add(1)
|
|
|
|
go iNode.delete(delData, segmentID, &wg)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
var res Msg = &serviceTimeMsg{
|
|
|
|
timeRange: iMsg.timeRange,
|
|
|
|
}
|
2021-03-25 14:41:46 +08:00
|
|
|
for _, sp := range spans {
|
|
|
|
sp.Finish()
|
|
|
|
}
|
2021-06-09 11:37:55 +08:00
|
|
|
|
2021-03-25 14:41:46 +08:00
|
|
|
return []Msg{res}
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-10-26 14:46:19 +08:00
|
|
|
func processDeleteMessages(replica ReplicaInterface, msg *msgstream.DeleteMsg, delData *deleteData) {
|
|
|
|
var partitionIDs []UniqueID
|
|
|
|
var err error
|
|
|
|
if msg.PartitionID != -1 {
|
|
|
|
partitionIDs = []UniqueID{msg.PartitionID}
|
|
|
|
} else {
|
|
|
|
partitionIDs, err = replica.getPartitionIDs(msg.CollectionID)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resultSegmentIDs := make([]UniqueID, 0)
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
segmentIDs, err := replica.getSegmentIDs(partitionID)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resultSegmentIDs = append(resultSegmentIDs, segmentIDs...)
|
|
|
|
}
|
|
|
|
for _, segmentID := range resultSegmentIDs {
|
|
|
|
segment, err := replica.getSegmentByID(segmentID)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pks, err := filterSegmentsByPKs(msg.PrimaryKeys, segment)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(pks) > 0 {
|
|
|
|
delData.deleteIDs[segmentID] = append(delData.deleteIDs[segmentID], pks...)
|
|
|
|
// TODO(yukun) get offset of pks
|
|
|
|
delData.deleteTimestamps[segmentID] = append(delData.deleteTimestamps[segmentID], msg.Timestamps[:len(pks)]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 16:34:36 +08:00
|
|
|
func filterSegmentsByPKs(pks []int64, segment *Segment) ([]int64, error) {
|
2021-10-18 20:08:42 +08:00
|
|
|
if pks == nil {
|
2021-10-20 16:34:36 +08:00
|
|
|
return nil, fmt.Errorf("pks is nil when getSegmentsByPKs")
|
2021-10-18 20:08:42 +08:00
|
|
|
}
|
|
|
|
if segment == nil {
|
2021-10-20 16:34:36 +08:00
|
|
|
return nil, fmt.Errorf("segments is nil when getSegmentsByPKs")
|
2021-10-18 20:08:42 +08:00
|
|
|
}
|
|
|
|
buf := make([]byte, 8)
|
2021-10-20 16:34:36 +08:00
|
|
|
res := make([]int64, 0)
|
2021-10-18 20:08:42 +08:00
|
|
|
for _, pk := range pks {
|
2021-11-02 18:16:32 +08:00
|
|
|
common.Endian.PutUint64(buf, uint64(pk))
|
2021-10-18 20:08:42 +08:00
|
|
|
exist := segment.pkFilter.Test(buf)
|
2021-10-20 16:34:36 +08:00
|
|
|
if exist {
|
|
|
|
res = append(res, pk)
|
|
|
|
}
|
2021-10-18 20:08:42 +08:00
|
|
|
}
|
2021-10-26 14:46:19 +08:00
|
|
|
log.Debug("In filterSegmentsByPKs", zap.Any("pk len", len(res)), zap.Any("segment", segment.segmentID))
|
2021-10-20 16:34:36 +08:00
|
|
|
return res, nil
|
2021-10-18 20:08:42 +08:00
|
|
|
}
|
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
func (iNode *insertNode) insert(iData *insertData, segmentID UniqueID, wg *sync.WaitGroup) {
|
2021-06-05 16:21:36 +08:00
|
|
|
log.Debug("QueryNode::iNode::insert", zap.Any("SegmentID", segmentID))
|
2021-10-26 14:46:19 +08:00
|
|
|
var targetSegment, err = iNode.streamingReplica.getSegmentByID(segmentID)
|
2020-11-09 16:27:11 +08:00
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn("cannot find segment:", zap.Int64("segmentID", segmentID))
|
2020-11-09 16:27:11 +08:00
|
|
|
// TODO: add error handling
|
2020-11-26 16:01:31 +08:00
|
|
|
wg.Done()
|
2020-11-09 16:27:11 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
if targetSegment.segmentType != segmentTypeGrowing {
|
|
|
|
wg.Done()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-09 22:52:59 +08:00
|
|
|
ids := iData.insertIDs[segmentID]
|
|
|
|
timestamps := iData.insertTimestamps[segmentID]
|
|
|
|
records := iData.insertRecords[segmentID]
|
|
|
|
offsets := iData.insertOffset[segmentID]
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
err = targetSegment.segmentInsert(offsets, &ids, ×tamps, &records)
|
|
|
|
if err != nil {
|
2021-06-05 16:21:36 +08:00
|
|
|
log.Debug("QueryNode: targetSegmentInsert failed", zap.Error(err))
|
2020-11-09 16:27:11 +08:00
|
|
|
// TODO: add error handling
|
2020-11-26 16:01:31 +08:00
|
|
|
wg.Done()
|
2020-11-09 16:27:11 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-20 19:51:23 +08:00
|
|
|
log.Debug("Do insert done", zap.Int("len", len(iData.insertIDs[segmentID])), zap.Int64("segmentID", segmentID))
|
2020-11-09 16:27:11 +08:00
|
|
|
wg.Done()
|
|
|
|
}
|
|
|
|
|
2021-10-15 11:02:32 +08:00
|
|
|
func (iNode *insertNode) delete(deleteData *deleteData, segmentID UniqueID, wg *sync.WaitGroup) {
|
|
|
|
defer wg.Done()
|
|
|
|
log.Debug("QueryNode::iNode::delete", zap.Any("SegmentID", segmentID))
|
2021-11-09 09:27:04 +08:00
|
|
|
targetSegment, err := iNode.streamingReplica.getSegmentByID(segmentID)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if targetSegment.segmentType != segmentTypeGrowing {
|
2021-10-15 11:02:32 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ids := deleteData.deleteIDs[segmentID]
|
|
|
|
timestamps := deleteData.deleteTimestamps[segmentID]
|
|
|
|
offset := deleteData.deleteOffset[segmentID]
|
|
|
|
|
2021-11-09 09:27:04 +08:00
|
|
|
err = targetSegment.segmentDelete(offset, &ids, ×tamps)
|
2021-10-15 11:02:32 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("QueryNode: targetSegmentDelete failed", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Do delete done", zap.Int("len", len(deleteData.deleteIDs[segmentID])), zap.Int64("segmentID", segmentID))
|
|
|
|
}
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
// TODO: remove this function to proper file
|
|
|
|
// TODO: why not return error?
|
2021-11-29 22:01:41 +08:00
|
|
|
func getPrimaryKeys(msg *msgstream.InsertMsg, streamingReplica ReplicaInterface) ([]int64, error) {
|
2021-10-19 20:18:47 +08:00
|
|
|
if len(msg.RowIDs) != len(msg.Timestamps) || len(msg.RowIDs) != len(msg.RowData) {
|
|
|
|
log.Warn("misaligned messages detected")
|
2021-11-29 22:01:41 +08:00
|
|
|
return nil, errors.New("misaligned messages detected")
|
2021-10-19 20:18:47 +08:00
|
|
|
}
|
|
|
|
collectionID := msg.GetCollectionID()
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
collection, err := streamingReplica.getCollectionByID(collectionID)
|
2021-11-09 09:27:04 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
2021-11-29 22:01:41 +08:00
|
|
|
return nil, err
|
2021-10-19 20:18:47 +08:00
|
|
|
}
|
|
|
|
offset := 0
|
|
|
|
for _, field := range collection.schema.Fields {
|
|
|
|
if field.IsPrimaryKey {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
switch field.DataType {
|
|
|
|
case schemapb.DataType_Bool:
|
|
|
|
offset++
|
|
|
|
case schemapb.DataType_Int8:
|
|
|
|
offset++
|
|
|
|
case schemapb.DataType_Int16:
|
|
|
|
offset += 2
|
|
|
|
case schemapb.DataType_Int32:
|
|
|
|
offset += 4
|
|
|
|
case schemapb.DataType_Int64:
|
|
|
|
offset += 8
|
|
|
|
case schemapb.DataType_Float:
|
|
|
|
offset += 4
|
|
|
|
case schemapb.DataType_Double:
|
|
|
|
offset += 8
|
|
|
|
case schemapb.DataType_FloatVector:
|
|
|
|
for _, t := range field.TypeParams {
|
|
|
|
if t.Key == "dim" {
|
|
|
|
dim, err := strconv.Atoi(t.Value)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("strconv wrong on get dim", zap.Error(err))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
offset += dim * 4
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case schemapb.DataType_BinaryVector:
|
|
|
|
for _, t := range field.TypeParams {
|
|
|
|
if t.Key == "dim" {
|
2021-10-26 14:46:19 +08:00
|
|
|
dim, err := strconv.Atoi(t.Value)
|
2021-10-19 20:18:47 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Error("strconv wrong on get dim", zap.Error(err))
|
2021-11-29 22:01:41 +08:00
|
|
|
return nil, err
|
2021-10-19 20:18:47 +08:00
|
|
|
}
|
|
|
|
offset += dim / 8
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blobReaders := make([]io.Reader, len(msg.RowData))
|
|
|
|
for i, blob := range msg.RowData {
|
|
|
|
blobReaders[i] = bytes.NewReader(blob.GetValue()[offset : offset+8])
|
|
|
|
}
|
|
|
|
pks := make([]int64, len(blobReaders))
|
|
|
|
|
|
|
|
for i, reader := range blobReaders {
|
2021-11-02 18:16:32 +08:00
|
|
|
err := binary.Read(reader, common.Endian, &pks[i])
|
2021-10-19 20:18:47 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("binary read blob value failed", zap.Error(err))
|
2021-11-29 22:01:41 +08:00
|
|
|
return nil, err
|
2021-10-19 20:18:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 22:01:41 +08:00
|
|
|
return pks, nil
|
2021-10-19 20:18:47 +08:00
|
|
|
}
|
2021-11-09 09:27:04 +08:00
|
|
|
func newInsertNode(streamingReplica ReplicaInterface) *insertNode {
|
2020-12-10 16:31:09 +08:00
|
|
|
maxQueueLength := Params.FlowGraphMaxQueueLength
|
|
|
|
maxParallelism := Params.FlowGraphMaxParallelism
|
2020-11-18 17:32:52 +08:00
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
baseNode := baseNode{}
|
2020-11-09 16:27:11 +08:00
|
|
|
baseNode.SetMaxQueueLength(maxQueueLength)
|
|
|
|
baseNode.SetMaxParallelism(maxParallelism)
|
|
|
|
|
|
|
|
return &insertNode{
|
2021-11-09 09:27:04 +08:00
|
|
|
baseNode: baseNode,
|
|
|
|
streamingReplica: streamingReplica,
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|