2020-10-29 12:39:41 +08:00
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-11-03 14:53:36 +08:00
|
|
|
"log"
|
|
|
|
|
2020-12-07 15:22:20 +08:00
|
|
|
ms "github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2020-10-29 12:39:41 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/servicepb"
|
|
|
|
)
|
|
|
|
|
|
|
|
const partitionMetaPrefix = "partition/"
|
|
|
|
|
|
|
|
type createPartitionTask struct {
|
|
|
|
baseTask
|
|
|
|
req *internalpb.CreatePartitionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type dropPartitionTask struct {
|
|
|
|
baseTask
|
|
|
|
req *internalpb.DropPartitionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type hasPartitionTask struct {
|
|
|
|
baseTask
|
|
|
|
hasPartition bool
|
|
|
|
req *internalpb.HasPartitionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type describePartitionTask struct {
|
|
|
|
baseTask
|
|
|
|
description *servicepb.PartitionDescription
|
|
|
|
req *internalpb.DescribePartitionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
type showPartitionTask struct {
|
|
|
|
baseTask
|
|
|
|
stringListResponse *servicepb.StringListResponse
|
|
|
|
req *internalpb.ShowPartitionRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 16:28:14 +08:00
|
|
|
func (t *createPartitionTask) Type() internalpb.MsgType {
|
2020-10-29 12:39:41 +08:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 16:28:14 +08:00
|
|
|
return t.req.MsgType
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *createPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
|
|
|
return Timestamp(t.req.Timestamp), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *createPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
ts, err := t.Ts()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = t.mt.AddPartition(collectionMeta.ID, partitionName.Tag)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
|
|
|
BeginTimestamp: ts,
|
|
|
|
EndTimestamp: ts,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2020-12-10 16:31:09 +08:00
|
|
|
|
|
|
|
t.req.CollectionID = collectionMeta.ID
|
2020-12-07 15:22:20 +08:00
|
|
|
timeTickMsg := &ms.CreatePartitionMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
CreatePartitionRequest: *t.req,
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, timeTickMsg)
|
|
|
|
return t.sch.ddMsgStream.Broadcast(&msgPack)
|
|
|
|
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 16:28:14 +08:00
|
|
|
func (t *dropPartitionTask) Type() internalpb.MsgType {
|
2020-10-29 12:39:41 +08:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 16:28:14 +08:00
|
|
|
return t.req.MsgType
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dropPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-13 17:20:13 +08:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dropPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
|
|
|
|
if err != nil {
|
2020-11-12 11:18:23 +08:00
|
|
|
return err
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 15:22:20 +08:00
|
|
|
err = t.mt.DeletePartition(collectionMeta.ID, partitionName.Tag)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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 16:31:09 +08:00
|
|
|
|
|
|
|
t.req.CollectionID = collectionMeta.ID
|
2020-12-07 15:22:20 +08:00
|
|
|
timeTickMsg := &ms.DropPartitionMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
DropPartitionRequest: *t.req,
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, timeTickMsg)
|
|
|
|
return t.sch.ddMsgStream.Broadcast(&msgPack)
|
|
|
|
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 16:28:14 +08:00
|
|
|
func (t *hasPartitionTask) Type() internalpb.MsgType {
|
2020-10-29 12:39:41 +08:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 16:28:14 +08:00
|
|
|
return t.req.MsgType
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-13 17:20:13 +08:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
2020-11-04 16:01:28 +08:00
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:17:18 +08:00
|
|
|
t.hasPartition = t.mt.HasPartition(collectionMeta.ID, partitionName.Tag)
|
2020-10-29 12:39:41 +08:00
|
|
|
|
|
|
|
return nil
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 16:28:14 +08:00
|
|
|
func (t *describePartitionTask) Type() internalpb.MsgType {
|
2020-10-29 12:39:41 +08:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 16:28:14 +08:00
|
|
|
return t.req.MsgType
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *describePartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-14 13:06:41 +08:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *describePartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
|
2020-11-03 14:53:36 +08:00
|
|
|
description := servicepb.PartitionDescription{
|
2020-10-29 12:39:41 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
2020-11-14 13:06:41 +08:00
|
|
|
Name: partitionName,
|
|
|
|
Statistics: nil,
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t.description = &description
|
|
|
|
|
|
|
|
return nil
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 16:28:14 +08:00
|
|
|
func (t *showPartitionTask) Type() internalpb.MsgType {
|
2020-10-29 12:39:41 +08:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 16:28:14 +08:00
|
|
|
return t.req.MsgType
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
2020-11-14 13:06:41 +08:00
|
|
|
return t.req.Timestamp, nil
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
collMeta, err := t.mt.GetCollectionByName(t.req.CollectionName.CollectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-11-26 15:18:36 +08:00
|
|
|
}
|
2020-11-26 16:01:31 +08:00
|
|
|
partitions := make([]string, 0)
|
|
|
|
partitions = append(partitions, collMeta.PartitionTags...)
|
2020-10-29 12:39:41 +08:00
|
|
|
|
2020-11-03 14:53:36 +08:00
|
|
|
stringListResponse := servicepb.StringListResponse{
|
2020-10-29 12:39:41 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
|
|
|
Values: partitions,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.stringListResponse = &stringListResponse
|
|
|
|
|
|
|
|
return nil
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2020-10-29 12:39:41 +08:00
|
|
|
}
|