2020-10-28 07:38:24 +00:00
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-11-03 06:53:36 +00:00
|
|
|
"log"
|
|
|
|
|
2020-11-12 03:18:23 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2020-12-07 07:22:20 +00:00
|
|
|
ms "github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2020-10-28 07:38:24 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/etcdpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
|
2020-10-29 04:39:41 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/servicepb"
|
2020-10-28 07:38:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type createCollectionTask struct {
|
|
|
|
baseTask
|
2020-10-29 04:39:41 +00:00
|
|
|
req *internalpb.CreateCollectionRequest
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type dropCollectionTask struct {
|
|
|
|
baseTask
|
2021-01-06 11:23:31 +00:00
|
|
|
req *internalpb.DropCollectionRequest
|
|
|
|
segManager SegmentManager
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
type hasCollectionTask struct {
|
|
|
|
baseTask
|
|
|
|
hasCollection bool
|
|
|
|
req *internalpb.HasCollectionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type describeCollectionTask struct {
|
|
|
|
baseTask
|
|
|
|
description *servicepb.CollectionDescription
|
|
|
|
req *internalpb.DescribeCollectionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type showCollectionsTask struct {
|
|
|
|
baseTask
|
|
|
|
stringListResponse *servicepb.StringListResponse
|
|
|
|
req *internalpb.ShowCollectionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:28:14 +00:00
|
|
|
func (t *createCollectionTask) Type() internalpb.MsgType {
|
2020-10-28 07:38:24 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
return t.req.MsgType
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *createCollectionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-12 03:18:23 +00:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
func (t *createCollectionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
2020-10-28 07:38:24 +00:00
|
|
|
var schema schemapb.CollectionSchema
|
2020-11-12 03:18:23 +00:00
|
|
|
err := proto.UnmarshalMerge(t.req.Schema.Value, &schema)
|
2020-10-29 04:39:41 +00:00
|
|
|
if err != nil {
|
2020-11-12 03:18:23 +00:00
|
|
|
return err
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 11:31:24 +00:00
|
|
|
for index, singleFiled := range schema.Fields {
|
|
|
|
singleFiled.FieldID = int64(index + 100)
|
|
|
|
}
|
|
|
|
|
2021-01-04 04:03:29 +00:00
|
|
|
zeroField := &schemapb.FieldSchema{
|
|
|
|
FieldID: int64(0),
|
|
|
|
Name: "RowID",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_INT64,
|
|
|
|
}
|
|
|
|
|
|
|
|
oneField := &schemapb.FieldSchema{
|
|
|
|
FieldID: int64(1),
|
|
|
|
Name: "Timestamp",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_INT64,
|
|
|
|
}
|
|
|
|
|
|
|
|
schema.Fields = append(schema.Fields, zeroField, oneField)
|
|
|
|
|
2020-11-20 09:10:24 +00:00
|
|
|
collectionID, err := t.sch.globalIDAllocator()
|
2020-11-12 03:18:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ts, err := t.Ts()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-28 07:38:24 +00:00
|
|
|
|
|
|
|
collection := etcdpb.CollectionMeta{
|
2020-12-10 08:31:09 +00:00
|
|
|
ID: collectionID,
|
|
|
|
Schema: &schema,
|
|
|
|
CreateTime: ts,
|
|
|
|
SegmentIDs: make([]UniqueID, 0),
|
2020-10-28 07:38:24 +00:00
|
|
|
PartitionTags: make([]string, 0),
|
|
|
|
}
|
2020-12-07 07:22:20 +00:00
|
|
|
err = t.mt.AddCollection(&collection)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-28 07:38:24 +00:00
|
|
|
|
2020-12-07 07:22:20 +00:00
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
|
|
|
BeginTimestamp: t.req.Timestamp,
|
|
|
|
EndTimestamp: t.req.Timestamp,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2020-12-10 08:31:09 +00:00
|
|
|
|
|
|
|
t.req.CollectionID = collectionID
|
2020-12-21 11:31:24 +00:00
|
|
|
t.req.Schema.Value, err = proto.Marshal(&schema)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-07 07:22:20 +00:00
|
|
|
timeTickMsg := &ms.CreateCollectionMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
CreateCollectionRequest: *t.req,
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, timeTickMsg)
|
|
|
|
return t.sch.ddMsgStream.Broadcast(&msgPack)
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:28:14 +00:00
|
|
|
func (t *dropCollectionTask) Type() internalpb.MsgType {
|
2020-10-28 07:38:24 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
return t.req.MsgType
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dropCollectionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-12-07 07:22:20 +00:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
func (t *dropCollectionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionName := t.req.CollectionName.CollectionName
|
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-13 07:17:18 +00:00
|
|
|
collectionID := collectionMeta.ID
|
2020-10-29 04:39:41 +00:00
|
|
|
|
2020-12-07 07:22:20 +00:00
|
|
|
err = t.mt.DeleteCollection(collectionID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-06 11:23:31 +00:00
|
|
|
// before drop collection in segment manager, if segment manager receive a time tick from write node,
|
|
|
|
// maybe this collection can not be found in meta table.
|
|
|
|
if err = t.segManager.DropCollection(collectionID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-07 07:22:20 +00:00
|
|
|
ts, err := t.Ts()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
|
|
|
BeginTimestamp: ts,
|
|
|
|
EndTimestamp: ts,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2020-12-10 08:31:09 +00:00
|
|
|
|
|
|
|
t.req.CollectionID = collectionID
|
2020-12-07 07:22:20 +00:00
|
|
|
timeTickMsg := &ms.DropCollectionMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
DropCollectionRequest: *t.req,
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, timeTickMsg)
|
|
|
|
return t.sch.ddMsgStream.Broadcast(&msgPack)
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:28:14 +00:00
|
|
|
func (t *hasCollectionTask) Type() internalpb.MsgType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
return t.req.MsgType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasCollectionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-12-07 07:22:20 +00:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasCollectionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionName := t.req.CollectionName.CollectionName
|
|
|
|
_, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err == nil {
|
|
|
|
t.hasCollection = true
|
|
|
|
}
|
2020-12-07 06:37:42 +00:00
|
|
|
return nil
|
2020-12-07 07:22:20 +00:00
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:28:14 +00:00
|
|
|
func (t *describeCollectionTask) Type() internalpb.MsgType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
return t.req.MsgType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *describeCollectionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-17 12:00:23 +00:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 03:41:19 +00:00
|
|
|
func (t *describeCollectionTask) filterSchema() error {
|
|
|
|
// remove system field
|
|
|
|
var newFields []*schemapb.FieldSchema
|
|
|
|
for _, fieldMeta := range t.description.Schema.Fields {
|
|
|
|
fieldID := fieldMeta.FieldID
|
|
|
|
// todo not hardcode
|
|
|
|
if fieldID < 100 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
newFields = append(newFields, fieldMeta)
|
|
|
|
}
|
|
|
|
t.description.Schema.Fields = newFields
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
func (t *describeCollectionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionName := t.req.CollectionName
|
|
|
|
collection, err := t.mt.GetCollectionByName(collectionName.CollectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-04 03:41:19 +00:00
|
|
|
cloneSchema := proto.Clone(collection.Schema)
|
|
|
|
t.description.Schema = cloneSchema.(*schemapb.CollectionSchema)
|
|
|
|
return t.filterSchema()
|
2020-12-07 07:22:20 +00:00
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:28:14 +00:00
|
|
|
func (t *showCollectionsTask) Type() internalpb.MsgType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
return t.req.MsgType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showCollectionsTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-17 12:00:23 +00:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showCollectionsTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
2020-10-29 04:39:41 +00:00
|
|
|
|
2020-11-14 07:37:07 +00:00
|
|
|
colls, err := t.mt.ListCollections()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 07:37:07 +00:00
|
|
|
t.stringListResponse.Values = colls
|
2020-10-29 04:39:41 +00:00
|
|
|
|
|
|
|
return nil
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|