task.go 19.9 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
	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 {
		return err
	}
	qt.Query = &commonpb.Blob{
		Value: queryBytes,
	}
348 349 350 351 352 353 354
	return nil
}

func (qt *QueryTask) Execute() error {
	var tsMsg msgstream.TsMsg = &msgstream.SearchMsg{
		SearchRequest: qt.SearchRequest,
		BaseMsg: msgstream.BaseMsg{
355
			HashValues:     []int32{int32(Params.ProxyID())},
356 357 358 359 360 361 362
			BeginTimestamp: qt.Timestamp,
			EndTimestamp:   qt.Timestamp,
		},
	}
	msgPack := &msgstream.MsgPack{
		BeginTs: qt.Timestamp,
		EndTs:   qt.Timestamp,
X
xige-16 已提交
363
		Msgs:    make([]msgstream.TsMsg, 1),
364
	}
X
xige-16 已提交
365
	msgPack.Msgs[0] = tsMsg
366 367 368 369 370 371
	err := qt.queryMsgStream.Produce(msgPack)
	log.Printf("[Proxy] length of searchMsg: %v", len(msgPack.Msgs))
	if err != nil {
		log.Printf("[Proxy] send search request failed: %v", err)
	}
	return err
372 373 374 375 376 377 378
}

func (qt *QueryTask) PostExecute() error {
	for {
		select {
		case <-qt.ctx.Done():
			log.Print("wait to finish failed, timeout!")
C
cai.zhang 已提交
379
			return errors.New("wait to finish failed, timeout")
380 381 382
		case searchResults := <-qt.resultBuf:
			rlen := len(searchResults) // query num
			if rlen <= 0 {
383
				qt.result = &servicepb.QueryResult{}
D
dragondriver 已提交
384
				return nil
385
			}
386

387 388
			n := len(searchResults[0].Hits) // n
			if n <= 0 {
389
				qt.result = &servicepb.QueryResult{}
D
dragondriver 已提交
390
				return nil
391
			}
392 393 394

			hits := make([][]*servicepb.Hits, rlen)
			for i, searchResult := range searchResults {
N
neza2017 已提交
395
				hits[i] = make([]*servicepb.Hits, n)
396 397
				for j, bs := range searchResult.Hits {
					hits[i][j] = &servicepb.Hits{}
N
neza2017 已提交
398 399 400 401 402 403
					err := proto.Unmarshal(bs, hits[i][j])
					if err != nil {
						return err
					}
				}
			}
404

N
neza2017 已提交
405
			k := len(hits[0][0].IDs)
406
			qt.result = &servicepb.QueryResult{
407 408 409
				Status: &commonpb.Status{
					ErrorCode: 0,
				},
410
				Hits: make([][]byte, 0),
411
			}
412 413

			for i := 0; i < n; i++ { // n
414
				locs := make([]int, rlen)
415 416 417 418 419 420
				reducedHits := &servicepb.Hits{
					IDs:     make([]int64, 0),
					RowData: make([][]byte, 0),
					Scores:  make([]float32, 0),
				}

421
				for j := 0; j < k; j++ { // k
N
neza2017 已提交
422
					choice, minDistance := 0, float32(math.MaxFloat32)
423
					for q, loc := range locs { // query num, the number of ways to merge
N
neza2017 已提交
424 425
						distance := hits[q][i].Scores[loc]
						if distance < minDistance {
426
							choice = q
N
neza2017 已提交
427
							minDistance = distance
428 429 430
						}
					}
					choiceOffset := locs[choice]
N
neza2017 已提交
431
					reducedHits.IDs = append(reducedHits.IDs, hits[choice][i].IDs[choiceOffset])
432 433 434
					if hits[choice][i].RowData != nil && len(hits[choice][i].RowData) > 0 {
						reducedHits.RowData = append(reducedHits.RowData, hits[choice][i].RowData[choiceOffset])
					}
N
neza2017 已提交
435
					reducedHits.Scores = append(reducedHits.Scores, hits[choice][i].Scores[choiceOffset])
436 437
					locs[choice]++
				}
N
neza2017 已提交
438 439 440 441
				reducedHitsBs, err := proto.Marshal(reducedHits)
				if err != nil {
					return err
				}
442
				qt.result.Hits = append(qt.result.Hits, reducedHitsBs)
443
			}
444
			return nil
445 446
		}
	}
D
dragondriver 已提交
447 448
}

449
type HasCollectionTask struct {
D
dragondriver 已提交
450
	Condition
451 452
	internalpb.HasCollectionRequest
	masterClient masterpb.MasterClient
453
	result       *servicepb.BoolResponse
454 455 456
	ctx          context.Context
}

C
cai.zhang 已提交
457
func (hct *HasCollectionTask) ID() UniqueID {
458
	return hct.ReqID
459 460
}

461 462 463 464
func (hct *HasCollectionTask) SetID(uid UniqueID) {
	hct.ReqID = uid
}

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
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 已提交
482 483 484
	if err := ValidateCollectionName(hct.CollectionName.CollectionName); err != nil {
		return err
	}
485 486 487 488 489 490 491
	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)
492
		hct.result = &servicepb.BoolResponse{
493 494 495 496 497 498 499
			Status: &commonpb.Status{
				ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
				Reason:    "internal error",
			},
			Value: false,
		}
	} else {
500
		hct.result = resp
501 502 503 504 505 506 507 508 509
	}
	return err
}

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

type DescribeCollectionTask struct {
D
dragondriver 已提交
510
	Condition
511 512
	internalpb.DescribeCollectionRequest
	masterClient masterpb.MasterClient
513
	result       *servicepb.CollectionDescription
514 515 516
	ctx          context.Context
}

C
cai.zhang 已提交
517
func (dct *DescribeCollectionTask) ID() UniqueID {
518
	return dct.ReqID
519 520
}

521 522 523 524
func (dct *DescribeCollectionTask) SetID(uid UniqueID) {
	dct.ReqID = uid
}

525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
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 已提交
542 543 544
	if err := ValidateCollectionName(dct.CollectionName.CollectionName); err != nil {
		return err
	}
545 546 547 548
	return nil
}

func (dct *DescribeCollectionTask) Execute() error {
549 550 551 552
	if !globalMetaCache.Hit(dct.CollectionName.CollectionName) {
		err := globalMetaCache.Update(dct.CollectionName.CollectionName)
		if err != nil {
			return err
553 554
		}
	}
555 556
	var err error
	dct.result, err = globalMetaCache.Get(dct.CollectionName.CollectionName)
557 558 559 560 561 562 563 564
	return err
}

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

type ShowCollectionsTask struct {
D
dragondriver 已提交
565
	Condition
566 567
	internalpb.ShowCollectionRequest
	masterClient masterpb.MasterClient
568
	result       *servicepb.StringListResponse
569 570 571
	ctx          context.Context
}

C
cai.zhang 已提交
572
func (sct *ShowCollectionsTask) ID() UniqueID {
573
	return sct.ReqID
574 575
}

576 577 578 579
func (sct *ShowCollectionsTask) SetID(uid UniqueID) {
	sct.ReqID = uid
}

580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
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)
604
		sct.result = &servicepb.StringListResponse{
605 606 607 608 609 610
			Status: &commonpb.Status{
				ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
				Reason:    "internal error",
			},
		}
	} else {
611
		sct.result = resp
612 613 614 615 616 617 618
	}
	return err
}

func (sct *ShowCollectionsTask) PostExecute() error {
	return nil
}
N
neza2017 已提交
619 620 621 622 623 624 625 626 627 628 629 630 631

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

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

632 633 634 635
func (cpt *CreatePartitionTask) SetID(uid UniqueID) {
	cpt.ReqID = uid
}

N
neza2017 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
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 已提交
653 654 655 656 657 658 659 660 661 662
	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 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
	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
}

687 688 689 690
func (dpt *DropPartitionTask) SetID(uid UniqueID) {
	dpt.ReqID = uid
}

N
neza2017 已提交
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
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 已提交
708 709 710 711 712 713 714 715 716 717
	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 已提交
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
	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
}

742 743 744 745
func (hpt *HasPartitionTask) SetID(uid UniqueID) {
	hpt.ReqID = uid
}

N
neza2017 已提交
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
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 已提交
763 764 765 766 767 768 769 770 771
	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 已提交
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
	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
}

796 797 798 799
func (dpt *DescribePartitionTask) SetID(uid UniqueID) {
	dpt.ReqID = uid
}

N
neza2017 已提交
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
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 已提交
817 818 819 820 821 822 823 824 825
	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 已提交
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
	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
}

850 851 852 853
func (spt *ShowPartitionsTask) SetID(uid UniqueID) {
	spt.ReqID = uid
}

N
neza2017 已提交
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
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 已提交
871 872 873
	if err := ValidateCollectionName(spt.CollectionName.CollectionName); err != nil {
		return err
	}
N
neza2017 已提交
874 875 876 877 878 879 880 881 882 883 884
	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
}