2021-04-19 10:09:43 +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.
2021-06-22 14:40:07 +08:00
package proxy
2020-11-03 14:53:36 +08:00
import (
2021-06-03 15:03:34 +08:00
"bytes"
2021-02-04 19:34:35 +08:00
"context"
2021-06-03 15:03:34 +08:00
"encoding/binary"
2021-03-08 19:39:36 +08:00
"errors"
2021-02-08 14:20:29 +08:00
"fmt"
2020-11-26 16:01:31 +08:00
"math"
2021-06-03 15:03:34 +08:00
"reflect"
2021-03-22 16:36:10 +08:00
"regexp"
2021-03-25 10:14:09 +08:00
"runtime"
2021-05-25 19:53:15 +08:00
"sort"
2020-11-26 16:01:31 +08:00
"strconv"
2021-07-14 18:51:54 +08:00
"strings"
2021-05-25 19:53:15 +08:00
"unsafe"
2021-03-26 11:19:02 +08:00
2021-03-08 19:39:36 +08:00
"go.uber.org/zap"
2021-03-05 10:15:27 +08:00
2020-11-26 16:01:31 +08:00
"github.com/golang/protobuf/proto"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/allocator"
2021-10-20 17:56:38 +08:00
"github.com/milvus-io/milvus/internal/common"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
2021-07-21 14:52:12 +08:00
"github.com/milvus-io/milvus/internal/proto/planpb"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/proto/querypb"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/types"
2021-07-21 14:52:12 +08:00
"github.com/milvus-io/milvus/internal/util/funcutil"
"github.com/milvus-io/milvus/internal/util/indexparamcheck"
2021-10-20 17:56:38 +08:00
"github.com/milvus-io/milvus/internal/util/timerecord"
2021-09-22 19:33:54 +08:00
"github.com/milvus-io/milvus/internal/util/trace"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/util/typeutil"
2020-11-03 14:53:36 +08:00
)
2021-02-23 09:58:06 +08:00
const (
2021-09-11 18:06:02 +08:00
InsertTaskName = "InsertTask"
2021-02-23 09:58:06 +08:00
CreateCollectionTaskName = "CreateCollectionTask"
DropCollectionTaskName = "DropCollectionTask"
2021-09-11 18:06:02 +08:00
SearchTaskName = "SearchTask"
2021-05-19 18:45:15 +08:00
RetrieveTaskName = "RetrieveTask"
2021-09-11 18:06:02 +08:00
QueryTaskName = "QueryTask"
2021-04-29 16:48:06 +08:00
AnnsFieldKey = "anns_field"
TopKKey = "topk"
MetricTypeKey = "metric_type"
SearchParamsKey = "params"
2021-10-08 17:39:55 +08:00
RoundDecimalKey = "round_decimal"
2021-02-23 09:58:06 +08:00
HasCollectionTaskName = "HasCollectionTask"
DescribeCollectionTaskName = "DescribeCollectionTask"
GetCollectionStatisticsTaskName = "GetCollectionStatisticsTask"
2021-05-10 17:39:08 +08:00
GetPartitionStatisticsTaskName = "GetPartitionStatisticsTask"
2021-02-23 09:58:06 +08:00
ShowCollectionTaskName = "ShowCollectionTask"
CreatePartitionTaskName = "CreatePartitionTask"
DropPartitionTaskName = "DropPartitionTask"
HasPartitionTaskName = "HasPartitionTask"
ShowPartitionTaskName = "ShowPartitionTask"
2021-09-11 18:06:02 +08:00
CreateIndexTaskName = "CreateIndexTask"
DescribeIndexTaskName = "DescribeIndexTask"
DropIndexTaskName = "DropIndexTask"
GetIndexStateTaskName = "GetIndexStateTask"
GetIndexBuildProgressTaskName = "GetIndexBuildProgressTask"
FlushTaskName = "FlushTask"
2021-02-23 09:58:06 +08:00
LoadCollectionTaskName = "LoadCollectionTask"
ReleaseCollectionTaskName = "ReleaseCollectionTask"
2021-09-09 19:02:08 +08:00
LoadPartitionTaskName = "LoadPartitionsTask"
ReleasePartitionTaskName = "ReleasePartitionsTask"
2021-09-15 14:04:54 +08:00
deleteTaskName = "DeleteTask"
2021-09-18 11:13:51 +08:00
CreateAliasTaskName = "CreateAliasTask"
DropAliasTaskName = "DropAliasTask"
AlterAliasTaskName = "AlterAliasTask"
2021-09-22 10:15:54 +08:00
minFloat32 = - 1 * float32 ( math . MaxFloat32 )
2021-02-23 09:58:06 +08:00
)
2020-11-03 14:53:36 +08:00
type task interface {
2021-03-25 14:41:46 +08:00
TraceCtx ( ) context . Context
2020-11-23 16:52:17 +08:00
ID ( ) UniqueID // return ReqID
SetID ( uid UniqueID ) // set ReqID
2021-02-23 09:58:06 +08:00
Name ( ) string
2021-01-16 15:06:19 +08:00
Type ( ) commonpb . MsgType
2020-11-05 18:01:33 +08:00
BeginTs ( ) Timestamp
EndTs ( ) Timestamp
2020-11-04 17:58:43 +08:00
SetTs ( ts Timestamp )
2021-01-22 09:36:18 +08:00
OnEnqueue ( ) error
2021-02-23 09:58:06 +08:00
PreExecute ( ctx context . Context ) error
Execute ( ctx context . Context ) error
PostExecute ( ctx context . Context ) error
2020-11-03 14:53:36 +08:00
WaitToFinish ( ) error
2020-11-05 18:01:33 +08:00
Notify ( err error )
2020-11-03 14:53:36 +08:00
}
2021-05-31 11:40:31 +08:00
type dmlTask interface {
task
2021-06-15 10:19:38 +08:00
getChannels ( ) ( [ ] vChan , error )
getPChanStats ( ) ( map [ pChan ] pChanStatistics , error )
2021-06-02 10:17:32 +08:00
}
2020-11-07 16:18:23 +08:00
type BaseInsertTask = msgstream . InsertMsg
2020-11-05 18:01:33 +08:00
2021-09-11 11:36:22 +08:00
type insertTask struct {
2020-11-07 16:18:23 +08:00
BaseInsertTask
2021-06-03 15:03:34 +08:00
req * milvuspb . InsertRequest
2020-11-17 20:00:23 +08:00
Condition
2021-06-22 16:44:09 +08:00
ctx context . Context
2021-06-21 11:42:18 +08:00
result * milvuspb . MutationResult
2021-03-08 10:09:48 +08:00
rowIDAllocator * allocator . IDAllocator
2021-10-02 18:43:56 +08:00
segIDAssigner * segIDAssigner
2021-05-27 17:09:50 +08:00
chMgr channelsMgr
2021-05-31 17:28:31 +08:00
chTicker channelsTimeTicker
2021-06-15 10:19:38 +08:00
vChannels [ ] vChan
pChannels [ ] pChan
2021-06-21 11:42:18 +08:00
schema * schemapb . CollectionSchema
2020-11-05 18:01:33 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return it . ctx
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) ID ( ) UniqueID {
2021-02-23 09:58:06 +08:00
return it . Base . MsgID
2021-01-22 09:36:18 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
it . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return InsertTaskName
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) Type ( ) commonpb . MsgType {
2021-02-23 09:58:06 +08:00
return it . Base . MsgType
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) BeginTs ( ) Timestamp {
2021-02-23 09:58:06 +08:00
return it . BeginTimestamp
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) SetTs ( ts Timestamp ) {
2020-11-26 16:01:31 +08:00
it . BeginTimestamp = ts
it . EndTimestamp = ts
2020-11-05 18:01:33 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) EndTs ( ) Timestamp {
2020-11-26 16:01:31 +08:00
return it . EndTimestamp
2020-11-05 18:01:33 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) getPChanStats ( ) ( map [ pChan ] pChanStatistics , error ) {
2021-06-15 10:19:38 +08:00
ret := make ( map [ pChan ] pChanStatistics )
channels , err := it . getChannels ( )
2021-05-31 11:40:31 +08:00
if err != nil {
2021-06-15 10:19:38 +08:00
return ret , err
2021-05-31 11:40:31 +08:00
}
2021-06-15 10:19:38 +08:00
beginTs := it . BeginTs ( )
endTs := it . EndTs ( )
for _ , channel := range channels {
ret [ channel ] = pChanStatistics {
minTs : beginTs ,
maxTs : endTs ,
2021-05-31 11:40:31 +08:00
}
}
2021-06-15 10:19:38 +08:00
return ret , nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) getChannels ( ) ( [ ] pChan , error ) {
2021-06-15 10:19:38 +08:00
collID , err := globalMetaCache . GetCollectionID ( it . ctx , it . CollectionName )
2021-05-31 11:40:31 +08:00
if err != nil {
2021-06-15 10:19:38 +08:00
return nil , err
2021-05-31 11:40:31 +08:00
}
2021-06-15 10:19:38 +08:00
var channels [ ] pChan
channels , err = it . chMgr . getChannels ( collID )
if err != nil {
err = it . chMgr . createDMLMsgStream ( collID )
if err != nil {
return nil , err
2021-05-31 11:40:31 +08:00
}
2021-06-15 10:19:38 +08:00
channels , err = it . chMgr . getChannels ( collID )
2021-09-06 20:49:04 +08:00
if err == nil {
for _ , pchan := range channels {
err := it . chTicker . addPChan ( pchan )
if err != nil {
log . Warn ( "failed to add pchan to channels time ticker" ,
zap . Error ( err ) ,
zap . Int64 ( "collection id" , collID ) ,
zap . String ( "pchan" , pchan ) )
}
}
}
2021-05-31 11:40:31 +08:00
}
2021-06-15 10:19:38 +08:00
return channels , err
2021-05-31 11:40:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) OnEnqueue ( ) error {
2021-03-22 19:28:43 +08:00
it . BaseInsertTask . InsertRequest . Base = & commonpb . MsgBase { }
2021-02-23 09:58:06 +08:00
return nil
2020-11-05 18:01:33 +08:00
}
2021-07-13 16:33:55 +08:00
func getNumRowsOfScalarField ( datas interface { } ) uint32 {
realTypeDatas := reflect . ValueOf ( datas )
return uint32 ( realTypeDatas . Len ( ) )
}
func getNumRowsOfFloatVectorField ( fDatas [ ] float32 , dim int64 ) ( uint32 , error ) {
if dim <= 0 {
return 0 , errDimLessThanOrEqualToZero ( int ( dim ) )
}
l := len ( fDatas )
if int64 ( l ) % dim != 0 {
return 0 , fmt . Errorf ( "the length(%d) of float data should divide the dim(%d)" , l , dim )
}
return uint32 ( int ( int64 ( l ) / dim ) ) , nil
}
func getNumRowsOfBinaryVectorField ( bDatas [ ] byte , dim int64 ) ( uint32 , error ) {
if dim <= 0 {
return 0 , errDimLessThanOrEqualToZero ( int ( dim ) )
}
if dim % 8 != 0 {
return 0 , errDimShouldDivide8 ( int ( dim ) )
}
l := len ( bDatas )
if ( 8 * int64 ( l ) ) % dim != 0 {
return 0 , fmt . Errorf ( "the num(%d) of all bits should divide the dim(%d)" , 8 * l , dim )
}
return uint32 ( int ( ( 8 * int64 ( l ) ) / dim ) ) , nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) checkLengthOfFieldsData ( ) error {
2021-07-13 16:33:55 +08:00
neededFieldsNum := 0
for _ , field := range it . schema . Fields {
if ! field . AutoID {
neededFieldsNum ++
}
}
if len ( it . req . FieldsData ) < neededFieldsNum {
return errFieldsLessThanNeeded ( len ( it . req . FieldsData ) , neededFieldsNum )
}
return nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) checkRowNums ( ) error {
2021-07-13 16:33:55 +08:00
if it . req . NumRows <= 0 {
return errNumRowsLessThanOrEqualToZero ( it . req . NumRows )
}
if err := it . checkLengthOfFieldsData ( ) ; err != nil {
return err
}
rowNums := it . req . NumRows
for i , field := range it . req . FieldsData {
switch field . Field . ( type ) {
case * schemapb . FieldData_Scalars :
scalarField := field . GetScalars ( )
switch scalarField . Data . ( type ) {
case * schemapb . ScalarField_BoolData :
fieldNumRows := getNumRowsOfScalarField ( scalarField . GetBoolData ( ) . Data )
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . ScalarField_IntData :
fieldNumRows := getNumRowsOfScalarField ( scalarField . GetIntData ( ) . Data )
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . ScalarField_LongData :
fieldNumRows := getNumRowsOfScalarField ( scalarField . GetLongData ( ) . Data )
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . ScalarField_FloatData :
fieldNumRows := getNumRowsOfScalarField ( scalarField . GetFloatData ( ) . Data )
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . ScalarField_DoubleData :
fieldNumRows := getNumRowsOfScalarField ( scalarField . GetDoubleData ( ) . Data )
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . ScalarField_BytesData :
return errUnsupportedDType ( "bytes" )
case * schemapb . ScalarField_StringData :
return errUnsupportedDType ( "string" )
case nil :
continue
default :
continue
}
case * schemapb . FieldData_Vectors :
vectorField := field . GetVectors ( )
switch vectorField . Data . ( type ) {
case * schemapb . VectorField_FloatVector :
dim := vectorField . GetDim ( )
fieldNumRows , err := getNumRowsOfFloatVectorField ( vectorField . GetFloatVector ( ) . Data , dim )
if err != nil {
return err
}
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case * schemapb . VectorField_BinaryVector :
dim := vectorField . GetDim ( )
fieldNumRows , err := getNumRowsOfBinaryVectorField ( vectorField . GetBinaryVector ( ) , dim )
if err != nil {
return err
}
if fieldNumRows != rowNums {
return errNumRowsOfFieldDataMismatchPassed ( i , fieldNumRows , rowNums )
}
case nil :
continue
default :
continue
}
}
}
return nil
}
2021-06-21 11:42:18 +08:00
// TODO(dragondriver): ignore the order of fields in request, use the order of CollectionSchema to reorganize data
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) transferColumnBasedRequestToRowBasedData ( ) error {
2021-06-03 15:03:34 +08:00
dTypes := make ( [ ] schemapb . DataType , 0 , len ( it . req . FieldsData ) )
datas := make ( [ ] [ ] interface { } , 0 , len ( it . req . FieldsData ) )
rowNum := 0
appendScalarField := func ( getDataFunc func ( ) interface { } ) error {
fieldDatas := reflect . ValueOf ( getDataFunc ( ) )
if rowNum != 0 && rowNum != fieldDatas . Len ( ) {
return errors . New ( "the row num of different column is not equal" )
}
rowNum = fieldDatas . Len ( )
datas = append ( datas , make ( [ ] interface { } , 0 , rowNum ) )
idx := len ( datas ) - 1
for i := 0 ; i < rowNum ; i ++ {
datas [ idx ] = append ( datas [ idx ] , fieldDatas . Index ( i ) . Interface ( ) )
}
return nil
}
appendFloatVectorField := func ( fDatas [ ] float32 , dim int64 ) error {
l := len ( fDatas )
if int64 ( l ) % dim != 0 {
return errors . New ( "invalid vectors" )
}
r := int64 ( l ) / dim
if rowNum != 0 && rowNum != int ( r ) {
return errors . New ( "the row num of different column is not equal" )
}
rowNum = int ( r )
datas = append ( datas , make ( [ ] interface { } , 0 , rowNum ) )
idx := len ( datas ) - 1
vector := make ( [ ] float32 , 0 , dim )
for i := 0 ; i < l ; i ++ {
vector = append ( vector , fDatas [ i ] )
if int64 ( i + 1 ) % dim == 0 {
datas [ idx ] = append ( datas [ idx ] , vector )
vector = make ( [ ] float32 , 0 , dim )
}
}
return nil
}
appendBinaryVectorField := func ( bDatas [ ] byte , dim int64 ) error {
l := len ( bDatas )
if dim % 8 != 0 {
return errors . New ( "invalid dim" )
}
if ( 8 * int64 ( l ) ) % dim != 0 {
return errors . New ( "invalid vectors" )
}
r := ( 8 * int64 ( l ) ) / dim
if rowNum != 0 && rowNum != int ( r ) {
return errors . New ( "the row num of different column is not equal" )
}
rowNum = int ( r )
datas = append ( datas , make ( [ ] interface { } , 0 , rowNum ) )
idx := len ( datas ) - 1
vector := make ( [ ] byte , 0 , dim )
for i := 0 ; i < l ; i ++ {
vector = append ( vector , bDatas [ i ] )
if ( 8 * int64 ( i + 1 ) ) % dim == 0 {
datas [ idx ] = append ( datas [ idx ] , vector )
vector = make ( [ ] byte , 0 , dim )
}
}
return nil
}
for _ , field := range it . req . FieldsData {
switch field . Field . ( type ) {
case * schemapb . FieldData_Scalars :
scalarField := field . GetScalars ( )
switch scalarField . Data . ( type ) {
case * schemapb . ScalarField_BoolData :
err := appendScalarField ( func ( ) interface { } {
return scalarField . GetBoolData ( ) . Data
} )
if err != nil {
return err
}
case * schemapb . ScalarField_IntData :
err := appendScalarField ( func ( ) interface { } {
return scalarField . GetIntData ( ) . Data
} )
if err != nil {
return err
}
case * schemapb . ScalarField_LongData :
err := appendScalarField ( func ( ) interface { } {
return scalarField . GetLongData ( ) . Data
} )
if err != nil {
return err
}
case * schemapb . ScalarField_FloatData :
err := appendScalarField ( func ( ) interface { } {
return scalarField . GetFloatData ( ) . Data
} )
if err != nil {
return err
}
case * schemapb . ScalarField_DoubleData :
err := appendScalarField ( func ( ) interface { } {
return scalarField . GetDoubleData ( ) . Data
} )
if err != nil {
return err
}
case * schemapb . ScalarField_BytesData :
return errors . New ( "bytes field is not supported now" )
case * schemapb . ScalarField_StringData :
return errors . New ( "string field is not supported now" )
case nil :
continue
default :
continue
}
case * schemapb . FieldData_Vectors :
vectorField := field . GetVectors ( )
switch vectorField . Data . ( type ) {
case * schemapb . VectorField_FloatVector :
floatVectorFieldData := vectorField . GetFloatVector ( ) . Data
dim := vectorField . GetDim ( )
err := appendFloatVectorField ( floatVectorFieldData , dim )
if err != nil {
return err
}
case * schemapb . VectorField_BinaryVector :
binaryVectorFieldData := vectorField . GetBinaryVector ( )
dim := vectorField . GetDim ( )
err := appendBinaryVectorField ( binaryVectorFieldData , dim )
if err != nil {
return err
}
case nil :
continue
default :
continue
}
case nil :
continue
default :
continue
}
dTypes = append ( dTypes , field . Type )
}
it . RowData = make ( [ ] * commonpb . Blob , 0 , rowNum )
l := len ( dTypes )
// TODO(dragondriver): big endian or little endian?
endian := binary . LittleEndian
2021-06-05 16:21:36 +08:00
printed := false
2021-06-03 15:03:34 +08:00
for i := 0 ; i < rowNum ; i ++ {
blob := & commonpb . Blob {
Value : make ( [ ] byte , 0 ) ,
}
for j := 0 ; j < l ; j ++ {
var buffer bytes . Buffer
switch dTypes [ j ] {
case schemapb . DataType_Bool :
d := datas [ j ] [ i ] . ( bool )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Int8 :
2021-06-23 12:06:10 +08:00
d := int8 ( datas [ j ] [ i ] . ( int32 ) )
2021-06-03 15:03:34 +08:00
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Int16 :
2021-06-23 12:06:10 +08:00
d := int16 ( datas [ j ] [ i ] . ( int32 ) )
2021-06-03 15:03:34 +08:00
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Int32 :
d := datas [ j ] [ i ] . ( int32 )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Int64 :
d := datas [ j ] [ i ] . ( int64 )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Float :
d := datas [ j ] [ i ] . ( float32 )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_Double :
d := datas [ j ] [ i ] . ( float64 )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_FloatVector :
d := datas [ j ] [ i ] . ( [ ] float32 )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
case schemapb . DataType_BinaryVector :
d := datas [ j ] [ i ] . ( [ ] byte )
err := binary . Write ( & buffer , endian , d )
if err != nil {
log . Warn ( "ConvertData" , zap . Error ( err ) )
}
blob . Value = append ( blob . Value , buffer . Bytes ( ) ... )
default :
log . Warn ( "unsupported data type" )
}
}
2021-06-05 16:21:36 +08:00
if ! printed {
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy, transform" , zap . Any ( "ID" , it . ID ( ) ) , zap . Any ( "BlobLen" , len ( blob . Value ) ) , zap . Any ( "dTypes" , dTypes ) )
2021-06-05 16:21:36 +08:00
printed = true
}
2021-06-03 15:03:34 +08:00
it . RowData = append ( it . RowData , blob )
}
return nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) checkFieldAutoID ( ) error {
2021-06-21 11:42:18 +08:00
// TODO(dragondriver): in fact, NumRows is not trustable, we should check all input fields
2021-07-13 16:33:55 +08:00
if it . req . NumRows <= 0 {
return errNumRowsLessThanOrEqualToZero ( it . req . NumRows )
2021-06-21 11:42:18 +08:00
}
2021-07-13 16:33:55 +08:00
if err := it . checkLengthOfFieldsData ( ) ; err != nil {
return err
}
rowNums := it . req . NumRows
2021-06-21 11:42:18 +08:00
primaryFieldName := ""
autoIDFieldName := ""
autoIDLoc := - 1
primaryLoc := - 1
fields := it . schema . Fields
for loc , field := range fields {
if field . AutoID {
autoIDLoc = loc
autoIDFieldName = field . Name
}
if field . IsPrimaryKey {
primaryLoc = loc
primaryFieldName = field . Name
}
}
if primaryLoc < 0 {
return fmt . Errorf ( "primary field is not found" )
}
if autoIDLoc >= 0 && autoIDLoc != primaryLoc {
return fmt . Errorf ( "currently auto id field is only supported on primary field" )
}
var primaryField * schemapb . FieldData
var primaryData [ ] int64
for _ , field := range it . req . FieldsData {
if field . FieldName == autoIDFieldName {
return fmt . Errorf ( "autoID field (%v) does not require data" , autoIDFieldName )
}
if field . FieldName == primaryFieldName {
primaryField = field
}
}
if primaryField != nil {
if primaryField . Type != schemapb . DataType_Int64 {
return fmt . Errorf ( "currently only support DataType Int64 as PrimaryField and Enable autoID" )
}
switch primaryField . Field . ( type ) {
case * schemapb . FieldData_Scalars :
scalarField := primaryField . GetScalars ( )
switch scalarField . Data . ( type ) {
case * schemapb . ScalarField_LongData :
primaryData = scalarField . GetLongData ( ) . Data
default :
return fmt . Errorf ( "currently only support DataType Int64 as PrimaryField and Enable autoID" )
}
default :
return fmt . Errorf ( "currently only support DataType Int64 as PrimaryField and Enable autoID" )
}
it . result . IDs . IdField = & schemapb . IDs_IntId {
IntId : & schemapb . LongArray {
Data : primaryData ,
} ,
}
}
var rowIDBegin UniqueID
var rowIDEnd UniqueID
rowIDBegin , rowIDEnd , _ = it . rowIDAllocator . Alloc ( rowNums )
it . BaseInsertTask . RowIDs = make ( [ ] UniqueID , rowNums )
for i := rowIDBegin ; i < rowIDEnd ; i ++ {
offset := i - rowIDBegin
it . BaseInsertTask . RowIDs [ offset ] = i
}
if autoIDLoc >= 0 {
fieldData := schemapb . FieldData {
FieldName : primaryFieldName ,
2021-07-16 17:19:55 +08:00
FieldId : - 1 ,
2021-06-22 18:46:04 +08:00
Type : schemapb . DataType_Int64 ,
2021-06-21 11:42:18 +08:00
Field : & schemapb . FieldData_Scalars {
Scalars : & schemapb . ScalarField {
Data : & schemapb . ScalarField_LongData {
LongData : & schemapb . LongArray {
Data : it . BaseInsertTask . RowIDs ,
} ,
} ,
} ,
} ,
}
// TODO(dragondriver): when we can ignore the order of input fields, use append directly
// it.req.FieldsData = append(it.req.FieldsData, &fieldData)
it . req . FieldsData = append ( it . req . FieldsData , & schemapb . FieldData { } )
copy ( it . req . FieldsData [ autoIDLoc + 1 : ] , it . req . FieldsData [ autoIDLoc : ] )
it . req . FieldsData [ autoIDLoc ] = & fieldData
it . result . IDs . IdField = & schemapb . IDs_IntId {
IntId : & schemapb . LongArray {
Data : it . BaseInsertTask . RowIDs ,
} ,
}
// TODO(dragondriver): in this case, should we directly overwrite the hash?
if len ( it . HashValues ) != 0 && len ( it . HashValues ) != len ( it . BaseInsertTask . RowIDs ) {
return fmt . Errorf ( "invalid length of input hash values" )
}
if it . HashValues == nil || len ( it . HashValues ) <= 0 {
it . HashValues = make ( [ ] uint32 , 0 , len ( it . BaseInsertTask . RowIDs ) )
for _ , rowID := range it . BaseInsertTask . RowIDs {
hash , _ := typeutil . Hash32Int64 ( rowID )
it . HashValues = append ( it . HashValues , hash )
}
}
} else {
// use primary keys as hash if hash is not provided
// in this case, primary field is required, we have already checked this
if uint32 ( len ( it . HashValues ) ) != 0 && uint32 ( len ( it . HashValues ) ) != rowNums {
return fmt . Errorf ( "invalid length of input hash values" )
}
if it . HashValues == nil || len ( it . HashValues ) <= 0 {
it . HashValues = make ( [ ] uint32 , 0 , len ( primaryData ) )
for _ , pk := range primaryData {
hash , _ := typeutil . Hash32Int64 ( pk )
it . HashValues = append ( it . HashValues , hash )
}
}
}
sliceIndex := make ( [ ] uint32 , rowNums )
for i := uint32 ( 0 ) ; i < rowNums ; i ++ {
sliceIndex [ i ] = i
}
it . result . SuccIndex = sliceIndex
return nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) PreExecute ( ctx context . Context ) error {
2021-09-22 19:33:54 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( it . ctx , "Proxy-Insert-PreExecute" )
defer sp . Finish ( )
2021-03-10 14:45:35 +08:00
it . Base . MsgType = commonpb . MsgType_Insert
2021-01-28 20:51:44 +08:00
it . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-06-21 11:42:18 +08:00
it . result = & milvuspb . MutationResult {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
} ,
IDs : & schemapb . IDs {
IdField : nil ,
} ,
Timestamp : it . BeginTs ( ) ,
}
2020-11-26 16:01:31 +08:00
collectionName := it . BaseInsertTask . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collectionName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-06-21 11:42:18 +08:00
2021-01-18 19:32:08 +08:00
partitionTag := it . BaseInsertTask . PartitionName
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionTag , true ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-06-21 11:42:18 +08:00
collSchema , err := globalMetaCache . GetCollectionSchema ( ctx , collectionName )
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy Insert PreExecute" , zap . Any ( "collSchema" , collSchema ) )
2021-06-21 11:42:18 +08:00
if err != nil {
return err
}
it . schema = collSchema
2021-07-13 16:33:55 +08:00
err = it . checkRowNums ( )
if err != nil {
return err
}
2021-06-21 11:42:18 +08:00
err = it . checkFieldAutoID ( )
if err != nil {
return err
}
err = it . transferColumnBasedRequestToRowBasedData ( )
2021-06-03 15:03:34 +08:00
if err != nil {
return err
}
rowNum := len ( it . RowData )
it . Timestamps = make ( [ ] uint64 , rowNum )
for index := range it . Timestamps {
it . Timestamps [ index ] = it . BeginTimestamp
}
2020-11-05 18:01:33 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) _assignSegmentID ( stream msgstream . MsgStream , pack * msgstream . MsgPack ) ( * msgstream . MsgPack , error ) {
2021-05-25 19:53:15 +08:00
newPack := & msgstream . MsgPack {
BeginTs : pack . BeginTs ,
EndTs : pack . EndTs ,
StartPositions : pack . StartPositions ,
EndPositions : pack . EndPositions ,
Msgs : nil ,
}
tsMsgs := pack . Msgs
hashKeys := stream . ComputeProduceChannelIndexes ( tsMsgs )
reqID := it . Base . MsgID
channelCountMap := make ( map [ int32 ] uint32 ) // channelID to count
channelMaxTSMap := make ( map [ int32 ] Timestamp ) // channelID to max Timestamp
2021-06-18 16:02:05 +08:00
channelNames , err := it . chMgr . getVChannels ( it . GetCollectionID ( ) )
if err != nil {
return nil , err
}
2021-05-25 19:53:15 +08:00
log . Debug ( "_assignSemgentID, produceChannels:" , zap . Any ( "Channels" , channelNames ) )
for i , request := range tsMsgs {
if request . Type ( ) != commonpb . MsgType_Insert {
return nil , fmt . Errorf ( "msg's must be Insert" )
}
insertRequest , ok := request . ( * msgstream . InsertMsg )
if ! ok {
return nil , fmt . Errorf ( "msg's must be Insert" )
}
keys := hashKeys [ i ]
timestampLen := len ( insertRequest . Timestamps )
rowIDLen := len ( insertRequest . RowIDs )
rowDataLen := len ( insertRequest . RowData )
keysLen := len ( keys )
if keysLen != timestampLen || keysLen != rowIDLen || keysLen != rowDataLen {
return nil , fmt . Errorf ( "the length of hashValue, timestamps, rowIDs, RowData are not equal" )
}
for idx , channelID := range keys {
channelCountMap [ channelID ] ++
if _ , ok := channelMaxTSMap [ channelID ] ; ! ok {
channelMaxTSMap [ channelID ] = typeutil . ZeroTimestamp
}
ts := insertRequest . Timestamps [ idx ]
if channelMaxTSMap [ channelID ] < ts {
channelMaxTSMap [ channelID ] = ts
}
}
}
reqSegCountMap := make ( map [ int32 ] map [ UniqueID ] uint32 )
for channelID , count := range channelCountMap {
ts , ok := channelMaxTSMap [ channelID ]
if ! ok {
ts = typeutil . ZeroTimestamp
log . Debug ( "Warning: did not get max Timestamp!" )
}
channelName := channelNames [ channelID ]
if channelName == "" {
2021-06-22 14:40:07 +08:00
return nil , fmt . Errorf ( "Proxy, repack_func, can not found channelName" )
2021-05-25 19:53:15 +08:00
}
mapInfo , err := it . segIDAssigner . GetSegmentID ( it . CollectionID , it . PartitionID , channelName , count , ts )
if err != nil {
2021-09-11 11:36:22 +08:00
log . Debug ( "insertTask.go" , zap . Any ( "MapInfo" , mapInfo ) ,
2021-07-24 20:49:20 +08:00
zap . Error ( err ) )
2021-05-25 19:53:15 +08:00
return nil , err
}
reqSegCountMap [ channelID ] = make ( map [ UniqueID ] uint32 )
reqSegCountMap [ channelID ] = mapInfo
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy" , zap . Int64 ( "repackFunc, reqSegCountMap, reqID" , reqID ) , zap . Any ( "mapinfo" , mapInfo ) )
2021-05-25 19:53:15 +08:00
}
reqSegAccumulateCountMap := make ( map [ int32 ] [ ] uint32 )
reqSegIDMap := make ( map [ int32 ] [ ] UniqueID )
reqSegAllocateCounter := make ( map [ int32 ] uint32 )
for channelID , segInfo := range reqSegCountMap {
reqSegAllocateCounter [ channelID ] = 0
keys := make ( [ ] UniqueID , len ( segInfo ) )
i := 0
for key := range segInfo {
keys [ i ] = key
i ++
}
sort . Slice ( keys , func ( i , j int ) bool { return keys [ i ] < keys [ j ] } )
accumulate := uint32 ( 0 )
for _ , key := range keys {
accumulate += segInfo [ key ]
if _ , ok := reqSegAccumulateCountMap [ channelID ] ; ! ok {
reqSegAccumulateCountMap [ channelID ] = make ( [ ] uint32 , 0 )
}
reqSegAccumulateCountMap [ channelID ] = append (
reqSegAccumulateCountMap [ channelID ] ,
accumulate ,
)
if _ , ok := reqSegIDMap [ channelID ] ; ! ok {
reqSegIDMap [ channelID ] = make ( [ ] UniqueID , 0 )
}
reqSegIDMap [ channelID ] = append (
reqSegIDMap [ channelID ] ,
key ,
)
}
}
var getSegmentID = func ( channelID int32 ) UniqueID {
reqSegAllocateCounter [ channelID ] ++
cur := reqSegAllocateCounter [ channelID ]
accumulateSlice := reqSegAccumulateCountMap [ channelID ]
segIDSlice := reqSegIDMap [ channelID ]
for index , count := range accumulateSlice {
if cur <= count {
return segIDSlice [ index ]
}
}
2021-07-24 20:49:20 +08:00
log . Warn ( "Can't Found SegmentID" , zap . Any ( "reqSegAllocateCounter" , reqSegAllocateCounter ) )
2021-05-25 19:53:15 +08:00
return 0
}
factor := 10
threshold := Params . PulsarMaxMessageSize / factor
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy" , zap . Int ( "threshold of message size: " , threshold ) )
2021-05-25 19:53:15 +08:00
// not accurate
2021-09-18 14:45:50 +08:00
/* #nosec G103 */
2021-05-25 19:53:15 +08:00
getFixedSizeOfInsertMsg := func ( msg * msgstream . InsertMsg ) int {
size := 0
size += int ( unsafe . Sizeof ( * msg . Base ) )
size += int ( unsafe . Sizeof ( msg . DbName ) )
size += int ( unsafe . Sizeof ( msg . CollectionName ) )
size += int ( unsafe . Sizeof ( msg . PartitionName ) )
size += int ( unsafe . Sizeof ( msg . DbID ) )
size += int ( unsafe . Sizeof ( msg . CollectionID ) )
size += int ( unsafe . Sizeof ( msg . PartitionID ) )
size += int ( unsafe . Sizeof ( msg . SegmentID ) )
2021-09-27 10:01:59 +08:00
size += int ( unsafe . Sizeof ( msg . ShardName ) )
2021-05-25 19:53:15 +08:00
size += int ( unsafe . Sizeof ( msg . Timestamps ) )
size += int ( unsafe . Sizeof ( msg . RowIDs ) )
return size
}
result := make ( map [ int32 ] msgstream . TsMsg )
curMsgSizeMap := make ( map [ int32 ] int )
for i , request := range tsMsgs {
insertRequest := request . ( * msgstream . InsertMsg )
keys := hashKeys [ i ]
collectionName := insertRequest . CollectionName
collectionID := insertRequest . CollectionID
partitionID := insertRequest . PartitionID
partitionName := insertRequest . PartitionName
proxyID := insertRequest . Base . SourceID
for index , key := range keys {
ts := insertRequest . Timestamps [ index ]
rowID := insertRequest . RowIDs [ index ]
row := insertRequest . RowData [ index ]
segmentID := getSegmentID ( key )
2021-07-24 20:49:20 +08:00
if segmentID == 0 {
return nil , fmt . Errorf ( "get SegmentID failed, segmentID is zero" )
}
2021-05-25 19:53:15 +08:00
_ , ok := result [ key ]
if ! ok {
sliceRequest := internalpb . InsertRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_Insert ,
MsgID : reqID ,
Timestamp : ts ,
SourceID : proxyID ,
} ,
CollectionID : collectionID ,
PartitionID : partitionID ,
CollectionName : collectionName ,
PartitionName : partitionName ,
SegmentID : segmentID ,
2021-09-27 10:01:59 +08:00
ShardName : channelNames [ key ] ,
2021-05-25 19:53:15 +08:00
}
insertMsg := & msgstream . InsertMsg {
BaseMsg : msgstream . BaseMsg {
Ctx : request . TraceCtx ( ) ,
} ,
InsertRequest : sliceRequest ,
}
result [ key ] = insertMsg
curMsgSizeMap [ key ] = getFixedSizeOfInsertMsg ( insertMsg )
}
curMsg := result [ key ] . ( * msgstream . InsertMsg )
curMsgSize := curMsgSizeMap [ key ]
curMsg . HashValues = append ( curMsg . HashValues , insertRequest . HashValues [ index ] )
curMsg . Timestamps = append ( curMsg . Timestamps , ts )
curMsg . RowIDs = append ( curMsg . RowIDs , rowID )
curMsg . RowData = append ( curMsg . RowData , row )
2021-09-18 14:45:50 +08:00
/* #nosec G103 */
2021-05-25 19:53:15 +08:00
curMsgSize += 4 + 8 + int ( unsafe . Sizeof ( row . Value ) )
curMsgSize += len ( row . Value )
if curMsgSize >= threshold {
newPack . Msgs = append ( newPack . Msgs , curMsg )
delete ( result , key )
curMsgSize = 0
}
curMsgSizeMap [ key ] = curMsgSize
}
}
for _ , msg := range result {
if msg != nil {
newPack . Msgs = append ( newPack . Msgs , msg )
}
}
return newPack , nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) Execute ( ctx context . Context ) error {
2021-09-22 19:33:54 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( it . ctx , "Proxy-Insert-Execute" )
defer sp . Finish ( )
2020-11-20 17:53:31 +08:00
collectionName := it . BaseInsertTask . CollectionName
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
2021-01-31 14:55:36 +08:00
if err != nil {
2020-11-20 17:53:31 +08:00
return err
}
2021-01-31 14:55:36 +08:00
it . CollectionID = collID
2021-02-03 17:30:10 +08:00
var partitionID UniqueID
if len ( it . PartitionName ) > 0 {
2021-02-26 17:44:24 +08:00
partitionID , err = globalMetaCache . GetPartitionID ( ctx , collectionName , it . PartitionName )
2021-02-03 17:30:10 +08:00
if err != nil {
return err
}
} else {
2021-04-13 10:04:39 +08:00
partitionID , err = globalMetaCache . GetPartitionID ( ctx , collectionName , Params . DefaultPartitionName )
2021-02-03 17:30:10 +08:00
if err != nil {
return err
}
2021-01-31 14:55:36 +08:00
}
it . PartitionID = partitionID
2020-11-20 17:53:31 +08:00
2020-11-07 16:18:23 +08:00
var tsMsg msgstream . TsMsg = & it . BaseInsertTask
2021-03-25 14:41:46 +08:00
it . BaseMsg . Ctx = ctx
msgPack := msgstream . MsgPack {
2020-11-05 18:01:33 +08:00
BeginTs : it . BeginTs ( ) ,
EndTs : it . EndTs ( ) ,
2020-11-17 14:10:07 +08:00
Msgs : make ( [ ] msgstream . TsMsg , 1 ) ,
2020-11-05 18:01:33 +08:00
}
2020-12-03 19:00:11 +08:00
2021-01-30 15:30:38 +08:00
msgPack . Msgs [ 0 ] = tsMsg
2021-05-27 17:09:50 +08:00
stream , err := it . chMgr . getDMLStream ( collID )
2021-01-30 15:30:38 +08:00
if err != nil {
2021-05-27 17:09:50 +08:00
err = it . chMgr . createDMLMsgStream ( collID )
2021-01-30 15:30:38 +08:00
if err != nil {
2021-06-15 10:19:38 +08:00
it . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
it . result . Status . Reason = err . Error ( )
return err
}
2021-09-06 20:49:04 +08:00
channels , err := it . chMgr . getChannels ( collID )
if err == nil {
for _ , pchan := range channels {
err := it . chTicker . addPChan ( pchan )
if err != nil {
log . Warn ( "failed to add pchan to channels time ticker" ,
zap . Error ( err ) ,
zap . String ( "pchan" , pchan ) )
}
}
}
2021-06-15 10:19:38 +08:00
stream , err = it . chMgr . getDMLStream ( collID )
if err != nil {
it . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
it . result . Status . Reason = err . Error ( )
2021-01-30 15:30:38 +08:00
return err
}
}
2021-05-25 19:53:15 +08:00
// Assign SegmentID
var pack * msgstream . MsgPack
pack , err = it . _assignSegmentID ( stream , & msgPack )
if err != nil {
return err
}
err = stream . Produce ( pack )
2020-11-14 18:18:10 +08:00
if err != nil {
2021-03-10 22:06:22 +08:00
it . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
2020-11-14 18:18:10 +08:00
it . result . Status . Reason = err . Error ( )
2021-01-30 15:30:38 +08:00
return err
2020-11-14 18:18:10 +08:00
}
2021-01-30 15:30:38 +08:00
2020-11-05 18:01:33 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) PostExecute ( ctx context . Context ) error {
2020-11-05 18:01:33 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type createCollectionTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . CreateCollectionRequest
2021-09-11 11:36:22 +08:00
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
schema * schemapb . CollectionSchema
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return cct . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return cct . Base . MsgID
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
cct . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return CreateCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return cct . Base . MsgType
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cct . Base . Timestamp
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cct . Base . Timestamp
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
cct . Base . Timestamp = ts
2020-11-05 18:01:33 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
cct . Base = & commonpb . MsgBase { }
2021-09-11 18:06:02 +08:00
cct . Base . MsgType = commonpb . MsgType_CreateCollection
cct . Base . SourceID = Params . ProxyID
2021-02-23 09:58:06 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
cct . Base . MsgType = commonpb . MsgType_CreateCollection
2021-01-28 20:51:44 +08:00
cct . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
cct . schema = & schemapb . CollectionSchema { }
err := proto . Unmarshal ( cct . Schema , cct . schema )
2021-09-11 18:06:02 +08:00
if err != nil {
return err
}
2021-06-21 11:42:18 +08:00
cct . schema . AutoID = false
2021-09-11 18:06:02 +08:00
cct . CreateCollectionRequest . Schema , err = proto . Marshal ( cct . schema )
2021-01-22 09:36:18 +08:00
if err != nil {
return err
}
2021-09-08 15:00:00 +08:00
if cct . ShardsNum > Params . MaxShardNum {
return fmt . Errorf ( "maximum shards's number should be limited to %d" , Params . MaxShardNum )
}
2021-01-28 20:51:44 +08:00
if int64 ( len ( cct . schema . Fields ) ) > Params . MaxFieldNum {
2021-03-05 10:15:27 +08:00
return fmt . Errorf ( "maximum field's number should be limited to %d" , Params . MaxFieldNum )
2020-11-26 16:01:31 +08:00
}
// validate collection name
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( cct . schema . Name ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-30 19:38:23 +08:00
if err := ValidateDuplicatedFieldName ( cct . schema . Fields ) ; err != nil {
return err
}
if err := ValidatePrimaryKey ( cct . schema ) ; err != nil {
return err
}
2021-06-21 11:42:18 +08:00
if err := ValidateFieldAutoID ( cct . schema ) ; err != nil {
return err
}
2020-11-26 16:01:31 +08:00
// validate field name
for _ , field := range cct . schema . Fields {
2021-10-23 18:25:37 +08:00
if err := validateFieldName ( field . Name ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-03-12 14:22:09 +08:00
if field . DataType == schemapb . DataType_FloatVector || field . DataType == schemapb . DataType_BinaryVector {
2020-11-26 16:01:31 +08:00
exist := false
var dim int64 = 0
for _ , param := range field . TypeParams {
if param . Key == "dim" {
exist = true
tmp , err := strconv . ParseInt ( param . Value , 10 , 64 )
if err != nil {
return err
}
dim = tmp
break
}
}
if ! exist {
2021-09-15 10:01:30 +08:00
return errors . New ( "dimension is not defined in field type params, check type param `dim` for vector field" )
2020-11-26 16:01:31 +08:00
}
2021-03-12 14:22:09 +08:00
if field . DataType == schemapb . DataType_FloatVector {
2020-11-26 16:01:31 +08:00
if err := ValidateDimension ( dim , false ) ; err != nil {
return err
}
} else {
if err := ValidateDimension ( dim , true ) ; err != nil {
return err
}
}
}
}
2020-11-05 18:01:33 +08:00
return nil
2020-11-03 14:53:36 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) Execute ( ctx context . Context ) error {
2021-01-22 09:36:18 +08:00
var err error
2021-06-21 17:28:03 +08:00
cct . result , err = cct . rootCoord . CreateCollection ( ctx , cct . CreateCollectionRequest )
2021-05-27 17:09:50 +08:00
return err
2020-11-03 14:53:36 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cct * createCollectionTask ) PostExecute ( ctx context . Context ) error {
2020-11-05 18:01:33 +08:00
return nil
2020-11-03 14:53:36 +08:00
}
2021-09-09 19:02:08 +08:00
type dropCollectionTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . DropCollectionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
chMgr channelsMgr
chTicker channelsTimeTicker
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return dct . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return dct . Base . MsgID
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
dct . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return DropCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return dct . Base . MsgType
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
dct . Base . Timestamp = ts
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
dct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
dct . Base . MsgType = commonpb . MsgType_DropCollection
2021-01-28 20:51:44 +08:00
dct . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( dct . CollectionName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-09 17:25:53 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) Execute ( ctx context . Context ) error {
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , dct . CollectionName )
2021-02-01 10:53:13 +08:00
if err != nil {
return err
}
2021-02-07 13:53:40 +08:00
2021-06-21 17:28:03 +08:00
dct . result , err = dct . rootCoord . DropCollection ( ctx , dct . DropCollectionRequest )
2021-02-07 13:53:40 +08:00
if err != nil {
return err
2021-01-30 15:30:38 +08:00
}
2021-02-07 13:53:40 +08:00
2021-06-08 19:25:37 +08:00
pchans , _ := dct . chMgr . getChannels ( collID )
for _ , pchan := range pchans {
_ = dct . chTicker . removePChan ( pchan )
2021-02-04 19:34:35 +08:00
}
2021-02-07 13:53:40 +08:00
2021-06-08 19:25:37 +08:00
_ = dct . chMgr . removeDMLStream ( collID )
2021-06-18 10:33:58 +08:00
_ = dct . chMgr . removeDQLStream ( collID )
2021-06-08 19:25:37 +08:00
2021-02-04 19:34:35 +08:00
return nil
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * dropCollectionTask ) PostExecute ( ctx context . Context ) error {
2021-02-26 17:44:24 +08:00
globalMetaCache . RemoveCollection ( ctx , dct . CollectionName )
2020-11-30 22:14:19 +08:00
return nil
2020-11-09 17:25:53 +08:00
}
2021-08-14 11:18:10 +08:00
// Support wildcard in output fields:
// "*" - all scalar fields
// "%" - all vector fields
// For example, A and B are scalar fields, C and D are vector fields, duplicated fields will automatically be removed.
// output_fields=["*"] ==> [A,B]
// output_fields=["%"] ==> [C,D]
// output_fields=["*","%"] ==> [A,B,C,D]
// output_fields=["*",A] ==> [A,B]
// output_fields=["*",C] ==> [A,B,C]
2021-07-21 14:52:12 +08:00
func translateOutputFields ( outputFields [ ] string , schema * schemapb . CollectionSchema , addPrimary bool ) ( [ ] string , error ) {
var primaryFieldName string
scalarFieldNameMap := make ( map [ string ] bool )
vectorFieldNameMap := make ( map [ string ] bool )
resultFieldNameMap := make ( map [ string ] bool )
resultFieldNames := make ( [ ] string , 0 )
for _ , field := range schema . Fields {
if field . IsPrimaryKey {
primaryFieldName = field . Name
}
if field . DataType == schemapb . DataType_BinaryVector || field . DataType == schemapb . DataType_FloatVector {
vectorFieldNameMap [ field . Name ] = true
} else {
scalarFieldNameMap [ field . Name ] = true
}
}
for _ , outputFieldName := range outputFields {
outputFieldName = strings . TrimSpace ( outputFieldName )
if outputFieldName == "*" {
for fieldName := range scalarFieldNameMap {
resultFieldNameMap [ fieldName ] = true
}
} else if outputFieldName == "%" {
for fieldName := range vectorFieldNameMap {
resultFieldNameMap [ fieldName ] = true
}
} else {
resultFieldNameMap [ outputFieldName ] = true
}
}
if addPrimary {
resultFieldNameMap [ primaryFieldName ] = true
}
for fieldName := range resultFieldNameMap {
resultFieldNames = append ( resultFieldNames , fieldName )
}
return resultFieldNames , nil
}
2021-09-11 11:36:22 +08:00
type searchTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-03-12 14:22:09 +08:00
* internalpb . SearchRequest
2021-06-18 10:33:58 +08:00
ctx context . Context
resultBuf chan [ ] * internalpb . SearchResults
result * milvuspb . SearchResults
query * milvuspb . SearchRequest
chMgr channelsMgr
2021-09-14 10:24:00 +08:00
qc types . QueryCoord
2021-01-22 09:36:18 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return st . ctx
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return st . Base . MsgID
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
st . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return SearchTaskName
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return st . Base . MsgType
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return st . Base . Timestamp
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return st . Base . Timestamp
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
st . Base . Timestamp = ts
2020-11-07 16:18:23 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) OnEnqueue ( ) error {
2021-03-22 19:28:43 +08:00
st . Base = & commonpb . MsgBase { }
2021-09-13 17:12:19 +08:00
st . Base . MsgType = commonpb . MsgType_Search
st . Base . SourceID = Params . ProxyID
2021-02-23 09:58:06 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) getChannels ( ) ( [ ] pChan , error ) {
2021-06-11 09:50:34 +08:00
collID , err := globalMetaCache . GetCollectionID ( st . ctx , st . query . CollectionName )
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
var channels [ ] pChan
channels , err = st . chMgr . getChannels ( collID )
2021-09-14 10:24:00 +08:00
if err != nil {
err := st . chMgr . createDMLMsgStream ( collID )
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
return st . chMgr . getChannels ( collID )
2021-09-14 10:24:00 +08:00
}
2021-10-15 20:37:04 +08:00
return channels , nil
2021-06-11 09:50:34 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) getVChannels ( ) ( [ ] vChan , error ) {
2021-06-02 10:17:32 +08:00
collID , err := globalMetaCache . GetCollectionID ( st . ctx , st . query . CollectionName )
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
var channels [ ] vChan
channels , err = st . chMgr . getVChannels ( collID )
2021-06-02 10:17:32 +08:00
if err != nil {
err := st . chMgr . createDMLMsgStream ( collID )
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
return st . chMgr . getVChannels ( collID )
2021-06-02 10:17:32 +08:00
}
2021-10-15 20:37:04 +08:00
return channels , nil
2021-06-02 10:17:32 +08:00
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) PreExecute ( ctx context . Context ) error {
2021-09-22 19:36:00 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( st . TraceCtx ( ) , "Proxy-Search-PreExecute" )
defer sp . Finish ( )
2021-03-10 14:45:35 +08:00
st . Base . MsgType = commonpb . MsgType_Search
2021-01-28 20:51:44 +08:00
st . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-01-18 19:32:08 +08:00
collectionName := st . query . CollectionName
2021-06-18 16:32:07 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
2020-11-30 19:08:32 +08:00
if err != nil { // err is not nil if collection not exists
return err
}
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( st . query . CollectionName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-01-22 09:36:18 +08:00
for _ , tag := range st . query . PartitionNames {
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( tag , false ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
}
2021-06-18 16:32:07 +08:00
// check if collection was already loaded into query node
2021-06-22 16:44:09 +08:00
showResp , err := st . qc . ShowCollections ( st . ctx , & querypb . ShowCollectionsRequest {
2021-06-18 16:32:07 +08:00
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowCollections ,
MsgID : st . Base . MsgID ,
Timestamp : st . Base . Timestamp ,
SourceID : Params . ProxyID ,
} ,
DbID : 0 , // TODO(dragondriver)
} )
if err != nil {
return err
}
if showResp . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( showResp . Status . Reason )
}
2021-06-22 16:44:09 +08:00
log . Debug ( "query coordinator show collections" ,
2021-06-21 19:20:31 +08:00
zap . Any ( "collID" , collID ) ,
2021-06-18 16:32:07 +08:00
zap . Any ( "collections" , showResp . CollectionIDs ) ,
2021-06-21 19:20:31 +08:00
)
2021-06-18 16:32:07 +08:00
collectionLoaded := false
2021-08-02 22:39:25 +08:00
2021-06-18 16:32:07 +08:00
for _ , collectionID := range showResp . CollectionIDs {
if collectionID == collID {
collectionLoaded = true
break
}
}
if ! collectionLoaded {
return fmt . Errorf ( "collection %v was not loaded into memory" , collectionName )
}
// TODO(dragondriver): necessary to check if partition was loaded into query node?
2021-03-10 14:45:35 +08:00
st . Base . MsgType = commonpb . MsgType_Search
2021-04-29 16:48:06 +08:00
2021-09-14 10:24:00 +08:00
schema , _ := globalMetaCache . GetCollectionSchema ( ctx , collectionName )
2021-07-14 18:51:54 +08:00
2021-07-21 14:52:12 +08:00
outputFields , err := translateOutputFields ( st . query . OutputFields , schema , false )
2021-07-14 18:51:54 +08:00
if err != nil {
return err
}
2021-07-17 10:53:30 +08:00
log . Debug ( "translate output fields" , zap . Any ( "OutputFields" , outputFields ) )
2021-07-14 18:51:54 +08:00
st . query . OutputFields = outputFields
2021-04-29 16:48:06 +08:00
if st . query . GetDslType ( ) == commonpb . DslType_BoolExprV1 {
2021-09-27 23:18:02 +08:00
annsField , err := funcutil . GetAttrByKeyFromRepeatedKV ( AnnsFieldKey , st . query . SearchParams )
2021-04-29 16:48:06 +08:00
if err != nil {
return errors . New ( AnnsFieldKey + " not found in search_params" )
}
2021-09-27 23:18:02 +08:00
topKStr , err := funcutil . GetAttrByKeyFromRepeatedKV ( TopKKey , st . query . SearchParams )
2021-04-29 16:48:06 +08:00
if err != nil {
return errors . New ( TopKKey + " not found in search_params" )
}
topK , err := strconv . Atoi ( topKStr )
if err != nil {
return errors . New ( TopKKey + " " + topKStr + " is not invalid" )
}
2021-09-27 23:18:02 +08:00
metricType , err := funcutil . GetAttrByKeyFromRepeatedKV ( MetricTypeKey , st . query . SearchParams )
2021-04-29 16:48:06 +08:00
if err != nil {
return errors . New ( MetricTypeKey + " not found in search_params" )
}
2021-09-27 23:18:02 +08:00
searchParams , err := funcutil . GetAttrByKeyFromRepeatedKV ( SearchParamsKey , st . query . SearchParams )
2021-04-29 16:48:06 +08:00
if err != nil {
return errors . New ( SearchParamsKey + " not found in search_params" )
}
2021-10-08 17:39:55 +08:00
roundDecimalStr , err := funcutil . GetAttrByKeyFromRepeatedKV ( RoundDecimalKey , st . query . SearchParams )
if err != nil {
return errors . New ( RoundDecimalKey + "not found in search_params" )
}
roundDeciaml , err := strconv . Atoi ( roundDecimalStr )
if err != nil {
return errors . New ( RoundDecimalKey + " " + roundDecimalStr + " is not invalid" )
}
2021-04-29 16:48:06 +08:00
queryInfo := & planpb . QueryInfo {
Topk : int64 ( topK ) ,
MetricType : metricType ,
SearchParams : searchParams ,
2021-10-08 17:39:55 +08:00
RoundDecimal : int64 ( roundDeciaml ) ,
2021-04-29 16:48:06 +08:00
}
2021-09-13 17:12:19 +08:00
log . Debug ( "create query plan" ,
//zap.Any("schema", schema),
zap . String ( "dsl" , st . query . Dsl ) ,
zap . String ( "anns field" , annsField ) ,
zap . Any ( "query info" , queryInfo ) )
2021-10-13 20:30:32 +08:00
plan , err := createQueryPlan ( schema , st . query . Dsl , annsField , queryInfo )
2021-04-29 16:48:06 +08:00
if err != nil {
2021-09-13 17:12:19 +08:00
log . Debug ( "failed to create query plan" ,
zap . Error ( err ) ,
//zap.Any("schema", schema),
zap . String ( "dsl" , st . query . Dsl ) ,
zap . String ( "anns field" , annsField ) ,
zap . Any ( "query info" , queryInfo ) )
return fmt . Errorf ( "failed to create query plan: %v" , err )
2021-04-29 16:48:06 +08:00
}
2021-06-28 12:16:13 +08:00
for _ , name := range st . query . OutputFields {
2021-07-11 19:39:52 +08:00
hitField := false
2021-06-28 12:16:13 +08:00
for _ , field := range schema . Fields {
2021-06-21 20:18:13 +08:00
if field . Name == name {
2021-06-28 12:16:13 +08:00
if field . DataType == schemapb . DataType_BinaryVector || field . DataType == schemapb . DataType_FloatVector {
return errors . New ( "Search doesn't support vector field as output_fields" )
}
2021-06-21 20:18:13 +08:00
st . SearchRequest . OutputFieldsId = append ( st . SearchRequest . OutputFieldsId , field . FieldID )
plan . OutputFieldIds = append ( plan . OutputFieldIds , field . FieldID )
2021-07-11 19:39:52 +08:00
hitField = true
break
2021-06-21 20:18:13 +08:00
}
}
2021-07-11 19:39:52 +08:00
if ! hitField {
errMsg := "Field " + name + " not exist"
return errors . New ( errMsg )
}
2021-06-21 20:18:13 +08:00
}
2021-05-07 15:20:47 +08:00
st . SearchRequest . DslType = commonpb . DslType_BoolExprV1
2021-05-07 19:27:17 +08:00
st . SearchRequest . SerializedExprPlan , err = proto . Marshal ( plan )
if err != nil {
return err
}
2021-09-11 11:36:22 +08:00
log . Debug ( "Proxy::searchTask::PreExecute" , zap . Any ( "plan.OutputFieldIds" , plan . OutputFieldIds ) ,
2021-07-11 19:39:52 +08:00
zap . Any ( "plan" , plan . String ( ) ) )
2021-04-29 16:48:06 +08:00
}
2021-06-21 10:42:10 +08:00
travelTimestamp := st . query . TravelTimestamp
if travelTimestamp == 0 {
travelTimestamp = st . BeginTs ( )
}
2021-06-30 21:02:13 +08:00
guaranteeTimestamp := st . query . GuaranteeTimestamp
if guaranteeTimestamp == 0 {
guaranteeTimestamp = st . BeginTs ( )
}
2021-06-21 10:42:10 +08:00
st . SearchRequest . TravelTimestamp = travelTimestamp
2021-06-30 21:02:13 +08:00
st . SearchRequest . GuaranteeTimestamp = guaranteeTimestamp
2021-04-29 16:48:06 +08:00
2021-05-07 15:20:47 +08:00
st . SearchRequest . ResultChannelID = Params . SearchResultChannelNames [ 0 ]
st . SearchRequest . DbID = 0 // todo
2021-09-14 10:24:00 +08:00
st . SearchRequest . CollectionID = collID
2021-05-07 15:20:47 +08:00
st . SearchRequest . PartitionIDs = make ( [ ] UniqueID , 0 )
2021-03-22 16:36:10 +08:00
partitionsMap , err := globalMetaCache . GetPartitions ( ctx , collectionName )
if err != nil {
return err
}
partitionsRecord := make ( map [ UniqueID ] bool )
2021-02-03 17:30:10 +08:00
for _ , partitionName := range st . query . PartitionNames {
2021-03-22 16:36:10 +08:00
pattern := fmt . Sprintf ( "^%s$" , partitionName )
re , err := regexp . Compile ( pattern )
2021-02-03 17:30:10 +08:00
if err != nil {
2021-03-22 16:36:10 +08:00
return errors . New ( "invalid partition names" )
}
found := false
for name , pID := range partitionsMap {
if re . MatchString ( name ) {
if _ , exist := partitionsRecord [ pID ] ; ! exist {
st . PartitionIDs = append ( st . PartitionIDs , pID )
partitionsRecord [ pID ] = true
}
found = true
}
}
if ! found {
errMsg := fmt . Sprintf ( "PartitonName: %s not found" , partitionName )
return errors . New ( errMsg )
2021-02-03 17:30:10 +08:00
}
}
2021-03-22 16:36:10 +08:00
2021-05-07 15:20:47 +08:00
st . SearchRequest . Dsl = st . query . Dsl
st . SearchRequest . PlaceholderGroup = st . query . PlaceholderGroup
2021-02-03 17:30:10 +08:00
2020-11-07 16:18:23 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) Execute ( ctx context . Context ) error {
2021-09-22 19:36:00 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( st . TraceCtx ( ) , "Proxy-Search-Execute" )
defer sp . Finish ( )
2020-11-07 16:18:23 +08:00
var tsMsg msgstream . TsMsg = & msgstream . SearchMsg {
2021-02-23 09:58:06 +08:00
SearchRequest : * st . SearchRequest ,
2020-11-07 16:18:23 +08:00
BaseMsg : msgstream . BaseMsg {
2021-03-25 14:41:46 +08:00
Ctx : ctx ,
2021-01-28 20:51:44 +08:00
HashValues : [ ] uint32 { uint32 ( Params . ProxyID ) } ,
2021-01-18 19:32:08 +08:00
BeginTimestamp : st . Base . Timestamp ,
EndTimestamp : st . Base . Timestamp ,
2020-11-07 16:18:23 +08:00
} ,
}
2021-03-25 14:41:46 +08:00
msgPack := msgstream . MsgPack {
2021-01-18 19:32:08 +08:00
BeginTs : st . Base . Timestamp ,
EndTs : st . Base . Timestamp ,
2020-11-17 14:10:07 +08:00
Msgs : make ( [ ] msgstream . TsMsg , 1 ) ,
2020-11-07 16:18:23 +08:00
}
2020-11-17 14:10:07 +08:00
msgPack . Msgs [ 0 ] = tsMsg
2021-06-18 10:33:58 +08:00
collectionName := st . query . CollectionName
collID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil { // err is not nil if collection not exists
return err
}
stream , err := st . chMgr . getDQLStream ( collID )
if err != nil {
err = st . chMgr . createDQLStream ( collID )
if err != nil {
2021-09-29 15:48:00 +08:00
st . result = & milvuspb . SearchResults {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_UnexpectedError ,
Reason : err . Error ( ) ,
} ,
}
2021-06-18 10:33:58 +08:00
return err
}
stream , err = st . chMgr . getDQLStream ( collID )
if err != nil {
2021-09-29 15:48:00 +08:00
st . result = & milvuspb . SearchResults {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_UnexpectedError ,
Reason : err . Error ( ) ,
} ,
}
2021-06-18 10:33:58 +08:00
return err
}
}
err = stream . Produce ( & msgPack )
2021-09-14 14:09:05 +08:00
if err != nil {
log . Debug ( "proxy" , zap . String ( "send search request failed" , err . Error ( ) ) )
}
2021-06-22 14:40:07 +08:00
log . Debug ( "proxy sent one searchMsg" ,
2021-06-15 12:41:40 +08:00
zap . Any ( "collectionID" , st . CollectionID ) ,
2021-06-03 14:58:34 +08:00
zap . Any ( "msgID" , tsMsg . ID ( ) ) ,
2021-09-14 14:09:05 +08:00
zap . Int ( "length of search msg" , len ( msgPack . Msgs ) ) ,
2021-06-15 12:41:40 +08:00
)
2020-11-28 19:06:48 +08:00
return err
2020-11-07 16:18:23 +08:00
}
2021-06-21 20:18:13 +08:00
func decodeSearchResultsSerial ( searchResults [ ] * internalpb . SearchResults ) ( [ ] * schemapb . SearchResultData , error ) {
2021-07-11 19:39:52 +08:00
log . Debug ( "reduceSearchResultDataParallel" , zap . Any ( "lenOfSearchResults" , len ( searchResults ) ) )
2021-06-21 20:18:13 +08:00
results := make ( [ ] * schemapb . SearchResultData , 0 )
// necessary to parallel this?
2021-07-11 19:39:52 +08:00
for i , partialSearchResult := range searchResults {
2021-07-23 20:33:34 +08:00
log . Debug ( "decodeSearchResultsSerial" , zap . Any ( "i" , i ) , zap . Any ( "len(SlicedBob)" , len ( partialSearchResult . SlicedBlob ) ) )
2021-06-21 20:18:13 +08:00
if partialSearchResult . SlicedBlob == nil {
continue
}
var partialResultData schemapb . SearchResultData
err := proto . Unmarshal ( partialSearchResult . SlicedBlob , & partialResultData )
2021-07-11 19:39:52 +08:00
log . Debug ( "decodeSearchResultsSerial, Unmarshal partitalSearchResult.SliceBlob" , zap . Error ( err ) )
2021-06-21 20:18:13 +08:00
if err != nil {
return nil , err
}
results = append ( results , & partialResultData )
}
2021-07-11 19:39:52 +08:00
log . Debug ( "reduceSearchResultDataParallel" , zap . Any ( "lenOfResults" , len ( results ) ) )
2021-06-21 20:18:13 +08:00
return results , nil
2021-03-26 11:19:02 +08:00
}
2021-03-25 10:14:09 +08:00
2021-10-20 17:56:38 +08:00
func decodeSearchResults ( searchResults [ ] * internalpb . SearchResults ) ( res [ ] * schemapb . SearchResultData , err error ) {
tr := timerecord . NewTimeRecorder ( "decodeSearchResults" )
res , err = decodeSearchResultsSerial ( searchResults )
// res, err = decodeSearchResultsParallelByCPU(searchResults)
tr . Elapse ( "done" )
return
2021-03-25 10:14:09 +08:00
}
2021-10-21 10:46:36 +08:00
func checkSearchResultData ( data * schemapb . SearchResultData , nq int64 , topk int64 ) error {
if data . NumQueries != nq {
return fmt . Errorf ( "search result's nq(%d) mis-match with %d" , data . NumQueries , nq )
}
if data . TopK != topk {
return fmt . Errorf ( "search result's topk(%d) mis-match with %d" , data . TopK , topk )
}
if len ( data . Ids . GetIntId ( ) . Data ) != ( int ) ( nq * topk ) {
return fmt . Errorf ( "search result's id length %d invalid" , len ( data . Ids . GetIntId ( ) . Data ) )
}
if len ( data . Scores ) != ( int ) ( nq * topk ) {
return fmt . Errorf ( "search result's score length %d invalid" , len ( data . Scores ) )
}
return nil
}
func selectSearchResultData ( dataArray [ ] * schemapb . SearchResultData , offsets [ ] int64 , topk int64 , idx int64 ) int {
sel := - 1
maxDistance := minFloat32
for q , loc := range offsets { // query num, the number of ways to merge
if loc >= topk {
continue
}
offset := idx * topk + loc
id := dataArray [ q ] . Ids . GetIntId ( ) . Data [ offset ]
if id != - 1 {
distance := dataArray [ q ] . Scores [ offset ]
if distance > maxDistance {
sel = q
maxDistance = distance
}
}
}
return sel
}
func copySearchResultData ( dst * schemapb . SearchResultData , src * schemapb . SearchResultData , idx int64 ) error {
for i , fieldData := range src . FieldsData {
switch fieldType := fieldData . Field . ( type ) {
case * schemapb . FieldData_Scalars :
if dst . FieldsData [ i ] == nil || dst . FieldsData [ i ] . GetScalars ( ) == nil {
dst . FieldsData [ i ] = & schemapb . FieldData {
FieldName : fieldData . FieldName ,
FieldId : fieldData . FieldId ,
Field : & schemapb . FieldData_Scalars {
Scalars : & schemapb . ScalarField { } ,
} ,
}
}
switch scalarType := fieldType . Scalars . Data . ( type ) {
case * schemapb . ScalarField_BoolData :
if dst . FieldsData [ i ] . GetScalars ( ) . GetBoolData ( ) == nil {
dst . FieldsData [ i ] . Field . ( * schemapb . FieldData_Scalars ) . Scalars = & schemapb . ScalarField {
Data : & schemapb . ScalarField_BoolData {
BoolData : & schemapb . BoolArray {
Data : [ ] bool { scalarType . BoolData . Data [ idx ] } ,
} ,
} ,
}
} else {
dst . FieldsData [ i ] . GetScalars ( ) . GetBoolData ( ) . Data = append ( dst . FieldsData [ i ] . GetScalars ( ) . GetBoolData ( ) . Data , scalarType . BoolData . Data [ idx ] )
}
case * schemapb . ScalarField_IntData :
if dst . FieldsData [ i ] . GetScalars ( ) . GetIntData ( ) == nil {
dst . FieldsData [ i ] . Field . ( * schemapb . FieldData_Scalars ) . Scalars = & schemapb . ScalarField {
Data : & schemapb . ScalarField_IntData {
IntData : & schemapb . IntArray {
Data : [ ] int32 { scalarType . IntData . Data [ idx ] } ,
} ,
} ,
}
} else {
dst . FieldsData [ i ] . GetScalars ( ) . GetIntData ( ) . Data = append ( dst . FieldsData [ i ] . GetScalars ( ) . GetIntData ( ) . Data , scalarType . IntData . Data [ idx ] )
}
case * schemapb . ScalarField_LongData :
if dst . FieldsData [ i ] . GetScalars ( ) . GetLongData ( ) == nil {
dst . FieldsData [ i ] . Field . ( * schemapb . FieldData_Scalars ) . Scalars = & schemapb . ScalarField {
Data : & schemapb . ScalarField_LongData {
LongData : & schemapb . LongArray {
Data : [ ] int64 { scalarType . LongData . Data [ idx ] } ,
} ,
} ,
}
} else {
dst . FieldsData [ i ] . GetScalars ( ) . GetLongData ( ) . Data = append ( dst . FieldsData [ i ] . GetScalars ( ) . GetLongData ( ) . Data , scalarType . LongData . Data [ idx ] )
}
case * schemapb . ScalarField_FloatData :
if dst . FieldsData [ i ] . GetScalars ( ) . GetFloatData ( ) == nil {
dst . FieldsData [ i ] . Field . ( * schemapb . FieldData_Scalars ) . Scalars = & schemapb . ScalarField {
Data : & schemapb . ScalarField_FloatData {
FloatData : & schemapb . FloatArray {
Data : [ ] float32 { scalarType . FloatData . Data [ idx ] } ,
} ,
} ,
}
} else {
dst . FieldsData [ i ] . GetScalars ( ) . GetFloatData ( ) . Data = append ( dst . FieldsData [ i ] . GetScalars ( ) . GetFloatData ( ) . Data , scalarType . FloatData . Data [ idx ] )
}
case * schemapb . ScalarField_DoubleData :
if dst . FieldsData [ i ] . GetScalars ( ) . GetDoubleData ( ) == nil {
dst . FieldsData [ i ] . Field . ( * schemapb . FieldData_Scalars ) . Scalars = & schemapb . ScalarField {
Data : & schemapb . ScalarField_DoubleData {
DoubleData : & schemapb . DoubleArray {
Data : [ ] float64 { scalarType . DoubleData . Data [ idx ] } ,
} ,
} ,
}
} else {
dst . FieldsData [ i ] . GetScalars ( ) . GetDoubleData ( ) . Data = append ( dst . FieldsData [ i ] . GetScalars ( ) . GetDoubleData ( ) . Data , scalarType . DoubleData . Data [ idx ] )
}
default :
log . Debug ( "Not supported field type" , zap . String ( "field type" , fieldData . Type . String ( ) ) )
return fmt . Errorf ( "not supported field type: %s" , fieldData . Type . String ( ) )
}
case * schemapb . FieldData_Vectors :
dim := fieldType . Vectors . Dim
if dst . FieldsData [ i ] == nil || dst . FieldsData [ i ] . GetVectors ( ) == nil {
dst . FieldsData [ i ] = & schemapb . FieldData {
FieldName : fieldData . FieldName ,
FieldId : fieldData . FieldId ,
Field : & schemapb . FieldData_Vectors {
Vectors : & schemapb . VectorField {
Dim : dim ,
} ,
} ,
}
}
switch vectorType := fieldType . Vectors . Data . ( type ) {
case * schemapb . VectorField_BinaryVector :
if dst . FieldsData [ i ] . GetVectors ( ) . GetBinaryVector ( ) == nil {
bvec := & schemapb . VectorField_BinaryVector {
BinaryVector : vectorType . BinaryVector [ idx * ( dim / 8 ) : ( idx + 1 ) * ( dim / 8 ) ] ,
}
dst . FieldsData [ i ] . GetVectors ( ) . Data = bvec
} else {
dst . FieldsData [ i ] . GetVectors ( ) . Data . ( * schemapb . VectorField_BinaryVector ) . BinaryVector = append ( dst . FieldsData [ i ] . GetVectors ( ) . Data . ( * schemapb . VectorField_BinaryVector ) . BinaryVector , vectorType . BinaryVector [ idx * ( dim / 8 ) : ( idx + 1 ) * ( dim / 8 ) ] ... )
}
case * schemapb . VectorField_FloatVector :
if dst . FieldsData [ i ] . GetVectors ( ) . GetFloatVector ( ) == nil {
fvec := & schemapb . VectorField_FloatVector {
FloatVector : & schemapb . FloatArray {
Data : vectorType . FloatVector . Data [ idx * dim : ( idx + 1 ) * dim ] ,
} ,
}
dst . FieldsData [ i ] . GetVectors ( ) . Data = fvec
} else {
dst . FieldsData [ i ] . GetVectors ( ) . GetFloatVector ( ) . Data = append ( dst . FieldsData [ i ] . GetVectors ( ) . GetFloatVector ( ) . Data , vectorType . FloatVector . Data [ idx * dim : ( idx + 1 ) * dim ] ... )
}
default :
log . Debug ( "Not supported field type" , zap . String ( "field type" , fieldData . Type . String ( ) ) )
return fmt . Errorf ( "not supported field type: %s" , fieldData . Type . String ( ) )
}
}
}
return nil
}
2021-10-21 19:52:28 +08:00
//func printSearchResultData(data *schemapb.SearchResultData, header string) {
// size := len(data.Ids.GetIntId().Data)
// if size != len(data.Scores) {
// log.Error("SearchResultData length mis-match")
// }
// log.Debug("==== SearchResultData ====",
// zap.String("header", header), zap.Int64("nq", data.NumQueries), zap.Int64("topk", data.TopK))
// for i := 0; i < size; i++ {
// log.Debug("", zap.Int("i", i), zap.Int64("id", data.Ids.GetIntId().Data[i]), zap.Float32("score", data.Scores[i]))
// }
//}
2021-08-24 11:13:52 +08:00
func reduceSearchResultDataParallel ( searchResultData [ ] * schemapb . SearchResultData , availableQueryNodeNum int64 ,
nq int64 , topk int64 , metricType string , maxParallel int ) ( * milvuspb . SearchResults , error ) {
2021-03-25 10:14:09 +08:00
2021-08-23 17:03:51 +08:00
log . Debug ( "reduceSearchResultDataParallel" ,
zap . Int ( "len(searchResultData)" , len ( searchResultData ) ) ,
zap . Int64 ( "availableQueryNodeNum" , availableQueryNodeNum ) ,
zap . Int64 ( "nq" , nq ) , zap . Int64 ( "topk" , topk ) , zap . String ( "metricType" , metricType ) ,
zap . Int ( "maxParallel" , maxParallel ) )
2021-03-25 10:14:09 +08:00
2021-06-21 20:18:13 +08:00
ret := & milvuspb . SearchResults {
Status : & commonpb . Status {
ErrorCode : 0 ,
} ,
Results : & schemapb . SearchResultData {
2021-08-23 17:03:51 +08:00
NumQueries : nq ,
TopK : topk ,
2021-06-21 20:18:13 +08:00
FieldsData : make ( [ ] * schemapb . FieldData , len ( searchResultData [ 0 ] . FieldsData ) ) ,
Scores : make ( [ ] float32 , 0 ) ,
Ids : & schemapb . IDs {
IdField : & schemapb . IDs_IntId {
IntId : & schemapb . LongArray {
Data : make ( [ ] int64 , 0 ) ,
} ,
} ,
} ,
2021-06-28 15:28:11 +08:00
Topks : make ( [ ] int64 , 0 ) ,
2021-06-21 20:18:13 +08:00
} ,
}
2021-08-23 17:03:51 +08:00
for i , sData := range searchResultData {
log . Debug ( "reduceSearchResultDataParallel" ,
zap . Int ( "i" , i ) ,
zap . Int64 ( "nq" , sData . NumQueries ) ,
zap . Int64 ( "topk" , sData . TopK ) ,
zap . Any ( "len(FieldsData)" , len ( sData . FieldsData ) ) )
2021-10-21 10:46:36 +08:00
if err := checkSearchResultData ( sData , nq , topk ) ; err != nil {
return ret , err
2021-08-23 17:03:51 +08:00
}
2021-10-21 19:52:28 +08:00
//printSearchResultData(sData, strconv.FormatInt(int64(i), 10))
2021-08-23 17:03:51 +08:00
}
2021-06-21 20:18:13 +08:00
// TODO(yukun): Use parallel function
2021-08-23 17:03:51 +08:00
var realTopK int64 = - 1
2021-10-21 10:46:36 +08:00
for i := int64 ( 0 ) ; i < nq ; i ++ {
offsets := make ( [ ] int64 , availableQueryNodeNum )
2021-10-21 19:52:28 +08:00
var prevIDSet = make ( map [ int64 ] struct { } )
var prevScore float32 = math . MaxFloat32
var loc int64
for loc = 0 ; loc < topk ; {
2021-10-21 10:46:36 +08:00
sel := selectSearchResultData ( searchResultData , offsets , topk , i )
if sel == - 1 {
2021-06-21 20:18:13 +08:00
break
}
2021-10-21 19:52:28 +08:00
idx := i * topk + offsets [ sel ]
2021-08-02 10:25:49 +08:00
2021-10-21 10:46:36 +08:00
id := searchResultData [ sel ] . Ids . GetIntId ( ) . Data [ idx ]
2021-10-21 19:52:28 +08:00
score := searchResultData [ sel ] . Scores [ idx ]
// ignore invalid search result
2021-08-02 10:25:49 +08:00
if id == - 1 {
continue
}
2021-10-21 19:52:28 +08:00
// remove duplicates
if math . Abs ( float64 ( score ) - float64 ( prevScore ) ) > 0.00001 {
copySearchResultData ( ret . Results , searchResultData [ sel ] , idx )
ret . Results . Ids . GetIntId ( ) . Data = append ( ret . Results . Ids . GetIntId ( ) . Data , id )
ret . Results . Scores = append ( ret . Results . Scores , score )
prevScore = score
prevIDSet = map [ int64 ] struct { } { id : { } }
loc ++
} else {
// To handle this case:
// e1: [100, 0.99]
// e2: [101, 0.99] ==> not duplicated, should keep
// e3: [100, 0.99] ==> duplicated, should remove
if _ , ok := prevIDSet [ id ] ; ! ok {
copySearchResultData ( ret . Results , searchResultData [ sel ] , idx )
ret . Results . Ids . GetIntId ( ) . Data = append ( ret . Results . Ids . GetIntId ( ) . Data , id )
ret . Results . Scores = append ( ret . Results . Scores , score )
prevIDSet [ id ] = struct { } { }
loc ++
} else {
// entity with same id and same score must be duplicated
log . Debug ( "skip duplicated search result" ,
zap . Int64 ( "id" , id ) ,
zap . Float32 ( "score" , score ) ,
zap . Float32 ( "prevScore" , prevScore ) )
}
}
2021-10-21 10:46:36 +08:00
offsets [ sel ] ++
2021-06-21 20:18:13 +08:00
}
2021-10-21 19:52:28 +08:00
if realTopK != - 1 && realTopK != loc {
2021-06-28 14:30:14 +08:00
log . Warn ( "Proxy Reduce Search Result" , zap . Error ( errors . New ( "the length (topk) between all result of query is different" ) ) )
// return nil, errors.New("the length (topk) between all result of query is different")
}
2021-10-21 19:52:28 +08:00
realTopK = loc
2021-08-23 17:03:51 +08:00
ret . Results . Topks = append ( ret . Results . Topks , realTopK )
2021-06-21 20:18:13 +08:00
}
2021-08-23 17:03:51 +08:00
ret . Results . TopK = realTopK
2021-06-28 14:30:14 +08:00
2021-06-21 20:18:13 +08:00
if metricType != "IP" {
for k := range ret . Results . Scores {
ret . Results . Scores [ k ] *= - 1
}
}
2021-06-28 14:30:14 +08:00
return ret , nil
2021-06-21 20:18:13 +08:00
}
2021-08-24 11:13:52 +08:00
func reduceSearchResultData ( searchResultData [ ] * schemapb . SearchResultData , availableQueryNodeNum int64 ,
2021-10-20 17:56:38 +08:00
nq int64 , topk int64 , metricType string ) ( res * milvuspb . SearchResults , err error ) {
tr := timerecord . NewTimeRecorder ( "reduceSearchResults" )
res , err = reduceSearchResultDataParallel ( searchResultData , availableQueryNodeNum , nq , topk , metricType , runtime . NumCPU ( ) )
tr . Elapse ( "done" )
return
2021-06-21 20:18:13 +08:00
}
2021-08-24 11:13:52 +08:00
//func printSearchResult(partialSearchResult *internalpb.SearchResults) {
// for i := 0; i < len(partialSearchResult.Hits); i++ {
// testHits := milvuspb.Hits{}
// err := proto.Unmarshal(partialSearchResult.Hits[i], &testHits)
// if err != nil {
// panic(err)
// }
// fmt.Println(testHits.IDs)
// fmt.Println(testHits.Scores)
// }
//}
2021-03-25 10:14:09 +08:00
2021-09-11 11:36:22 +08:00
func ( st * searchTask ) PostExecute ( ctx context . Context ) error {
2021-09-22 19:36:00 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( st . TraceCtx ( ) , "Proxy-Search-PostExecute" )
defer sp . Finish ( )
2021-10-20 17:56:38 +08:00
tr := timerecord . NewTimeRecorder ( "searchTask PostExecute" )
2021-03-26 11:19:02 +08:00
defer func ( ) {
2021-10-20 17:56:38 +08:00
tr . Elapse ( "done" )
2021-03-26 11:19:02 +08:00
} ( )
2020-11-07 16:18:23 +08:00
for {
select {
2021-03-25 14:41:46 +08:00
case <- st . TraceCtx ( ) . Done ( ) :
2021-09-11 11:36:22 +08:00
log . Debug ( "Proxy" , zap . Int64 ( "searchTask PostExecute Loop exit caused by ctx.Done" , st . ID ( ) ) )
return fmt . Errorf ( "searchTask:wait to finish failed, timeout: %d" , st . ID ( ) )
2021-01-18 19:32:08 +08:00
case searchResults := <- st . resultBuf :
2021-01-23 20:58:46 +08:00
// fmt.Println("searchResults: ", searchResults)
2021-03-12 14:22:09 +08:00
filterSearchResult := make ( [ ] * internalpb . SearchResults , 0 )
2020-11-30 22:14:19 +08:00
var filterReason string
2020-11-30 19:08:32 +08:00
for _ , partialSearchResult := range searchResults {
2021-03-10 22:06:22 +08:00
if partialSearchResult . Status . ErrorCode == commonpb . ErrorCode_Success {
2020-11-30 19:08:32 +08:00
filterSearchResult = append ( filterSearchResult , partialSearchResult )
2021-01-18 19:32:08 +08:00
// For debugging, please don't delete.
2021-03-25 10:14:09 +08:00
// printSearchResult(partialSearchResult)
2020-11-30 22:14:19 +08:00
} else {
filterReason += partialSearchResult . Status . Reason + "\n"
2020-11-30 19:08:32 +08:00
}
}
2020-12-10 16:31:09 +08:00
availableQueryNodeNum := len ( filterSearchResult )
2021-09-12 17:54:01 +08:00
log . Debug ( "Proxy Search PostExecute stage1" ,
2021-10-20 17:56:38 +08:00
zap . Any ( "availableQueryNodeNum" , availableQueryNodeNum ) )
tr . Record ( "Proxy Search PostExecute stage1 done" )
2020-12-10 16:31:09 +08:00
if availableQueryNodeNum <= 0 {
2021-01-22 09:36:18 +08:00
st . result = & milvuspb . SearchResults {
2020-11-30 22:14:19 +08:00
Status : & commonpb . Status {
2021-03-10 22:06:22 +08:00
ErrorCode : commonpb . ErrorCode_UnexpectedError ,
2020-11-30 22:14:19 +08:00
Reason : filterReason ,
} ,
}
2021-09-12 17:54:01 +08:00
return fmt . Errorf ( "No Available Query node result, filter reason %s: id %d" , filterReason , st . ID ( ) )
2020-11-07 16:18:23 +08:00
}
2020-11-28 19:06:48 +08:00
2021-03-25 10:14:09 +08:00
availableQueryNodeNum = 0
2020-12-10 16:31:09 +08:00
for _ , partialSearchResult := range filterSearchResult {
2021-06-21 20:18:13 +08:00
if partialSearchResult . SlicedBlob == nil {
2021-08-24 11:13:52 +08:00
filterReason += "empty search result\n"
} else {
availableQueryNodeNum ++
2020-12-10 16:31:09 +08:00
}
}
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy Search PostExecute stage2" , zap . Any ( "availableQueryNodeNum" , availableQueryNodeNum ) )
2020-12-10 16:31:09 +08:00
if availableQueryNodeNum <= 0 {
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy Search PostExecute stage2 failed" , zap . Any ( "filterReason" , filterReason ) )
2021-06-11 09:50:34 +08:00
2021-01-22 09:36:18 +08:00
st . result = & milvuspb . SearchResults {
2020-12-10 16:31:09 +08:00
Status : & commonpb . Status {
2021-03-10 22:06:22 +08:00
ErrorCode : commonpb . ErrorCode_Success ,
2020-12-10 16:31:09 +08:00
Reason : filterReason ,
} ,
2021-08-24 11:13:52 +08:00
Results : & schemapb . SearchResultData {
NumQueries : searchResults [ 0 ] . NumQueries ,
Topks : make ( [ ] int64 , searchResults [ 0 ] . NumQueries ) ,
} ,
2020-12-10 16:31:09 +08:00
}
return nil
}
2021-06-21 20:18:13 +08:00
results , err := decodeSearchResults ( filterSearchResult )
2021-03-25 10:14:09 +08:00
if err != nil {
return err
}
2021-08-24 11:13:52 +08:00
st . result , err = reduceSearchResultData ( results , int64 ( availableQueryNodeNum ) ,
searchResults [ 0 ] . NumQueries , searchResults [ 0 ] . TopK , searchResults [ 0 ] . MetricType )
2021-06-28 14:30:14 +08:00
if err != nil {
return err
}
2021-06-21 20:18:13 +08:00
schema , err := globalMetaCache . GetCollectionSchema ( ctx , st . query . CollectionName )
if err != nil {
return err
}
2021-07-11 19:39:52 +08:00
if len ( st . query . OutputFields ) != 0 && len ( st . result . Results . FieldsData ) != 0 {
2021-06-28 12:16:13 +08:00
for k , fieldName := range st . query . OutputFields {
for _ , field := range schema . Fields {
2021-07-11 19:39:52 +08:00
if st . result . Results . FieldsData [ k ] != nil && field . Name == fieldName {
2021-07-16 17:19:55 +08:00
st . result . Results . FieldsData [ k ] . FieldName = field . Name
st . result . Results . FieldsData [ k ] . FieldId = field . FieldID
2021-06-28 12:16:13 +08:00
st . result . Results . FieldsData [ k ] . Type = field . DataType
}
2021-06-21 20:18:13 +08:00
}
}
2021-01-12 18:03:24 +08:00
}
2020-11-28 19:06:48 +08:00
return nil
2020-11-07 16:18:23 +08:00
}
}
2020-11-16 17:01:10 +08:00
}
2021-09-11 11:36:22 +08:00
type queryTask struct {
2021-05-20 15:02:31 +08:00
Condition
* internalpb . RetrieveRequest
2021-06-18 10:33:58 +08:00
ctx context . Context
resultBuf chan [ ] * internalpb . RetrieveResults
2021-08-16 17:06:10 +08:00
result * milvuspb . QueryResults
query * milvuspb . QueryRequest
2021-06-18 10:33:58 +08:00
chMgr channelsMgr
2021-06-22 16:44:09 +08:00
qc types . QueryCoord
2021-09-03 17:12:55 +08:00
ids * schemapb . IDs
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) TraceCtx ( ) context . Context {
2021-08-16 17:06:10 +08:00
return qt . ctx
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) ID ( ) UniqueID {
2021-08-16 17:06:10 +08:00
return qt . Base . MsgID
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) SetID ( uid UniqueID ) {
2021-08-16 17:06:10 +08:00
qt . Base . MsgID = uid
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) Name ( ) string {
2021-05-20 15:02:31 +08:00
return RetrieveTaskName
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) Type ( ) commonpb . MsgType {
2021-08-16 17:06:10 +08:00
return qt . Base . MsgType
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) BeginTs ( ) Timestamp {
2021-08-16 17:06:10 +08:00
return qt . Base . Timestamp
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) EndTs ( ) Timestamp {
2021-08-16 17:06:10 +08:00
return qt . Base . Timestamp
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) SetTs ( ts Timestamp ) {
2021-08-16 17:06:10 +08:00
qt . Base . Timestamp = ts
2021-05-20 15:02:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) OnEnqueue ( ) error {
2021-08-16 17:06:10 +08:00
qt . Base . MsgType = commonpb . MsgType_Retrieve
2021-05-20 15:02:31 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) getChannels ( ) ( [ ] pChan , error ) {
2021-08-16 17:06:10 +08:00
collID , err := globalMetaCache . GetCollectionID ( qt . ctx , qt . query . CollectionName )
2021-06-16 20:15:59 +08:00
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
var channels [ ] pChan
channels , err = qt . chMgr . getChannels ( collID )
2021-09-14 16:19:08 +08:00
if err != nil {
err := qt . chMgr . createDMLMsgStream ( collID )
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
return qt . chMgr . getChannels ( collID )
2021-09-14 16:19:08 +08:00
}
2021-10-15 20:37:04 +08:00
return channels , nil
2021-06-16 20:15:59 +08:00
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) getVChannels ( ) ( [ ] vChan , error ) {
2021-08-16 17:06:10 +08:00
collID , err := globalMetaCache . GetCollectionID ( qt . ctx , qt . query . CollectionName )
2021-06-16 20:15:59 +08:00
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
var channels [ ] vChan
channels , err = qt . chMgr . getVChannels ( collID )
2021-06-16 20:15:59 +08:00
if err != nil {
2021-08-16 17:06:10 +08:00
err := qt . chMgr . createDMLMsgStream ( collID )
2021-06-16 20:15:59 +08:00
if err != nil {
return nil , err
}
2021-10-15 20:37:04 +08:00
return qt . chMgr . getVChannels ( collID )
2021-06-16 20:15:59 +08:00
}
2021-10-15 20:37:04 +08:00
return channels , nil
2021-06-16 20:15:59 +08:00
}
2021-09-03 17:12:55 +08:00
func IDs2Expr ( fieldName string , ids [ ] int64 ) string {
idsStr := strings . Trim ( strings . Join ( strings . Fields ( fmt . Sprint ( ids ) ) , ", " ) , "[]" )
return fieldName + " in [ " + idsStr + " ]"
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) PreExecute ( ctx context . Context ) error {
2021-08-16 17:06:10 +08:00
qt . Base . MsgType = commonpb . MsgType_Retrieve
qt . Base . SourceID = Params . ProxyID
collectionName := qt . query . CollectionName
2021-09-14 16:19:08 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( qt . query . CollectionName ) ; err != nil {
2021-09-14 16:19:08 +08:00
log . Debug ( "Invalid collection name." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return err
}
2021-09-14 16:19:08 +08:00
log . Info ( "Validate collection name." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
2021-09-14 16:19:08 +08:00
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil {
log . Debug ( "Failed to get collection id." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return err
}
2021-09-14 16:19:08 +08:00
log . Info ( "Get collection id by name." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
2021-08-16 17:06:10 +08:00
for _ , tag := range qt . query . PartitionNames {
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( tag , false ) ; err != nil {
2021-05-29 11:19:30 +08:00
log . Debug ( "Invalid partition name." , zap . Any ( "partitionName" , tag ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return err
}
}
2021-05-29 11:19:30 +08:00
log . Info ( "Validate partition names." ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
2021-06-18 16:32:07 +08:00
// check if collection was already loaded into query node
2021-08-16 17:06:10 +08:00
showResp , err := qt . qc . ShowCollections ( qt . ctx , & querypb . ShowCollectionsRequest {
2021-06-18 16:32:07 +08:00
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowCollections ,
2021-08-16 17:06:10 +08:00
MsgID : qt . Base . MsgID ,
Timestamp : qt . Base . Timestamp ,
2021-06-18 16:32:07 +08:00
SourceID : Params . ProxyID ,
} ,
DbID : 0 , // TODO(dragondriver)
} )
if err != nil {
return err
}
if showResp . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( showResp . Status . Reason )
}
2021-06-22 16:44:09 +08:00
log . Debug ( "query coordinator show collections" ,
2021-06-18 16:32:07 +08:00
zap . Any ( "collections" , showResp . CollectionIDs ) ,
zap . Any ( "collID" , collectionID ) )
2021-08-02 22:39:25 +08:00
2021-06-18 16:32:07 +08:00
collectionLoaded := false
for _ , collID := range showResp . CollectionIDs {
if collectionID == collID {
collectionLoaded = true
break
}
}
if ! collectionLoaded {
return fmt . Errorf ( "collection %v was not loaded into memory" , collectionName )
}
2021-09-14 16:19:08 +08:00
schema , _ := globalMetaCache . GetCollectionSchema ( ctx , qt . query . CollectionName )
2021-09-03 17:12:55 +08:00
if qt . ids != nil {
pkField := ""
for _ , field := range schema . Fields {
if field . IsPrimaryKey {
pkField = field . Name
}
2021-08-16 17:06:10 +08:00
}
2021-09-03 17:12:55 +08:00
qt . query . Expr = IDs2Expr ( pkField , qt . ids . GetIntId ( ) . Data )
}
2021-08-16 17:06:10 +08:00
2021-09-03 17:12:55 +08:00
if qt . query . Expr == "" {
errMsg := "Query expression is empty"
return fmt . Errorf ( errMsg )
}
2021-10-13 20:30:32 +08:00
plan , err := createExprPlan ( schema , qt . query . Expr )
2021-09-03 17:12:55 +08:00
if err != nil {
return err
2021-08-16 17:06:10 +08:00
}
qt . query . OutputFields , err = translateOutputFields ( qt . query . OutputFields , schema , true )
2021-07-14 18:51:54 +08:00
if err != nil {
return err
}
2021-08-16 17:06:10 +08:00
log . Debug ( "translate output fields" , zap . Any ( "OutputFields" , qt . query . OutputFields ) )
if len ( qt . query . OutputFields ) == 0 {
2021-06-05 10:57:34 +08:00
for _ , field := range schema . Fields {
2021-06-25 16:52:11 +08:00
if field . FieldID >= 100 && field . DataType != schemapb . DataType_FloatVector && field . DataType != schemapb . DataType_BinaryVector {
2021-08-16 17:06:10 +08:00
qt . OutputFieldsId = append ( qt . OutputFieldsId , field . FieldID )
2021-06-15 11:01:13 +08:00
}
2021-06-05 10:57:34 +08:00
}
} else {
2021-07-17 10:53:30 +08:00
addPrimaryKey := false
2021-08-16 17:06:10 +08:00
for _ , reqField := range qt . query . OutputFields {
2021-06-28 10:12:13 +08:00
findField := false
2021-06-25 16:52:11 +08:00
for _ , field := range schema . Fields {
if reqField == field . Name {
if field . IsPrimaryKey {
2021-06-28 10:12:13 +08:00
addPrimaryKey = true
}
findField = true
2021-08-16 17:06:10 +08:00
qt . OutputFieldsId = append ( qt . OutputFieldsId , field . FieldID )
2021-09-03 17:12:55 +08:00
plan . OutputFieldIds = append ( plan . OutputFieldIds , field . FieldID )
2021-06-28 10:12:13 +08:00
} else {
if field . IsPrimaryKey && ! addPrimaryKey {
2021-08-16 17:06:10 +08:00
qt . OutputFieldsId = append ( qt . OutputFieldsId , field . FieldID )
2021-09-03 17:12:55 +08:00
plan . OutputFieldIds = append ( plan . OutputFieldIds , field . FieldID )
2021-06-28 10:12:13 +08:00
addPrimaryKey = true
2021-06-24 21:08:14 +08:00
}
}
}
2021-06-28 10:12:13 +08:00
if ! findField {
errMsg := "Field " + reqField + " not exist"
return errors . New ( errMsg )
}
2021-06-24 21:08:14 +08:00
}
2021-06-05 10:57:34 +08:00
}
2021-08-16 17:06:10 +08:00
log . Debug ( "translate output fields to field ids" , zap . Any ( "OutputFieldsID" , qt . OutputFieldsId ) )
2021-05-20 15:02:31 +08:00
2021-09-03 17:12:55 +08:00
qt . RetrieveRequest . SerializedExprPlan , err = proto . Marshal ( plan )
if err != nil {
return err
}
2021-08-16 17:06:10 +08:00
travelTimestamp := qt . query . TravelTimestamp
2021-06-21 10:42:10 +08:00
if travelTimestamp == 0 {
2021-08-16 17:06:10 +08:00
travelTimestamp = qt . BeginTs ( )
2021-06-21 10:42:10 +08:00
}
2021-08-16 17:06:10 +08:00
guaranteeTimestamp := qt . query . GuaranteeTimestamp
2021-06-30 21:02:13 +08:00
if guaranteeTimestamp == 0 {
2021-08-16 17:06:10 +08:00
guaranteeTimestamp = qt . BeginTs ( )
2021-06-30 21:02:13 +08:00
}
2021-08-16 17:06:10 +08:00
qt . TravelTimestamp = travelTimestamp
qt . GuaranteeTimestamp = guaranteeTimestamp
2021-06-21 10:42:10 +08:00
2021-08-16 17:06:10 +08:00
qt . ResultChannelID = Params . RetrieveResultChannelNames [ 0 ]
qt . DbID = 0 // todo(yukun)
2021-05-20 15:02:31 +08:00
2021-08-16 17:06:10 +08:00
qt . CollectionID = collectionID
qt . PartitionIDs = make ( [ ] UniqueID , 0 )
2021-05-20 15:02:31 +08:00
partitionsMap , err := globalMetaCache . GetPartitions ( ctx , collectionName )
if err != nil {
2021-05-29 11:19:30 +08:00
log . Debug ( "Failed to get partitions in collection." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return err
}
2021-05-29 11:19:30 +08:00
log . Info ( "Get partitions in collection." , zap . Any ( "collectionName" , collectionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
partitionsRecord := make ( map [ UniqueID ] bool )
2021-08-16 17:06:10 +08:00
for _ , partitionName := range qt . query . PartitionNames {
2021-05-20 15:02:31 +08:00
pattern := fmt . Sprintf ( "^%s$" , partitionName )
re , err := regexp . Compile ( pattern )
if err != nil {
2021-05-29 11:19:30 +08:00
log . Debug ( "Failed to compile partition name regex expression." , zap . Any ( "partitionName" , partitionName ) ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return errors . New ( "invalid partition names" )
}
found := false
for name , pID := range partitionsMap {
if re . MatchString ( name ) {
if _ , exist := partitionsRecord [ pID ] ; ! exist {
2021-08-16 17:06:10 +08:00
qt . PartitionIDs = append ( qt . PartitionIDs , pID )
2021-05-20 15:02:31 +08:00
partitionsRecord [ pID ] = true
}
found = true
}
}
if ! found {
2021-05-29 11:19:30 +08:00
// FIXME(wxyu): undefined behavior
2021-05-20 15:02:31 +08:00
errMsg := fmt . Sprintf ( "PartitonName: %s not found" , partitionName )
return errors . New ( errMsg )
}
}
2021-08-16 17:06:10 +08:00
log . Info ( "Query PreExecute done." ,
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) Execute ( ctx context . Context ) error {
2021-05-20 15:02:31 +08:00
var tsMsg msgstream . TsMsg = & msgstream . RetrieveMsg {
2021-08-16 17:06:10 +08:00
RetrieveRequest : * qt . RetrieveRequest ,
2021-05-20 15:02:31 +08:00
BaseMsg : msgstream . BaseMsg {
Ctx : ctx ,
HashValues : [ ] uint32 { uint32 ( Params . ProxyID ) } ,
2021-08-16 17:06:10 +08:00
BeginTimestamp : qt . Base . Timestamp ,
EndTimestamp : qt . Base . Timestamp ,
2021-05-20 15:02:31 +08:00
} ,
}
msgPack := msgstream . MsgPack {
2021-08-16 17:06:10 +08:00
BeginTs : qt . Base . Timestamp ,
EndTs : qt . Base . Timestamp ,
2021-05-20 15:02:31 +08:00
Msgs : make ( [ ] msgstream . TsMsg , 1 ) ,
}
msgPack . Msgs [ 0 ] = tsMsg
2021-06-18 10:33:58 +08:00
2021-09-25 00:21:57 +08:00
stream , err := qt . chMgr . getDQLStream ( qt . CollectionID )
2021-06-18 10:33:58 +08:00
if err != nil {
2021-09-25 00:21:57 +08:00
err = qt . chMgr . createDQLStream ( qt . CollectionID )
2021-06-18 10:33:58 +08:00
if err != nil {
2021-08-16 17:06:10 +08:00
qt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
qt . result . Status . Reason = err . Error ( )
2021-06-18 10:33:58 +08:00
return err
}
2021-09-25 00:21:57 +08:00
stream , err = qt . chMgr . getDQLStream ( qt . CollectionID )
2021-06-18 10:33:58 +08:00
if err != nil {
2021-08-16 17:06:10 +08:00
qt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
qt . result . Status . Reason = err . Error ( )
2021-06-18 10:33:58 +08:00
return err
}
}
err = stream . Produce ( & msgPack )
2021-06-22 14:40:07 +08:00
log . Debug ( "proxy" , zap . Int ( "length of retrieveMsg" , len ( msgPack . Msgs ) ) )
2021-05-20 15:02:31 +08:00
if err != nil {
2021-05-29 11:19:30 +08:00
log . Debug ( "Failed to send retrieve request." ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
}
2021-05-29 11:19:30 +08:00
2021-08-16 17:06:10 +08:00
log . Info ( "Query Execute done." ,
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-20 15:02:31 +08:00
return err
}
2021-09-11 11:36:22 +08:00
func ( qt * queryTask ) PostExecute ( ctx context . Context ) error {
2021-10-20 17:56:38 +08:00
tr := timerecord . NewTimeRecorder ( "queryTask PostExecute" )
2021-05-21 16:39:28 +08:00
defer func ( ) {
2021-10-20 17:56:38 +08:00
tr . Elapse ( "done" )
2021-05-21 16:39:28 +08:00
} ( )
2021-05-29 11:19:30 +08:00
select {
2021-08-16 17:06:10 +08:00
case <- qt . TraceCtx ( ) . Done ( ) :
log . Debug ( "proxy" , zap . Int64 ( "Query: wait to finish failed, timeout!, taskID:" , qt . ID ( ) ) )
2021-09-11 11:36:22 +08:00
return fmt . Errorf ( "queryTask:wait to finish failed, timeout : %d" , qt . ID ( ) )
2021-08-16 17:06:10 +08:00
case retrieveResults := <- qt . resultBuf :
2021-05-29 11:19:30 +08:00
retrieveResult := make ( [ ] * internalpb . RetrieveResults , 0 )
var reason string
for _ , partialRetrieveResult := range retrieveResults {
if partialRetrieveResult . Status . ErrorCode == commonpb . ErrorCode_Success {
retrieveResult = append ( retrieveResult , partialRetrieveResult )
} else {
reason += partialRetrieveResult . Status . Reason + "\n"
2021-05-21 16:39:28 +08:00
}
2021-05-29 11:19:30 +08:00
}
2021-05-21 16:39:28 +08:00
2021-05-29 11:19:30 +08:00
if len ( retrieveResult ) == 0 {
2021-08-16 17:06:10 +08:00
qt . result = & milvuspb . QueryResults {
2021-05-29 11:19:30 +08:00
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_UnexpectedError ,
Reason : reason ,
} ,
2021-05-21 16:39:28 +08:00
}
2021-08-16 17:06:10 +08:00
log . Debug ( "Query failed on all querynodes." ,
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-29 11:19:30 +08:00
return errors . New ( reason )
}
2021-05-21 16:39:28 +08:00
2021-05-29 11:19:30 +08:00
availableQueryNodeNum := 0
2021-08-16 17:06:10 +08:00
qt . result = & milvuspb . QueryResults {
2021-06-03 19:41:33 +08:00
Status : & commonpb . Status {
2021-06-08 16:26:36 +08:00
ErrorCode : commonpb . ErrorCode_Success ,
2021-06-03 19:41:33 +08:00
} ,
FieldsData : make ( [ ] * schemapb . FieldData , 0 ) ,
}
2021-09-16 20:03:50 +08:00
for _ , partialRetrieveResult := range retrieveResult {
2021-06-25 16:52:11 +08:00
availableQueryNodeNum ++
2021-05-29 11:19:30 +08:00
if partialRetrieveResult . Ids == nil {
reason += "ids is nil\n"
continue
} else {
2021-09-16 20:03:50 +08:00
// handles initialization, cannot use idx==0 since first result may be empty
if len ( qt . result . FieldsData ) == 0 {
2021-08-16 17:06:10 +08:00
qt . result . FieldsData = append ( qt . result . FieldsData , partialRetrieveResult . FieldsData ... )
2021-06-21 09:42:07 +08:00
} else {
for k , fieldData := range partialRetrieveResult . FieldsData {
switch fieldType := fieldData . Field . ( type ) {
case * schemapb . FieldData_Scalars :
switch scalarType := fieldType . Scalars . Data . ( type ) {
case * schemapb . ScalarField_BoolData :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetScalars ( ) . GetBoolData ( ) . Data = append ( qt . result . FieldsData [ k ] . GetScalars ( ) . GetBoolData ( ) . Data , scalarType . BoolData . Data ... )
2021-06-21 09:42:07 +08:00
case * schemapb . ScalarField_IntData :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetScalars ( ) . GetIntData ( ) . Data = append ( qt . result . FieldsData [ k ] . GetScalars ( ) . GetIntData ( ) . Data , scalarType . IntData . Data ... )
2021-06-21 09:42:07 +08:00
case * schemapb . ScalarField_LongData :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetScalars ( ) . GetLongData ( ) . Data = append ( qt . result . FieldsData [ k ] . GetScalars ( ) . GetLongData ( ) . Data , scalarType . LongData . Data ... )
2021-06-21 09:42:07 +08:00
case * schemapb . ScalarField_FloatData :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetScalars ( ) . GetFloatData ( ) . Data = append ( qt . result . FieldsData [ k ] . GetScalars ( ) . GetFloatData ( ) . Data , scalarType . FloatData . Data ... )
2021-06-21 09:42:07 +08:00
case * schemapb . ScalarField_DoubleData :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetScalars ( ) . GetDoubleData ( ) . Data = append ( qt . result . FieldsData [ k ] . GetScalars ( ) . GetDoubleData ( ) . Data , scalarType . DoubleData . Data ... )
2021-06-21 09:42:07 +08:00
default :
2021-08-16 17:06:10 +08:00
log . Debug ( "Query received not supported data type" )
2021-06-21 09:42:07 +08:00
}
case * schemapb . FieldData_Vectors :
switch vectorType := fieldType . Vectors . Data . ( type ) {
case * schemapb . VectorField_BinaryVector :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetVectors ( ) . Data . ( * schemapb . VectorField_BinaryVector ) . BinaryVector = append ( qt . result . FieldsData [ k ] . GetVectors ( ) . Data . ( * schemapb . VectorField_BinaryVector ) . BinaryVector , vectorType . BinaryVector ... )
2021-06-21 09:42:07 +08:00
case * schemapb . VectorField_FloatVector :
2021-08-16 17:06:10 +08:00
qt . result . FieldsData [ k ] . GetVectors ( ) . GetFloatVector ( ) . Data = append ( qt . result . FieldsData [ k ] . GetVectors ( ) . GetFloatVector ( ) . Data , vectorType . FloatVector . Data ... )
2021-06-21 09:42:07 +08:00
}
default :
}
}
}
2021-05-21 16:39:28 +08:00
}
2021-05-29 11:19:30 +08:00
}
2021-05-21 16:39:28 +08:00
2021-05-29 11:19:30 +08:00
if availableQueryNodeNum == 0 {
log . Info ( "Not any valid result found." ,
2021-08-16 17:06:10 +08:00
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
qt . result = & milvuspb . QueryResults {
2021-05-29 11:19:30 +08:00
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_UnexpectedError ,
Reason : reason ,
} ,
2021-05-21 16:39:28 +08:00
}
return nil
}
2021-06-08 16:26:36 +08:00
2021-08-16 17:06:10 +08:00
if len ( qt . result . FieldsData ) == 0 {
log . Info ( "Query result is nil." ,
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
qt . result = & milvuspb . QueryResults {
2021-06-25 16:52:11 +08:00
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_EmptyCollection ,
Reason : reason ,
} ,
}
return nil
}
2021-08-16 17:06:10 +08:00
schema , err := globalMetaCache . GetCollectionSchema ( ctx , qt . query . CollectionName )
2021-06-08 16:26:36 +08:00
if err != nil {
return err
}
2021-08-16 17:06:10 +08:00
for i := 0 ; i < len ( qt . result . FieldsData ) ; i ++ {
2021-06-08 16:26:36 +08:00
for _ , field := range schema . Fields {
2021-08-16 17:06:10 +08:00
if field . FieldID == qt . OutputFieldsId [ i ] {
qt . result . FieldsData [ i ] . FieldName = field . Name
qt . result . FieldsData [ i ] . FieldId = field . FieldID
qt . result . FieldsData [ i ] . Type = field . DataType
2021-06-08 16:26:36 +08:00
}
}
}
2021-05-21 16:39:28 +08:00
}
2021-05-29 11:19:30 +08:00
2021-08-16 17:06:10 +08:00
log . Info ( "Query PostExecute done." ,
zap . Any ( "requestID" , qt . Base . MsgID ) , zap . Any ( "requestType" , "query" ) )
2021-05-29 11:19:30 +08:00
return nil
2021-05-21 16:39:28 +08:00
}
2021-09-09 19:02:08 +08:00
type hasCollectionTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . HasCollectionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * milvuspb . BoolResponse
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return hct . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return hct . Base . MsgID
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
hct . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return HasCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return hct . Base . MsgType
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return hct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return hct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
hct . Base . Timestamp = ts
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
hct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
hct . Base . MsgType = commonpb . MsgType_HasCollection
2021-01-28 20:51:44 +08:00
hct . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( hct . CollectionName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-09 17:25:53 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) Execute ( ctx context . Context ) error {
2021-01-22 09:36:18 +08:00
var err error
2021-06-21 17:28:03 +08:00
hct . result , err = hct . rootCoord . HasCollection ( ctx , hct . HasCollectionRequest )
2021-02-04 19:34:35 +08:00
if hct . result == nil {
return errors . New ( "has collection resp is nil" )
}
2021-03-10 22:06:22 +08:00
if hct . result . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( hct . result . Status . Reason )
}
2020-11-09 17:25:53 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( hct * hasCollectionTask ) PostExecute ( ctx context . Context ) error {
2020-11-09 17:25:53 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type describeCollectionTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . DescribeCollectionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * milvuspb . DescribeCollectionResponse
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return dct . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return dct . Base . MsgID
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
dct . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return DescribeCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return dct . Base . MsgType
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
dct . Base . Timestamp = ts
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
dct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
dct . Base . MsgType = commonpb . MsgType_DescribeCollection
2021-01-28 20:51:44 +08:00
dct . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-10-09 16:10:56 +08:00
if dct . CollectionID != 0 && len ( dct . CollectionName ) == 0 {
return nil
2020-11-26 16:01:31 +08:00
}
2021-10-09 16:10:56 +08:00
2021-10-23 10:53:12 +08:00
return validateCollectionName ( dct . CollectionName )
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) Execute ( ctx context . Context ) error {
2021-01-22 09:36:18 +08:00
var err error
2021-06-08 19:25:37 +08:00
dct . result = & milvuspb . DescribeCollectionResponse {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
} ,
Schema : & schemapb . CollectionSchema {
Name : "" ,
Description : "" ,
AutoID : false ,
Fields : make ( [ ] * schemapb . FieldSchema , 0 ) ,
} ,
CollectionID : 0 ,
VirtualChannelNames : nil ,
PhysicalChannelNames : nil ,
}
2021-06-21 17:28:03 +08:00
result , err := dct . rootCoord . DescribeCollection ( ctx , dct . DescribeCollectionRequest )
2021-06-08 19:25:37 +08:00
2021-06-11 15:33:18 +08:00
if err != nil {
return err
2021-02-04 19:34:35 +08:00
}
2021-06-08 19:25:37 +08:00
2021-06-11 15:33:18 +08:00
if result . Status . ErrorCode != commonpb . ErrorCode_Success {
dct . result . Status = result . Status
} else {
dct . result . Schema . Name = result . Schema . Name
dct . result . Schema . Description = result . Schema . Description
dct . result . Schema . AutoID = result . Schema . AutoID
dct . result . CollectionID = result . CollectionID
dct . result . VirtualChannelNames = result . VirtualChannelNames
dct . result . PhysicalChannelNames = result . PhysicalChannelNames
2021-07-21 18:00:14 +08:00
dct . result . CreatedTimestamp = result . CreatedTimestamp
dct . result . CreatedUtcTimestamp = result . CreatedUtcTimestamp
2021-09-14 11:59:47 +08:00
dct . result . ShardsNum = result . ShardsNum
2021-06-11 15:33:18 +08:00
for _ , field := range result . Schema . Fields {
2021-09-13 17:12:19 +08:00
if field . FieldID >= common . StartOfUserFieldID {
2021-06-11 15:33:18 +08:00
dct . result . Schema . Fields = append ( dct . result . Schema . Fields , & schemapb . FieldSchema {
FieldID : field . FieldID ,
Name : field . Name ,
IsPrimaryKey : field . IsPrimaryKey ,
2021-06-21 11:42:18 +08:00
AutoID : field . AutoID ,
2021-06-11 15:33:18 +08:00
Description : field . Description ,
DataType : field . DataType ,
TypeParams : field . TypeParams ,
IndexParams : field . IndexParams ,
} )
}
2021-06-08 19:25:37 +08:00
}
}
2021-06-11 15:33:18 +08:00
return nil
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dct * describeCollectionTask ) PostExecute ( ctx context . Context ) error {
2021-02-02 19:54:31 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type getCollectionStatisticsTask struct {
2021-02-02 19:54:31 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . GetCollectionStatisticsRequest
2021-06-21 18:22:13 +08:00
ctx context . Context
dataCoord types . DataCoord
result * milvuspb . GetCollectionStatisticsResponse
2021-02-02 19:54:31 +08:00
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return g . ctx
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) ID ( ) UniqueID {
2021-02-02 19:54:31 +08:00
return g . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) SetID ( uid UniqueID ) {
2021-02-02 19:54:31 +08:00
g . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return GetCollectionStatisticsTaskName
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) Type ( ) commonpb . MsgType {
2021-02-02 19:54:31 +08:00
return g . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) BeginTs ( ) Timestamp {
2021-02-02 19:54:31 +08:00
return g . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) EndTs ( ) Timestamp {
2021-02-02 19:54:31 +08:00
return g . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) SetTs ( ts Timestamp ) {
2021-02-02 19:54:31 +08:00
g . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) OnEnqueue ( ) error {
2021-02-02 19:54:31 +08:00
g . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
g . Base . MsgType = commonpb . MsgType_GetCollectionStatistics
2021-02-02 19:54:31 +08:00
g . Base . SourceID = Params . ProxyID
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) Execute ( ctx context . Context ) error {
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , g . CollectionName )
2021-02-02 19:54:31 +08:00
if err != nil {
return err
}
2021-03-12 14:22:09 +08:00
req := & datapb . GetCollectionStatisticsRequest {
2021-02-02 19:54:31 +08:00
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_GetCollectionStatistics ,
2021-02-02 19:54:31 +08:00
MsgID : g . Base . MsgID ,
Timestamp : g . Base . Timestamp ,
SourceID : g . Base . SourceID ,
} ,
CollectionID : collID ,
}
2021-06-21 18:22:13 +08:00
result , _ := g . dataCoord . GetCollectionStatistics ( ctx , req )
2021-02-04 19:34:35 +08:00
if result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if result . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( result . Status . Reason )
2021-02-02 19:54:31 +08:00
}
2021-03-12 14:22:09 +08:00
g . result = & milvuspb . GetCollectionStatisticsResponse {
2021-02-02 19:54:31 +08:00
Status : & commonpb . Status {
2021-03-10 22:06:22 +08:00
ErrorCode : commonpb . ErrorCode_Success ,
2021-02-02 19:54:31 +08:00
Reason : "" ,
} ,
Stats : result . Stats ,
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getCollectionStatisticsTask ) PostExecute ( ctx context . Context ) error {
2021-05-10 17:39:08 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type getPartitionStatisticsTask struct {
2021-05-10 17:39:08 +08:00
Condition
* milvuspb . GetPartitionStatisticsRequest
2021-06-21 18:22:13 +08:00
ctx context . Context
dataCoord types . DataCoord
result * milvuspb . GetPartitionStatisticsResponse
2021-05-10 17:39:08 +08:00
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) TraceCtx ( ) context . Context {
2021-05-10 17:39:08 +08:00
return g . ctx
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) ID ( ) UniqueID {
2021-05-10 17:39:08 +08:00
return g . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) SetID ( uid UniqueID ) {
2021-05-10 17:39:08 +08:00
g . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) Name ( ) string {
2021-05-10 17:39:08 +08:00
return GetPartitionStatisticsTaskName
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) Type ( ) commonpb . MsgType {
2021-05-10 17:39:08 +08:00
return g . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) BeginTs ( ) Timestamp {
2021-05-10 17:39:08 +08:00
return g . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) EndTs ( ) Timestamp {
2021-05-10 17:39:08 +08:00
return g . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) SetTs ( ts Timestamp ) {
2021-05-10 17:39:08 +08:00
g . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) OnEnqueue ( ) error {
2021-05-10 17:39:08 +08:00
g . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) PreExecute ( ctx context . Context ) error {
2021-05-10 17:39:08 +08:00
g . Base . MsgType = commonpb . MsgType_GetPartitionStatistics
g . Base . SourceID = Params . ProxyID
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) Execute ( ctx context . Context ) error {
2021-05-10 17:39:08 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , g . CollectionName )
if err != nil {
return err
}
partitionID , err := globalMetaCache . GetPartitionID ( ctx , g . CollectionName , g . PartitionName )
if err != nil {
return err
}
req := & datapb . GetPartitionStatisticsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_GetPartitionStatistics ,
MsgID : g . Base . MsgID ,
Timestamp : g . Base . Timestamp ,
SourceID : g . Base . SourceID ,
} ,
CollectionID : collID ,
PartitionID : partitionID ,
}
2021-06-21 18:22:13 +08:00
result , _ := g . dataCoord . GetPartitionStatistics ( ctx , req )
2021-05-10 17:39:08 +08:00
if result == nil {
return errors . New ( "get partition statistics resp is nil" )
}
if result . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( result . Status . Reason )
}
g . result = & milvuspb . GetPartitionStatisticsResponse {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
Reason : "" ,
} ,
Stats : result . Stats ,
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( g * getPartitionStatisticsTask ) PostExecute ( ctx context . Context ) error {
2020-11-09 17:25:53 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type showCollectionsTask struct {
2020-11-17 20:00:23 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . ShowCollectionsRequest
2021-06-22 16:44:09 +08:00
ctx context . Context
rootCoord types . RootCoord
queryCoord types . QueryCoord
result * milvuspb . ShowCollectionsResponse
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return sct . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return sct . Base . MsgID
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
sct . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return ShowCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return sct . Base . MsgType
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return sct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return sct . Base . Timestamp
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
sct . Base . Timestamp = ts
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
sct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
sct . Base . MsgType = commonpb . MsgType_ShowCollections
2021-01-28 20:51:44 +08:00
sct . Base . SourceID = Params . ProxyID
2021-08-02 22:39:25 +08:00
if sct . GetType ( ) == milvuspb . ShowType_InMemory {
for _ , collectionName := range sct . CollectionNames {
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collectionName ) ; err != nil {
2021-08-02 22:39:25 +08:00
return err
}
}
}
2021-01-22 09:36:18 +08:00
2020-11-09 17:25:53 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) Execute ( ctx context . Context ) error {
2021-06-21 17:28:03 +08:00
respFromRootCoord , err := sct . rootCoord . ShowCollections ( ctx , sct . ShowCollectionsRequest )
2021-06-03 19:09:33 +08:00
if err != nil {
return err
2021-02-04 19:34:35 +08:00
}
2021-06-03 19:09:33 +08:00
2021-06-21 17:28:03 +08:00
if respFromRootCoord == nil {
2021-06-03 19:09:33 +08:00
return errors . New ( "failed to show collections" )
2021-02-04 19:34:35 +08:00
}
2021-06-03 19:09:33 +08:00
2021-06-21 17:28:03 +08:00
if respFromRootCoord . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( respFromRootCoord . Status . Reason )
2021-06-03 19:09:33 +08:00
}
2021-08-02 22:39:25 +08:00
if sct . GetType ( ) == milvuspb . ShowType_InMemory {
IDs2Names := make ( map [ UniqueID ] string )
for offset , collectionName := range respFromRootCoord . CollectionNames {
collectionID := respFromRootCoord . CollectionIds [ offset ]
IDs2Names [ collectionID ] = collectionName
}
collectionIDs := make ( [ ] UniqueID , 0 )
for _ , collectionName := range sct . CollectionNames {
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil {
log . Debug ( "Failed to get collection id." , zap . Any ( "collectionName" , collectionName ) ,
zap . Any ( "requestID" , sct . Base . MsgID ) , zap . Any ( "requestType" , "showCollections" ) )
return err
}
collectionIDs = append ( collectionIDs , collectionID )
IDs2Names [ collectionID ] = collectionName
}
2021-06-22 16:44:09 +08:00
resp , err := sct . queryCoord . ShowCollections ( ctx , & querypb . ShowCollectionsRequest {
2021-06-03 19:09:33 +08:00
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowCollections ,
2021-08-02 22:39:25 +08:00
MsgID : sct . Base . MsgID ,
Timestamp : sct . Base . Timestamp ,
SourceID : sct . Base . SourceID ,
2021-06-03 19:09:33 +08:00
} ,
//DbID: sct.ShowCollectionsRequest.DbName,
2021-08-02 22:39:25 +08:00
CollectionIDs : collectionIDs ,
2021-06-03 19:09:33 +08:00
} )
if err != nil {
return err
}
if resp == nil {
return errors . New ( "failed to show collections" )
}
if resp . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( resp . Status . Reason )
}
sct . result = & milvuspb . ShowCollectionsResponse {
2021-07-21 18:00:14 +08:00
Status : resp . Status ,
CollectionNames : make ( [ ] string , 0 , len ( resp . CollectionIDs ) ) ,
CollectionIds : make ( [ ] int64 , 0 , len ( resp . CollectionIDs ) ) ,
CreatedTimestamps : make ( [ ] uint64 , 0 , len ( resp . CollectionIDs ) ) ,
CreatedUtcTimestamps : make ( [ ] uint64 , 0 , len ( resp . CollectionIDs ) ) ,
2021-08-02 22:39:25 +08:00
InMemoryPercentages : make ( [ ] int64 , 0 , len ( resp . CollectionIDs ) ) ,
2021-06-03 19:09:33 +08:00
}
2021-08-02 22:39:25 +08:00
for offset , id := range resp . CollectionIDs {
collectionName , ok := IDs2Names [ id ]
if ! ok {
log . Debug ( "Failed to get collection info." , zap . Any ( "collectionName" , collectionName ) ,
zap . Any ( "requestID" , sct . Base . MsgID ) , zap . Any ( "requestType" , "showCollections" ) )
return errors . New ( "failed to show collections" )
}
collectionInfo , err := globalMetaCache . GetCollectionInfo ( ctx , collectionName )
if err != nil {
log . Debug ( "Failed to get collection info." , zap . Any ( "collectionName" , collectionName ) ,
zap . Any ( "requestID" , sct . Base . MsgID ) , zap . Any ( "requestType" , "showCollections" ) )
return err
}
2021-06-03 19:09:33 +08:00
sct . result . CollectionIds = append ( sct . result . CollectionIds , id )
2021-08-02 22:39:25 +08:00
sct . result . CollectionNames = append ( sct . result . CollectionNames , collectionName )
sct . result . CreatedTimestamps = append ( sct . result . CreatedTimestamps , collectionInfo . createdTimestamp )
sct . result . CreatedUtcTimestamps = append ( sct . result . CreatedUtcTimestamps , collectionInfo . createdUtcTimestamp )
sct . result . InMemoryPercentages = append ( sct . result . InMemoryPercentages , resp . InMemoryPercentages [ offset ] )
2021-06-03 19:09:33 +08:00
}
2021-06-27 12:10:08 +08:00
} else {
sct . result = respFromRootCoord
2021-06-03 19:09:33 +08:00
}
return nil
2020-11-09 17:25:53 +08:00
}
2021-09-09 19:02:08 +08:00
func ( sct * showCollectionsTask ) PostExecute ( ctx context . Context ) error {
2020-11-09 17:25:53 +08:00
return nil
}
2020-11-19 17:09:22 +08:00
2021-09-09 19:02:08 +08:00
type createPartitionTask struct {
2020-11-19 17:09:22 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . CreatePartitionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return cpt . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return cpt . Base . MsgID
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
cpt . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return CreatePartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return cpt . Base . MsgType
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
cpt . Base . Timestamp = ts
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
cpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
cpt . Base . MsgType = commonpb . MsgType_CreatePartition
2021-01-28 20:51:44 +08:00
cpt . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-01-18 19:32:08 +08:00
collName , partitionTag := cpt . CollectionName , cpt . PartitionName
2020-11-26 16:01:31 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionTag , true ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) Execute ( ctx context . Context ) ( err error ) {
2021-06-21 17:28:03 +08:00
cpt . result , err = cpt . rootCoord . CreatePartition ( ctx , cpt . CreatePartitionRequest )
2021-02-04 19:34:35 +08:00
if cpt . result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if cpt . result . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( cpt . result . Reason )
}
2020-11-19 17:09:22 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( cpt * createPartitionTask ) PostExecute ( ctx context . Context ) error {
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type dropPartitionTask struct {
2020-11-19 17:09:22 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . DropPartitionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return dpt . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return dpt . Base . MsgID
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
dpt . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return DropPartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return dpt . Base . MsgType
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
dpt . Base . Timestamp = ts
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
dpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
dpt . Base . MsgType = commonpb . MsgType_DropPartition
2021-01-28 20:51:44 +08:00
dpt . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-01-18 19:32:08 +08:00
collName , partitionTag := dpt . CollectionName , dpt . PartitionName
2020-11-26 16:01:31 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionTag , true ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) Execute ( ctx context . Context ) ( err error ) {
2021-06-21 17:28:03 +08:00
dpt . result , err = dpt . rootCoord . DropPartition ( ctx , dpt . DropPartitionRequest )
2021-02-04 19:34:35 +08:00
if dpt . result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if dpt . result . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( dpt . result . Reason )
}
2020-11-19 17:09:22 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( dpt * dropPartitionTask ) PostExecute ( ctx context . Context ) error {
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type hasPartitionTask struct {
2020-11-19 17:09:22 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . HasPartitionRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * milvuspb . BoolResponse
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return hpt . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return hpt . Base . MsgID
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
hpt . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return HasPartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return hpt . Base . MsgType
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return hpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return hpt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
hpt . Base . Timestamp = ts
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
hpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
hpt . Base . MsgType = commonpb . MsgType_HasPartition
2021-01-28 20:51:44 +08:00
hpt . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-01-18 19:32:08 +08:00
collName , partitionTag := hpt . CollectionName , hpt . PartitionName
2020-11-26 16:01:31 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionTag , true ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) Execute ( ctx context . Context ) ( err error ) {
2021-06-21 17:28:03 +08:00
hpt . result , err = hpt . rootCoord . HasPartition ( ctx , hpt . HasPartitionRequest )
2021-02-04 19:34:35 +08:00
if hpt . result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if hpt . result . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( hpt . result . Status . Reason )
}
2020-11-19 17:09:22 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( hpt * hasPartitionTask ) PostExecute ( ctx context . Context ) error {
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type showPartitionsTask struct {
2020-11-19 17:09:22 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . ShowPartitionsRequest
2021-08-02 22:39:25 +08:00
ctx context . Context
rootCoord types . RootCoord
queryCoord types . QueryCoord
result * milvuspb . ShowPartitionsResponse
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return spt . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return spt . Base . MsgID
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
spt . Base . MsgID = uid
2020-11-23 16:52:17 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return ShowPartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return spt . Base . MsgType
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return spt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return spt . Base . Timestamp
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
spt . Base . Timestamp = ts
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
spt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
spt . Base . MsgType = commonpb . MsgType_ShowPartitions
2021-01-28 20:51:44 +08:00
spt . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( spt . CollectionName ) ; err != nil {
2020-11-26 16:01:31 +08:00
return err
}
2021-08-02 22:39:25 +08:00
if spt . GetType ( ) == milvuspb . ShowType_InMemory {
for _ , partitionName := range spt . PartitionNames {
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionName , true ) ; err != nil {
2021-08-02 22:39:25 +08:00
return err
}
}
}
2020-11-19 17:09:22 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) Execute ( ctx context . Context ) error {
2021-08-02 22:39:25 +08:00
respFromRootCoord , err := spt . rootCoord . ShowPartitions ( ctx , spt . ShowPartitionsRequest )
if err != nil {
return err
2021-01-31 14:55:36 +08:00
}
2021-08-02 22:39:25 +08:00
if respFromRootCoord == nil {
return errors . New ( "failed to show partitions" )
2021-02-04 19:34:35 +08:00
}
2021-08-02 22:39:25 +08:00
if respFromRootCoord . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( respFromRootCoord . Status . Reason )
}
if spt . GetType ( ) == milvuspb . ShowType_InMemory {
collectionName := spt . CollectionName
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil {
log . Debug ( "Failed to get collection id." , zap . Any ( "collectionName" , collectionName ) ,
zap . Any ( "requestID" , spt . Base . MsgID ) , zap . Any ( "requestType" , "showPartitions" ) )
return err
}
IDs2Names := make ( map [ UniqueID ] string )
for offset , partitionName := range respFromRootCoord . PartitionNames {
partitionID := respFromRootCoord . PartitionIDs [ offset ]
IDs2Names [ partitionID ] = partitionName
}
partitionIDs := make ( [ ] UniqueID , 0 )
for _ , partitionName := range spt . PartitionNames {
partitionID , err := globalMetaCache . GetPartitionID ( ctx , collectionName , partitionName )
if err != nil {
log . Debug ( "Failed to get partition id." , zap . Any ( "partitionName" , partitionName ) ,
zap . Any ( "requestID" , spt . Base . MsgID ) , zap . Any ( "requestType" , "showPartitions" ) )
return err
}
partitionIDs = append ( partitionIDs , partitionID )
IDs2Names [ partitionID ] = partitionName
}
resp , err := spt . queryCoord . ShowPartitions ( ctx , & querypb . ShowPartitionsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowCollections ,
MsgID : spt . Base . MsgID ,
Timestamp : spt . Base . Timestamp ,
SourceID : spt . Base . SourceID ,
} ,
CollectionID : collectionID ,
PartitionIDs : partitionIDs ,
} )
if err != nil {
return err
}
if resp == nil {
return errors . New ( "failed to show partitions" )
}
if resp . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( resp . Status . Reason )
}
spt . result = & milvuspb . ShowPartitionsResponse {
Status : resp . Status ,
PartitionNames : make ( [ ] string , 0 , len ( resp . PartitionIDs ) ) ,
PartitionIDs : make ( [ ] int64 , 0 , len ( resp . PartitionIDs ) ) ,
CreatedTimestamps : make ( [ ] uint64 , 0 , len ( resp . PartitionIDs ) ) ,
CreatedUtcTimestamps : make ( [ ] uint64 , 0 , len ( resp . PartitionIDs ) ) ,
InMemoryPercentages : make ( [ ] int64 , 0 , len ( resp . PartitionIDs ) ) ,
}
for offset , id := range resp . PartitionIDs {
partitionName , ok := IDs2Names [ id ]
if ! ok {
log . Debug ( "Failed to get partition id." , zap . Any ( "partitionName" , partitionName ) ,
zap . Any ( "requestID" , spt . Base . MsgID ) , zap . Any ( "requestType" , "showPartitions" ) )
return errors . New ( "failed to show partitions" )
}
partitionInfo , err := globalMetaCache . GetPartitionInfo ( ctx , collectionName , partitionName )
if err != nil {
log . Debug ( "Failed to get partition id." , zap . Any ( "partitionName" , partitionName ) ,
zap . Any ( "requestID" , spt . Base . MsgID ) , zap . Any ( "requestType" , "showPartitions" ) )
return err
}
spt . result . PartitionIDs = append ( spt . result . PartitionIDs , id )
spt . result . PartitionNames = append ( spt . result . PartitionNames , partitionName )
spt . result . CreatedTimestamps = append ( spt . result . CreatedTimestamps , partitionInfo . createdTimestamp )
spt . result . CreatedUtcTimestamps = append ( spt . result . CreatedUtcTimestamps , partitionInfo . createdUtcTimestamp )
spt . result . InMemoryPercentages = append ( spt . result . InMemoryPercentages , resp . InMemoryPercentages [ offset ] )
}
} else {
spt . result = respFromRootCoord
}
return nil
2020-11-19 17:09:22 +08:00
}
2021-09-09 19:02:08 +08:00
func ( spt * showPartitionsTask ) PostExecute ( ctx context . Context ) error {
2020-11-19 17:09:22 +08:00
return nil
}
2020-12-22 15:39:10 +08:00
2021-09-11 11:36:22 +08:00
type createIndexTask struct {
2020-12-22 15:39:10 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . CreateIndexRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return cit . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return cit . Base . MsgID
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
cit . Base . MsgID = uid
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return CreateIndexTaskName
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return cit . Base . MsgType
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cit . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return cit . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
cit . Base . Timestamp = ts
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
cit . Base = & commonpb . MsgBase { }
return nil
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
cit . Base . MsgType = commonpb . MsgType_CreateIndex
2021-01-28 20:51:44 +08:00
cit . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2020-12-22 15:39:10 +08:00
collName , fieldName := cit . CollectionName , cit . FieldName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2020-12-22 15:39:10 +08:00
return err
}
2021-10-23 18:25:37 +08:00
if err := validateFieldName ( fieldName ) ; err != nil {
2020-12-22 15:39:10 +08:00
return err
}
2021-06-22 15:28:04 +08:00
// check index param, not accurate, only some static rules
indexParams := make ( map [ string ] string )
for _ , kv := range cit . CreateIndexRequest . ExtraParams {
if kv . Key == "params" { // TODO(dragondriver): change `params` to const variable
params , err := funcutil . ParseIndexParamsMap ( kv . Value )
if err != nil {
log . Warn ( "Failed to parse index params" ,
zap . String ( "params" , kv . Value ) ,
zap . Error ( err ) )
continue
}
for k , v := range params {
indexParams [ k ] = v
}
} else {
indexParams [ kv . Key ] = kv . Value
}
}
indexType , exist := indexParams [ "index_type" ] // TODO(dragondriver): change `index_type` to const variable
if ! exist {
indexType = indexparamcheck . IndexFaissIvfPQ // IVF_PQ is the default index type
}
adapter , err := indexparamcheck . GetConfAdapterMgrInstance ( ) . GetAdapter ( indexType )
if err != nil {
log . Warn ( "Failed to get conf adapter" , zap . String ( "index_type" , indexType ) )
return fmt . Errorf ( "invalid index type: %s" , indexType )
}
ok := adapter . CheckTrain ( indexParams )
if ! ok {
log . Warn ( "Create index with invalid params" , zap . Any ( "index_params" , indexParams ) )
return fmt . Errorf ( "invalid index params: %v" , cit . CreateIndexRequest . ExtraParams )
}
2020-12-22 15:39:10 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) Execute ( ctx context . Context ) error {
2021-02-04 19:34:35 +08:00
var err error
2021-06-21 17:28:03 +08:00
cit . result , err = cit . rootCoord . CreateIndex ( ctx , cit . CreateIndexRequest )
2021-02-04 19:34:35 +08:00
if cit . result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if cit . result . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( cit . result . Reason )
}
2020-12-22 15:39:10 +08:00
return err
}
2021-09-11 11:36:22 +08:00
func ( cit * createIndexTask ) PostExecute ( ctx context . Context ) error {
2020-12-22 15:39:10 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
type describeIndexTask struct {
2020-12-22 15:39:10 +08:00
Condition
2021-01-22 09:36:18 +08:00
* milvuspb . DescribeIndexRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
rootCoord types . RootCoord
result * milvuspb . DescribeIndexResponse
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return dit . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) ID ( ) UniqueID {
2021-01-18 19:32:08 +08:00
return dit . Base . MsgID
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) SetID ( uid UniqueID ) {
2021-01-18 19:32:08 +08:00
dit . Base . MsgID = uid
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return DescribeIndexTaskName
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) Type ( ) commonpb . MsgType {
2021-01-18 19:32:08 +08:00
return dit . Base . MsgType
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) BeginTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dit . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) EndTs ( ) Timestamp {
2021-01-18 19:32:08 +08:00
return dit . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) SetTs ( ts Timestamp ) {
2021-01-18 19:32:08 +08:00
dit . Base . Timestamp = ts
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
dit . Base = & commonpb . MsgBase { }
return nil
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
dit . Base . MsgType = commonpb . MsgType_DescribeIndex
2021-01-28 20:51:44 +08:00
dit . Base . SourceID = Params . ProxyID
2021-01-22 09:36:18 +08:00
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( dit . CollectionName ) ; err != nil {
2020-12-22 15:39:10 +08:00
return err
}
2021-02-19 09:52:06 +08:00
// only support default index name for now. @2021.02.18
if dit . IndexName == "" {
dit . IndexName = Params . DefaultIndexName
}
2020-12-22 15:39:10 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) Execute ( ctx context . Context ) error {
2021-01-22 09:36:18 +08:00
var err error
2021-06-21 17:28:03 +08:00
dit . result , err = dit . rootCoord . DescribeIndex ( ctx , dit . DescribeIndexRequest )
2021-02-04 19:34:35 +08:00
if dit . result == nil {
return errors . New ( "get collection statistics resp is nil" )
}
2021-03-10 22:06:22 +08:00
if dit . result . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-02-04 19:34:35 +08:00
return errors . New ( dit . result . Status . Reason )
}
2020-12-22 15:39:10 +08:00
return err
}
2021-09-11 11:36:22 +08:00
func ( dit * describeIndexTask ) PostExecute ( ctx context . Context ) error {
2020-12-22 15:39:10 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
type dropIndexTask struct {
2021-02-20 18:30:37 +08:00
Condition
2021-02-23 09:58:06 +08:00
ctx context . Context
2021-02-20 18:30:37 +08:00
* milvuspb . DropIndexRequest
2021-06-21 17:28:03 +08:00
rootCoord types . RootCoord
result * commonpb . Status
2021-02-20 18:30:37 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return dit . ctx
2021-02-20 18:30:37 +08:00
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) ID ( ) UniqueID {
2021-02-20 18:30:37 +08:00
return dit . Base . MsgID
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) SetID ( uid UniqueID ) {
2021-02-20 18:30:37 +08:00
dit . Base . MsgID = uid
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return DropIndexTaskName
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) Type ( ) commonpb . MsgType {
2021-02-20 18:30:37 +08:00
return dit . Base . MsgType
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) BeginTs ( ) Timestamp {
2021-02-20 18:30:37 +08:00
return dit . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) EndTs ( ) Timestamp {
2021-02-20 18:30:37 +08:00
return dit . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) SetTs ( ts Timestamp ) {
2021-02-20 18:30:37 +08:00
dit . Base . Timestamp = ts
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
dit . Base = & commonpb . MsgBase { }
return nil
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
dit . Base . MsgType = commonpb . MsgType_DropIndex
2021-02-20 18:30:37 +08:00
dit . Base . SourceID = Params . ProxyID
collName , fieldName := dit . CollectionName , dit . FieldName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-02-20 18:30:37 +08:00
return err
}
2021-10-23 18:25:37 +08:00
if err := validateFieldName ( fieldName ) ; err != nil {
2021-02-20 18:30:37 +08:00
return err
}
2021-06-30 17:56:12 +08:00
if dit . IndexName == "" {
dit . IndexName = Params . DefaultIndexName
}
2021-02-20 18:30:37 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) Execute ( ctx context . Context ) error {
2021-02-20 18:30:37 +08:00
var err error
2021-06-21 17:28:03 +08:00
dit . result , err = dit . rootCoord . DropIndex ( ctx , dit . DropIndexRequest )
2021-02-20 18:30:37 +08:00
if dit . result == nil {
return errors . New ( "drop index resp is nil" )
}
2021-03-10 22:06:22 +08:00
if dit . result . ErrorCode != commonpb . ErrorCode_Success {
2021-02-20 18:30:37 +08:00
return errors . New ( dit . result . Reason )
}
return err
}
2021-09-11 11:36:22 +08:00
func ( dit * dropIndexTask ) PostExecute ( ctx context . Context ) error {
2021-02-20 18:30:37 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
type getIndexBuildProgressTask struct {
2021-04-28 11:15:28 +08:00
Condition
* milvuspb . GetIndexBuildProgressRequest
2021-06-21 18:22:13 +08:00
ctx context . Context
indexCoord types . IndexCoord
rootCoord types . RootCoord
dataCoord types . DataCoord
result * milvuspb . GetIndexBuildProgressResponse
2021-04-28 11:15:28 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) TraceCtx ( ) context . Context {
2021-04-28 11:15:28 +08:00
return gibpt . ctx
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) ID ( ) UniqueID {
2021-04-28 11:15:28 +08:00
return gibpt . Base . MsgID
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) SetID ( uid UniqueID ) {
2021-04-28 11:15:28 +08:00
gibpt . Base . MsgID = uid
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) Name ( ) string {
2021-04-28 11:15:28 +08:00
return GetIndexBuildProgressTaskName
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) Type ( ) commonpb . MsgType {
2021-04-28 11:15:28 +08:00
return gibpt . Base . MsgType
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) BeginTs ( ) Timestamp {
2021-04-28 11:15:28 +08:00
return gibpt . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) EndTs ( ) Timestamp {
2021-04-28 11:15:28 +08:00
return gibpt . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) SetTs ( ts Timestamp ) {
2021-04-28 11:15:28 +08:00
gibpt . Base . Timestamp = ts
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) OnEnqueue ( ) error {
2021-04-28 11:15:28 +08:00
gibpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) PreExecute ( ctx context . Context ) error {
2021-04-28 11:15:28 +08:00
gibpt . Base . MsgType = commonpb . MsgType_GetIndexBuildProgress
gibpt . Base . SourceID = Params . ProxyID
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( gibpt . CollectionName ) ; err != nil {
2021-04-28 11:15:28 +08:00
return err
}
return nil
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) Execute ( ctx context . Context ) error {
2021-04-28 11:15:28 +08:00
collectionName := gibpt . CollectionName
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil { // err is not nil if collection not exists
return err
}
showPartitionRequest := & milvuspb . ShowPartitionsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowPartitions ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
SourceID : Params . ProxyID ,
} ,
DbName : gibpt . DbName ,
CollectionName : collectionName ,
CollectionID : collectionID ,
}
2021-06-21 17:28:03 +08:00
partitions , err := gibpt . rootCoord . ShowPartitions ( ctx , showPartitionRequest )
2021-04-28 11:15:28 +08:00
if err != nil {
return err
}
if gibpt . IndexName == "" {
gibpt . IndexName = Params . DefaultIndexName
}
describeIndexReq := milvuspb . DescribeIndexRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_DescribeIndex ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
SourceID : Params . ProxyID ,
} ,
DbName : gibpt . DbName ,
CollectionName : gibpt . CollectionName ,
// IndexName: gibpt.IndexName,
}
2021-06-21 17:28:03 +08:00
indexDescriptionResp , err2 := gibpt . rootCoord . DescribeIndex ( ctx , & describeIndexReq )
2021-04-28 11:15:28 +08:00
if err2 != nil {
return err2
}
matchIndexID := int64 ( - 1 )
foundIndexID := false
for _ , desc := range indexDescriptionResp . IndexDescriptions {
if desc . IndexName == gibpt . IndexName {
matchIndexID = desc . IndexID
foundIndexID = true
break
}
}
if ! foundIndexID {
2021-06-22 18:04:07 +08:00
return fmt . Errorf ( "no index is created" )
2021-04-28 11:15:28 +08:00
}
var allSegmentIDs [ ] UniqueID
for _ , partitionID := range partitions . PartitionIDs {
showSegmentsRequest := & milvuspb . ShowSegmentsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowSegments ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
SourceID : Params . ProxyID ,
} ,
CollectionID : collectionID ,
PartitionID : partitionID ,
}
2021-06-21 17:28:03 +08:00
segments , err := gibpt . rootCoord . ShowSegments ( ctx , showSegmentsRequest )
2021-04-28 11:15:28 +08:00
if err != nil {
return err
}
if segments . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( segments . Status . Reason )
}
allSegmentIDs = append ( allSegmentIDs , segments . SegmentIDs ... )
}
getIndexStatesRequest := & indexpb . GetIndexStatesRequest {
IndexBuildIDs : make ( [ ] UniqueID , 0 ) ,
}
buildIndexMap := make ( map [ int64 ] int64 )
for _ , segmentID := range allSegmentIDs {
describeSegmentRequest := & milvuspb . DescribeSegmentRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_DescribeSegment ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
SourceID : Params . ProxyID ,
} ,
CollectionID : collectionID ,
SegmentID : segmentID ,
}
2021-06-21 17:28:03 +08:00
segmentDesc , err := gibpt . rootCoord . DescribeSegment ( ctx , describeSegmentRequest )
2021-04-28 11:15:28 +08:00
if err != nil {
return err
}
if segmentDesc . IndexID == matchIndexID {
if segmentDesc . EnableIndex {
getIndexStatesRequest . IndexBuildIDs = append ( getIndexStatesRequest . IndexBuildIDs , segmentDesc . BuildID )
buildIndexMap [ segmentID ] = segmentDesc . BuildID
}
}
}
2021-06-21 17:28:03 +08:00
states , err := gibpt . indexCoord . GetIndexStates ( ctx , getIndexStatesRequest )
2021-04-28 11:15:28 +08:00
if err != nil {
return err
}
if states . Status . ErrorCode != commonpb . ErrorCode_Success {
gibpt . result = & milvuspb . GetIndexBuildProgressResponse {
Status : states . Status ,
}
}
buildFinishMap := make ( map [ int64 ] bool )
for _ , state := range states . States {
if state . State == commonpb . IndexState_Finished {
buildFinishMap [ state . IndexBuildID ] = true
}
}
2021-06-21 18:22:13 +08:00
infoResp , err := gibpt . dataCoord . GetSegmentInfo ( ctx , & datapb . GetSegmentInfoRequest {
2021-04-28 11:15:28 +08:00
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_SegmentInfo ,
MsgID : 0 ,
Timestamp : 0 ,
SourceID : Params . ProxyID ,
} ,
SegmentIDs : allSegmentIDs ,
} )
if err != nil {
return err
}
total := int64 ( 0 )
indexed := int64 ( 0 )
for _ , info := range infoResp . Infos {
2021-06-04 11:45:45 +08:00
total += info . NumOfRows
2021-04-28 11:15:28 +08:00
if buildFinishMap [ buildIndexMap [ info . ID ] ] {
2021-06-04 11:45:45 +08:00
indexed += info . NumOfRows
2021-04-28 11:15:28 +08:00
}
}
gibpt . result = & milvuspb . GetIndexBuildProgressResponse {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
Reason : "" ,
} ,
TotalRows : total ,
IndexedRows : indexed ,
}
return nil
}
2021-09-11 11:36:22 +08:00
func ( gibpt * getIndexBuildProgressTask ) PostExecute ( ctx context . Context ) error {
2021-04-28 11:15:28 +08:00
return nil
}
2021-09-11 11:36:22 +08:00
type getIndexStateTask struct {
2020-12-22 15:39:10 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . GetIndexStateRequest
2021-06-21 17:28:03 +08:00
ctx context . Context
indexCoord types . IndexCoord
rootCoord types . RootCoord
result * milvuspb . GetIndexStateResponse
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return gist . ctx
2021-01-22 09:36:18 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) ID ( ) UniqueID {
2021-02-23 09:58:06 +08:00
return gist . Base . MsgID
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) SetID ( uid UniqueID ) {
2021-02-23 09:58:06 +08:00
gist . Base . MsgID = uid
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return GetIndexStateTaskName
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) Type ( ) commonpb . MsgType {
2021-02-23 09:58:06 +08:00
return gist . Base . MsgType
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) BeginTs ( ) Timestamp {
2021-02-23 09:58:06 +08:00
return gist . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) EndTs ( ) Timestamp {
2021-02-23 09:58:06 +08:00
return gist . Base . Timestamp
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) SetTs ( ts Timestamp ) {
2021-02-23 09:58:06 +08:00
gist . Base . Timestamp = ts
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
gist . Base = & commonpb . MsgBase { }
return nil
}
2021-01-22 09:36:18 +08:00
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
gist . Base . MsgType = commonpb . MsgType_GetIndexState
2021-02-23 09:58:06 +08:00
gist . Base . SourceID = Params . ProxyID
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( gist . CollectionName ) ; err != nil {
2020-12-22 15:39:10 +08:00
return err
}
return nil
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) Execute ( ctx context . Context ) error {
2021-02-23 09:58:06 +08:00
collectionName := gist . CollectionName
2021-02-26 17:44:24 +08:00
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
2021-02-04 14:37:12 +08:00
if err != nil { // err is not nil if collection not exists
return err
}
2021-03-12 14:22:09 +08:00
showPartitionRequest := & milvuspb . ShowPartitionsRequest {
2021-02-04 14:37:12 +08:00
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_ShowPartitions ,
2021-02-23 09:58:06 +08:00
MsgID : gist . Base . MsgID ,
Timestamp : gist . Base . Timestamp ,
2021-02-04 14:37:12 +08:00
SourceID : Params . ProxyID ,
} ,
2021-02-23 09:58:06 +08:00
DbName : gist . DbName ,
2021-02-04 14:37:12 +08:00
CollectionName : collectionName ,
CollectionID : collectionID ,
}
2021-06-21 17:28:03 +08:00
partitions , err := gist . rootCoord . ShowPartitions ( ctx , showPartitionRequest )
2021-02-04 14:37:12 +08:00
if err != nil {
return err
}
2021-02-23 09:58:06 +08:00
if gist . IndexName == "" {
gist . IndexName = Params . DefaultIndexName
2021-02-08 14:20:29 +08:00
}
describeIndexReq := milvuspb . DescribeIndexRequest {
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_DescribeIndex ,
2021-02-23 09:58:06 +08:00
MsgID : gist . Base . MsgID ,
Timestamp : gist . Base . Timestamp ,
2021-02-08 14:20:29 +08:00
SourceID : Params . ProxyID ,
} ,
2021-02-23 09:58:06 +08:00
DbName : gist . DbName ,
CollectionName : gist . CollectionName ,
IndexName : gist . IndexName ,
2021-02-08 14:20:29 +08:00
}
2021-06-21 17:28:03 +08:00
indexDescriptionResp , err2 := gist . rootCoord . DescribeIndex ( ctx , & describeIndexReq )
2021-02-08 14:20:29 +08:00
if err2 != nil {
return err2
}
matchIndexID := int64 ( - 1 )
foundIndexID := false
for _ , desc := range indexDescriptionResp . IndexDescriptions {
2021-02-23 09:58:06 +08:00
if desc . IndexName == gist . IndexName {
2021-02-08 14:20:29 +08:00
matchIndexID = desc . IndexID
foundIndexID = true
break
}
}
if ! foundIndexID {
2021-06-22 18:04:07 +08:00
return fmt . Errorf ( "no index is created" )
2021-02-08 14:20:29 +08:00
}
2021-02-19 09:52:06 +08:00
var allSegmentIDs [ ] UniqueID
2021-02-04 14:37:12 +08:00
for _ , partitionID := range partitions . PartitionIDs {
2021-03-12 14:22:09 +08:00
showSegmentsRequest := & milvuspb . ShowSegmentsRequest {
2021-02-04 14:37:12 +08:00
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_ShowSegments ,
2021-02-23 09:58:06 +08:00
MsgID : gist . Base . MsgID ,
Timestamp : gist . Base . Timestamp ,
2021-02-04 14:37:12 +08:00
SourceID : Params . ProxyID ,
} ,
CollectionID : collectionID ,
PartitionID : partitionID ,
}
2021-06-21 17:28:03 +08:00
segments , err := gist . rootCoord . ShowSegments ( ctx , showSegmentsRequest )
2021-02-04 14:37:12 +08:00
if err != nil {
return err
}
2021-03-10 22:06:22 +08:00
if segments . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-02-19 09:52:06 +08:00
return errors . New ( segments . Status . Reason )
2021-02-04 14:37:12 +08:00
}
2021-02-19 09:52:06 +08:00
allSegmentIDs = append ( allSegmentIDs , segments . SegmentIDs ... )
}
2021-03-12 14:22:09 +08:00
getIndexStatesRequest := & indexpb . GetIndexStatesRequest {
2021-02-19 09:52:06 +08:00
IndexBuildIDs : make ( [ ] UniqueID , 0 ) ,
}
2021-02-04 14:37:12 +08:00
2021-02-19 09:52:06 +08:00
for _ , segmentID := range allSegmentIDs {
describeSegmentRequest := & milvuspb . DescribeSegmentRequest {
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_DescribeSegment ,
2021-02-23 09:58:06 +08:00
MsgID : gist . Base . MsgID ,
Timestamp : gist . Base . Timestamp ,
2021-02-19 09:52:06 +08:00
SourceID : Params . ProxyID ,
} ,
CollectionID : collectionID ,
SegmentID : segmentID ,
}
2021-06-21 17:28:03 +08:00
segmentDesc , err := gist . rootCoord . DescribeSegment ( ctx , describeSegmentRequest )
2021-02-04 14:37:12 +08:00
if err != nil {
return err
}
2021-02-19 09:52:06 +08:00
if segmentDesc . IndexID == matchIndexID {
2021-03-08 15:46:51 +08:00
if segmentDesc . EnableIndex {
2021-06-21 20:34:16 +08:00
getIndexStatesRequest . IndexBuildIDs = append ( getIndexStatesRequest . IndexBuildIDs , segmentDesc . BuildID )
2021-03-08 15:46:51 +08:00
}
2021-02-19 09:52:06 +08:00
}
}
2021-02-04 14:37:12 +08:00
2021-06-21 20:34:16 +08:00
gist . result = & milvuspb . GetIndexStateResponse {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
Reason : "" ,
} ,
2021-07-29 14:47:22 +08:00
State : commonpb . IndexState_Finished ,
FailReason : "" ,
2021-02-19 09:52:06 +08:00
}
2021-06-22 14:40:07 +08:00
log . Debug ( "Proxy GetIndexState" , zap . Int ( "IndexBuildIDs" , len ( getIndexStatesRequest . IndexBuildIDs ) ) , zap . Error ( err ) )
2021-06-21 20:34:16 +08:00
if len ( getIndexStatesRequest . IndexBuildIDs ) == 0 {
return nil
2021-03-08 15:46:51 +08:00
}
2021-06-21 17:28:03 +08:00
states , err := gist . indexCoord . GetIndexStates ( ctx , getIndexStatesRequest )
2021-02-19 09:52:06 +08:00
if err != nil {
return err
}
2021-03-10 22:06:22 +08:00
if states . Status . ErrorCode != commonpb . ErrorCode_Success {
2021-03-12 14:22:09 +08:00
gist . result = & milvuspb . GetIndexStateResponse {
2021-02-19 09:52:06 +08:00
Status : states . Status ,
2021-03-11 14:14:29 +08:00
State : commonpb . IndexState_Failed ,
2021-02-19 09:52:06 +08:00
}
return nil
}
for _ , state := range states . States {
2021-03-11 14:14:29 +08:00
if state . State != commonpb . IndexState_Finished {
2021-03-12 14:22:09 +08:00
gist . result = & milvuspb . GetIndexStateResponse {
2021-07-29 14:47:22 +08:00
Status : states . Status ,
State : state . State ,
FailReason : state . Reason ,
2021-02-04 14:37:12 +08:00
}
2021-02-19 09:52:06 +08:00
return nil
2021-02-04 14:37:12 +08:00
}
}
2021-01-28 20:51:44 +08:00
return nil
2020-12-22 15:39:10 +08:00
}
2021-09-11 11:36:22 +08:00
func ( gist * getIndexStateTask ) PostExecute ( ctx context . Context ) error {
2020-12-22 15:39:10 +08:00
return nil
}
2021-02-02 10:58:39 +08:00
2021-09-11 11:36:22 +08:00
type flushTask struct {
2021-02-02 10:58:39 +08:00
Condition
* milvuspb . FlushRequest
2021-06-21 18:22:13 +08:00
ctx context . Context
dataCoord types . DataCoord
2021-06-23 16:56:11 +08:00
result * milvuspb . FlushResponse
2021-02-02 10:58:39 +08:00
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return ft . ctx
2021-02-02 10:58:39 +08:00
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) ID ( ) UniqueID {
2021-02-02 10:58:39 +08:00
return ft . Base . MsgID
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) SetID ( uid UniqueID ) {
2021-02-02 10:58:39 +08:00
ft . Base . MsgID = uid
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return FlushTaskName
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) Type ( ) commonpb . MsgType {
2021-02-02 10:58:39 +08:00
return ft . Base . MsgType
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) BeginTs ( ) Timestamp {
2021-02-02 10:58:39 +08:00
return ft . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) EndTs ( ) Timestamp {
2021-02-02 10:58:39 +08:00
return ft . Base . Timestamp
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) SetTs ( ts Timestamp ) {
2021-02-02 10:58:39 +08:00
ft . Base . Timestamp = ts
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
ft . Base = & commonpb . MsgBase { }
return nil
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
ft . Base . MsgType = commonpb . MsgType_Flush
2021-02-02 10:58:39 +08:00
ft . Base . SourceID = Params . ProxyID
return nil
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) Execute ( ctx context . Context ) error {
2021-06-23 16:56:11 +08:00
coll2Segments := make ( map [ string ] * schemapb . LongArray )
2021-02-03 17:30:10 +08:00
for _ , collName := range ft . CollectionNames {
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , collName )
2021-02-03 17:30:10 +08:00
if err != nil {
return err
}
flushReq := & datapb . FlushRequest {
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_Flush ,
2021-02-03 17:30:10 +08:00
MsgID : ft . Base . MsgID ,
Timestamp : ft . Base . Timestamp ,
SourceID : ft . Base . SourceID ,
} ,
DbID : 0 ,
CollectionID : collID ,
}
2021-06-23 16:56:11 +08:00
resp , err := ft . dataCoord . Flush ( ctx , flushReq )
if err != nil {
return fmt . Errorf ( "Failed to call flush to data coordinator: %s" , err . Error ( ) )
2021-02-03 17:30:10 +08:00
}
2021-06-23 16:56:11 +08:00
if resp . Status . ErrorCode != commonpb . ErrorCode_Success {
return errors . New ( resp . Status . Reason )
2021-02-03 17:30:10 +08:00
}
2021-06-23 16:56:11 +08:00
coll2Segments [ collName ] = & schemapb . LongArray { Data : resp . GetSegmentIDs ( ) }
2021-02-02 10:58:39 +08:00
}
2021-06-23 16:56:11 +08:00
ft . result = & milvuspb . FlushResponse {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
Reason : "" ,
} ,
DbName : "" ,
CollSegIDs : coll2Segments ,
2021-02-02 10:58:39 +08:00
}
2021-02-03 17:30:10 +08:00
return nil
2021-02-02 10:58:39 +08:00
}
2021-09-11 11:36:22 +08:00
func ( ft * flushTask ) PostExecute ( ctx context . Context ) error {
2021-02-02 10:58:39 +08:00
return nil
}
2021-02-04 15:31:02 +08:00
2021-09-09 19:02:08 +08:00
type loadCollectionTask struct {
2021-02-04 15:31:02 +08:00
Condition
* milvuspb . LoadCollectionRequest
2021-06-22 16:44:09 +08:00
ctx context . Context
queryCoord types . QueryCoord
result * commonpb . Status
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return lct . ctx
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) ID ( ) UniqueID {
2021-02-04 15:31:02 +08:00
return lct . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) SetID ( uid UniqueID ) {
2021-02-04 15:31:02 +08:00
lct . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return LoadCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) Type ( ) commonpb . MsgType {
2021-02-04 15:31:02 +08:00
return lct . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) BeginTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return lct . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) EndTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return lct . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) SetTs ( ts Timestamp ) {
2021-02-04 15:31:02 +08:00
lct . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
lct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) PreExecute ( ctx context . Context ) error {
log . Debug ( "loadCollectionTask PreExecute" , zap . String ( "role" , Params . RoleName ) , zap . Int64 ( "msgID" , lct . Base . MsgID ) )
2021-03-10 14:45:35 +08:00
lct . Base . MsgType = commonpb . MsgType_LoadCollection
2021-02-04 15:31:02 +08:00
lct . Base . SourceID = Params . ProxyID
collName := lct . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-02-04 15:31:02 +08:00
return err
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) Execute ( ctx context . Context ) ( err error ) {
log . Debug ( "loadCollectionTask Execute" , zap . String ( "role" , Params . RoleName ) , zap . Int64 ( "msgID" , lct . Base . MsgID ) )
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , lct . CollectionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
2021-02-26 17:44:24 +08:00
collSchema , err := globalMetaCache . GetCollectionSchema ( ctx , lct . CollectionName )
2021-02-06 21:17:18 +08:00
if err != nil {
return err
}
2021-02-04 15:31:02 +08:00
request := & querypb . LoadCollectionRequest {
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_LoadCollection ,
2021-02-04 15:31:02 +08:00
MsgID : lct . Base . MsgID ,
Timestamp : lct . Base . Timestamp ,
SourceID : lct . Base . SourceID ,
} ,
DbID : 0 ,
CollectionID : collID ,
2021-02-06 21:17:18 +08:00
Schema : collSchema ,
2021-02-04 15:31:02 +08:00
}
2021-06-22 16:44:09 +08:00
log . Debug ( "send LoadCollectionRequest to query coordinator" , zap . String ( "role" , Params . RoleName ) , zap . Int64 ( "msgID" , request . Base . MsgID ) , zap . Int64 ( "collectionID" , request . CollectionID ) ,
2021-03-13 11:59:24 +08:00
zap . Any ( "schema" , request . Schema ) )
2021-06-22 16:44:09 +08:00
lct . result , err = lct . queryCoord . LoadCollection ( ctx , request )
2021-03-13 11:59:24 +08:00
if err != nil {
2021-06-22 16:44:09 +08:00
return fmt . Errorf ( "call query coordinator LoadCollection: %s" , err )
2021-03-13 11:59:24 +08:00
}
return nil
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( lct * loadCollectionTask ) PostExecute ( ctx context . Context ) error {
log . Debug ( "loadCollectionTask PostExecute" , zap . String ( "role" , Params . RoleName ) , zap . Int64 ( "msgID" , lct . Base . MsgID ) )
2021-02-04 15:31:02 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type releaseCollectionTask struct {
2021-02-04 15:31:02 +08:00
Condition
* milvuspb . ReleaseCollectionRequest
2021-06-22 16:44:09 +08:00
ctx context . Context
queryCoord types . QueryCoord
result * commonpb . Status
chMgr channelsMgr
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return rct . ctx
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) ID ( ) UniqueID {
2021-02-04 15:31:02 +08:00
return rct . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) SetID ( uid UniqueID ) {
2021-02-04 15:31:02 +08:00
rct . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return ReleaseCollectionTaskName
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) Type ( ) commonpb . MsgType {
2021-02-04 15:31:02 +08:00
return rct . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) BeginTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return rct . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) EndTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return rct . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) SetTs ( ts Timestamp ) {
2021-02-04 15:31:02 +08:00
rct . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
rct . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
rct . Base . MsgType = commonpb . MsgType_ReleaseCollection
2021-02-04 15:31:02 +08:00
rct . Base . SourceID = Params . ProxyID
collName := rct . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-02-04 15:31:02 +08:00
return err
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) Execute ( ctx context . Context ) ( err error ) {
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , rct . CollectionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
request := & querypb . ReleaseCollectionRequest {
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_ReleaseCollection ,
2021-02-04 15:31:02 +08:00
MsgID : rct . Base . MsgID ,
Timestamp : rct . Base . Timestamp ,
SourceID : rct . Base . SourceID ,
} ,
DbID : 0 ,
CollectionID : collID ,
}
2021-06-18 10:33:58 +08:00
2021-06-22 16:44:09 +08:00
rct . result , err = rct . queryCoord . ReleaseCollection ( ctx , request )
2021-06-18 10:33:58 +08:00
_ = rct . chMgr . removeDQLStream ( collID )
2021-02-04 15:31:02 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( rct * releaseCollectionTask ) PostExecute ( ctx context . Context ) error {
2021-02-04 15:31:02 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type loadPartitionsTask struct {
2021-02-04 15:31:02 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . LoadPartitionsRequest
2021-06-22 16:44:09 +08:00
ctx context . Context
queryCoord types . QueryCoord
result * commonpb . Status
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) TraceCtx ( ) context . Context {
2021-03-25 14:41:46 +08:00
return lpt . ctx
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) ID ( ) UniqueID {
2021-02-04 15:31:02 +08:00
return lpt . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) SetID ( uid UniqueID ) {
2021-02-04 15:31:02 +08:00
lpt . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return LoadPartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) Type ( ) commonpb . MsgType {
2021-02-04 15:31:02 +08:00
return lpt . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) BeginTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return lpt . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) EndTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return lpt . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) SetTs ( ts Timestamp ) {
2021-02-04 15:31:02 +08:00
lpt . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
lpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
lpt . Base . MsgType = commonpb . MsgType_LoadPartitions
2021-02-04 15:31:02 +08:00
lpt . Base . SourceID = Params . ProxyID
collName := lpt . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-02-04 15:31:02 +08:00
return err
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) Execute ( ctx context . Context ) error {
2021-02-04 15:31:02 +08:00
var partitionIDs [ ] int64
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , lpt . CollectionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
2021-02-26 17:44:24 +08:00
collSchema , err := globalMetaCache . GetCollectionSchema ( ctx , lpt . CollectionName )
2021-02-06 21:17:18 +08:00
if err != nil {
return err
}
2021-02-04 15:31:02 +08:00
for _ , partitionName := range lpt . PartitionNames {
2021-02-26 17:44:24 +08:00
partitionID , err := globalMetaCache . GetPartitionID ( ctx , lpt . CollectionName , partitionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
partitionIDs = append ( partitionIDs , partitionID )
}
2021-03-12 14:22:09 +08:00
request := & querypb . LoadPartitionsRequest {
2021-02-04 15:31:02 +08:00
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_LoadPartitions ,
2021-02-04 15:31:02 +08:00
MsgID : lpt . Base . MsgID ,
Timestamp : lpt . Base . Timestamp ,
SourceID : lpt . Base . SourceID ,
} ,
DbID : 0 ,
CollectionID : collID ,
PartitionIDs : partitionIDs ,
2021-02-06 21:17:18 +08:00
Schema : collSchema ,
2021-02-04 15:31:02 +08:00
}
2021-06-22 16:44:09 +08:00
lpt . result , err = lpt . queryCoord . LoadPartitions ( ctx , request )
2021-02-04 15:31:02 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( lpt * loadPartitionsTask ) PostExecute ( ctx context . Context ) error {
2021-02-04 15:31:02 +08:00
return nil
}
2021-09-09 19:02:08 +08:00
type releasePartitionsTask struct {
2021-02-04 15:31:02 +08:00
Condition
2021-03-12 14:22:09 +08:00
* milvuspb . ReleasePartitionsRequest
2021-06-22 16:44:09 +08:00
ctx context . Context
queryCoord types . QueryCoord
result * commonpb . Status
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) TraceCtx ( ) context . Context {
2021-02-23 09:58:06 +08:00
return rpt . ctx
2021-02-04 15:31:02 +08:00
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) ID ( ) UniqueID {
2021-02-04 15:31:02 +08:00
return rpt . Base . MsgID
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) SetID ( uid UniqueID ) {
2021-02-04 15:31:02 +08:00
rpt . Base . MsgID = uid
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) Type ( ) commonpb . MsgType {
2021-02-04 15:31:02 +08:00
return rpt . Base . MsgType
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) Name ( ) string {
2021-02-23 09:58:06 +08:00
return ReleasePartitionTaskName
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) BeginTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return rpt . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) EndTs ( ) Timestamp {
2021-02-04 15:31:02 +08:00
return rpt . Base . Timestamp
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) SetTs ( ts Timestamp ) {
2021-02-04 15:31:02 +08:00
rpt . Base . Timestamp = ts
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
rpt . Base = & commonpb . MsgBase { }
return nil
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) PreExecute ( ctx context . Context ) error {
2021-03-10 14:45:35 +08:00
rpt . Base . MsgType = commonpb . MsgType_ReleasePartitions
2021-02-04 15:31:02 +08:00
rpt . Base . SourceID = Params . ProxyID
collName := rpt . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-02-04 15:31:02 +08:00
return err
}
return nil
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) Execute ( ctx context . Context ) ( err error ) {
2021-02-04 15:31:02 +08:00
var partitionIDs [ ] int64
2021-02-26 17:44:24 +08:00
collID , err := globalMetaCache . GetCollectionID ( ctx , rpt . CollectionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
for _ , partitionName := range rpt . PartitionNames {
2021-02-26 17:44:24 +08:00
partitionID , err := globalMetaCache . GetPartitionID ( ctx , rpt . CollectionName , partitionName )
2021-02-04 15:31:02 +08:00
if err != nil {
return err
}
partitionIDs = append ( partitionIDs , partitionID )
}
2021-03-12 14:22:09 +08:00
request := & querypb . ReleasePartitionsRequest {
2021-02-04 15:31:02 +08:00
Base : & commonpb . MsgBase {
2021-03-10 14:45:35 +08:00
MsgType : commonpb . MsgType_ReleasePartitions ,
2021-02-04 15:31:02 +08:00
MsgID : rpt . Base . MsgID ,
Timestamp : rpt . Base . Timestamp ,
SourceID : rpt . Base . SourceID ,
} ,
DbID : 0 ,
CollectionID : collID ,
PartitionIDs : partitionIDs ,
}
2021-06-22 16:44:09 +08:00
rpt . result , err = rpt . queryCoord . ReleasePartitions ( ctx , request )
2021-02-04 15:31:02 +08:00
return err
}
2021-09-09 19:02:08 +08:00
func ( rpt * releasePartitionsTask ) PostExecute ( ctx context . Context ) error {
2021-02-04 15:31:02 +08:00
return nil
}
2021-08-26 12:15:52 +08:00
2021-09-15 14:04:54 +08:00
type deleteTask struct {
2021-08-26 12:15:52 +08:00
Condition
2021-10-11 07:48:55 +08:00
* internalpb . DeleteRequest
ctx context . Context
req * milvuspb . DeleteRequest
result * milvuspb . MutationResult
chMgr channelsMgr
chTicker channelsTimeTicker
vChannels [ ] vChan
pChannels [ ] pChan
2021-08-26 12:15:52 +08:00
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) TraceCtx ( ) context . Context {
2021-08-26 12:15:52 +08:00
return dt . ctx
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) ID ( ) UniqueID {
2021-08-26 12:15:52 +08:00
return dt . Base . MsgID
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) SetID ( uid UniqueID ) {
2021-08-26 12:15:52 +08:00
dt . Base . MsgID = uid
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) Type ( ) commonpb . MsgType {
2021-08-26 12:15:52 +08:00
return dt . Base . MsgType
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) Name ( ) string {
return deleteTaskName
2021-08-26 12:15:52 +08:00
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) BeginTs ( ) Timestamp {
2021-08-26 12:15:52 +08:00
return dt . Base . Timestamp
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) EndTs ( ) Timestamp {
2021-08-26 12:15:52 +08:00
return dt . Base . Timestamp
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) SetTs ( ts Timestamp ) {
2021-08-26 12:15:52 +08:00
dt . Base . Timestamp = ts
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) OnEnqueue ( ) error {
2021-10-11 07:48:55 +08:00
dt . DeleteRequest . Base = & commonpb . MsgBase { }
2021-08-26 12:15:52 +08:00
return nil
}
2021-10-11 07:48:55 +08:00
func getPrimaryKeysFromExpr ( schema * schemapb . CollectionSchema , expr string ) ( res [ ] int64 , err error ) {
if len ( expr ) == 0 {
log . Warn ( "empty expr" )
return
}
2021-10-13 20:30:32 +08:00
plan , err := createExprPlan ( schema , expr )
2021-10-11 07:48:55 +08:00
if err != nil {
return res , fmt . Errorf ( "failed to create expr plan, expr = %s" , expr )
}
// delete request only support expr "id in [a, b]"
termExpr , ok := plan . Node . ( * planpb . PlanNode_Predicates ) . Predicates . Expr . ( * planpb . Expr_TermExpr )
if ! ok {
return res , fmt . Errorf ( "invalid plan node type" )
}
for _ , v := range termExpr . TermExpr . Values {
res = append ( res , v . GetInt64Val ( ) )
}
return res , nil
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) PreExecute ( ctx context . Context ) error {
dt . Base . MsgType = commonpb . MsgType_Delete
2021-08-26 12:15:52 +08:00
dt . Base . SourceID = Params . ProxyID
2021-10-11 07:48:55 +08:00
dt . result = & milvuspb . MutationResult {
Status : & commonpb . Status {
ErrorCode : commonpb . ErrorCode_Success ,
} ,
IDs : & schemapb . IDs {
IdField : nil ,
} ,
Timestamp : dt . BeginTs ( ) ,
}
collName := dt . req . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-10-11 07:48:55 +08:00
log . Error ( "Invalid collection name" , zap . String ( "collectionName" , collName ) )
return err
}
collID , err := globalMetaCache . GetCollectionID ( ctx , collName )
if err != nil {
log . Debug ( "Failed to get collection id" , zap . String ( "collectionName" , collName ) )
2021-08-26 12:15:52 +08:00
return err
}
2021-10-11 07:48:55 +08:00
dt . DeleteRequest . CollectionID = collID
2021-08-26 12:15:52 +08:00
2021-10-18 20:08:42 +08:00
// If partitionName is not empty, partitionID will be set.
2021-10-11 07:48:55 +08:00
if len ( dt . req . PartitionName ) > 0 {
partName := dt . req . PartitionName
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partName , true ) ; err != nil {
2021-10-11 07:48:55 +08:00
log . Error ( "Invalid partition name" , zap . String ( "partitionName" , partName ) )
2021-10-09 22:50:39 +08:00
return err
}
2021-10-11 07:48:55 +08:00
partID , err := globalMetaCache . GetPartitionID ( ctx , collName , partName )
if err != nil {
log . Debug ( "Failed to get partition id" , zap . String ( "collectionName" , collName ) , zap . String ( "partitionName" , partName ) )
return err
}
dt . DeleteRequest . PartitionID = partID
2021-10-18 20:08:42 +08:00
} else {
dt . DeleteRequest . PartitionID = common . InvalidPartitionID
2021-10-11 07:48:55 +08:00
}
schema , err := globalMetaCache . GetCollectionSchema ( ctx , dt . req . CollectionName )
if err != nil {
log . Error ( "Failed to get collection schema" , zap . String ( "collectionName" , dt . req . CollectionName ) )
return err
}
primaryKeys , err := getPrimaryKeysFromExpr ( schema , dt . req . Expr )
if err != nil {
log . Error ( "Failed to get primary keys from expr" , zap . Error ( err ) )
return err
}
log . Debug ( "get primary keys from expr" , zap . Any ( "primary keys" , dt . DeleteRequest . PrimaryKeys ) )
dt . DeleteRequest . PrimaryKeys = primaryKeys
// set result
dt . result . IDs . IdField = & schemapb . IDs_IntId {
IntId : & schemapb . LongArray {
Data : primaryKeys ,
} ,
2021-08-26 12:15:52 +08:00
}
2021-10-11 07:48:55 +08:00
dt . result . DeleteCnt = int64 ( len ( primaryKeys ) )
2021-10-14 14:48:34 +08:00
rowNum := len ( primaryKeys )
dt . Timestamps = make ( [ ] uint64 , rowNum )
for index := range dt . Timestamps {
dt . Timestamps [ index ] = dt . BeginTs ( )
}
2021-08-26 12:15:52 +08:00
return nil
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) Execute ( ctx context . Context ) ( err error ) {
2021-10-11 07:48:55 +08:00
sp , ctx := trace . StartSpanFromContextWithOperationName ( dt . ctx , "Proxy-Delete-Execute" )
defer sp . Finish ( )
var tsMsg msgstream . TsMsg = & msgstream . DeleteMsg {
DeleteRequest : * dt . DeleteRequest ,
BaseMsg : msgstream . BaseMsg {
Ctx : ctx ,
HashValues : [ ] uint32 { uint32 ( Params . ProxyID ) } ,
BeginTimestamp : dt . BeginTs ( ) ,
EndTimestamp : dt . EndTs ( ) ,
} ,
}
msgPack := msgstream . MsgPack {
BeginTs : dt . BeginTs ( ) ,
EndTs : dt . EndTs ( ) ,
Msgs : make ( [ ] msgstream . TsMsg , 1 ) ,
}
msgPack . Msgs [ 0 ] = tsMsg
2021-10-11 16:31:44 +08:00
collID := dt . DeleteRequest . CollectionID
stream , err := dt . chMgr . getDMLStream ( collID )
if err != nil {
err = dt . chMgr . createDMLMsgStream ( collID )
if err != nil {
dt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
dt . result . Status . Reason = err . Error ( )
return err
}
channels , err := dt . chMgr . getChannels ( collID )
if err == nil {
for _ , pchan := range channels {
err := dt . chTicker . addPChan ( pchan )
if err != nil {
log . Warn ( "failed to add pchan to channels time ticker" ,
zap . Error ( err ) ,
zap . String ( "pchan" , pchan ) )
}
}
}
stream , err = dt . chMgr . getDMLStream ( collID )
if err != nil {
dt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
dt . result . Status . Reason = err . Error ( )
return err
}
}
err = stream . Produce ( & msgPack )
if err != nil {
dt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
dt . result . Status . Reason = err . Error ( )
return err
}
2021-08-26 12:15:52 +08:00
return nil
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) PostExecute ( ctx context . Context ) error {
2021-08-26 12:15:52 +08:00
return nil
}
2021-09-18 11:13:51 +08:00
type CreateAliasTask struct {
Condition
* milvuspb . CreateAliasRequest
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
}
func ( c * CreateAliasTask ) TraceCtx ( ) context . Context {
return c . ctx
}
func ( c * CreateAliasTask ) ID ( ) UniqueID {
return c . Base . MsgID
}
func ( c * CreateAliasTask ) SetID ( uid UniqueID ) {
c . Base . MsgID = uid
}
func ( c * CreateAliasTask ) Name ( ) string {
return CreateAliasTaskName
}
func ( c * CreateAliasTask ) Type ( ) commonpb . MsgType {
return c . Base . MsgType
}
func ( c * CreateAliasTask ) BeginTs ( ) Timestamp {
return c . Base . Timestamp
}
func ( c * CreateAliasTask ) EndTs ( ) Timestamp {
return c . Base . Timestamp
}
func ( c * CreateAliasTask ) SetTs ( ts Timestamp ) {
c . Base . Timestamp = ts
}
func ( c * CreateAliasTask ) OnEnqueue ( ) error {
c . Base = & commonpb . MsgBase { }
return nil
}
func ( c * CreateAliasTask ) PreExecute ( ctx context . Context ) error {
c . Base . MsgType = commonpb . MsgType_CreateAlias
c . Base . SourceID = Params . ProxyID
collAlias := c . Alias
// collection alias uses the same format as collection name
if err := ValidateCollectionAlias ( collAlias ) ; err != nil {
return err
}
collName := c . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-09-18 11:13:51 +08:00
return err
}
return nil
}
func ( c * CreateAliasTask ) Execute ( ctx context . Context ) error {
var err error
c . result , err = c . rootCoord . CreateAlias ( ctx , c . CreateAliasRequest )
return err
}
func ( c * CreateAliasTask ) PostExecute ( ctx context . Context ) error {
return nil
}
type DropAliasTask struct {
Condition
* milvuspb . DropAliasRequest
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
}
func ( d * DropAliasTask ) TraceCtx ( ) context . Context {
return d . ctx
}
func ( d * DropAliasTask ) ID ( ) UniqueID {
return d . Base . MsgID
}
func ( d * DropAliasTask ) SetID ( uid UniqueID ) {
d . Base . MsgID = uid
}
func ( d * DropAliasTask ) Name ( ) string {
return DropAliasTaskName
}
func ( d * DropAliasTask ) Type ( ) commonpb . MsgType {
return d . Base . MsgType
}
func ( d * DropAliasTask ) BeginTs ( ) Timestamp {
return d . Base . Timestamp
}
func ( d * DropAliasTask ) EndTs ( ) Timestamp {
return d . Base . Timestamp
}
func ( d * DropAliasTask ) SetTs ( ts Timestamp ) {
d . Base . Timestamp = ts
}
func ( d * DropAliasTask ) OnEnqueue ( ) error {
d . Base = & commonpb . MsgBase { }
return nil
}
func ( d * DropAliasTask ) PreExecute ( ctx context . Context ) error {
d . Base . MsgType = commonpb . MsgType_DropAlias
d . Base . SourceID = Params . ProxyID
collAlias := d . Alias
if err := ValidateCollectionAlias ( collAlias ) ; err != nil {
return err
}
return nil
}
func ( d * DropAliasTask ) Execute ( ctx context . Context ) error {
var err error
d . result , err = d . rootCoord . DropAlias ( ctx , d . DropAliasRequest )
return err
}
func ( d * DropAliasTask ) PostExecute ( ctx context . Context ) error {
return nil
}
type AlterAliasTask struct {
Condition
* milvuspb . AlterAliasRequest
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
}
func ( a * AlterAliasTask ) TraceCtx ( ) context . Context {
return a . ctx
}
func ( a * AlterAliasTask ) ID ( ) UniqueID {
return a . Base . MsgID
}
func ( a * AlterAliasTask ) SetID ( uid UniqueID ) {
a . Base . MsgID = uid
}
func ( a * AlterAliasTask ) Name ( ) string {
return AlterAliasTaskName
}
func ( a * AlterAliasTask ) Type ( ) commonpb . MsgType {
return a . Base . MsgType
}
func ( a * AlterAliasTask ) BeginTs ( ) Timestamp {
return a . Base . Timestamp
}
func ( a * AlterAliasTask ) EndTs ( ) Timestamp {
return a . Base . Timestamp
}
func ( a * AlterAliasTask ) SetTs ( ts Timestamp ) {
a . Base . Timestamp = ts
}
func ( a * AlterAliasTask ) OnEnqueue ( ) error {
a . Base = & commonpb . MsgBase { }
return nil
}
func ( a * AlterAliasTask ) PreExecute ( ctx context . Context ) error {
a . Base . MsgType = commonpb . MsgType_AlterAlias
a . Base . SourceID = Params . ProxyID
collAlias := a . Alias
// collection alias uses the same format as collection name
if err := ValidateCollectionAlias ( collAlias ) ; err != nil {
return err
}
collName := a . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collName ) ; err != nil {
2021-09-18 11:13:51 +08:00
return err
}
return nil
}
func ( a * AlterAliasTask ) Execute ( ctx context . Context ) error {
var err error
a . result , err = a . rootCoord . AlterAlias ( ctx , a . AlterAliasRequest )
return err
}
func ( a * AlterAliasTask ) PostExecute ( ctx context . Context ) error {
return nil
}