2021-11-10 23:55:48 +08:00
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
2021-04-19 10:09:43 +08:00
// with the License. You may obtain a copy of the License at
//
2021-11-10 23:55:48 +08:00
// http://www.apache.org/licenses/LICENSE-2.0
2021-04-19 10:09:43 +08:00
//
2021-11-10 23:55:48 +08:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2021-04-19 10:09:43 +08:00
2021-06-22 14:40:07 +08:00
package proxy
2020-11-03 14:53:36 +08:00
import (
2021-02-04 19:34:35 +08:00
"context"
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"
"strconv"
2021-07-14 18:51:54 +08:00
"strings"
2021-03-26 11:19:02 +08:00
2022-04-29 13:35:49 +08:00
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
2021-12-08 14:15:03 +08:00
"github.com/golang/protobuf/proto"
2021-03-08 19:39:36 +08:00
"go.uber.org/zap"
2021-03-05 10:15:27 +08:00
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"
2022-03-02 16:23:55 +08:00
"github.com/milvus-io/milvus/internal/metrics"
2022-03-03 21:57:56 +08:00
"github.com/milvus-io/milvus/internal/mq/msgstream"
2022-04-01 18:59:29 +08:00
"github.com/milvus-io/milvus/internal/types"
2021-04-22 14:45:57 +08:00
"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"
2022-04-01 18:59:29 +08:00
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
2022-01-04 14:13:44 +08:00
// minFloat32 minimum float.
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
2022-06-02 15:34:04 +08:00
getChannels ( ) ( [ ] pChan , error )
2021-06-15 10:19:38 +08:00
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
2022-03-25 14:27:25 +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-12-22 20:29:29 +08:00
// TraceCtx returns insertTask context
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
}
2022-06-02 15:34:04 +08:00
return it . chMgr . getChannels ( collID )
2021-05-31 11:40:31 +08:00
}
2021-09-11 11:36:22 +08:00
func ( it * insertTask ) OnEnqueue ( ) error {
2021-02-23 09:58:06 +08:00
return nil
2020-11-05 18:01:33 +08:00
}
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 ++
}
}
2022-03-25 14:27:25 +08:00
if len ( it . FieldsData ) < neededFieldsNum {
return errFieldsLessThanNeeded ( len ( it . FieldsData ) , neededFieldsNum )
2021-07-13 16:33:55 +08:00
}
return nil
}
2022-03-25 14:27:25 +08:00
func ( it * insertTask ) checkPrimaryFieldData ( ) error {
rowNums := uint32 ( it . NRows ( ) )
2021-06-21 11:42:18 +08:00
// TODO(dragondriver): in fact, NumRows is not trustable, we should check all input fields
2022-03-25 14:27:25 +08:00
if it . NRows ( ) <= 0 {
return errNumRowsLessThanOrEqualToZero ( rowNums )
2021-06-21 11:42:18 +08:00
}
2021-07-13 16:33:55 +08:00
if err := it . checkLengthOfFieldsData ( ) ; err != nil {
return err
}
2022-03-25 14:27:25 +08:00
primaryFieldSchema , err := typeutil . GetPrimaryFieldSchema ( it . schema )
if err != nil {
log . Error ( "get primary field schema failed" , zap . String ( "collection name" , it . CollectionName ) , zap . Any ( "schema" , it . schema ) , zap . Error ( err ) )
return err
2021-06-21 11:42:18 +08:00
}
2022-03-25 14:27:25 +08:00
// get primaryFieldData whether autoID is true or not
var primaryFieldData * schemapb . FieldData
if ! primaryFieldSchema . AutoID {
2022-04-02 17:43:29 +08:00
primaryFieldData , err = typeutil . GetPrimaryFieldData ( it . GetFieldsData ( ) , primaryFieldSchema )
2022-03-25 14:27:25 +08:00
if err != nil {
log . Error ( "get primary field data failed" , zap . String ( "collection name" , it . CollectionName ) , zap . Error ( err ) )
return err
2021-06-21 11:42:18 +08:00
}
} else {
2022-03-25 14:27:25 +08:00
// if autoID == true, currently only support autoID for int64 PrimaryField
primaryFieldData , err = autoGenPrimaryFieldData ( primaryFieldSchema , it . RowIDs )
if err != nil {
log . Error ( "generate primary field data failed when autoID == true" , zap . String ( "collection name" , it . CollectionName ) , zap . Error ( err ) )
return err
}
// if autoID == true, set the primary field data
it . FieldsData = append ( it . FieldsData , primaryFieldData )
2021-06-21 11:42:18 +08:00
}
2022-03-25 14:27:25 +08:00
// parse primaryFieldData to result.IDs, and as returned primary keys
it . result . IDs , err = parsePrimaryFieldData2IDs ( primaryFieldData )
if err != nil {
log . Error ( "parse primary field data to IDs failed" , zap . String ( "collection name" , it . CollectionName ) , zap . Error ( err ) )
return err
2021-06-21 11:42:18 +08:00
}
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-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 ,
} ,
2021-11-05 09:14:02 +08:00
Timestamp : it . EndTs ( ) ,
2021-06-21 11:42:18 +08:00
}
2022-03-25 14:27:25 +08:00
collectionName := it . CollectionName
2021-10-23 10:53:12 +08:00
if err := validateCollectionName ( collectionName ) ; err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "valid collection name failed" , zap . String ( "collection name" , collectionName ) , zap . Error ( err ) )
2020-11-26 16:01:31 +08:00
return err
}
2021-06-21 11:42:18 +08:00
2022-03-25 14:27:25 +08:00
partitionTag := it . PartitionName
2021-10-23 18:23:44 +08:00
if err := validatePartitionTag ( partitionTag , true ) ; err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "valid partition name failed" , zap . String ( "partition name" , partitionTag ) , zap . Error ( err ) )
2020-11-26 16:01:31 +08:00
return err
}
2021-06-21 11:42:18 +08:00
collSchema , err := globalMetaCache . GetCollectionSchema ( ctx , collectionName )
if err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "get collection schema from global meta cache failed" , zap . String ( "collection name" , collectionName ) , zap . Error ( err ) )
2021-06-21 11:42:18 +08:00
return err
}
it . schema = collSchema
2022-03-25 14:27:25 +08:00
rowNums := uint32 ( it . NRows ( ) )
// set insertTask.rowIDs
var rowIDBegin UniqueID
var rowIDEnd UniqueID
tr := timerecord . NewTimeRecorder ( "applyPK" )
rowIDBegin , rowIDEnd , _ = it . rowIDAllocator . Alloc ( rowNums )
2022-04-24 22:03:44 +08:00
metrics . ProxyApplyPrimaryKeyLatency . WithLabelValues ( strconv . FormatInt ( Params . ProxyCfg . GetNodeID ( ) , 10 ) ) . Observe ( float64 ( tr . ElapseSpan ( ) ) )
2022-03-25 14:27:25 +08:00
it . RowIDs = make ( [ ] UniqueID , rowNums )
for i := rowIDBegin ; i < rowIDEnd ; i ++ {
offset := i - rowIDBegin
it . RowIDs [ offset ] = i
}
// set insertTask.timeStamps
rowNum := it . NRows ( )
it . Timestamps = make ( [ ] uint64 , rowNum )
for index := range it . Timestamps {
it . Timestamps [ index ] = it . BeginTimestamp
}
// set result.SuccIndex
sliceIndex := make ( [ ] uint32 , rowNums )
for i := uint32 ( 0 ) ; i < rowNums ; i ++ {
sliceIndex [ i ] = i
2021-07-13 16:33:55 +08:00
}
2022-03-25 14:27:25 +08:00
it . result . SuccIndex = sliceIndex
2021-07-13 16:33:55 +08:00
2022-03-25 14:27:25 +08:00
// check primaryFieldData whether autoID is true or not
// set rowIDs as primary data if autoID == true
err = it . checkPrimaryFieldData ( )
2021-06-21 11:42:18 +08:00
if err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "check primary field data and hash primary key failed" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . String ( "collection name" , collectionName ) , zap . Error ( err ) )
2021-06-21 11:42:18 +08:00
return err
}
2022-03-25 14:27:25 +08:00
// set field ID to insert field data
err = fillFieldIDBySchema ( it . GetFieldsData ( ) , collSchema )
2021-06-03 15:03:34 +08:00
if err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "set fieldID to fieldData failed" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . String ( "collection name" , collectionName ) , zap . Error ( err ) )
2021-06-03 15:03:34 +08:00
return err
}
2022-03-25 14:27:25 +08:00
// check that all field's number rows are equal
if err = it . CheckAligned ( ) ; err != nil {
log . Error ( "field data is not aligned" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . String ( "collection name" , collectionName ) , zap . Error ( err ) )
return err
2021-06-03 15:03:34 +08:00
}
2022-03-25 14:27:25 +08:00
log . Debug ( "Proxy Insert PreExecute done" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . String ( "collection name" , collectionName ) )
2020-11-05 18:01:33 +08:00
return nil
}
2022-03-25 14:27:25 +08:00
func ( it * insertTask ) assignSegmentID ( channelNames [ ] string ) ( * msgstream . MsgPack , error ) {
threshold := Params . PulsarCfg . MaxMessageSize
2021-05-25 19:53:15 +08:00
2022-03-25 14:27:25 +08:00
result := & msgstream . MsgPack {
BeginTs : it . BeginTs ( ) ,
EndTs : it . EndTs ( ) ,
}
2021-05-25 19:53:15 +08:00
2022-03-25 14:27:25 +08:00
// generate hash value for every primary key
if len ( it . HashValues ) != 0 {
log . Warn ( "the hashvalues passed through client is not supported now, and will be overwritten" )
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
it . HashValues = typeutil . HashPK2Channels ( it . result . IDs , channelNames )
// groupedHashKeys represents the dmChannel index
channel2RowOffsets := make ( map [ string ] [ ] int ) // channelName to count
channelMaxTSMap := make ( map [ string ] Timestamp ) // channelName to max Timestamp
2021-05-25 19:53:15 +08:00
2022-03-25 14:27:25 +08:00
// assert len(it.hashValues) < maxInt
for offset , channelID := range it . HashValues {
2021-05-25 19:53:15 +08:00
channelName := channelNames [ channelID ]
2022-03-25 14:27:25 +08:00
if _ , ok := channel2RowOffsets [ channelName ] ; ! ok {
channel2RowOffsets [ channelName ] = [ ] int { }
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
channel2RowOffsets [ channelName ] = append ( channel2RowOffsets [ channelName ] , offset )
if _ , ok := channelMaxTSMap [ channelName ] ; ! ok {
channelMaxTSMap [ channelName ] = typeutil . ZeroTimestamp
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
ts := it . Timestamps [ offset ]
if channelMaxTSMap [ channelName ] < ts {
channelMaxTSMap [ channelName ] = ts
2021-05-25 19:53:15 +08:00
}
}
2022-03-25 14:27:25 +08:00
// create empty insert message
createInsertMsg := func ( segmentID UniqueID , channelName string ) * msgstream . InsertMsg {
insertReq := internalpb . InsertRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_Insert ,
MsgID : it . Base . MsgID ,
Timestamp : it . BeginTimestamp , // entity's timestamp was set to equal it.BeginTimestamp in preExecute()
SourceID : it . Base . SourceID ,
} ,
CollectionID : it . CollectionID ,
PartitionID : it . PartitionID ,
CollectionName : it . CollectionName ,
PartitionName : it . PartitionName ,
SegmentID : segmentID ,
ShardName : channelName ,
Version : internalpb . InsertDataVersion_ColumnBased ,
}
insertReq . FieldsData = make ( [ ] * schemapb . FieldData , len ( it . GetFieldsData ( ) ) )
insertMsg := & msgstream . InsertMsg {
BaseMsg : msgstream . BaseMsg {
Ctx : it . TraceCtx ( ) ,
} ,
InsertRequest : insertReq ,
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
return insertMsg
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
// repack the row data corresponding to the offset to insertMsg
getInsertMsgsBySegmentID := func ( segmentID UniqueID , rowOffsets [ ] int , channelName string , mexMessageSize int ) ( [ ] msgstream . TsMsg , error ) {
repackedMsgs := make ( [ ] msgstream . TsMsg , 0 )
requestSize := 0
insertMsg := createInsertMsg ( segmentID , channelName )
for _ , offset := range rowOffsets {
curRowMessageSize , err := typeutil . EstimateEntitySize ( it . InsertRequest . GetFieldsData ( ) , offset )
if err != nil {
return nil , err
2021-07-24 20:49:20 +08:00
}
2022-03-04 15:09:56 +08:00
2022-03-25 14:27:25 +08:00
// if insertMsg's size is greater than the threshold, split into multiple insertMsgs
if requestSize + curRowMessageSize >= mexMessageSize {
repackedMsgs = append ( repackedMsgs , insertMsg )
insertMsg = createInsertMsg ( segmentID , channelName )
requestSize = 0
2021-05-25 19:53:15 +08:00
}
2022-03-04 15:09:56 +08:00
2022-03-25 14:27:25 +08:00
typeutil . AppendFieldData ( insertMsg . FieldsData , it . GetFieldsData ( ) , int64 ( offset ) )
insertMsg . HashValues = append ( insertMsg . HashValues , it . HashValues [ offset ] )
insertMsg . Timestamps = append ( insertMsg . Timestamps , it . Timestamps [ offset ] )
insertMsg . RowIDs = append ( insertMsg . RowIDs , it . RowIDs [ offset ] )
insertMsg . NumRows ++
requestSize += curRowMessageSize
}
repackedMsgs = append ( repackedMsgs , insertMsg )
2022-03-04 15:09:56 +08:00
2022-03-25 14:27:25 +08:00
return repackedMsgs , nil
}
2022-03-04 15:09:56 +08:00
2022-03-25 14:27:25 +08:00
// get allocated segmentID info for every dmChannel and repack insertMsgs for every segmentID
for channelName , rowOffsets := range channel2RowOffsets {
assignedSegmentInfos , err := it . segIDAssigner . GetSegmentID ( it . CollectionID , it . PartitionID , channelName , uint32 ( len ( rowOffsets ) ) , channelMaxTSMap [ channelName ] )
if err != nil {
log . Error ( "allocate segmentID for insert data failed" ,
zap . Int64 ( "collectionID" , it . CollectionID ) ,
zap . String ( "channel name" , channelName ) ,
zap . Int ( "allocate count" , len ( rowOffsets ) ) ,
zap . Error ( err ) )
return nil , err
}
2021-05-25 19:53:15 +08:00
2022-03-25 14:27:25 +08:00
startPos := 0
for segmentID , count := range assignedSegmentInfos {
subRowOffsets := rowOffsets [ startPos : startPos + int ( count ) ]
insertMsgs , err := getInsertMsgsBySegmentID ( segmentID , subRowOffsets , channelName , threshold )
if err != nil {
log . Error ( "repack insert data to insert msgs failed" ,
zap . Int64 ( "collectionID" , it . CollectionID ) ,
zap . Error ( err ) )
return nil , err
2021-05-25 19:53:15 +08:00
}
2022-03-25 14:27:25 +08:00
result . Msgs = append ( result . Msgs , insertMsgs ... )
startPos += int ( count )
2021-05-25 19:53:15 +08:00
}
}
2022-03-25 14:27:25 +08:00
return result , nil
2021-05-25 19:53:15 +08:00
}
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 ( )
2021-12-16 22:27:42 +08:00
tr := timerecord . NewTimeRecorder ( fmt . Sprintf ( "proxy execute insert %d" , it . ID ( ) ) )
2022-04-27 23:03:47 +08:00
defer tr . Elapse ( "insert execute done" )
2021-12-16 22:27:42 +08:00
2022-03-25 14:27:25 +08:00
collectionName := it . 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 {
2022-01-10 19:03:35 +08:00
partitionID , err = globalMetaCache . GetPartitionID ( ctx , collectionName , Params . CommonCfg . 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
2021-12-16 22:27:42 +08:00
tr . Record ( "get collection id & partition id from cache" )
2020-11-20 17:53:31 +08:00
2022-06-09 17:34:09 +08:00
stream , err := it . chMgr . getOrCreateDmlStream ( collID )
2021-01-30 15:30:38 +08:00
if err != nil {
2022-06-02 15:34:04 +08:00
return err
2021-01-30 15:30:38 +08:00
}
2021-12-16 22:27:42 +08:00
tr . Record ( "get used message stream" )
2021-01-30 15:30:38 +08:00
2022-03-25 14:27:25 +08:00
channelNames , err := it . chMgr . getVChannels ( collID )
if err != nil {
log . Error ( "get vChannels failed" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . Int64 ( "collectionID" , collID ) , zap . Error ( err ) )
it . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
it . result . Status . Reason = err . Error ( )
return err
}
2022-06-02 15:34:04 +08:00
log . Info ( "send insert request to virtual channels" ,
zap . String ( "collection" , it . GetCollectionName ( ) ) ,
zap . String ( "partition" , it . GetPartitionName ( ) ) ,
zap . Int64 ( "collection_id" , collID ) ,
zap . Int64 ( "partition_id" , partitionID ) ,
zap . Strings ( "virtual_channels" , channelNames ) ,
zap . Int64 ( "task_id" , it . ID ( ) ) )
2022-03-25 14:27:25 +08:00
// assign segmentID for insert data and repack data by segmentID
msgPack , err := it . assignSegmentID ( channelNames )
2021-05-25 19:53:15 +08:00
if err != nil {
2022-03-25 14:27:25 +08:00
log . Error ( "assign segmentID and repack insert data failed" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . Int64 ( "collectionID" , collID ) , zap . Error ( err ) )
it . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
it . result . Status . Reason = err . Error ( )
2021-05-25 19:53:15 +08:00
return err
}
2022-03-25 14:27:25 +08:00
log . Debug ( "assign segmentID for insert data success" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . Int64 ( "collectionID" , collID ) , zap . String ( "collection name" , it . CollectionName ) )
2021-12-16 22:27:42 +08:00
tr . Record ( "assign segment id" )
2022-03-25 14:27:25 +08:00
err = stream . Produce ( msgPack )
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
}
2022-04-27 23:03:47 +08:00
sendMsgDur := tr . Record ( "send insert request to dml channel" )
metrics . ProxySendMutationReqLatency . WithLabelValues ( strconv . FormatInt ( Params . ProxyCfg . GetNodeID ( ) , 10 ) , metrics . InsertLabel ) . Observe ( float64 ( sendMsgDur . Milliseconds ( ) ) )
2021-01-30 15:30:38 +08:00
2022-03-25 14:27:25 +08:00
log . Debug ( "Proxy Insert Execute done" , zap . Int64 ( "msgID" , it . Base . MsgID ) , zap . String ( "collection name" , collectionName ) )
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
2022-04-24 22:03:44 +08:00
cct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
2022-04-24 22:03:44 +08:00
cct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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-01-22 09:36:18 +08:00
2021-12-23 18:39:11 +08:00
if cct . ShardsNum > Params . ProxyCfg . MaxShardNum {
return fmt . Errorf ( "maximum shards's number should be limited to %d" , Params . ProxyCfg . MaxShardNum )
2021-09-08 15:00:00 +08:00
}
2021-12-23 18:39:11 +08:00
if int64 ( len ( cct . schema . Fields ) ) > Params . ProxyCfg . MaxFieldNum {
return fmt . Errorf ( "maximum field's number should be limited to %d" , Params . ProxyCfg . 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
}
2022-03-03 16:57:56 +08:00
// validate whether field names duplicates
2021-10-26 10:38:41 +08:00
if err := validateDuplicatedFieldName ( cct . schema . Fields ) ; err != nil {
2020-11-30 19:38:23 +08:00
return err
}
2022-03-03 16:57:56 +08:00
// validate primary key definition
2021-10-25 23:42:29 +08:00
if err := validatePrimaryKey ( cct . schema ) ; err != nil {
2020-11-30 19:38:23 +08:00
return err
}
2022-03-03 16:57:56 +08:00
// validate auto id definition
2021-06-21 11:42:18 +08:00
if err := ValidateFieldAutoID ( cct . schema ) ; err != nil {
return err
}
2022-03-03 16:57:56 +08:00
// validate field type definition
if err := validateFieldType ( cct . schema ) ; err != nil {
return err
}
2020-11-26 16:01:31 +08:00
for _ , field := range cct . schema . Fields {
2022-03-03 16:57:56 +08:00
// validate field name
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
}
2022-03-03 16:57:56 +08:00
// validate vector field type parameters
2021-03-12 14:22:09 +08:00
if field . DataType == schemapb . DataType_FloatVector || field . DataType == schemapb . DataType_BinaryVector {
2022-04-29 13:35:49 +08:00
err = validateDimension ( field )
if err != nil {
return err
2020-11-26 16:01:31 +08:00
}
2022-04-29 13:35:49 +08:00
}
// valid max length per row parameters
2022-06-07 15:58:06 +08:00
// if max_length not specified, return error
2022-04-29 13:35:49 +08:00
if field . DataType == schemapb . DataType_VarChar {
err = validateMaxLengthPerRow ( cct . schema . Name , field )
if err != nil {
return err
2020-11-26 16:01:31 +08:00
}
}
}
2021-12-06 10:03:34 +08:00
if err := validateMultipleVectorFields ( cct . schema ) ; err != nil {
return err
}
2022-04-29 13:35:49 +08:00
cct . CreateCollectionRequest . Schema , err = proto . Marshal ( cct . schema )
if 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
2022-04-24 22:03:44 +08:00
dct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
_ = dct . chMgr . removeDMLStream ( collID )
2022-05-19 10:13:56 +08:00
globalMetaCache . RemoveCollection ( ctx , dct . CollectionName )
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-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
2022-04-24 22:03:44 +08:00
hct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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-12-23 21:46:10 +08:00
if err != nil {
return err
}
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 )
}
2021-12-23 21:46:10 +08:00
return nil
2020-11-09 17:25:53 +08:00
}
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
2022-04-24 22:03:44 +08:00
dct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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-12-21 19:49:02 +08:00
dct . result . ConsistencyLevel = result . ConsistencyLevel
2022-06-13 19:22:10 +08:00
dct . result . Aliases = result . Aliases
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
g . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-02 19:54:31 +08:00
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
}
2022-03-02 16:23:55 +08:00
g . collectionID = collID
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
g . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-05-10 17:39:08 +08:00
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
}
2022-03-02 16:23:55 +08:00
g . collectionID = collID
2021-05-10 17:39:08 +08:00
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
2022-04-24 22:03:44 +08:00
sct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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 {
2022-05-11 09:47:53 +08:00
// update collectionID to collection name, and return new error info to sdk
newErrorReason := resp . Status . Reason
for _ , collectionID := range collectionIDs {
newErrorReason = ReplaceID2Name ( newErrorReason , collectionID , IDs2Names [ collectionID ] )
}
return errors . New ( newErrorReason )
2021-06-03 19:09:33 +08:00
}
sct . result = & milvuspb . ShowCollectionsResponse {
2022-06-09 18:20:07 +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 ) ) ,
InMemoryPercentages : make ( [ ] int64 , 0 , len ( resp . CollectionIDs ) ) ,
QueryServiceAvailable : make ( [ ] bool , 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 ] )
2022-06-09 18:20:07 +08:00
sct . result . QueryServiceAvailable = append ( sct . result . QueryServiceAvailable , resp . QueryServiceAvailable [ 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
2022-04-24 22:03:44 +08:00
cpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
2022-04-24 22:03:44 +08:00
dpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
2022-04-24 22:03:44 +08:00
hpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
2022-04-24 22:03:44 +08:00
spt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
}
2022-04-29 18:01:49 +08:00
func parseIndexParams ( m [ ] * commonpb . KeyValuePair ) ( map [ string ] string , error ) {
2021-06-22 15:28:04 +08:00
indexParams := make ( map [ string ] string )
2022-04-29 18:01:49 +08:00
for _ , kv := range m {
2021-06-22 15:28:04 +08:00
if kv . Key == "params" { // TODO(dragondriver): change `params` to const variable
params , err := funcutil . ParseIndexParamsMap ( kv . Value )
if err != nil {
2022-04-29 18:01:49 +08:00
return nil , err
2021-06-22 15:28:04 +08:00
}
for k , v := range params {
indexParams [ k ] = v
}
} else {
indexParams [ kv . Key ] = kv . Value
}
}
2022-04-29 18:01:49 +08:00
_ , exist := indexParams [ "index_type" ] // TODO(dragondriver): change `index_type` to const variable
2021-06-22 15:28:04 +08:00
if ! exist {
2022-04-29 18:01:49 +08:00
indexParams [ "index_type" ] = indexparamcheck . IndexFaissIvfPQ // IVF_PQ is the default index type
2021-06-22 15:28:04 +08:00
}
2022-04-29 18:01:49 +08:00
return indexParams , nil
}
2021-06-22 15:28:04 +08:00
2022-04-29 18:01:49 +08:00
func ( cit * createIndexTask ) getIndexedField ( ctx context . Context ) ( * schemapb . FieldSchema , error ) {
schema , err := globalMetaCache . GetCollectionSchema ( ctx , cit . GetCollectionName ( ) )
if err != nil {
log . Error ( "failed to get collection schema" , zap . Error ( err ) )
return nil , fmt . Errorf ( "failed to get collection schema: %s" , err )
}
schemaHelper , err := typeutil . CreateSchemaHelper ( schema )
if err != nil {
log . Error ( "failed to parse collection schema" , zap . Error ( err ) )
return nil , fmt . Errorf ( "failed to parse collection schema: %s" , err )
}
field , err := schemaHelper . GetFieldFromName ( cit . GetFieldName ( ) )
if err != nil {
log . Error ( "create index on non-exist field" , zap . Error ( err ) )
return nil , fmt . Errorf ( "cannot create index on non-exist field: %s" , cit . GetFieldName ( ) )
}
return field , nil
}
2022-04-29 13:35:49 +08:00
2022-04-29 18:01:49 +08:00
func fillDimension ( field * schemapb . FieldSchema , indexParams map [ string ] string ) error {
2022-03-21 14:23:24 +08:00
vecDataTypes := [ ] schemapb . DataType {
schemapb . DataType_FloatVector ,
schemapb . DataType_BinaryVector ,
}
2022-04-29 18:01:49 +08:00
if ! funcutil . SliceContain ( vecDataTypes , field . GetDataType ( ) ) {
return nil
}
params := make ( [ ] * commonpb . KeyValuePair , 0 , len ( field . GetTypeParams ( ) ) + len ( field . GetIndexParams ( ) ) )
params = append ( params , field . GetTypeParams ( ) ... )
params = append ( params , field . GetIndexParams ( ) ... )
dimensionInSchema , err := funcutil . GetAttrByKeyFromRepeatedKV ( "dim" , params )
if err != nil {
return fmt . Errorf ( "dimension not found in schema" )
}
dimension , exist := indexParams [ "dim" ]
if exist {
if dimensionInSchema != dimension {
return fmt . Errorf ( "dimension mismatch, dimension in schema: %s, dimension: %s" , dimensionInSchema , dimension )
2022-03-21 14:23:24 +08:00
}
2022-04-29 18:01:49 +08:00
} else {
indexParams [ "dim" ] = dimensionInSchema
}
return nil
}
func checkTrain ( field * schemapb . FieldSchema , indexParams map [ string ] string ) error {
indexType := indexParams [ "index_type" ]
// skip params check of non-vector field.
vecDataTypes := [ ] schemapb . DataType {
schemapb . DataType_FloatVector ,
schemapb . DataType_BinaryVector ,
}
if ! funcutil . SliceContain ( vecDataTypes , field . GetDataType ( ) ) {
return indexparamcheck . CheckIndexValid ( field . GetDataType ( ) , indexType , indexParams )
2022-03-21 14:23:24 +08:00
}
2021-06-22 15:28:04 +08:00
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 )
}
2022-04-29 18:01:49 +08:00
if err := fillDimension ( field , indexParams ) ; err != nil {
return err
}
2021-06-22 15:28:04 +08:00
ok := adapter . CheckTrain ( indexParams )
if ! ok {
log . Warn ( "Create index with invalid params" , zap . Any ( "index_params" , indexParams ) )
2022-04-29 18:01:49 +08:00
return fmt . Errorf ( "invalid index params: %v" , indexParams )
2021-06-22 15:28:04 +08:00
}
2020-12-22 15:39:10 +08:00
return nil
}
2022-04-29 18:01:49 +08:00
func ( cit * createIndexTask ) PreExecute ( ctx context . Context ) error {
cit . Base . MsgType = commonpb . MsgType_CreateIndex
cit . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
collName := cit . CollectionName
collID , err := globalMetaCache . GetCollectionID ( ctx , collName )
if err != nil {
return err
}
cit . collectionID = collID
field , err := cit . getIndexedField ( ctx )
if err != nil {
return err
}
// check index param, not accurate, only some static rules
indexParams , err := parseIndexParams ( cit . GetExtraParams ( ) )
if err != nil {
log . Error ( "failed to parse index params" , zap . Error ( err ) )
return fmt . Errorf ( "failed to parse index params: %s" , err )
}
return checkTrain ( field , indexParams )
}
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
dit . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
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
}
2022-03-02 16:23:55 +08:00
collID , _ := globalMetaCache . GetCollectionID ( ctx , dit . CollectionName )
dit . collectionID = collID
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
dit . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-20 18:30:37 +08:00
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 == "" {
2022-01-10 19:03:35 +08:00
dit . IndexName = Params . CommonCfg . DefaultIndexName
2021-06-30 17:56:12 +08:00
}
2022-03-02 16:23:55 +08:00
collID , _ := globalMetaCache . GetCollectionID ( ctx , dit . CollectionName )
dit . collectionID = collID
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
gibpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-04-28 11:15:28 +08:00
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
}
2022-03-02 16:23:55 +08:00
gibpt . collectionID = collectionID
2021-04-28 11:15:28 +08:00
showPartitionRequest := & milvuspb . ShowPartitionsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_ShowPartitions ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-04-28 11:15:28 +08:00
} ,
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 == "" {
2022-01-10 19:03:35 +08:00
gibpt . IndexName = Params . CommonCfg . DefaultIndexName
2021-04-28 11:15:28 +08:00
}
2022-03-28 16:41:28 +08:00
describeIndexReq := & milvuspb . DescribeIndexRequest {
2021-04-28 11:15:28 +08:00
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_DescribeIndex ,
MsgID : gibpt . Base . MsgID ,
Timestamp : gibpt . Base . Timestamp ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-04-28 11:15:28 +08:00
} ,
DbName : gibpt . DbName ,
CollectionName : gibpt . CollectionName ,
// IndexName: gibpt.IndexName,
}
2022-03-28 16:41:28 +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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-04-28 11:15:28 +08:00
} ,
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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-04-28 11:15:28 +08:00
} ,
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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-04-28 11:15:28 +08:00
} ,
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
gist . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-23 09:58:06 +08:00
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
}
2022-04-29 13:35:49 +08:00
func ( gist * getIndexStateTask ) getPartitions ( ctx context . Context , collectionName string , collectionID UniqueID ) ( * milvuspb . ShowPartitionsResponse , error ) {
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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-02-04 14:37:12 +08:00
} ,
2021-02-23 09:58:06 +08:00
DbName : gist . DbName ,
2021-02-04 14:37:12 +08:00
CollectionName : collectionName ,
CollectionID : collectionID ,
}
2022-04-29 13:35:49 +08:00
ret , err := gist . rootCoord . ShowPartitions ( ctx , showPartitionRequest )
2021-02-04 14:37:12 +08:00
if err != nil {
2022-04-29 13:35:49 +08:00
return nil , err
2021-02-04 14:37:12 +08:00
}
2022-04-29 13:35:49 +08:00
if ret . GetStatus ( ) . GetErrorCode ( ) != commonpb . ErrorCode_Success {
return nil , errors . New ( ret . GetStatus ( ) . GetReason ( ) )
2021-02-08 14:20:29 +08:00
}
2022-04-29 13:35:49 +08:00
return ret , nil
}
2021-02-08 14:20:29 +08:00
2022-04-29 13:35:49 +08:00
func ( gist * getIndexStateTask ) describeIndex ( ctx context . Context ) ( * milvuspb . DescribeIndexResponse , error ) {
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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-02-08 14:20:29 +08:00
} ,
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
}
2022-04-29 13:35:49 +08:00
ret , err := gist . rootCoord . DescribeIndex ( ctx , & describeIndexReq )
if err != nil {
return nil , err
2021-02-08 14:20:29 +08:00
}
2022-04-29 13:35:49 +08:00
if ret . GetStatus ( ) . GetErrorCode ( ) != commonpb . ErrorCode_Success {
return nil , errors . New ( ret . GetStatus ( ) . GetReason ( ) )
2021-02-08 14:20:29 +08:00
}
2022-04-29 13:35:49 +08:00
return ret , nil
}
2021-02-08 14:20:29 +08:00
2022-04-29 13:35:49 +08:00
func ( gist * getIndexStateTask ) getSegmentIDs ( ctx context . Context , collectionID UniqueID , partitions * milvuspb . ShowPartitionsResponse ) ( [ ] UniqueID , error ) {
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 ,
2022-04-24 22:03:44 +08:00
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
2021-02-04 14:37:12 +08:00
} ,
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 {
2022-04-29 13:35:49 +08:00
return nil , err
2021-02-04 14:37:12 +08:00
}
2021-03-10 22:06:22 +08:00
if segments . Status . ErrorCode != commonpb . ErrorCode_Success {
2022-04-29 13:35:49 +08:00
return nil , 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 ... )
}
2022-04-29 13:35:49 +08:00
return allSegmentIDs , nil
}
2021-02-19 09:52:06 +08:00
2022-04-29 13:35:49 +08:00
func ( gist * getIndexStateTask ) getIndexBuildIDs ( ctx context . Context , collectionID UniqueID , allSegmentIDs [ ] UniqueID , indexID UniqueID ) ( [ ] UniqueID , error ) {
indexBuildIDs := make ( [ ] UniqueID , 0 )
segmentsDesc , err := gist . rootCoord . DescribeSegments ( ctx , & rootcoordpb . DescribeSegmentsRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_DescribeSegments ,
MsgID : gist . Base . MsgID ,
Timestamp : gist . Base . Timestamp ,
SourceID : Params . ProxyCfg . GetNodeID ( ) ,
} ,
CollectionID : collectionID ,
SegmentIDs : allSegmentIDs ,
} )
if err != nil {
return nil , err
2021-02-19 09:52:06 +08:00
}
2021-02-04 14:37:12 +08:00
2022-04-29 13:35:49 +08:00
if segmentsDesc . GetStatus ( ) . GetErrorCode ( ) != commonpb . ErrorCode_Success {
return nil , errors . New ( segmentsDesc . GetStatus ( ) . GetReason ( ) )
}
for _ , segmentDesc := range segmentsDesc . GetSegmentInfos ( ) {
for _ , segmentIndexInfo := range segmentDesc . GetIndexInfos ( ) {
if segmentIndexInfo . IndexID == indexID && segmentIndexInfo . EnableIndex {
indexBuildIDs = append ( indexBuildIDs , segmentIndexInfo . GetBuildID ( ) )
2021-03-08 15:46:51 +08:00
}
2021-02-19 09:52:06 +08:00
}
}
2022-04-29 13:35:49 +08:00
return indexBuildIDs , nil
}
func ( gist * getIndexStateTask ) Execute ( ctx context . Context ) error {
collectionName := gist . CollectionName
collectionID , err := globalMetaCache . GetCollectionID ( ctx , collectionName )
if err != nil { // err is not nil if collection not exists
return err
}
gist . collectionID = collectionID
// Get partition result for the given collection.
partitions , err := gist . getPartitions ( ctx , collectionName , collectionID )
if err != nil {
return err
}
if gist . IndexName == "" {
gist . IndexName = Params . CommonCfg . DefaultIndexName
}
// Retrieve index status and detailed index information.
indexDescriptionResp , err := gist . describeIndex ( ctx )
if err != nil {
return err
}
// Check if the target index name exists.
matchIndexID := int64 ( - 1 )
foundIndexID := false
for _ , desc := range indexDescriptionResp . IndexDescriptions {
if desc . IndexName == gist . IndexName {
matchIndexID = desc . IndexID
foundIndexID = true
break
}
}
if ! foundIndexID {
return fmt . Errorf ( "no index is created" )
}
// Fetch segments for partitions.
allSegmentIDs , err := gist . getSegmentIDs ( ctx , collectionID , partitions )
if err != nil {
return err
}
// Get all index build ids.
indexBuildIDs , err := gist . getIndexBuildIDs ( ctx , collectionID , allSegmentIDs , matchIndexID )
if err != nil {
return err
}
log . Debug ( "get index state" , zap . String ( "role" , typeutil . ProxyRole ) , zap . Int64s ( "indexBuildIDs" , indexBuildIDs ) )
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
}
2022-04-29 13:35:49 +08:00
if len ( indexBuildIDs ) <= 0 {
2021-06-21 20:34:16 +08:00
return nil
2021-03-08 15:46:51 +08:00
}
2022-04-29 13:35:49 +08:00
// Get index states.
getIndexStatesRequest := & indexpb . GetIndexStatesRequest {
IndexBuildIDs : indexBuildIDs ,
}
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
2022-04-24 22:03:44 +08:00
ft . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-02 10:58:39 +08:00
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 {
2021-11-29 12:25:17 +08:00
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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 {
2021-12-13 10:01:18 +08:00
log . Debug ( "loadCollectionTask PreExecute" , zap . String ( "role" , typeutil . ProxyRole ) , zap . Int64 ( "msgID" , lct . Base . MsgID ) )
2021-03-10 14:45:35 +08:00
lct . Base . MsgType = commonpb . MsgType_LoadCollection
2022-04-24 22:03:44 +08:00
lct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-04 15:31:02 +08:00
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 ) {
2021-12-13 10:01:18 +08:00
log . Debug ( "loadCollectionTask Execute" , zap . String ( "role" , typeutil . ProxyRole ) , 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
}
2022-03-02 16:23:55 +08:00
lct . collectionID = collID
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 ,
} ,
2022-04-20 16:15:41 +08:00
DbID : 0 ,
CollectionID : collID ,
Schema : collSchema ,
ReplicaNumber : lct . ReplicaNumber ,
2021-02-04 15:31:02 +08:00
}
2021-12-13 10:01:18 +08:00
log . Debug ( "send LoadCollectionRequest to query coordinator" , zap . String ( "role" , typeutil . ProxyRole ) ,
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 {
2021-12-13 10:01:18 +08:00
log . Debug ( "loadCollectionTask PostExecute" , zap . String ( "role" , typeutil . ProxyRole ) ,
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
rct . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-04 15:31:02 +08:00
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
}
2022-03-02 16:23:55 +08:00
rct . collectionID = collID
2021-02-04 15:31:02 +08:00
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
2022-05-19 10:13:56 +08:00
globalMetaCache . RemoveCollection ( ctx , rct . CollectionName )
2021-06-18 10:33:58 +08:00
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 {
2022-05-17 11:11:56 +08:00
globalMetaCache . ClearShards ( rct . CollectionName )
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
lpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-04 15:31:02 +08:00
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
}
2022-03-02 16:23:55 +08:00
lpt . collectionID = collID
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 ,
} ,
2022-04-20 16:15:41 +08:00
DbID : 0 ,
CollectionID : collID ,
PartitionIDs : partitionIDs ,
Schema : collSchema ,
ReplicaNumber : lpt . ReplicaNumber ,
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
2022-03-02 16:23:55 +08:00
collectionID UniqueID
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
2022-04-24 22:03:44 +08:00
rpt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-02-04 15:31:02 +08:00
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
}
2022-03-02 16:23:55 +08:00
rpt . collectionID = collID
2021-02-04 15:31:02 +08:00
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 {
2022-05-17 11:11:56 +08:00
globalMetaCache . ClearShards ( rpt . CollectionName )
2021-02-04 15:31:02 +08:00
return nil
}
2021-08-26 12:15:52 +08:00
2021-10-25 22:20:20 +08:00
type BaseDeleteTask = msgstream . DeleteMsg
2021-09-15 14:04:54 +08:00
type deleteTask struct {
2021-08-26 12:15:52 +08:00
Condition
2021-10-25 22:20:20 +08:00
BaseDeleteTask
2022-04-02 17:43:29 +08:00
ctx context . Context
deleteExpr string
//req *milvuspb.DeleteRequest
2021-10-11 07:48:55 +08:00
result * milvuspb . MutationResult
chMgr channelsMgr
chTicker channelsTimeTicker
vChannels [ ] vChan
pChannels [ ] pChan
2022-03-02 16:23:55 +08:00
collectionID UniqueID
2022-04-02 17:43:29 +08:00
schema * schemapb . CollectionSchema
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-11-24 16:01:17 +08:00
func ( dt * deleteTask ) getPChanStats ( ) ( map [ pChan ] pChanStatistics , error ) {
ret := make ( map [ pChan ] pChanStatistics )
channels , err := dt . getChannels ( )
if err != nil {
return ret , err
}
beginTs := dt . BeginTs ( )
endTs := dt . EndTs ( )
for _ , channel := range channels {
ret [ channel ] = pChanStatistics {
minTs : beginTs ,
maxTs : endTs ,
}
}
return ret , nil
}
func ( dt * deleteTask ) getChannels ( ) ( [ ] pChan , error ) {
collID , err := globalMetaCache . GetCollectionID ( dt . ctx , dt . CollectionName )
if err != nil {
return nil , err
}
2022-06-02 15:34:04 +08:00
return dt . chMgr . getChannels ( collID )
2021-11-24 16:01:17 +08:00
}
2022-04-02 17:43:29 +08:00
func getPrimaryKeysFromExpr ( schema * schemapb . CollectionSchema , expr string ) ( res * schemapb . IDs , rowNum int64 , err error ) {
2021-10-11 07:48:55 +08:00
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 {
2022-04-02 17:43:29 +08:00
return res , 0 , fmt . Errorf ( "failed to create expr plan, expr = %s" , expr )
2021-10-11 07:48:55 +08:00
}
// delete request only support expr "id in [a, b]"
termExpr , ok := plan . Node . ( * planpb . PlanNode_Predicates ) . Predicates . Expr . ( * planpb . Expr_TermExpr )
if ! ok {
2022-05-13 18:19:53 +08:00
return res , 0 , fmt . Errorf ( "invalid plan node type, only pk in [1, 2] supported" )
2021-10-11 07:48:55 +08:00
}
2022-04-02 17:43:29 +08:00
res = & schemapb . IDs { }
rowNum = int64 ( len ( termExpr . TermExpr . Values ) )
switch termExpr . TermExpr . ColumnInfo . GetDataType ( ) {
case schemapb . DataType_Int64 :
ids := make ( [ ] int64 , 0 )
for _ , v := range termExpr . TermExpr . Values {
ids = append ( ids , v . GetInt64Val ( ) )
}
res . IdField = & schemapb . IDs_IntId {
IntId : & schemapb . LongArray {
Data : ids ,
} ,
}
case schemapb . DataType_VarChar :
ids := make ( [ ] string , 0 )
for _ , v := range termExpr . TermExpr . Values {
ids = append ( ids , v . GetStringVal ( ) )
}
res . IdField = & schemapb . IDs_StrId {
StrId : & schemapb . StringArray {
Data : ids ,
} ,
}
default :
return res , 0 , fmt . Errorf ( "invalid field data type specifyed in delete expr" )
2021-10-11 07:48:55 +08:00
}
2022-04-02 17:43:29 +08:00
return res , rowNum , nil
2021-10-11 07:48:55 +08:00
}
2021-09-15 14:04:54 +08:00
func ( dt * deleteTask ) PreExecute ( ctx context . Context ) error {
dt . Base . MsgType = commonpb . MsgType_Delete
2022-04-24 22:03:44 +08:00
dt . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-08-26 12:15:52 +08:00
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 ( ) ,
}
2022-04-02 17:43:29 +08:00
collName := dt . 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
2022-03-02 16:23:55 +08:00
dt . 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.
2022-04-02 17:43:29 +08:00
if len ( dt . PartitionName ) > 0 {
partName := dt . 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
}
2022-04-02 17:43:29 +08:00
schema , err := globalMetaCache . GetCollectionSchema ( ctx , collName )
2021-10-11 07:48:55 +08:00
if err != nil {
2022-04-02 17:43:29 +08:00
log . Error ( "Failed to get collection schema" , zap . String ( "collectionName" , collName ) )
2021-10-11 07:48:55 +08:00
return err
}
2022-04-02 17:43:29 +08:00
dt . schema = schema
2021-10-11 07:48:55 +08:00
2022-04-02 17:43:29 +08:00
// get delete.primaryKeys from delete expr
primaryKeys , numRow , err := getPrimaryKeysFromExpr ( schema , dt . deleteExpr )
2021-10-11 07:48:55 +08:00
if err != nil {
log . Error ( "Failed to get primary keys from expr" , zap . Error ( err ) )
return err
}
2022-04-02 17:43:29 +08:00
dt . DeleteRequest . NumRows = numRow
2021-10-11 07:48:55 +08:00
dt . DeleteRequest . PrimaryKeys = primaryKeys
2022-04-02 17:43:29 +08:00
log . Debug ( "get primary keys from expr" , zap . Int64 ( "len of primary keys" , dt . DeleteRequest . NumRows ) )
2021-10-11 07:48:55 +08:00
// set result
2022-04-02 17:43:29 +08:00
dt . result . IDs = primaryKeys
dt . result . DeleteCnt = dt . DeleteRequest . NumRows
2021-10-11 07:48:55 +08:00
2022-04-02 17:43:29 +08:00
dt . Timestamps = make ( [ ] uint64 , numRow )
2021-10-14 14:48:34 +08:00
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 ( )
2022-04-27 23:03:47 +08:00
tr := timerecord . NewTimeRecorder ( fmt . Sprintf ( "proxy execute delete %d" , dt . ID ( ) ) )
2021-10-11 16:31:44 +08:00
collID := dt . DeleteRequest . CollectionID
2022-06-09 17:34:09 +08:00
stream , err := dt . chMgr . getOrCreateDmlStream ( collID )
2021-10-11 16:31:44 +08:00
if err != nil {
2022-06-02 15:34:04 +08:00
return err
2021-10-11 16:31:44 +08:00
}
2022-03-25 14:27:25 +08:00
// hash primary keys to channels
channelNames , err := dt . chMgr . getVChannels ( collID )
if err != nil {
log . Error ( "get vChannels failed" , zap . Int64 ( "collectionID" , collID ) , zap . Error ( err ) )
dt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
dt . result . Status . Reason = err . Error ( )
return err
}
dt . HashValues = typeutil . HashPK2Channels ( dt . result . IDs , channelNames )
2022-06-02 15:34:04 +08:00
log . Info ( "send delete request to virtual channels" ,
zap . String ( "collection" , dt . GetCollectionName ( ) ) ,
zap . Int64 ( "collection_id" , collID ) ,
zap . Strings ( "virtual_channels" , channelNames ) ,
zap . Int64 ( "task_id" , dt . ID ( ) ) )
2022-04-27 23:03:47 +08:00
tr . Record ( "get vchannels" )
2022-03-25 14:27:25 +08:00
// repack delete msg by dmChannel
result := make ( map [ uint32 ] msgstream . TsMsg )
collectionName := dt . CollectionName
collectionID := dt . CollectionID
partitionID := dt . PartitionID
partitionName := dt . PartitionName
proxyID := dt . Base . SourceID
for index , key := range dt . HashValues {
ts := dt . Timestamps [ index ]
_ , ok := result [ key ]
if ! ok {
sliceRequest := internalpb . DeleteRequest {
Base : & commonpb . MsgBase {
MsgType : commonpb . MsgType_Delete ,
MsgID : dt . Base . MsgID ,
Timestamp : ts ,
SourceID : proxyID ,
} ,
CollectionID : collectionID ,
PartitionID : partitionID ,
CollectionName : collectionName ,
PartitionName : partitionName ,
2022-04-02 17:43:29 +08:00
PrimaryKeys : & schemapb . IDs { } ,
2021-10-25 22:20:20 +08:00
}
2022-03-25 14:27:25 +08:00
deleteMsg := & msgstream . DeleteMsg {
BaseMsg : msgstream . BaseMsg {
Ctx : ctx ,
} ,
DeleteRequest : sliceRequest ,
}
result [ key ] = deleteMsg
2021-10-25 22:20:20 +08:00
}
2022-03-25 14:27:25 +08:00
curMsg := result [ key ] . ( * msgstream . DeleteMsg )
curMsg . HashValues = append ( curMsg . HashValues , dt . HashValues [ index ] )
curMsg . Timestamps = append ( curMsg . Timestamps , dt . Timestamps [ index ] )
2022-04-02 17:43:29 +08:00
typeutil . AppendIDs ( curMsg . PrimaryKeys , dt . PrimaryKeys , index )
curMsg . NumRows ++
2021-10-25 22:20:20 +08:00
}
2022-03-25 14:27:25 +08:00
// send delete request to log broker
msgPack := & msgstream . MsgPack {
BeginTs : dt . BeginTs ( ) ,
EndTs : dt . EndTs ( ) ,
2021-10-25 22:20:20 +08:00
}
for _ , msg := range result {
if msg != nil {
2022-03-25 14:27:25 +08:00
msgPack . Msgs = append ( msgPack . Msgs , msg )
2021-10-25 22:20:20 +08:00
}
}
2022-04-27 23:03:47 +08:00
tr . Record ( "pack messages" )
2022-03-25 14:27:25 +08:00
err = stream . Produce ( msgPack )
2021-10-11 16:31:44 +08:00
if err != nil {
dt . result . Status . ErrorCode = commonpb . ErrorCode_UnexpectedError
dt . result . Status . Reason = err . Error ( )
return err
}
2022-04-27 23:03:47 +08:00
sendMsgDur := tr . Record ( "send delete request to dml channels" )
metrics . ProxySendMutationReqLatency . WithLabelValues ( strconv . FormatInt ( Params . ProxyCfg . GetNodeID ( ) , 10 ) , metrics . DeleteLabel ) . Observe ( float64 ( sendMsgDur . Milliseconds ( ) ) )
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
2021-12-28 22:22:46 +08:00
// CreateAliasTask contains task information of CreateAlias
2021-09-18 11:13:51 +08:00
type CreateAliasTask struct {
Condition
* milvuspb . CreateAliasRequest
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
}
2021-11-17 16:13:17 +08:00
// TraceCtx returns the trace context of the task.
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) TraceCtx ( ) context . Context {
return c . ctx
}
2021-11-17 16:13:17 +08:00
// ID return the id of the task
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) ID ( ) UniqueID {
return c . Base . MsgID
}
2021-11-17 16:13:17 +08:00
// SetID sets the id of the task
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) SetID ( uid UniqueID ) {
c . Base . MsgID = uid
}
2021-11-17 16:13:17 +08:00
// Name returns the name of the task
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) Name ( ) string {
return CreateAliasTaskName
}
2021-11-17 16:13:17 +08:00
// Type returns the type of the task
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) Type ( ) commonpb . MsgType {
return c . Base . MsgType
}
2021-12-23 11:05:09 +08:00
// BeginTs returns the ts
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) BeginTs ( ) Timestamp {
return c . Base . Timestamp
}
2021-12-23 11:05:09 +08:00
// EndTs returns the ts
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) EndTs ( ) Timestamp {
return c . Base . Timestamp
}
2021-12-23 11:05:09 +08:00
// SetTs sets the ts
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) SetTs ( ts Timestamp ) {
c . Base . Timestamp = ts
}
2021-12-29 22:40:27 +08:00
// OnEnqueue defines the behavior task enqueued
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) OnEnqueue ( ) error {
c . Base = & commonpb . MsgBase { }
return nil
}
2021-12-29 22:40:27 +08:00
// PreExecute defines the action before task execution
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) PreExecute ( ctx context . Context ) error {
c . Base . MsgType = commonpb . MsgType_CreateAlias
2022-04-24 22:03:44 +08:00
c . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-09-18 11:13:51 +08:00
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
}
2021-12-29 22:40:27 +08:00
// Execute defines the actual execution of create alias
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) Execute ( ctx context . Context ) error {
var err error
c . result , err = c . rootCoord . CreateAlias ( ctx , c . CreateAliasRequest )
return err
}
2021-12-29 22:40:27 +08:00
// PostExecute defines the post execution, do nothing for create alias
2021-09-18 11:13:51 +08:00
func ( c * CreateAliasTask ) PostExecute ( ctx context . Context ) error {
return nil
}
2021-12-17 18:46:38 +08:00
// DropAliasTask is the task to drop alias
2021-09-18 11:13:51 +08:00
type DropAliasTask struct {
Condition
* milvuspb . DropAliasRequest
ctx context . Context
rootCoord types . RootCoord
result * commonpb . Status
}
2022-01-10 18:33:46 +08:00
// TraceCtx returns the context for trace
2021-09-18 11:13:51 +08:00
func ( d * DropAliasTask ) TraceCtx ( ) context . Context {
return d . ctx
}
2022-01-10 18:33:46 +08:00
// ID returns the MsgID
2021-09-18 11:13:51 +08:00
func ( d * DropAliasTask ) ID ( ) UniqueID {
return d . Base . MsgID
}
2022-01-10 18:33:46 +08:00
// SetID sets the MsgID
2021-09-18 11:13:51 +08:00
func ( d * DropAliasTask ) SetID ( uid UniqueID ) {
d . Base . MsgID = uid
}
2022-01-10 18:33:46 +08:00
// Name returns the name of the task
2021-09-18 11:13:51 +08:00
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
2022-04-24 22:03:44 +08:00
d . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-09-18 11:13:51 +08:00
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
}
2021-12-24 13:33:45 +08:00
// AlterAliasTask is the task to alter alias
2021-09-18 11:13:51 +08:00
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
2022-04-24 22:03:44 +08:00
a . Base . SourceID = Params . ProxyCfg . GetNodeID ( )
2021-09-18 11:13:51 +08:00
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
}