2020-10-29 04:39:41 +00:00
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2020-11-03 06:53:36 +00:00
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
|
2020-10-29 04:39:41 +00: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 08:01:28 +00:00
|
|
|
func (t *createPartitionTask) Type() internalpb.ReqType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:01:28 +00:00
|
|
|
return t.req.ReqType
|
2020-10-29 04:39:41 +00: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 {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMeta.PartitionTags = append(collectionMeta.PartitionTags, partitionName.Tag)
|
|
|
|
|
|
|
|
collectionJson, err := json.Marshal(&collectionMeta)
|
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("marshal collection failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionId := collectionMeta.Id
|
2020-10-29 11:55:57 +00:00
|
|
|
err = (*t.kvBase).Save(partitionMetaPrefix+strconv.FormatInt(collectionId, 10), string(collectionJson))
|
2020-10-29 04:39:41 +00:00
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("save collection failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = t.Notify()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:01:28 +00:00
|
|
|
func (t *dropPartitionTask) Type() internalpb.ReqType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:01:28 +00:00
|
|
|
return t.req.ReqType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dropPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
|
|
|
return Timestamp(t.req.Timestamp), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *dropPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-04 08:01:28 +00:00
|
|
|
err = t.mt.DeletePartition(collectionMeta.Id, partitionName.Tag)
|
2020-10-29 04:39:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionJson, err := json.Marshal(&collectionMeta)
|
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("marshal collection failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionId := collectionMeta.Id
|
2020-10-29 11:55:57 +00:00
|
|
|
err = (*t.kvBase).Save(partitionMetaPrefix+strconv.FormatInt(collectionId, 10), string(collectionJson))
|
2020-10-29 04:39:41 +00:00
|
|
|
if err != nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("save collection failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = t.Notify()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:01:28 +00:00
|
|
|
func (t *hasPartitionTask) Type() internalpb.ReqType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:01:28 +00:00
|
|
|
return t.req.ReqType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
|
|
|
return Timestamp(t.req.Timestamp), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *hasPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
collectionName := partitionName.CollectionName
|
2020-11-04 08:01:28 +00:00
|
|
|
collectionMeta, err := t.mt.GetCollectionByName(collectionName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.hasPartition = t.mt.HasPartition(collectionMeta.Id, partitionName.Tag)
|
2020-10-29 04:39:41 +00:00
|
|
|
|
|
|
|
_ = t.Notify()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:01:28 +00:00
|
|
|
func (t *describePartitionTask) Type() internalpb.ReqType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:01:28 +00:00
|
|
|
return t.req.ReqType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *describePartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
|
|
|
return Timestamp(t.req.Timestamp), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *describePartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitionName := t.req.PartitionName
|
|
|
|
|
2020-11-03 06:53:36 +00:00
|
|
|
description := servicepb.PartitionDescription{
|
2020-10-29 04:39:41 +00:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
|
|
|
Name: partitionName,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.description = &description
|
|
|
|
|
|
|
|
_ = t.Notify()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-11-04 08:01:28 +00:00
|
|
|
func (t *showPartitionTask) Type() internalpb.ReqType {
|
2020-10-29 04:39:41 +00:00
|
|
|
if t.req == nil {
|
|
|
|
log.Printf("null request")
|
|
|
|
return 0
|
|
|
|
}
|
2020-11-04 08:01:28 +00:00
|
|
|
return t.req.ReqType
|
2020-10-29 04:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showPartitionTask) Ts() (Timestamp, error) {
|
|
|
|
if t.req == nil {
|
|
|
|
return 0, errors.New("null request")
|
|
|
|
}
|
|
|
|
return Timestamp(t.req.Timestamp), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *showPartitionTask) Execute() error {
|
|
|
|
if t.req == nil {
|
|
|
|
_ = t.Notify()
|
|
|
|
return errors.New("null request")
|
|
|
|
}
|
|
|
|
|
|
|
|
partitions := make([]string, 0)
|
2020-11-02 02:26:33 +00:00
|
|
|
for _, collection := range t.mt.collId2Meta {
|
2020-10-29 04:39:41 +00:00
|
|
|
for _, partition := range collection.PartitionTags {
|
|
|
|
partitions = append(partitions, partition)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 06:53:36 +00:00
|
|
|
stringListResponse := servicepb.StringListResponse{
|
2020-10-29 04:39:41 +00:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
|
|
},
|
|
|
|
Values: partitions,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.stringListResponse = &stringListResponse
|
|
|
|
|
|
|
|
_ = t.Notify()
|
|
|
|
return nil
|
|
|
|
}
|