2020-11-03 14:53:36 +08:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
2020-11-05 18:01:33 +08:00
|
|
|
"context"
|
|
|
|
"errors"
|
2020-11-05 19:11:12 +08:00
|
|
|
"log"
|
2020-11-26 16:01:31 +08:00
|
|
|
"math"
|
|
|
|
"strconv"
|
|
|
|
|
2021-01-06 11:17:35 +08:00
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
oplog "github.com/opentracing/opentracing-go/log"
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2020-11-20 17:53:31 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/allocator"
|
2020-11-05 18:01:33 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2020-11-03 14:53:36 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2020-11-05 18:01:33 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
|
2020-11-26 16:01:31 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
|
2020-11-05 18:01:33 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/servicepb"
|
2020-12-23 19:06:11 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
|
2020-11-03 14:53:36 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type task interface {
|
2020-11-23 16:52:17 +08:00
|
|
|
ID() UniqueID // return ReqID
|
|
|
|
SetID(uid UniqueID) // set ReqID
|
2020-11-04 16:28:14 +08:00
|
|
|
Type() internalpb.MsgType
|
2020-11-05 18:01:33 +08:00
|
|
|
BeginTs() Timestamp
|
|
|
|
EndTs() Timestamp
|
2020-11-04 17:58:43 +08:00
|
|
|
SetTs(ts Timestamp)
|
2020-11-03 14:53:36 +08:00
|
|
|
PreExecute() error
|
|
|
|
Execute() error
|
|
|
|
PostExecute() error
|
|
|
|
WaitToFinish() error
|
2020-11-05 18:01:33 +08:00
|
|
|
Notify(err error)
|
2020-11-03 14:53:36 +08:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:18:23 +08:00
|
|
|
type BaseInsertTask = msgstream.InsertMsg
|
2020-11-05 18:01:33 +08:00
|
|
|
|
|
|
|
type InsertTask struct {
|
2020-11-07 16:18:23 +08:00
|
|
|
BaseInsertTask
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-14 11:24:49 +08:00
|
|
|
result *servicepb.IntegerRangeResponse
|
2020-11-05 18:01:33 +08:00
|
|
|
manipulationMsgStream *msgstream.PulsarMsgStream
|
|
|
|
ctx context.Context
|
2020-11-20 17:53:31 +08:00
|
|
|
rowIDAllocator *allocator.IDAllocator
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (it *InsertTask) SetID(uid UniqueID) {
|
|
|
|
it.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
func (it *InsertTask) SetTs(ts Timestamp) {
|
2020-11-26 16:01:31 +08:00
|
|
|
rowNum := len(it.RowData)
|
|
|
|
it.Timestamps = make([]uint64, rowNum)
|
|
|
|
for index := range it.Timestamps {
|
|
|
|
it.Timestamps[index] = ts
|
|
|
|
}
|
|
|
|
it.BeginTimestamp = ts
|
|
|
|
it.EndTimestamp = ts
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (it *InsertTask) BeginTs() Timestamp {
|
2020-11-26 16:01:31 +08:00
|
|
|
return it.BeginTimestamp
|
2020-11-05 18:01:33 +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
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (it *InsertTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return it.ReqID
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (it *InsertTask) Type() internalpb.MsgType {
|
|
|
|
return it.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *InsertTask) PreExecute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span := opentracing.StartSpan("InsertTask preExecute")
|
|
|
|
defer span.Finish()
|
|
|
|
it.ctx = opentracing.ContextWithSpan(it.ctx, span)
|
|
|
|
span.SetTag("hash keys", it.ReqID)
|
|
|
|
span.SetTag("start time", it.BeginTs())
|
2020-11-26 16:01:31 +08:00
|
|
|
collectionName := it.BaseInsertTask.CollectionName
|
|
|
|
if err := ValidateCollectionName(collectionName); err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
partitionTag := it.BaseInsertTask.PartitionTag
|
|
|
|
if err := ValidatePartitionTag(partitionTag, true); err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *InsertTask) Execute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(it.ctx, "InsertTask Execute")
|
|
|
|
defer span.Finish()
|
|
|
|
it.ctx = ctx
|
|
|
|
span.SetTag("hash keys", it.ReqID)
|
|
|
|
span.SetTag("start time", it.BeginTs())
|
2020-11-20 17:53:31 +08:00
|
|
|
collectionName := it.BaseInsertTask.CollectionName
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.String("collection_name", collectionName))
|
2020-11-20 17:53:31 +08:00
|
|
|
if !globalMetaCache.Hit(collectionName) {
|
2020-12-03 19:00:11 +08:00
|
|
|
err := globalMetaCache.Sync(collectionName)
|
2020-11-20 17:53:31 +08:00
|
|
|
if err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-20 17:53:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
description, err := globalMetaCache.Get(collectionName)
|
|
|
|
if err != nil || description == nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-20 17:53:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
autoID := description.Schema.AutoID
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Bool("auto_id", autoID))
|
2020-11-30 12:08:47 +08:00
|
|
|
var rowIDBegin UniqueID
|
|
|
|
var rowIDEnd UniqueID
|
2020-12-03 19:00:11 +08:00
|
|
|
rowNums := len(it.BaseInsertTask.RowData)
|
|
|
|
rowIDBegin, rowIDEnd, _ = it.rowIDAllocator.Alloc(uint32(rowNums))
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Int("rowNums", rowNums),
|
|
|
|
oplog.Int("rowIDBegin", int(rowIDBegin)),
|
|
|
|
oplog.Int("rowIDEnd", int(rowIDEnd)))
|
2020-12-03 19:00:11 +08:00
|
|
|
it.BaseInsertTask.RowIDs = make([]UniqueID, rowNums)
|
|
|
|
for i := rowIDBegin; i < rowIDEnd; i++ {
|
|
|
|
offset := i - rowIDBegin
|
|
|
|
it.BaseInsertTask.RowIDs[offset] = i
|
|
|
|
}
|
|
|
|
|
|
|
|
if autoID {
|
2020-11-30 19:38:23 +08:00
|
|
|
if it.HashValues == nil || len(it.HashValues) == 0 {
|
|
|
|
it.HashValues = make([]uint32, 0)
|
|
|
|
}
|
2020-12-03 19:00:11 +08:00
|
|
|
for _, rowID := range it.RowIDs {
|
|
|
|
hashValue, _ := typeutil.Hash32Int64(rowID)
|
2020-11-30 19:38:23 +08:00
|
|
|
it.HashValues = append(it.HashValues, hashValue)
|
2020-11-20 17:53:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:18:23 +08:00
|
|
|
var tsMsg msgstream.TsMsg = &it.BaseInsertTask
|
2020-11-05 18:01:33 +08:00
|
|
|
msgPack := &msgstream.MsgPack{
|
|
|
|
BeginTs: it.BeginTs(),
|
|
|
|
EndTs: it.EndTs(),
|
2020-11-17 14:10:07 +08:00
|
|
|
Msgs: make([]msgstream.TsMsg, 1),
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
tsMsg.SetContext(it.ctx)
|
|
|
|
span.LogFields(oplog.String("send msg", "send msg"))
|
2020-11-17 14:10:07 +08:00
|
|
|
msgPack.Msgs[0] = tsMsg
|
2020-11-20 17:53:31 +08:00
|
|
|
err = it.manipulationMsgStream.Produce(msgPack)
|
2020-12-03 19:00:11 +08:00
|
|
|
|
2020-11-14 18:18:10 +08:00
|
|
|
it.result = &servicepb.IntegerRangeResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
2020-11-30 12:08:47 +08:00
|
|
|
Begin: rowIDBegin,
|
|
|
|
End: rowIDEnd,
|
2020-11-14 18:18:10 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
it.result.Status.ErrorCode = commonpb.ErrorCode_UNEXPECTED_ERROR
|
|
|
|
it.result.Status.Reason = err.Error()
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
2020-11-14 18:18:10 +08:00
|
|
|
}
|
2020-11-05 18:01:33 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *InsertTask) PostExecute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span, _ := opentracing.StartSpanFromContext(it.ctx, "InsertTask postExecute")
|
|
|
|
defer span.Finish()
|
2020-11-05 18:01:33 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateCollectionTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-05 18:01:33 +08:00
|
|
|
internalpb.CreateCollectionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
2020-11-14 11:24:49 +08:00
|
|
|
result *commonpb.Status
|
2020-11-05 19:11:12 +08:00
|
|
|
ctx context.Context
|
2020-11-26 16:01:31 +08:00
|
|
|
schema *schemapb.CollectionSchema
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (cct *CreateCollectionTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return cct.ReqID
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (cct *CreateCollectionTask) SetID(uid UniqueID) {
|
|
|
|
cct.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
func (cct *CreateCollectionTask) Type() internalpb.MsgType {
|
|
|
|
return cct.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cct *CreateCollectionTask) BeginTs() Timestamp {
|
|
|
|
return cct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cct *CreateCollectionTask) EndTs() Timestamp {
|
|
|
|
return cct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cct *CreateCollectionTask) SetTs(ts Timestamp) {
|
|
|
|
cct.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cct *CreateCollectionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
if int64(len(cct.schema.Fields)) > Params.MaxFieldNum() {
|
|
|
|
return errors.New("maximum field's number should be limited to " + strconv.FormatInt(Params.MaxFieldNum(), 10))
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate collection name
|
|
|
|
if err := ValidateCollectionName(cct.schema.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-30 19:38:23 +08:00
|
|
|
if err := ValidateDuplicatedFieldName(cct.schema.Fields); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidatePrimaryKey(cct.schema); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
// validate field name
|
|
|
|
for _, field := range cct.schema.Fields {
|
|
|
|
if err := ValidateFieldName(field.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if field.DataType == schemapb.DataType_VECTOR_FLOAT || field.DataType == schemapb.DataType_VECTOR_BINARY {
|
|
|
|
exist := false
|
|
|
|
var dim int64 = 0
|
|
|
|
for _, param := range field.TypeParams {
|
|
|
|
if param.Key == "dim" {
|
|
|
|
exist = true
|
|
|
|
tmp, err := strconv.ParseInt(param.Value, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dim = tmp
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !exist {
|
|
|
|
return errors.New("dimension is not defined in field type params")
|
|
|
|
}
|
|
|
|
if field.DataType == schemapb.DataType_VECTOR_FLOAT {
|
|
|
|
if err := ValidateDimension(dim, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := ValidateDimension(dim, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-30 19:38:23 +08:00
|
|
|
if err := ValidateVectorFieldMetricType(field); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
return nil
|
2020-11-03 14:53:36 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
func (cct *CreateCollectionTask) Execute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
schemaBytes, _ := proto.Marshal(cct.schema)
|
|
|
|
cct.CreateCollectionRequest.Schema.Value = schemaBytes
|
2020-11-05 18:01:33 +08:00
|
|
|
resp, err := cct.masterClient.CreateCollection(cct.ctx, &cct.CreateCollectionRequest)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("create collection failed, error= %v", err)
|
2020-11-14 11:24:49 +08:00
|
|
|
cct.result = &commonpb.Status{
|
2020-11-05 18:01:33 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
2020-11-05 19:11:12 +08:00
|
|
|
Reason: err.Error(),
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-11-14 11:24:49 +08:00
|
|
|
cct.result = resp
|
2020-11-05 18:01:33 +08:00
|
|
|
}
|
|
|
|
return err
|
2020-11-03 14:53:36 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 18:01:33 +08:00
|
|
|
func (cct *CreateCollectionTask) PostExecute() error {
|
|
|
|
return nil
|
2020-11-03 14:53:36 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
type DropCollectionTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-09 17:25:53 +08:00
|
|
|
internalpb.DropCollectionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
2020-11-14 11:24:49 +08:00
|
|
|
result *commonpb.Status
|
2020-11-09 17:25:53 +08:00
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (dct *DropCollectionTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return dct.ReqID
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (dct *DropCollectionTask) SetID(uid UniqueID) {
|
|
|
|
dct.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
func (dct *DropCollectionTask) Type() internalpb.MsgType {
|
|
|
|
return dct.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) BeginTs() Timestamp {
|
|
|
|
return dct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) EndTs() Timestamp {
|
|
|
|
return dct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) SetTs(ts Timestamp) {
|
|
|
|
dct.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
if err := ValidateCollectionName(dct.CollectionName.CollectionName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-09 17:25:53 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) Execute() error {
|
|
|
|
resp, err := dct.masterClient.DropCollection(dct.ctx, &dct.DropCollectionRequest)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("drop collection failed, error= %v", err)
|
2020-11-14 11:24:49 +08:00
|
|
|
dct.result = &commonpb.Status{
|
2020-11-09 17:25:53 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
|
|
|
Reason: err.Error(),
|
|
|
|
}
|
|
|
|
} else {
|
2020-11-14 11:24:49 +08:00
|
|
|
dct.result = resp
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DropCollectionTask) PostExecute() error {
|
2020-12-01 02:16:53 +08:00
|
|
|
if globalMetaCache.Hit(dct.CollectionName.CollectionName) {
|
|
|
|
return globalMetaCache.Remove(dct.CollectionName.CollectionName)
|
|
|
|
}
|
2020-11-30 22:14:19 +08:00
|
|
|
return nil
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:18:23 +08:00
|
|
|
type QueryTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-07 16:18:23 +08:00
|
|
|
internalpb.SearchRequest
|
|
|
|
queryMsgStream *msgstream.PulsarMsgStream
|
|
|
|
resultBuf chan []*internalpb.SearchResult
|
2020-11-14 11:24:49 +08:00
|
|
|
result *servicepb.QueryResult
|
2020-11-07 16:18:23 +08:00
|
|
|
ctx context.Context
|
2020-11-26 16:01:31 +08:00
|
|
|
query *servicepb.Query
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (qt *QueryTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return qt.ReqID
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (qt *QueryTask) SetID(uid UniqueID) {
|
|
|
|
qt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:18:23 +08:00
|
|
|
func (qt *QueryTask) Type() internalpb.MsgType {
|
|
|
|
return qt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) BeginTs() Timestamp {
|
|
|
|
return qt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) EndTs() Timestamp {
|
|
|
|
return qt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) SetTs(ts Timestamp) {
|
|
|
|
qt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) PreExecute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span := opentracing.StartSpan("InsertTask preExecute")
|
|
|
|
defer span.Finish()
|
|
|
|
qt.ctx = opentracing.ContextWithSpan(qt.ctx, span)
|
|
|
|
span.SetTag("hash keys", qt.ReqID)
|
|
|
|
span.SetTag("start time", qt.BeginTs())
|
|
|
|
|
2020-11-30 19:08:32 +08:00
|
|
|
collectionName := qt.query.CollectionName
|
|
|
|
if !globalMetaCache.Hit(collectionName) {
|
2020-12-03 19:00:11 +08:00
|
|
|
err := globalMetaCache.Sync(collectionName)
|
2020-11-30 19:08:32 +08:00
|
|
|
if err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-30 19:08:32 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err := globalMetaCache.Get(collectionName)
|
|
|
|
if err != nil { // err is not nil if collection not exists
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-30 19:08:32 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
if err := ValidateCollectionName(qt.query.CollectionName); err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tag := range qt.query.PartitionTags {
|
|
|
|
if err := ValidatePartitionTag(tag, false); err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 19:06:48 +08:00
|
|
|
qt.MsgType = internalpb.MsgType_kSearch
|
|
|
|
if qt.query.PartitionTags == nil || len(qt.query.PartitionTags) <= 0 {
|
|
|
|
qt.query.PartitionTags = []string{Params.defaultPartitionTag()}
|
|
|
|
}
|
|
|
|
queryBytes, err := proto.Marshal(qt.query)
|
|
|
|
if err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-28 19:06:48 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
qt.Query = &commonpb.Blob{
|
|
|
|
Value: queryBytes,
|
|
|
|
}
|
2020-11-07 16:18:23 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) Execute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(qt.ctx, "InsertTask Execute")
|
|
|
|
defer span.Finish()
|
|
|
|
span.SetTag("hash keys", qt.ReqID)
|
|
|
|
span.SetTag("start time", qt.BeginTs())
|
2020-11-07 16:18:23 +08:00
|
|
|
var tsMsg msgstream.TsMsg = &msgstream.SearchMsg{
|
|
|
|
SearchRequest: qt.SearchRequest,
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
2020-11-30 19:38:23 +08:00
|
|
|
HashValues: []uint32{uint32(Params.ProxyID())},
|
2020-11-07 16:18:23 +08:00
|
|
|
BeginTimestamp: qt.Timestamp,
|
|
|
|
EndTimestamp: qt.Timestamp,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msgPack := &msgstream.MsgPack{
|
|
|
|
BeginTs: qt.Timestamp,
|
|
|
|
EndTs: qt.Timestamp,
|
2020-11-17 14:10:07 +08:00
|
|
|
Msgs: make([]msgstream.TsMsg, 1),
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
tsMsg.SetContext(ctx)
|
2020-11-17 14:10:07 +08:00
|
|
|
msgPack.Msgs[0] = tsMsg
|
2020-11-28 19:06:48 +08:00
|
|
|
err := qt.queryMsgStream.Produce(msgPack)
|
|
|
|
log.Printf("[Proxy] length of searchMsg: %v", len(msgPack.Msgs))
|
|
|
|
if err != nil {
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-28 19:06:48 +08:00
|
|
|
log.Printf("[Proxy] send search request failed: %v", err)
|
|
|
|
}
|
|
|
|
return err
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (qt *QueryTask) PostExecute() error {
|
2021-01-06 11:17:35 +08:00
|
|
|
span, _ := opentracing.StartSpanFromContext(qt.ctx, "InsertTask postExecute")
|
|
|
|
span.SetTag("hash keys", qt.ReqID)
|
|
|
|
span.SetTag("start time", qt.BeginTs())
|
2020-11-07 16:18:23 +08:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-qt.ctx.Done():
|
|
|
|
log.Print("wait to finish failed, timeout!")
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.String("wait to finish failed, timeout", "wait to finish failed, timeout"))
|
|
|
|
span.Finish()
|
2020-11-12 12:04:12 +08:00
|
|
|
return errors.New("wait to finish failed, timeout")
|
2020-11-07 16:18:23 +08:00
|
|
|
case searchResults := <-qt.resultBuf:
|
2020-11-30 19:08:32 +08:00
|
|
|
filterSearchResult := make([]*internalpb.SearchResult, 0)
|
2020-11-30 22:14:19 +08:00
|
|
|
var filterReason string
|
2020-11-30 19:08:32 +08:00
|
|
|
for _, partialSearchResult := range searchResults {
|
|
|
|
if partialSearchResult.Status.ErrorCode == commonpb.ErrorCode_SUCCESS {
|
|
|
|
filterSearchResult = append(filterSearchResult, partialSearchResult)
|
2020-11-30 22:14:19 +08:00
|
|
|
} else {
|
|
|
|
filterReason += partialSearchResult.Status.Reason + "\n"
|
2020-11-30 19:08:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
availableQueryNodeNum := len(filterSearchResult)
|
|
|
|
if availableQueryNodeNum <= 0 {
|
2020-11-30 22:14:19 +08:00
|
|
|
qt.result = &servicepb.QueryResult{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
|
|
|
Reason: filterReason,
|
|
|
|
},
|
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(errors.New(filterReason)))
|
|
|
|
span.Finish()
|
2020-11-30 22:14:19 +08:00
|
|
|
return errors.New(filterReason)
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
2020-11-28 19:06:48 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
hits := make([][]*servicepb.Hits, 0)
|
|
|
|
for _, partialSearchResult := range filterSearchResult {
|
|
|
|
if len(partialSearchResult.Hits) <= 0 {
|
|
|
|
filterReason += "nq is zero\n"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
partialHits := make([]*servicepb.Hits, 0)
|
|
|
|
for _, bs := range partialSearchResult.Hits {
|
|
|
|
partialHit := &servicepb.Hits{}
|
|
|
|
err := proto.Unmarshal(bs, partialHit)
|
2020-11-26 16:01:31 +08:00
|
|
|
if err != nil {
|
2020-11-30 11:22:59 +08:00
|
|
|
log.Println("unmarshal error")
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
2020-12-10 16:31:09 +08:00
|
|
|
partialHits = append(partialHits, partialHit)
|
|
|
|
}
|
|
|
|
hits = append(hits, partialHits)
|
|
|
|
}
|
|
|
|
|
|
|
|
availableQueryNodeNum = len(hits)
|
|
|
|
if availableQueryNodeNum <= 0 {
|
|
|
|
qt.result = &servicepb.QueryResult{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
Reason: filterReason,
|
|
|
|
},
|
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
span.Finish()
|
2020-12-10 16:31:09 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nq := len(hits[0])
|
|
|
|
if nq <= 0 {
|
|
|
|
qt.result = &servicepb.QueryResult{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
Reason: filterReason,
|
|
|
|
},
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
span.Finish()
|
2020-12-10 16:31:09 +08:00
|
|
|
return nil
|
2020-11-26 16:01:31 +08:00
|
|
|
}
|
2020-11-28 19:06:48 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
topk := len(hits[0][0].IDs)
|
2020-11-28 19:06:48 +08:00
|
|
|
qt.result = &servicepb.QueryResult{
|
2020-11-07 16:18:23 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: 0,
|
|
|
|
},
|
2020-11-28 19:06:48 +08:00
|
|
|
Hits: make([][]byte, 0),
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
2020-11-28 19:06:48 +08:00
|
|
|
|
2020-12-27 09:05:24 +08:00
|
|
|
const minFloat32 = -1 * float32(math.MaxFloat32)
|
2020-12-10 16:31:09 +08:00
|
|
|
for i := 0; i < nq; i++ {
|
|
|
|
locs := make([]int, availableQueryNodeNum)
|
2020-11-28 19:06:48 +08:00
|
|
|
reducedHits := &servicepb.Hits{
|
|
|
|
IDs: make([]int64, 0),
|
|
|
|
RowData: make([][]byte, 0),
|
|
|
|
Scores: make([]float32, 0),
|
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
for j := 0; j < topk; j++ {
|
2020-12-27 09:05:24 +08:00
|
|
|
choice, maxDistance := 0, minFloat32
|
2020-11-07 16:18:23 +08:00
|
|
|
for q, loc := range locs { // query num, the number of ways to merge
|
2020-11-26 16:01:31 +08:00
|
|
|
distance := hits[q][i].Scores[loc]
|
2020-12-27 09:05:24 +08:00
|
|
|
if distance > maxDistance {
|
2020-11-07 16:18:23 +08:00
|
|
|
choice = q
|
2020-12-27 09:05:24 +08:00
|
|
|
maxDistance = distance
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
choiceOffset := locs[choice]
|
2020-11-30 19:08:32 +08:00
|
|
|
// check if distance is valid, `invalid` here means very very big,
|
|
|
|
// in this process, distance here is the smallest, so the rest of distance are all invalid
|
2020-12-27 09:05:24 +08:00
|
|
|
if hits[choice][i].Scores[choiceOffset] <= minFloat32 {
|
2020-12-01 02:16:53 +08:00
|
|
|
break
|
2020-11-30 19:08:32 +08:00
|
|
|
}
|
2020-11-26 16:01:31 +08:00
|
|
|
reducedHits.IDs = append(reducedHits.IDs, hits[choice][i].IDs[choiceOffset])
|
2020-11-28 19:06:48 +08:00
|
|
|
if hits[choice][i].RowData != nil && len(hits[choice][i].RowData) > 0 {
|
|
|
|
reducedHits.RowData = append(reducedHits.RowData, hits[choice][i].RowData[choiceOffset])
|
|
|
|
}
|
2020-11-26 16:01:31 +08:00
|
|
|
reducedHits.Scores = append(reducedHits.Scores, hits[choice][i].Scores[choiceOffset])
|
2020-11-07 16:18:23 +08:00
|
|
|
locs[choice]++
|
|
|
|
}
|
2020-12-27 09:05:24 +08:00
|
|
|
if searchResults[0].MetricType != "IP" {
|
|
|
|
for k := range reducedHits.Scores {
|
|
|
|
reducedHits.Scores[k] *= -1
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 16:01:31 +08:00
|
|
|
reducedHitsBs, err := proto.Marshal(reducedHits)
|
|
|
|
if err != nil {
|
2020-11-30 11:22:59 +08:00
|
|
|
log.Println("marshal error")
|
2021-01-06 11:17:35 +08:00
|
|
|
span.LogFields(oplog.Error(err))
|
|
|
|
span.Finish()
|
2020-11-26 16:01:31 +08:00
|
|
|
return err
|
|
|
|
}
|
2020-11-28 19:06:48 +08:00
|
|
|
qt.result.Hits = append(qt.result.Hits, reducedHitsBs)
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
2021-01-06 11:17:35 +08:00
|
|
|
span.Finish()
|
2020-11-28 19:06:48 +08:00
|
|
|
return nil
|
2020-11-07 16:18:23 +08:00
|
|
|
}
|
|
|
|
}
|
2020-11-16 17:01:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
type HasCollectionTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-09 17:25:53 +08:00
|
|
|
internalpb.HasCollectionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
2020-11-14 11:24:49 +08:00
|
|
|
result *servicepb.BoolResponse
|
2020-11-09 17:25:53 +08:00
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (hct *HasCollectionTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return hct.ReqID
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (hct *HasCollectionTask) SetID(uid UniqueID) {
|
|
|
|
hct.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
func (hct *HasCollectionTask) Type() internalpb.MsgType {
|
|
|
|
return hct.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) BeginTs() Timestamp {
|
|
|
|
return hct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) EndTs() Timestamp {
|
|
|
|
return hct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) SetTs(ts Timestamp) {
|
|
|
|
hct.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
if err := ValidateCollectionName(hct.CollectionName.CollectionName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-09 17:25:53 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) Execute() error {
|
|
|
|
resp, err := hct.masterClient.HasCollection(hct.ctx, &hct.HasCollectionRequest)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("has collection failed, error= %v", err)
|
2020-11-14 11:24:49 +08:00
|
|
|
hct.result = &servicepb.BoolResponse{
|
2020-11-09 17:25:53 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
|
|
|
Reason: "internal error",
|
|
|
|
},
|
|
|
|
Value: false,
|
|
|
|
}
|
|
|
|
} else {
|
2020-11-14 11:24:49 +08:00
|
|
|
hct.result = resp
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hct *HasCollectionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeCollectionTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-09 17:25:53 +08:00
|
|
|
internalpb.DescribeCollectionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
2020-11-14 11:24:49 +08:00
|
|
|
result *servicepb.CollectionDescription
|
2020-11-09 17:25:53 +08:00
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (dct *DescribeCollectionTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return dct.ReqID
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (dct *DescribeCollectionTask) SetID(uid UniqueID) {
|
|
|
|
dct.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
func (dct *DescribeCollectionTask) Type() internalpb.MsgType {
|
|
|
|
return dct.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) BeginTs() Timestamp {
|
|
|
|
return dct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) EndTs() Timestamp {
|
|
|
|
return dct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) SetTs(ts Timestamp) {
|
|
|
|
dct.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
if err := ValidateCollectionName(dct.CollectionName.CollectionName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-09 17:25:53 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) Execute() error {
|
2020-11-20 17:53:31 +08:00
|
|
|
var err error
|
2020-12-03 19:00:11 +08:00
|
|
|
dct.result, err = dct.masterClient.DescribeCollection(dct.ctx, &dct.DescribeCollectionRequest)
|
2021-01-06 11:17:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = globalMetaCache.Update(dct.CollectionName.CollectionName, dct.result)
|
2020-11-09 17:25:53 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dct *DescribeCollectionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShowCollectionsTask struct {
|
2020-11-17 20:00:23 +08:00
|
|
|
Condition
|
2020-11-09 17:25:53 +08:00
|
|
|
internalpb.ShowCollectionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
2020-11-14 11:24:49 +08:00
|
|
|
result *servicepb.StringListResponse
|
2020-11-09 17:25:53 +08:00
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (sct *ShowCollectionsTask) ID() UniqueID {
|
2020-11-13 15:17:18 +08:00
|
|
|
return sct.ReqID
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (sct *ShowCollectionsTask) SetID(uid UniqueID) {
|
|
|
|
sct.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:25:53 +08:00
|
|
|
func (sct *ShowCollectionsTask) Type() internalpb.MsgType {
|
|
|
|
return sct.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) BeginTs() Timestamp {
|
|
|
|
return sct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) EndTs() Timestamp {
|
|
|
|
return sct.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) SetTs(ts Timestamp) {
|
|
|
|
sct.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) PreExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) Execute() error {
|
|
|
|
resp, err := sct.masterClient.ShowCollections(sct.ctx, &sct.ShowCollectionRequest)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("show collections failed, error= %v", err)
|
2020-11-14 11:24:49 +08:00
|
|
|
sct.result = &servicepb.StringListResponse{
|
2020-11-09 17:25:53 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
|
|
|
Reason: "internal error",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
2020-11-14 11:24:49 +08:00
|
|
|
sct.result = resp
|
2020-11-09 17:25:53 +08:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sct *ShowCollectionsTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-19 17:09:22 +08:00
|
|
|
|
|
|
|
type CreatePartitionTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.CreatePartitionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *commonpb.Status
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) ID() UniqueID {
|
|
|
|
return cpt.ReqID
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (cpt *CreatePartitionTask) SetID(uid UniqueID) {
|
|
|
|
cpt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
func (cpt *CreatePartitionTask) Type() internalpb.MsgType {
|
|
|
|
return cpt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) BeginTs() Timestamp {
|
|
|
|
return cpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) EndTs() Timestamp {
|
|
|
|
return cpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) SetTs(ts Timestamp) {
|
|
|
|
cpt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
collName, partitionTag := cpt.PartitionName.CollectionName, cpt.PartitionName.Tag
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidatePartitionTag(partitionTag, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) Execute() (err error) {
|
|
|
|
cpt.result, err = cpt.masterClient.CreatePartition(cpt.ctx, &cpt.CreatePartitionRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cpt *CreatePartitionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DropPartitionTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.DropPartitionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *commonpb.Status
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) ID() UniqueID {
|
|
|
|
return dpt.ReqID
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (dpt *DropPartitionTask) SetID(uid UniqueID) {
|
|
|
|
dpt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
func (dpt *DropPartitionTask) Type() internalpb.MsgType {
|
|
|
|
return dpt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) BeginTs() Timestamp {
|
|
|
|
return dpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) EndTs() Timestamp {
|
|
|
|
return dpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) SetTs(ts Timestamp) {
|
|
|
|
dpt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
collName, partitionTag := dpt.PartitionName.CollectionName, dpt.PartitionName.Tag
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidatePartitionTag(partitionTag, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) Execute() (err error) {
|
|
|
|
dpt.result, err = dpt.masterClient.DropPartition(dpt.ctx, &dpt.DropPartitionRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DropPartitionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HasPartitionTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.HasPartitionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *servicepb.BoolResponse
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) ID() UniqueID {
|
|
|
|
return hpt.ReqID
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (hpt *HasPartitionTask) SetID(uid UniqueID) {
|
|
|
|
hpt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
func (hpt *HasPartitionTask) Type() internalpb.MsgType {
|
|
|
|
return hpt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) BeginTs() Timestamp {
|
|
|
|
return hpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) EndTs() Timestamp {
|
|
|
|
return hpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) SetTs(ts Timestamp) {
|
|
|
|
hpt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
collName, partitionTag := hpt.PartitionName.CollectionName, hpt.PartitionName.Tag
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidatePartitionTag(partitionTag, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-19 17:09:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) Execute() (err error) {
|
|
|
|
hpt.result, err = hpt.masterClient.HasPartition(hpt.ctx, &hpt.HasPartitionRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hpt *HasPartitionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribePartitionTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.DescribePartitionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *servicepb.PartitionDescription
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) ID() UniqueID {
|
|
|
|
return dpt.ReqID
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (dpt *DescribePartitionTask) SetID(uid UniqueID) {
|
|
|
|
dpt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
func (dpt *DescribePartitionTask) Type() internalpb.MsgType {
|
|
|
|
return dpt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) BeginTs() Timestamp {
|
|
|
|
return dpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) EndTs() Timestamp {
|
|
|
|
return dpt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) SetTs(ts Timestamp) {
|
|
|
|
dpt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
collName, partitionTag := dpt.PartitionName.CollectionName, dpt.PartitionName.Tag
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidatePartitionTag(partitionTag, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-19 17:09:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) Execute() (err error) {
|
|
|
|
dpt.result, err = dpt.masterClient.DescribePartition(dpt.ctx, &dpt.DescribePartitionRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dpt *DescribePartitionTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShowPartitionsTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.ShowPartitionRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *servicepb.StringListResponse
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) ID() UniqueID {
|
|
|
|
return spt.ReqID
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:52:17 +08:00
|
|
|
func (spt *ShowPartitionsTask) SetID(uid UniqueID) {
|
|
|
|
spt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
func (spt *ShowPartitionsTask) Type() internalpb.MsgType {
|
|
|
|
return spt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) BeginTs() Timestamp {
|
|
|
|
return spt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) EndTs() Timestamp {
|
|
|
|
return spt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) SetTs(ts Timestamp) {
|
|
|
|
spt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) PreExecute() error {
|
2020-11-26 16:01:31 +08:00
|
|
|
if err := ValidateCollectionName(spt.CollectionName.CollectionName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-19 17:09:22 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) Execute() (err error) {
|
|
|
|
spt.result, err = spt.masterClient.ShowPartitions(spt.ctx, &spt.ShowPartitionRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (spt *ShowPartitionsTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-22 15:39:10 +08:00
|
|
|
|
|
|
|
type CreateIndexTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.CreateIndexRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *commonpb.Status
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) ID() UniqueID {
|
|
|
|
return cit.ReqID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) SetID(uid UniqueID) {
|
|
|
|
cit.ReqID = uid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) Type() internalpb.MsgType {
|
|
|
|
return cit.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) BeginTs() Timestamp {
|
|
|
|
return cit.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) EndTs() Timestamp {
|
|
|
|
return cit.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) SetTs(ts Timestamp) {
|
|
|
|
cit.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) PreExecute() error {
|
|
|
|
collName, fieldName := cit.CollectionName, cit.FieldName
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateFieldName(fieldName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) Execute() (err error) {
|
|
|
|
cit.result, err = cit.masterClient.CreateIndex(cit.ctx, &cit.CreateIndexRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cit *CreateIndexTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeIndexTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.DescribeIndexRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *servicepb.DescribeIndexResponse
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) ID() UniqueID {
|
|
|
|
return dit.ReqID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) SetID(uid UniqueID) {
|
|
|
|
dit.ReqID = uid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) Type() internalpb.MsgType {
|
|
|
|
return dit.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) BeginTs() Timestamp {
|
|
|
|
return dit.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) EndTs() Timestamp {
|
|
|
|
return dit.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) SetTs(ts Timestamp) {
|
|
|
|
dit.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) PreExecute() error {
|
|
|
|
collName, fieldName := dit.CollectionName, dit.FieldName
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateFieldName(fieldName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) Execute() (err error) {
|
|
|
|
dit.result, err = dit.masterClient.DescribeIndex(dit.ctx, &dit.DescribeIndexRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dit *DescribeIndexTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeIndexProgressTask struct {
|
|
|
|
Condition
|
|
|
|
internalpb.DescribeIndexProgressRequest
|
|
|
|
masterClient masterpb.MasterClient
|
|
|
|
result *servicepb.BoolResponse
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) ID() UniqueID {
|
|
|
|
return dipt.ReqID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) SetID(uid UniqueID) {
|
|
|
|
dipt.ReqID = uid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) Type() internalpb.MsgType {
|
|
|
|
return dipt.MsgType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) BeginTs() Timestamp {
|
|
|
|
return dipt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) EndTs() Timestamp {
|
|
|
|
return dipt.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) SetTs(ts Timestamp) {
|
|
|
|
dipt.Timestamp = ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) PreExecute() error {
|
|
|
|
collName, fieldName := dipt.CollectionName, dipt.FieldName
|
|
|
|
|
|
|
|
if err := ValidateCollectionName(collName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateFieldName(fieldName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) Execute() (err error) {
|
|
|
|
dipt.result, err = dipt.masterClient.DescribeIndexProgress(dipt.ctx, &dipt.DescribeIndexProgressRequest)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dipt *DescribeIndexProgressTask) PostExecute() error {
|
|
|
|
return nil
|
|
|
|
}
|