task.go 19.4 KB
Newer Older
Z
zhenshan.cao 已提交
1 2 3
package proxy

import (
4 5
	"context"
	"errors"
Z
zhenshan.cao 已提交
6
	"log"
N
neza2017 已提交
7 8 9 10
	"math"
	"strconv"

	"github.com/golang/protobuf/proto"
Z
zhenshan.cao 已提交
11

12
	"github.com/zilliztech/milvus-distributed/internal/allocator"
13 14
	"github.com/zilliztech/milvus-distributed/internal/msgstream"
	"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
Z
zhenshan.cao 已提交
15
	"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
16
	"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
N
neza2017 已提交
17
	"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
18
	"github.com/zilliztech/milvus-distributed/internal/proto/servicepb"
Z
zhenshan.cao 已提交
19 20 21
)

type task interface {
22 23
	ID() UniqueID       // return ReqID
	SetID(uid UniqueID) // set ReqID
N
neza2017 已提交
24
	Type() internalpb.MsgType
25 26
	BeginTs() Timestamp
	EndTs() Timestamp
Z
zhenshan.cao 已提交
27
	SetTs(ts Timestamp)
Z
zhenshan.cao 已提交
28 29 30 31
	PreExecute() error
	Execute() error
	PostExecute() error
	WaitToFinish() error
32
	Notify(err error)
Z
zhenshan.cao 已提交
33 34
}

35
type BaseInsertTask = msgstream.InsertMsg
36 37

type InsertTask struct {
38
	BaseInsertTask
D
dragondriver 已提交
39
	Condition
40
	result                *servicepb.IntegerRangeResponse
41 42
	manipulationMsgStream *msgstream.PulsarMsgStream
	ctx                   context.Context
43
	rowIDAllocator        *allocator.IDAllocator
44 45
}

46 47 48 49
func (it *InsertTask) SetID(uid UniqueID) {
	it.ReqID = uid
}

50
func (it *InsertTask) SetTs(ts Timestamp) {
N
neza2017 已提交
51 52 53 54 55 56 57
	rowNum := len(it.RowData)
	it.Timestamps = make([]uint64, rowNum)
	for index := range it.Timestamps {
		it.Timestamps[index] = ts
	}
	it.BeginTimestamp = ts
	it.EndTimestamp = ts
58 59 60
}

func (it *InsertTask) BeginTs() Timestamp {
N
neza2017 已提交
61
	return it.BeginTimestamp
62 63 64
}

func (it *InsertTask) EndTs() Timestamp {
N
neza2017 已提交
65
	return it.EndTimestamp
66 67
}

C
cai.zhang 已提交
68
func (it *InsertTask) ID() UniqueID {
69
	return it.ReqID
70 71 72 73 74 75 76
}

func (it *InsertTask) Type() internalpb.MsgType {
	return it.MsgType
}

func (it *InsertTask) PreExecute() error {
N
neza2017 已提交
77 78 79 80 81 82 83 84 85
	collectionName := it.BaseInsertTask.CollectionName
	if err := ValidateCollectionName(collectionName); err != nil {
		return err
	}
	partitionTag := it.BaseInsertTask.PartitionTag
	if err := ValidatePartitionTag(partitionTag, true); err != nil {
		return err
	}

86 87 88 89
	return nil
}

func (it *InsertTask) Execute() error {
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	collectionName := it.BaseInsertTask.CollectionName
	if !globalMetaCache.Hit(collectionName) {
		err := globalMetaCache.Update(collectionName)
		if err != nil {
			return err
		}
	}
	description, err := globalMetaCache.Get(collectionName)
	if err != nil || description == nil {
		return err
	}
	autoID := description.Schema.AutoID
	if autoID || true {
		rowNums := len(it.BaseInsertTask.RowData)
		rowIDBegin, rowIDEnd, _ := it.rowIDAllocator.Alloc(uint32(rowNums))
		it.BaseInsertTask.RowIDs = make([]UniqueID, rowNums)
		for i := rowIDBegin; i < rowIDEnd; i++ {
			offset := i - rowIDBegin
			it.BaseInsertTask.RowIDs[offset] = i
		}
	}

112
	var tsMsg msgstream.TsMsg = &it.BaseInsertTask
113 114 115
	msgPack := &msgstream.MsgPack{
		BeginTs: it.BeginTs(),
		EndTs:   it.EndTs(),
X
xige-16 已提交
116
		Msgs:    make([]msgstream.TsMsg, 1),
117
	}
X
xige-16 已提交
118
	msgPack.Msgs[0] = tsMsg
119
	err = it.manipulationMsgStream.Produce(msgPack)
120 121 122 123 124 125 126 127 128
	it.result = &servicepb.IntegerRangeResponse{
		Status: &commonpb.Status{
			ErrorCode: commonpb.ErrorCode_SUCCESS,
		},
	}
	if err != nil {
		it.result.Status.ErrorCode = commonpb.ErrorCode_UNEXPECTED_ERROR
		it.result.Status.Reason = err.Error()
	}
129 130 131 132 133 134 135 136
	return nil
}

func (it *InsertTask) PostExecute() error {
	return nil
}

type CreateCollectionTask struct {
D
dragondriver 已提交
137
	Condition
138 139
	internalpb.CreateCollectionRequest
	masterClient masterpb.MasterClient
140
	result       *commonpb.Status
Z
zhenshan.cao 已提交
141
	ctx          context.Context
N
neza2017 已提交
142
	schema       *schemapb.CollectionSchema
143 144
}

C
cai.zhang 已提交
145
func (cct *CreateCollectionTask) ID() UniqueID {
146
	return cct.ReqID
147 148
}

149 150 151 152
func (cct *CreateCollectionTask) SetID(uid UniqueID) {
	cct.ReqID = uid
}

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
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 {
N
neza2017 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	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
	}

	// 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
				}
			}
		}
	}

213
	return nil
Z
zhenshan.cao 已提交
214 215
}

216
func (cct *CreateCollectionTask) Execute() error {
N
neza2017 已提交
217 218
	schemaBytes, _ := proto.Marshal(cct.schema)
	cct.CreateCollectionRequest.Schema.Value = schemaBytes
219 220 221
	resp, err := cct.masterClient.CreateCollection(cct.ctx, &cct.CreateCollectionRequest)
	if err != nil {
		log.Printf("create collection failed, error= %v", err)
222
		cct.result = &commonpb.Status{
223
			ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
Z
zhenshan.cao 已提交
224
			Reason:    err.Error(),
225 226
		}
	} else {
227
		cct.result = resp
228 229
	}
	return err
Z
zhenshan.cao 已提交
230 231
}

232 233
func (cct *CreateCollectionTask) PostExecute() error {
	return nil
Z
zhenshan.cao 已提交
234 235
}

236
type DropCollectionTask struct {
D
dragondriver 已提交
237
	Condition
238 239
	internalpb.DropCollectionRequest
	masterClient masterpb.MasterClient
240
	result       *commonpb.Status
241 242 243
	ctx          context.Context
}

C
cai.zhang 已提交
244
func (dct *DropCollectionTask) ID() UniqueID {
245
	return dct.ReqID
246 247
}

248 249 250 251
func (dct *DropCollectionTask) SetID(uid UniqueID) {
	dct.ReqID = uid
}

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
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 {
N
neza2017 已提交
269 270 271
	if err := ValidateCollectionName(dct.CollectionName.CollectionName); err != nil {
		return err
	}
272 273 274 275 276 277 278
	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)
279
		dct.result = &commonpb.Status{
280 281 282 283
			ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
			Reason:    err.Error(),
		}
	} else {
284
		dct.result = resp
285 286 287 288 289 290 291 292
	}
	return err
}

func (dct *DropCollectionTask) PostExecute() error {
	return nil
}

293
type QueryTask struct {
D
dragondriver 已提交
294
	Condition
295 296 297
	internalpb.SearchRequest
	queryMsgStream *msgstream.PulsarMsgStream
	resultBuf      chan []*internalpb.SearchResult
298
	result         *servicepb.QueryResult
299
	ctx            context.Context
N
neza2017 已提交
300
	query          *servicepb.Query
301 302
}

C
cai.zhang 已提交
303
func (qt *QueryTask) ID() UniqueID {
304
	return qt.ReqID
305 306
}

307 308 309 310
func (qt *QueryTask) SetID(uid UniqueID) {
	qt.ReqID = uid
}

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
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 {
N
neza2017 已提交
328 329 330 331 332 333 334 335 336
	if err := ValidateCollectionName(qt.query.CollectionName); err != nil {
		return err
	}

	for _, tag := range qt.query.PartitionTags {
		if err := ValidatePartitionTag(tag, false); err != nil {
			return err
		}
	}
337 338 339 340 341 342 343 344 345 346 347 348 349 350
	return nil
}

func (qt *QueryTask) Execute() error {
	var tsMsg msgstream.TsMsg = &msgstream.SearchMsg{
		SearchRequest: qt.SearchRequest,
		BaseMsg: msgstream.BaseMsg{
			BeginTimestamp: qt.Timestamp,
			EndTimestamp:   qt.Timestamp,
		},
	}
	msgPack := &msgstream.MsgPack{
		BeginTs: qt.Timestamp,
		EndTs:   qt.Timestamp,
X
xige-16 已提交
351
		Msgs:    make([]msgstream.TsMsg, 1),
352
	}
X
xige-16 已提交
353
	msgPack.Msgs[0] = tsMsg
354 355
	qt.queryMsgStream.Produce(msgPack)
	return nil
356 357 358 359 360 361 362
}

func (qt *QueryTask) PostExecute() error {
	for {
		select {
		case <-qt.ctx.Done():
			log.Print("wait to finish failed, timeout!")
C
cai.zhang 已提交
363
			return errors.New("wait to finish failed, timeout")
364 365 366
		case searchResults := <-qt.resultBuf:
			rlen := len(searchResults) // query num
			if rlen <= 0 {
367
				qt.result = &servicepb.QueryResult{}
D
dragondriver 已提交
368
				return nil
369 370 371
			}
			n := len(searchResults[0].Hits) // n
			if n <= 0 {
372
				qt.result = &servicepb.QueryResult{}
D
dragondriver 已提交
373
				return nil
374
			}
375 376
			var hits [][]*servicepb.Hits = make([][]*servicepb.Hits, rlen)
			for i, sr := range searchResults {
N
neza2017 已提交
377
				hits[i] = make([]*servicepb.Hits, n)
378
				for j, bs := range sr.Hits {
N
neza2017 已提交
379 380 381 382 383 384 385
					err := proto.Unmarshal(bs, hits[i][j])
					if err != nil {
						return err
					}
				}
			}
			k := len(hits[0][0].IDs)
386
			queryResult := &servicepb.QueryResult{
387 388 389 390
				Status: &commonpb.Status{
					ErrorCode: 0,
				},
			}
391 392 393 394 395 396
			// reduce by score, TODO: use better algorithm
			// use merge-sort here, the number of ways to merge is `rlen`
			// in this process, we must make sure:
			//		len(queryResult.Hits) == n
			//		len(queryResult.Hits[i].Ids) == k for i in range(n)
			for i := 0; i < n; n++ { // n
397
				locs := make([]int, rlen)
398
				reducedHits := &servicepb.Hits{}
399
				for j := 0; j < k; j++ { // k
N
neza2017 已提交
400
					choice, minDistance := 0, float32(math.MaxFloat32)
401
					for q, loc := range locs { // query num, the number of ways to merge
N
neza2017 已提交
402 403
						distance := hits[q][i].Scores[loc]
						if distance < minDistance {
404
							choice = q
N
neza2017 已提交
405
							minDistance = distance
406 407 408
						}
					}
					choiceOffset := locs[choice]
N
neza2017 已提交
409
					reducedHits.IDs = append(reducedHits.IDs, hits[choice][i].IDs[choiceOffset])
410
					reducedHits.RowData = append(reducedHits.RowData, hits[choice][i].RowData[choiceOffset])
N
neza2017 已提交
411
					reducedHits.Scores = append(reducedHits.Scores, hits[choice][i].Scores[choiceOffset])
412 413
					locs[choice]++
				}
N
neza2017 已提交
414 415 416 417
				reducedHitsBs, err := proto.Marshal(reducedHits)
				if err != nil {
					return err
				}
418
				queryResult.Hits = append(queryResult.Hits, reducedHitsBs)
419
			}
420
			qt.result = queryResult
421 422
		}
	}
423
	//return nil
D
dragondriver 已提交
424 425
}

426
type HasCollectionTask struct {
D
dragondriver 已提交
427
	Condition
428 429
	internalpb.HasCollectionRequest
	masterClient masterpb.MasterClient
430
	result       *servicepb.BoolResponse
431 432 433
	ctx          context.Context
}

C
cai.zhang 已提交
434
func (hct *HasCollectionTask) ID() UniqueID {
435
	return hct.ReqID
436 437
}

438 439 440 441
func (hct *HasCollectionTask) SetID(uid UniqueID) {
	hct.ReqID = uid
}

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
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 {
N
neza2017 已提交
459 460 461
	if err := ValidateCollectionName(hct.CollectionName.CollectionName); err != nil {
		return err
	}
462 463 464 465 466 467 468
	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)
469
		hct.result = &servicepb.BoolResponse{
470 471 472 473 474 475 476
			Status: &commonpb.Status{
				ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
				Reason:    "internal error",
			},
			Value: false,
		}
	} else {
477
		hct.result = resp
478 479 480 481 482 483 484 485 486
	}
	return err
}

func (hct *HasCollectionTask) PostExecute() error {
	return nil
}

type DescribeCollectionTask struct {
D
dragondriver 已提交
487
	Condition
488 489
	internalpb.DescribeCollectionRequest
	masterClient masterpb.MasterClient
490
	result       *servicepb.CollectionDescription
491 492 493
	ctx          context.Context
}

C
cai.zhang 已提交
494
func (dct *DescribeCollectionTask) ID() UniqueID {
495
	return dct.ReqID
496 497
}

498 499 500 501
func (dct *DescribeCollectionTask) SetID(uid UniqueID) {
	dct.ReqID = uid
}

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
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 {
N
neza2017 已提交
519 520 521
	if err := ValidateCollectionName(dct.CollectionName.CollectionName); err != nil {
		return err
	}
522 523 524 525
	return nil
}

func (dct *DescribeCollectionTask) Execute() error {
526 527 528 529
	if !globalMetaCache.Hit(dct.CollectionName.CollectionName) {
		err := globalMetaCache.Update(dct.CollectionName.CollectionName)
		if err != nil {
			return err
530 531
		}
	}
532 533
	var err error
	dct.result, err = globalMetaCache.Get(dct.CollectionName.CollectionName)
534 535 536 537 538 539 540 541
	return err
}

func (dct *DescribeCollectionTask) PostExecute() error {
	return nil
}

type ShowCollectionsTask struct {
D
dragondriver 已提交
542
	Condition
543 544
	internalpb.ShowCollectionRequest
	masterClient masterpb.MasterClient
545
	result       *servicepb.StringListResponse
546 547 548
	ctx          context.Context
}

C
cai.zhang 已提交
549
func (sct *ShowCollectionsTask) ID() UniqueID {
550
	return sct.ReqID
551 552
}

553 554 555 556
func (sct *ShowCollectionsTask) SetID(uid UniqueID) {
	sct.ReqID = uid
}

557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
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)
581
		sct.result = &servicepb.StringListResponse{
582 583 584 585 586 587
			Status: &commonpb.Status{
				ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
				Reason:    "internal error",
			},
		}
	} else {
588
		sct.result = resp
589 590 591 592 593 594 595
	}
	return err
}

func (sct *ShowCollectionsTask) PostExecute() error {
	return nil
}
N
neza2017 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608

type CreatePartitionTask struct {
	Condition
	internalpb.CreatePartitionRequest
	masterClient masterpb.MasterClient
	result       *commonpb.Status
	ctx          context.Context
}

func (cpt *CreatePartitionTask) ID() UniqueID {
	return cpt.ReqID
}

609 610 611 612
func (cpt *CreatePartitionTask) SetID(uid UniqueID) {
	cpt.ReqID = uid
}

N
neza2017 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
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 {
N
neza2017 已提交
630 631 632 633 634 635 636 637 638 639
	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
	}

N
neza2017 已提交
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
	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
}

664 665 666 667
func (dpt *DropPartitionTask) SetID(uid UniqueID) {
	dpt.ReqID = uid
}

N
neza2017 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
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 {
N
neza2017 已提交
685 686 687 688 689 690 691 692 693 694
	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
	}

N
neza2017 已提交
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
	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
}

719 720 721 722
func (hpt *HasPartitionTask) SetID(uid UniqueID) {
	hpt.ReqID = uid
}

N
neza2017 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
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 {
N
neza2017 已提交
740 741 742 743 744 745 746 747 748
	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
	}
N
neza2017 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
	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
}

773 774 775 776
func (dpt *DescribePartitionTask) SetID(uid UniqueID) {
	dpt.ReqID = uid
}

N
neza2017 已提交
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
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 {
N
neza2017 已提交
794 795 796 797 798 799 800 801 802
	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
	}
N
neza2017 已提交
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
	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
}

827 828 829 830
func (spt *ShowPartitionsTask) SetID(uid UniqueID) {
	spt.ReqID = uid
}

N
neza2017 已提交
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
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 {
N
neza2017 已提交
848 849 850
	if err := ValidateCollectionName(spt.CollectionName.CollectionName); err != nil {
		return err
	}
N
neza2017 已提交
851 852 853 854 855 856 857 858 859 860 861
	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
}