2021-04-19 11:12:56 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-06-18 21:30:08 +08:00
|
|
|
package rootcoord
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-12 15:33:53 +08:00
|
|
|
"encoding/json"
|
2021-08-25 14:41:52 +08:00
|
|
|
"errors"
|
2021-01-24 20:26:35 +08:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2021-05-24 09:44:49 +08:00
|
|
|
"path"
|
2021-01-24 20:26:35 +08:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
2021-09-14 11:59:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-09-15 22:05:49 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/kv"
|
2021-04-22 14:45:57 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-09-15 22:05:49 +08:00
|
|
|
memkv "github.com/milvus-io/milvus/internal/kv/mem"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-09-14 11:59:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-09-15 22:05:49 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
2021-07-03 14:36:18 +08:00
|
|
|
|
2021-05-15 18:08:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-07-03 14:36:18 +08:00
|
|
|
|
2021-06-22 16:14:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-05-21 16:08:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-01-24 20:26:35 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-09-15 22:05:49 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-08-24 09:45:51 +08:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
2021-01-24 20:26:35 +08:00
|
|
|
)
|
|
|
|
|
2021-09-09 17:39:30 +08:00
|
|
|
const TestDMLChannelNum = 32
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
type proxyMock struct {
|
|
|
|
types.Proxy
|
2021-05-26 20:14:30 +08:00
|
|
|
collArray []string
|
|
|
|
mutex sync.Mutex
|
|
|
|
}
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
func (p *proxyMock) InvalidateCollectionMetaCache(ctx context.Context, request *proxypb.InvalidateCollMetaCacheRequest) (*commonpb.Status, error) {
|
2021-01-24 20:26:35 +08:00
|
|
|
p.mutex.Lock()
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
p.collArray = append(p.collArray, request.CollectionName)
|
2021-02-04 19:34:35 +08:00
|
|
|
return &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-04 19:34:35 +08:00
|
|
|
}, nil
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-06-22 19:08:03 +08:00
|
|
|
func (p *proxyMock) GetCollArray() []string {
|
2021-01-24 20:26:35 +08:00
|
|
|
p.mutex.Lock()
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
ret := make([]string, 0, len(p.collArray))
|
|
|
|
ret = append(ret, p.collArray...)
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:16:37 +08:00
|
|
|
func (p *proxyMock) ReleaseDQLMessageStream(ctx context.Context, request *proxypb.ReleaseDQLMessageStreamRequest) (*commonpb.Status, error) {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
type dataMock struct {
|
2021-06-21 18:22:13 +08:00
|
|
|
types.DataCoord
|
2021-01-24 20:26:35 +08:00
|
|
|
randVal int
|
2021-07-03 14:36:18 +08:00
|
|
|
mu sync.Mutex
|
|
|
|
segs []typeutil.UniqueID
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-25 16:48:10 +08:00
|
|
|
func (d *dataMock) Init() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataMock) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (d *dataMock) GetInsertBinlogPaths(ctx context.Context, req *datapb.GetInsertBinlogPathsRequest) (*datapb.GetInsertBinlogPathsResponse, error) {
|
|
|
|
rst := &datapb.GetInsertBinlogPathsResponse{
|
2021-01-24 20:26:35 +08:00
|
|
|
FieldIDs: []int64{},
|
2021-03-12 14:22:09 +08:00
|
|
|
Paths: []*internalpb.StringList{},
|
2021-01-24 20:26:35 +08:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-24 20:26:35 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i := 0; i < 200; i++ {
|
|
|
|
rst.FieldIDs = append(rst.FieldIDs, int64(i))
|
2021-03-12 14:22:09 +08:00
|
|
|
path := &internalpb.StringList{
|
2021-01-24 20:26:35 +08:00
|
|
|
Values: []string{fmt.Sprintf("file0-%d", i), fmt.Sprintf("file1-%d", i), fmt.Sprintf("file2-%d", i)},
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-24 20:26:35 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
rst.Paths = append(rst.Paths, path)
|
|
|
|
}
|
|
|
|
return rst, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (d *dataMock) GetSegmentInfo(ctx context.Context, req *datapb.GetSegmentInfoRequest) (*datapb.GetSegmentInfoResponse, error) {
|
|
|
|
return &datapb.GetSegmentInfoResponse{
|
2021-03-08 15:46:51 +08:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-03-08 15:46:51 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Infos: []*datapb.SegmentInfo{
|
|
|
|
{
|
2021-06-04 11:45:45 +08:00
|
|
|
NumOfRows: Params.MinSegmentSizeToEnableIndex,
|
|
|
|
State: commonpb.SegmentState_Flushed,
|
2021-03-08 15:46:51 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
func (d *dataMock) GetFlushedSegments(ctx context.Context, req *datapb.GetFlushedSegmentsRequest) (*datapb.GetFlushedSegmentsResponse, error) {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
|
|
|
|
rsp := &datapb.GetFlushedSegmentsResponse{
|
2021-03-13 17:05:36 +08:00
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-07-03 14:36:18 +08:00
|
|
|
Reason: "",
|
2021-03-13 17:05:36 +08:00
|
|
|
},
|
2021-07-03 14:36:18 +08:00
|
|
|
}
|
|
|
|
rsp.Segments = append(rsp.Segments, d.segs...)
|
|
|
|
return rsp, nil
|
2021-03-13 17:05:36 +08:00
|
|
|
}
|
|
|
|
|
2021-02-05 14:09:55 +08:00
|
|
|
type queryMock struct {
|
2021-06-22 16:44:09 +08:00
|
|
|
types.QueryCoord
|
2021-02-05 14:09:55 +08:00
|
|
|
collID []typeutil.UniqueID
|
|
|
|
mutex sync.Mutex
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:48:10 +08:00
|
|
|
func (q *queryMock) Init() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *queryMock) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
func (q *queryMock) ReleaseCollection(ctx context.Context, req *querypb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2021-02-05 14:09:55 +08:00
|
|
|
q.mutex.Lock()
|
|
|
|
defer q.mutex.Unlock()
|
|
|
|
q.collID = append(q.collID, req.CollectionID)
|
|
|
|
return &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-05 14:09:55 +08:00
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:08:08 +08:00
|
|
|
func (q *queryMock) ReleasePartitions(ctx context.Context, req *querypb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
type indexMock struct {
|
2021-06-21 17:28:03 +08:00
|
|
|
types.IndexCoord
|
2021-02-20 15:38:44 +08:00
|
|
|
fileArray []string
|
|
|
|
idxBuildID []int64
|
|
|
|
idxID []int64
|
|
|
|
idxDropID []int64
|
|
|
|
mutex sync.Mutex
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-25 16:48:10 +08:00
|
|
|
func (idx *indexMock) Init() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (idx *indexMock) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
func (idx *indexMock) BuildIndex(ctx context.Context, req *indexpb.BuildIndexRequest) (*indexpb.BuildIndexResponse, error) {
|
2021-01-24 20:26:35 +08:00
|
|
|
idx.mutex.Lock()
|
|
|
|
defer idx.mutex.Unlock()
|
|
|
|
idx.fileArray = append(idx.fileArray, req.DataPaths...)
|
2021-02-20 15:38:44 +08:00
|
|
|
idx.idxBuildID = append(idx.idxBuildID, rand.Int63())
|
|
|
|
idx.idxID = append(idx.idxID, req.IndexID)
|
2021-01-24 20:26:35 +08:00
|
|
|
return &indexpb.BuildIndexResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-24 20:26:35 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
2021-02-20 15:38:44 +08:00
|
|
|
IndexBuildID: idx.idxBuildID[len(idx.idxBuildID)-1],
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
func (idx *indexMock) DropIndex(ctx context.Context, req *indexpb.DropIndexRequest) (*commonpb.Status, error) {
|
2021-02-20 15:38:44 +08:00
|
|
|
idx.mutex.Lock()
|
|
|
|
defer idx.mutex.Unlock()
|
|
|
|
idx.idxDropID = append(idx.idxDropID, req.IndexID)
|
|
|
|
return &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-20 15:38:44 +08:00
|
|
|
Reason: "",
|
2021-01-24 20:26:35 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (idx *indexMock) getFileArray() []string {
|
|
|
|
idx.mutex.Lock()
|
|
|
|
defer idx.mutex.Unlock()
|
|
|
|
|
|
|
|
ret := make([]string, 0, len(idx.fileArray))
|
|
|
|
ret = append(ret, idx.fileArray...)
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
func clearMsgChan(timeout time.Duration, targetChan <-chan *msgstream.MsgPack) {
|
2021-05-31 16:48:31 +08:00
|
|
|
ch := time.After(timeout)
|
2021-02-04 14:37:12 +08:00
|
|
|
for {
|
|
|
|
select {
|
2021-05-31 16:48:31 +08:00
|
|
|
case <-ch:
|
2021-02-04 14:37:12 +08:00
|
|
|
return
|
|
|
|
case <-targetChan:
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
func getNotTtMsg(ctx context.Context, n int, ch <-chan *msgstream.MsgPack) []msgstream.TsMsg {
|
|
|
|
ret := make([]msgstream.TsMsg, 0, n)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil
|
|
|
|
case msg, ok := <-ch:
|
|
|
|
if ok {
|
|
|
|
for _, v := range msg.Msgs {
|
|
|
|
if _, ok := v.(*msgstream.TimeTickMsg); !ok {
|
|
|
|
ret = append(ret, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(ret) >= n {
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
func createCollectionInMeta(dbName, collName string, core *Core, shardsNum int32, modifyFunc func(*etcdpb.CollectionInfo)) error {
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: collName,
|
|
|
|
}
|
|
|
|
|
|
|
|
sbf, err := proto.Marshal(&schema)
|
2021-09-09 17:39:30 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
t := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
Timestamp: 100,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
Schema: sbf,
|
|
|
|
ShardsNum: shardsNum,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = proto.Unmarshal(t.Schema, &schema)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unmarshal schema error= %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, field := range schema.Fields {
|
|
|
|
field.FieldID = int64(idx + StartOfUserFieldID)
|
|
|
|
}
|
|
|
|
rowIDField := &schemapb.FieldSchema{
|
|
|
|
FieldID: int64(RowIDField),
|
|
|
|
Name: RowIDFieldName,
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "row id",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
}
|
|
|
|
timeStampField := &schemapb.FieldSchema{
|
|
|
|
FieldID: int64(TimeStampField),
|
|
|
|
Name: TimeStampFieldName,
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "time stamp",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
}
|
|
|
|
schema.Fields = append(schema.Fields, rowIDField, timeStampField)
|
|
|
|
|
|
|
|
collID, _, err := core.IDAllocator(1)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("alloc collection id error = %w", err)
|
|
|
|
}
|
|
|
|
partID, _, err := core.IDAllocator(1)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("alloc partition id error = %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
vchanNames := make([]string, t.ShardsNum)
|
|
|
|
chanNames := make([]string, t.ShardsNum)
|
|
|
|
for i := int32(0); i < t.ShardsNum; i++ {
|
2021-09-10 13:00:00 +08:00
|
|
|
vchanNames[i] = fmt.Sprintf("%s_%d_%d_v%d", collName, collID, i, i)
|
2021-09-08 15:00:00 +08:00
|
|
|
chanNames[i] = ToPhysicalChannel(vchanNames[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
collInfo := etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
Schema: &schema,
|
|
|
|
PartitionIDs: []typeutil.UniqueID{partID},
|
|
|
|
PartitionNames: []string{Params.DefaultPartitionName},
|
|
|
|
FieldIndexes: make([]*etcdpb.FieldIndexInfo, 0, 16),
|
|
|
|
VirtualChannelNames: vchanNames,
|
|
|
|
PhysicalChannelNames: chanNames,
|
|
|
|
ShardsNum: 0, // intend to set zero
|
|
|
|
PartitionCreatedTimestamps: []uint64{0},
|
|
|
|
}
|
|
|
|
|
|
|
|
if modifyFunc != nil {
|
|
|
|
modifyFunc(&collInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
idxInfo := make([]*etcdpb.IndexInfo, 0, 16)
|
|
|
|
|
|
|
|
// schema is modified (add RowIDField and TimestampField),
|
|
|
|
// so need Marshal again
|
|
|
|
schemaBytes, err := proto.Marshal(&schema)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("marshal schema error = %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ddCollReq := internalpb.CreateCollectionRequest{
|
|
|
|
Base: t.Base,
|
|
|
|
DbName: t.DbName,
|
|
|
|
CollectionName: t.CollectionName,
|
|
|
|
PartitionName: Params.DefaultPartitionName,
|
|
|
|
DbID: 0, //TODO,not used
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
Schema: schemaBytes,
|
|
|
|
VirtualChannelNames: vchanNames,
|
|
|
|
PhysicalChannelNames: chanNames,
|
|
|
|
}
|
|
|
|
|
|
|
|
// build DdOperation and save it into etcd, when ddmsg send fail,
|
|
|
|
// system can restore ddmsg from etcd and re-send
|
|
|
|
ddOp := func(ts typeutil.Timestamp) (string, error) {
|
|
|
|
ddCollReq.Base.Timestamp = ts
|
|
|
|
return EncodeDdOperation(&ddCollReq, CreateCollectionDDType)
|
|
|
|
}
|
|
|
|
|
|
|
|
reason := fmt.Sprintf("create collection %d", collID)
|
|
|
|
ts, err := core.TSOAllocator(1)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("TSO alloc fail, error = %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// use lambda function here to guarantee all resources to be released
|
|
|
|
createCollectionFn := func() error {
|
|
|
|
// lock for ddl operation
|
|
|
|
core.ddlLock.Lock()
|
|
|
|
defer core.ddlLock.Unlock()
|
|
|
|
|
|
|
|
core.chanTimeTick.AddDdlTimeTick(ts, reason)
|
|
|
|
// clear ddl timetick in all conditions
|
|
|
|
defer core.chanTimeTick.RemoveDdlTimeTick(ts, reason)
|
|
|
|
|
|
|
|
err = core.MetaTable.AddCollection(&collInfo, ts, idxInfo, ddOp)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("meta table add collection failed,error = %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = createCollectionFn()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
// a mock kv that always fail when LoadWithPrefix
|
|
|
|
type loadPrefixFailKV struct {
|
|
|
|
kv.TxnKV
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadWithPrefix override behavior
|
|
|
|
func (kv *loadPrefixFailKV) LoadWithPrefix(key string) ([]string, []string, error) {
|
|
|
|
return []string{}, []string{}, retry.NoRetryError(errors.New("mocked fail"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCoordInit(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
coreFactory := msgstream.NewPmsFactory()
|
|
|
|
Params.Init()
|
|
|
|
Params.DmlChannelNum = TestDMLChannelNum
|
|
|
|
core, err := NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal := rand.Int()
|
|
|
|
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = core.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
// inject kvBaseCreate fail
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal = rand.Int()
|
|
|
|
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
|
|
|
return nil, retry.NoRetryError(errors.New("injected"))
|
|
|
|
}
|
|
|
|
err = core.Init()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// inject metaKV create fail
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal = rand.Int()
|
|
|
|
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
core.kvBaseCreate = func(root string) (kv.TxnKV, error) {
|
|
|
|
if root == Params.MetaRootPath {
|
|
|
|
return nil, retry.NoRetryError(errors.New("injected"))
|
|
|
|
}
|
|
|
|
return memkv.NewMemoryKV(), nil
|
|
|
|
}
|
|
|
|
err = core.Init()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// inject newSuffixSnapshot failure
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal = rand.Int()
|
|
|
|
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
err = core.Init()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
// inject newMetaTable failure
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal = rand.Int()
|
|
|
|
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
|
|
|
kv := memkv.NewMemoryKV()
|
|
|
|
return &loadPrefixFailKV{TxnKV: kv}, nil
|
|
|
|
}
|
|
|
|
err = core.Init()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:14:08 +08:00
|
|
|
func TestRootCoord(t *testing.T) {
|
2021-05-17 19:15:01 +08:00
|
|
|
const (
|
|
|
|
dbName = "testDb"
|
|
|
|
collName = "testColl"
|
|
|
|
partName = "testPartition"
|
2021-06-02 22:36:41 +08:00
|
|
|
segID = 1001
|
2021-05-17 19:15:01 +08:00
|
|
|
)
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
coreFactory := msgstream.NewPmsFactory()
|
2021-02-23 11:40:30 +08:00
|
|
|
Params.Init()
|
2021-09-09 17:39:30 +08:00
|
|
|
Params.DmlChannelNum = TestDMLChannelNum
|
2021-06-03 18:03:33 +08:00
|
|
|
core, err := NewCore(ctx, coreFactory)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal := rand.Int()
|
|
|
|
|
2021-06-25 10:24:11 +08:00
|
|
|
Params.TimeTickChannel = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.StatisticsChannel = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2021-01-24 20:26:35 +08:00
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
Params.MsgChannelSubName = fmt.Sprintf("subname-%d", randVal)
|
2021-09-08 15:00:00 +08:00
|
|
|
Params.DmlChannelName = fmt.Sprintf("rootcoord-dml-test-%d", randVal)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-11 22:04:41 +08:00
|
|
|
etcdCli, err := clientv3.New(clientv3.Config{Endpoints: Params.EtcdEndpoints, DialTimeout: 5 * time.Second})
|
2021-05-21 16:08:12 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-26 20:14:30 +08:00
|
|
|
sessKey := path.Join(Params.MetaRootPath, sessionutil.DefaultServiceRoot)
|
|
|
|
_, err = etcdCli.Delete(ctx, sessKey, clientv3.WithPrefix())
|
2021-05-21 16:08:12 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer func() {
|
2021-05-26 20:14:30 +08:00
|
|
|
_, _ = etcdCli.Delete(ctx, sessKey, clientv3.WithPrefix())
|
2021-05-21 16:08:12 +08:00
|
|
|
}()
|
|
|
|
|
2021-05-26 20:14:30 +08:00
|
|
|
pnb, err := json.Marshal(
|
|
|
|
&sessionutil.Session{
|
|
|
|
ServerID: 100,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.Nil(t, err)
|
2021-06-22 14:40:07 +08:00
|
|
|
_, err = etcdCli.Put(ctx, path.Join(sessKey, typeutil.ProxyRole+"-100"), string(pnb))
|
2021-05-26 20:14:30 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
pnm := &proxyMock{
|
2021-05-26 20:14:30 +08:00
|
|
|
collArray: make([]string, 0, 16),
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
2021-06-22 19:08:03 +08:00
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
return pnm, nil
|
|
|
|
}
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
dm := &dataMock{randVal: randVal}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetDataCoord(ctx, dm)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
im := &indexMock{
|
2021-02-20 15:38:44 +08:00
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetIndexCoord(im)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-02-05 14:09:55 +08:00
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetQueryCoord(qm)
|
2021-02-05 14:09:55 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
tmpFactory := msgstream.NewPmsFactory()
|
2021-05-31 16:48:31 +08:00
|
|
|
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"pulsarAddress": Params.PulsarAddress,
|
2021-06-02 22:36:41 +08:00
|
|
|
"receiveBufSize": 1024,
|
2021-02-08 14:30:54 +08:00
|
|
|
"pulsarBufSize": 1024}
|
2021-06-03 18:03:33 +08:00
|
|
|
err = tmpFactory.SetParams(m)
|
2021-02-08 14:30:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
timeTickStream, _ := tmpFactory.NewMsgStream(ctx)
|
2021-02-04 14:37:12 +08:00
|
|
|
timeTickStream.AsConsumer([]string{Params.TimeTickChannel}, Params.MsgChannelSubName)
|
2021-01-24 20:26:35 +08:00
|
|
|
timeTickStream.Start()
|
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
dmlStream, _ := tmpFactory.NewMsgStream(ctx)
|
2021-09-08 15:00:00 +08:00
|
|
|
clearMsgChan(1500*time.Millisecond, dmlStream.Chan())
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-06-02 22:36:41 +08:00
|
|
|
err = core.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
var localTSO uint64 = 0
|
|
|
|
localTSOLock := sync.RWMutex{}
|
|
|
|
core.TSOAllocator = func(c uint32) (uint64, error) {
|
|
|
|
localTSOLock.Lock()
|
|
|
|
defer localTSOLock.Unlock()
|
|
|
|
localTSO += uint64(c)
|
|
|
|
return localTSO, nil
|
|
|
|
}
|
|
|
|
|
2021-06-02 22:36:41 +08:00
|
|
|
err = core.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-09-08 15:00:00 +08:00
|
|
|
shardsNum := int32(8)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-05-31 16:48:31 +08:00
|
|
|
t.Run("time tick", func(t *testing.T) {
|
2021-01-24 20:26:35 +08:00
|
|
|
ttmsg, ok := <-timeTickStream.Chan()
|
|
|
|
assert.True(t, ok)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(ttmsg.Msgs))
|
2021-04-02 13:48:25 +08:00
|
|
|
ttm, ok := (ttmsg.Msgs[0]).(*msgstream.TimeTickMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.True(t, ok)
|
2021-05-31 16:48:31 +08:00
|
|
|
assert.Greater(t, ttm.Base.Timestamp, uint64(0))
|
|
|
|
t.Log(ttm.Base.Timestamp)
|
|
|
|
|
|
|
|
ttmsg2, ok := <-timeTickStream.Chan()
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, 1, len(ttmsg2.Msgs))
|
|
|
|
ttm2, ok := (ttmsg2.Msgs[0]).(*msgstream.TimeTickMsg)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Greater(t, ttm2.Base.Timestamp, uint64(0))
|
|
|
|
assert.Equal(t, ttm2.Base.Timestamp, ttm.Base.Timestamp+1)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("create collection", func(t *testing.T) {
|
|
|
|
schema := schemapb.CollectionSchema{
|
2021-05-17 19:15:01 +08:00
|
|
|
Name: collName,
|
|
|
|
AutoID: true,
|
2021-01-24 20:26:35 +08:00
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: 100,
|
|
|
|
Name: "vector",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "vector",
|
2021-03-12 14:22:09 +08:00
|
|
|
DataType: schemapb.DataType_FloatVector,
|
2021-01-24 20:26:35 +08:00
|
|
|
TypeParams: nil,
|
2021-02-02 10:09:10 +08:00
|
|
|
IndexParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "ik1",
|
|
|
|
Value: "iv1",
|
|
|
|
},
|
|
|
|
},
|
2021-01-24 20:26:35 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
sbf, err := proto.Marshal(&schema)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 100,
|
|
|
|
Timestamp: 100,
|
|
|
|
SourceID: 100,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
Schema: sbf,
|
2021-09-08 15:00:00 +08:00
|
|
|
ShardsNum: shardsNum,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.CreateCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(core.dmlChannels.GetNumChannels()))
|
2021-02-03 20:04:29 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
pChan := core.MetaTable.ListCollectionPhysicalChannels()
|
|
|
|
dmlStream.AsConsumer([]string{pChan[0]}, Params.MsgChannelSubName)
|
|
|
|
dmlStream.Start()
|
|
|
|
|
2021-09-06 11:52:41 +08:00
|
|
|
// get CreateCollectionMsg
|
|
|
|
msgs := getNotTtMsg(ctx, 1, dmlStream.Chan())
|
|
|
|
assert.Equal(t, 1, len(msgs))
|
|
|
|
createMsg, ok := (msgs[0]).(*msgstream.CreateCollectionMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.True(t, ok)
|
2021-05-18 14:18:02 +08:00
|
|
|
createMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, createMeta.ID, createMsg.CollectionID)
|
|
|
|
assert.Equal(t, 1, len(createMeta.PartitionIDs))
|
2021-07-06 09:16:03 +08:00
|
|
|
assert.Equal(t, createMeta.PartitionIDs[0], createMsg.PartitionID)
|
|
|
|
assert.Equal(t, 1, len(createMeta.PartitionNames))
|
|
|
|
assert.Equal(t, createMeta.PartitionNames[0], createMsg.PartitionName)
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(len(createMeta.VirtualChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, int32(len(createMeta.PhysicalChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, createMeta.ShardsNum)
|
2021-05-17 19:15:01 +08:00
|
|
|
|
|
|
|
vChanName := createMeta.VirtualChannelNames[0]
|
2021-06-23 11:18:05 +08:00
|
|
|
assert.Equal(t, createMeta.PhysicalChannelNames[0], ToPhysicalChannel(vChanName))
|
2021-02-03 20:04:29 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
// get TimeTickMsg
|
2021-06-11 16:39:29 +08:00
|
|
|
//msgPack, ok = <-dmlStream.Chan()
|
|
|
|
//assert.True(t, ok)
|
|
|
|
//assert.Equal(t, 1, len(msgPack.Msgs))
|
|
|
|
//ddm, ok := (msgPack.Msgs[0]).(*msgstream.TimeTickMsg)
|
|
|
|
//assert.True(t, ok)
|
|
|
|
//assert.Greater(t, ddm.Base.Timestamp, uint64(0))
|
|
|
|
core.chanTimeTick.lock.Lock()
|
|
|
|
assert.Equal(t, len(core.chanTimeTick.proxyTimeTick), 2)
|
|
|
|
pt, ok := core.chanTimeTick.proxyTimeTick[core.session.ServerID]
|
2021-06-04 15:00:34 +08:00
|
|
|
assert.True(t, ok)
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(len(pt.in.ChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, int32(len(pt.in.Timestamps)))
|
|
|
|
assert.Equal(t, shardsNum, int32(len(pt.timeTick)))
|
2021-08-03 09:59:24 +08:00
|
|
|
assert.ElementsMatch(t, pt.in.ChannelNames, createMeta.PhysicalChannelNames)
|
2021-06-17 15:54:07 +08:00
|
|
|
assert.Equal(t, pt.in.Timestamps[0], pt.in.Timestamps[1])
|
|
|
|
assert.Equal(t, pt.in.Timestamps[0], pt.in.DefaultTimestamp)
|
|
|
|
assert.Equal(t, pt.timeTick[pt.in.ChannelNames[0]], pt.in.DefaultTimestamp)
|
|
|
|
assert.Equal(t, pt.timeTick[pt.in.ChannelNames[1]], pt.in.DefaultTimestamp)
|
2021-07-06 09:16:03 +08:00
|
|
|
assert.LessOrEqual(t, createMsg.BeginTimestamp, pt.in.Timestamps[0])
|
2021-06-11 16:39:29 +08:00
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
|
|
|
|
// check DD operation info
|
|
|
|
flag, err := core.MetaTable.client.Load(DDMsgSendPrefix, 0)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "true", flag)
|
|
|
|
ddOpStr, err := core.MetaTable.client.Load(DDOperationPrefix, 0)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
var ddOp DdOperation
|
|
|
|
err = DecodeDdOperation(ddOpStr, &ddOp)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, CreateCollectionDDType, ddOp.Type)
|
|
|
|
|
|
|
|
var ddCollReq = internalpb.CreateCollectionRequest{}
|
|
|
|
err = proto.UnmarshalText(ddOp.Body, &ddCollReq)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, createMeta.ID, ddCollReq.CollectionID)
|
2021-07-06 09:16:03 +08:00
|
|
|
assert.Equal(t, createMeta.PartitionIDs[0], ddCollReq.PartitionID)
|
2021-06-04 15:00:34 +08:00
|
|
|
|
|
|
|
// check invalid operation
|
2021-01-24 20:26:35 +08:00
|
|
|
req.Base.MsgID = 101
|
|
|
|
req.Base.Timestamp = 101
|
|
|
|
req.Base.SourceID = 101
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err = core.CreateCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
req.Base.MsgID = 102
|
|
|
|
req.Base.Timestamp = 102
|
|
|
|
req.Base.SourceID = 102
|
|
|
|
req.CollectionName = "testColl-again"
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err = core.CreateCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
schema.Name = req.CollectionName
|
|
|
|
sbf, err = proto.Marshal(&schema)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req.Schema = sbf
|
|
|
|
req.Base.MsgID = 103
|
|
|
|
req.Base.Timestamp = 103
|
|
|
|
req.Base.SourceID = 103
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err = core.CreateCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
|
|
|
assert.Nil(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("has collection", func(t *testing.T) {
|
|
|
|
req := &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_HasCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 110,
|
|
|
|
Timestamp: 110,
|
|
|
|
SourceID: 110,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.HasCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, true, rsp.Value)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
req = &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_HasCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 111,
|
|
|
|
Timestamp: 111,
|
|
|
|
SourceID: 111,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
2021-01-24 20:26:35 +08:00
|
|
|
CollectionName: "testColl2",
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err = core.HasCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, false, rsp.Value)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
// test time stamp go back
|
|
|
|
req = &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_HasCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 111,
|
|
|
|
Timestamp: 111,
|
|
|
|
SourceID: 111,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err = core.HasCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, true, rsp.Value)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
req := &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 120,
|
|
|
|
Timestamp: 120,
|
|
|
|
SourceID: 120,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DescribeCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, collName, rsp.Schema.Name)
|
|
|
|
assert.Equal(t, collMeta.ID, rsp.CollectionID)
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(len(rsp.VirtualChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, int32(len(rsp.PhysicalChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, rsp.ShardsNum)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("show collection", func(t *testing.T) {
|
2021-03-12 14:22:09 +08:00
|
|
|
req := &milvuspb.ShowCollectionsRequest{
|
2021-01-24 20:26:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_ShowCollections,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 130,
|
|
|
|
Timestamp: 130,
|
|
|
|
SourceID: 130,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.ShowCollections(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.ElementsMatch(t, rsp.CollectionNames, []string{collName, "testColl-again"})
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Equal(t, len(rsp.CollectionNames), 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("create partition", func(t *testing.T) {
|
|
|
|
req := &milvuspb.CreatePartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_CreatePartition,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 140,
|
|
|
|
Timestamp: 140,
|
|
|
|
SourceID: 140,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
PartitionName: partName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
clearMsgChan(10*time.Millisecond, dmlStream.Chan())
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.CreatePartition(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-31 16:48:31 +08:00
|
|
|
t.Log(status.Reason)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 2, len(collMeta.PartitionIDs))
|
2021-07-03 14:36:18 +08:00
|
|
|
partNameIdx1, err := core.MetaTable.GetPartitionNameByID(collMeta.ID, collMeta.PartitionIDs[1], 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-03 14:36:18 +08:00
|
|
|
assert.Equal(t, partName, partNameIdx1)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
msgs := getNotTtMsg(ctx, 1, dmlStream.Chan())
|
2021-05-31 16:48:31 +08:00
|
|
|
assert.Equal(t, 1, len(msgs))
|
|
|
|
partMsg, ok := (msgs[0]).(*msgstream.CreatePartitionMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.True(t, ok)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, collMeta.ID, partMsg.CollectionID)
|
2021-07-03 14:36:18 +08:00
|
|
|
assert.Equal(t, collMeta.PartitionIDs[1], partMsg.PartitionID)
|
2021-03-22 16:36:10 +08:00
|
|
|
|
2021-05-26 20:14:30 +08:00
|
|
|
assert.Equal(t, 1, len(pnm.GetCollArray()))
|
|
|
|
assert.Equal(t, collName, pnm.GetCollArray()[0])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-05-18 14:18:02 +08:00
|
|
|
flag, err := core.MetaTable.client.Load(DDMsgSendPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-05-18 14:18:02 +08:00
|
|
|
ddOpStr, err := core.MetaTable.client.Load(DDOperationPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
var ddOp DdOperation
|
2021-06-02 22:36:41 +08:00
|
|
|
err = DecodeDdOperation(ddOpStr, &ddOp)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, CreatePartitionDDType, ddOp.Type)
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
var ddReq = internalpb.CreatePartitionRequest{}
|
|
|
|
err = proto.UnmarshalText(ddOp.Body, &ddReq)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
2021-07-03 14:36:18 +08:00
|
|
|
assert.Equal(t, collMeta.PartitionIDs[1], ddReq.PartitionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
|
|
|
assert.NotNil(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("has partition", func(t *testing.T) {
|
|
|
|
req := &milvuspb.HasPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_HasPartition,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 150,
|
|
|
|
Timestamp: 150,
|
|
|
|
SourceID: 150,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
PartitionName: partName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.HasPartition(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, true, rsp.Value)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("show partition", func(t *testing.T) {
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-03-12 14:22:09 +08:00
|
|
|
req := &milvuspb.ShowPartitionsRequest{
|
2021-01-24 20:26:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-04-08 15:26:18 +08:00
|
|
|
MsgType: commonpb.MsgType_ShowPartitions,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 160,
|
|
|
|
Timestamp: 160,
|
|
|
|
SourceID: 160,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
CollectionID: coll.ID,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.ShowPartitions(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, 2, len(rsp.PartitionNames))
|
|
|
|
assert.Equal(t, 2, len(rsp.PartitionIDs))
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("show segment", func(t *testing.T) {
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
partID := coll.PartitionIDs[1]
|
2021-07-03 14:36:18 +08:00
|
|
|
dm.mu.Lock()
|
|
|
|
dm.segs = []typeutil.UniqueID{1000}
|
|
|
|
dm.mu.Unlock()
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
req := &milvuspb.ShowSegmentsRequest{
|
2021-01-24 20:26:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_ShowSegments,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 170,
|
|
|
|
Timestamp: 170,
|
|
|
|
SourceID: 170,
|
|
|
|
},
|
|
|
|
CollectionID: coll.ID,
|
|
|
|
PartitionID: partID,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.ShowSegments(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, int64(1000), rsp.SegmentIDs[0])
|
|
|
|
assert.Equal(t, 1, len(rsp.SegmentIDs))
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("create index", func(t *testing.T) {
|
|
|
|
req := &milvuspb.CreateIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_CreateIndex,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 180,
|
|
|
|
Timestamp: 180,
|
|
|
|
SourceID: 180,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
FieldName: "vector",
|
2021-02-02 10:09:10 +08:00
|
|
|
ExtraParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "ik2",
|
|
|
|
Value: "iv2",
|
|
|
|
},
|
|
|
|
},
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-02-02 10:09:10 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 0, len(collMeta.FieldIndexes))
|
2021-02-02 10:09:10 +08:00
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.CreateIndex(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-01-24 20:26:35 +08:00
|
|
|
files := im.getFileArray()
|
|
|
|
assert.Equal(t, 3, len(files))
|
|
|
|
assert.ElementsMatch(t, files, []string{"file0-100", "file1-100", "file2-100"})
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err = core.MetaTable.GetCollectionByName(collName, 0)
|
2021-02-02 10:09:10 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(collMeta.FieldIndexes))
|
2021-02-26 14:40:53 +08:00
|
|
|
idxMeta, err := core.MetaTable.GetIndexByID(collMeta.FieldIndexes[0].IndexID)
|
2021-02-11 08:41:59 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, Params.DefaultIndexName, idxMeta.IndexName)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
req.FieldName = "no field"
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err = core.CreateIndex(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("describe segment", func(t *testing.T) {
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
req := &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeSegment,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 190,
|
|
|
|
Timestamp: 190,
|
|
|
|
SourceID: 190,
|
|
|
|
},
|
|
|
|
CollectionID: coll.ID,
|
|
|
|
SegmentID: 1000,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DescribeSegment(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Logf("index id = %d", rsp.IndexID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("describe index", func(t *testing.T) {
|
|
|
|
req := &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 200,
|
|
|
|
Timestamp: 200,
|
|
|
|
SourceID: 200,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
FieldName: "vector",
|
|
|
|
IndexName: "",
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DescribeIndex(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, 1, len(rsp.IndexDescriptions))
|
|
|
|
assert.Equal(t, Params.DefaultIndexName, rsp.IndexDescriptions[0].IndexName)
|
|
|
|
assert.Equal(t, "vector", rsp.IndexDescriptions[0].FieldName)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-03-05 20:41:34 +08:00
|
|
|
t.Run("describe index not exist", func(t *testing.T) {
|
|
|
|
req := &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
2021-03-05 20:41:34 +08:00
|
|
|
MsgID: 200,
|
|
|
|
Timestamp: 200,
|
|
|
|
SourceID: 200,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-03-05 20:41:34 +08:00
|
|
|
FieldName: "vector",
|
|
|
|
IndexName: "not-exist-index",
|
|
|
|
}
|
|
|
|
rsp, err := core.DescribeIndex(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_IndexNotExist, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, 0, len(rsp.IndexDescriptions))
|
2021-03-05 20:41:34 +08:00
|
|
|
})
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("flush segment", func(t *testing.T) {
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
partID := coll.PartitionIDs[1]
|
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
flushMsg := datapb.SegmentFlushCompletedMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_SegmentFlushDone,
|
|
|
|
},
|
|
|
|
Segment: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
|
|
|
CollectionID: coll.ID,
|
|
|
|
PartitionID: partID,
|
|
|
|
},
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-07-03 14:36:18 +08:00
|
|
|
st, err := core.SegmentFlushCompleted(ctx, &flushMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-03 14:36:18 +08:00
|
|
|
assert.Equal(t, st.ErrorCode, commonpb.ErrorCode_Success)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
req := &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 210,
|
|
|
|
Timestamp: 210,
|
|
|
|
SourceID: 210,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
FieldName: "vector",
|
|
|
|
IndexName: "",
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DescribeIndex(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, 1, len(rsp.IndexDescriptions))
|
|
|
|
assert.Equal(t, Params.DefaultIndexName, rsp.IndexDescriptions[0].IndexName)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-03-10 16:21:49 +08:00
|
|
|
t.Run("over ride index", func(t *testing.T) {
|
|
|
|
req := &milvuspb.CreateIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateIndex,
|
|
|
|
MsgID: 211,
|
|
|
|
Timestamp: 211,
|
|
|
|
SourceID: 211,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-03-10 16:21:49 +08:00
|
|
|
FieldName: "vector",
|
|
|
|
ExtraParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "ik3",
|
|
|
|
Value: "iv3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-03-10 16:21:49 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(collMeta.FieldIndexes))
|
2021-03-10 16:21:49 +08:00
|
|
|
oldIdx := collMeta.FieldIndexes[0].IndexID
|
|
|
|
|
|
|
|
rsp, err := core.CreateIndex(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-03-10 16:21:49 +08:00
|
|
|
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err = core.MetaTable.GetCollectionByName(collName, 0)
|
2021-03-10 16:21:49 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 2, len(collMeta.FieldIndexes))
|
2021-03-10 16:21:49 +08:00
|
|
|
assert.Equal(t, oldIdx, collMeta.FieldIndexes[0].IndexID)
|
|
|
|
|
|
|
|
idxMeta, err := core.MetaTable.GetIndexByID(collMeta.FieldIndexes[1].IndexID)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, Params.DefaultIndexName, idxMeta.IndexName)
|
2021-03-10 16:21:49 +08:00
|
|
|
|
|
|
|
idxMeta, err = core.MetaTable.GetIndexByID(collMeta.FieldIndexes[0].IndexID)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, Params.DefaultIndexName+"_bak", idxMeta.IndexName)
|
2021-03-10 16:21:49 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
|
2021-02-20 15:38:44 +08:00
|
|
|
t.Run("drop index", func(t *testing.T) {
|
|
|
|
req := &milvuspb.DropIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DropIndex,
|
2021-02-20 15:38:44 +08:00
|
|
|
MsgID: 215,
|
|
|
|
Timestamp: 215,
|
|
|
|
SourceID: 215,
|
|
|
|
},
|
|
|
|
DbName: "",
|
2021-05-17 19:15:01 +08:00
|
|
|
CollectionName: collName,
|
2021-02-20 15:38:44 +08:00
|
|
|
FieldName: "vector",
|
|
|
|
IndexName: Params.DefaultIndexName,
|
|
|
|
}
|
2021-05-17 19:15:01 +08:00
|
|
|
_, idx, err := core.MetaTable.GetIndexByName(collName, Params.DefaultIndexName)
|
2021-02-20 15:38:44 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(idx))
|
2021-02-20 15:38:44 +08:00
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DropIndex(ctx, req)
|
2021-02-20 15:38:44 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
2021-02-20 15:38:44 +08:00
|
|
|
|
|
|
|
im.mutex.Lock()
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(im.idxDropID))
|
|
|
|
assert.Equal(t, idx[0].IndexID, im.idxDropID[0])
|
2021-02-20 15:38:44 +08:00
|
|
|
im.mutex.Unlock()
|
|
|
|
|
2021-05-17 19:15:01 +08:00
|
|
|
_, idx, err = core.MetaTable.GetIndexByName(collName, Params.DefaultIndexName)
|
2021-02-20 15:38:44 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 0, len(idx))
|
2021-02-20 15:38:44 +08:00
|
|
|
})
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("drop partition", func(t *testing.T) {
|
|
|
|
req := &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DropPartition,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 220,
|
|
|
|
Timestamp: 220,
|
|
|
|
SourceID: 220,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
PartitionName: partName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
dropPartID := collMeta.PartitionIDs[1]
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.DropPartition(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err = core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(collMeta.PartitionIDs))
|
2021-07-03 14:36:18 +08:00
|
|
|
partName, err := core.MetaTable.GetPartitionNameByID(collMeta.ID, collMeta.PartitionIDs[0], 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-03 14:36:18 +08:00
|
|
|
assert.Equal(t, Params.DefaultPartitionName, partName)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
msgs := getNotTtMsg(ctx, 1, dmlStream.Chan())
|
2021-05-31 16:48:31 +08:00
|
|
|
assert.Equal(t, 1, len(msgs))
|
|
|
|
dmsg, ok := (msgs[0]).(*msgstream.DropPartitionMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.True(t, ok)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, collMeta.ID, dmsg.CollectionID)
|
|
|
|
assert.Equal(t, dropPartID, dmsg.PartitionID)
|
2021-03-22 16:36:10 +08:00
|
|
|
|
2021-05-26 20:14:30 +08:00
|
|
|
assert.Equal(t, 2, len(pnm.GetCollArray()))
|
|
|
|
assert.Equal(t, collName, pnm.GetCollArray()[1])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-05-18 14:18:02 +08:00
|
|
|
flag, err := core.MetaTable.client.Load(DDMsgSendPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-05-18 14:18:02 +08:00
|
|
|
ddOpStr, err := core.MetaTable.client.Load(DDOperationPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
var ddOp DdOperation
|
2021-06-02 22:36:41 +08:00
|
|
|
err = DecodeDdOperation(ddOpStr, &ddOp)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, DropPartitionDDType, ddOp.Type)
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
var ddReq = internalpb.DropPartitionRequest{}
|
|
|
|
err = proto.UnmarshalText(ddOp.Body, &ddReq)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
|
|
|
assert.Equal(t, dropPartID, ddReq.PartitionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("remove DQL msgstream", func(t *testing.T) {
|
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
req := &proxypb.ReleaseDQLMessageStreamRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_RemoveQueryChannels,
|
|
|
|
SourceID: core.session.ServerID,
|
|
|
|
},
|
|
|
|
CollectionID: collMeta.ID,
|
|
|
|
}
|
|
|
|
status, err := core.ReleaseDQLMessageStream(core.ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("drop collection", func(t *testing.T) {
|
|
|
|
req := &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 230,
|
|
|
|
Timestamp: 230,
|
|
|
|
SourceID: 230,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.DropCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
vChanName := collMeta.VirtualChannelNames[0]
|
2021-06-23 11:18:05 +08:00
|
|
|
assert.Equal(t, collMeta.PhysicalChannelNames[0], ToPhysicalChannel(vChanName))
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
msgs := getNotTtMsg(ctx, 1, dmlStream.Chan())
|
2021-05-31 16:48:31 +08:00
|
|
|
assert.Equal(t, 1, len(msgs))
|
|
|
|
dmsg, ok := (msgs[0]).(*msgstream.DropCollectionMsg)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.True(t, ok)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, collMeta.ID, dmsg.CollectionID)
|
2021-05-26 20:14:30 +08:00
|
|
|
collArray := pnm.GetCollArray()
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 3, len(collArray))
|
|
|
|
assert.Equal(t, collName, collArray[2])
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-02-05 14:09:55 +08:00
|
|
|
qm.mutex.Lock()
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 1, len(qm.collID))
|
|
|
|
assert.Equal(t, collMeta.ID, qm.collID[0])
|
2021-02-05 14:09:55 +08:00
|
|
|
qm.mutex.Unlock()
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
req = &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 231,
|
|
|
|
Timestamp: 231,
|
|
|
|
SourceID: 231,
|
|
|
|
},
|
2021-05-17 19:15:01 +08:00
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err = core.DropCollection(ctx, req)
|
2021-01-24 20:26:35 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-26 20:14:30 +08:00
|
|
|
collArray = pnm.GetCollArray()
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, 3, len(collArray))
|
|
|
|
assert.Equal(t, collName, collArray[2])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-05-18 14:18:02 +08:00
|
|
|
flag, err := core.MetaTable.client.Load(DDMsgSendPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-05-18 14:18:02 +08:00
|
|
|
ddOpStr, err := core.MetaTable.client.Load(DDOperationPrefix, 0)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
var ddOp DdOperation
|
2021-06-02 22:36:41 +08:00
|
|
|
err = DecodeDdOperation(ddOpStr, &ddOp)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, DropCollectionDDType, ddOp.Type)
|
|
|
|
|
|
|
|
var ddReq = internalpb.DropCollectionRequest{}
|
|
|
|
err = proto.UnmarshalText(ddOp.Body, &ddReq)
|
2021-05-12 15:33:53 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
|
|
|
assert.NotNil(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("context_cancel", func(t *testing.T) {
|
|
|
|
ctx2, cancel2 := context.WithTimeout(ctx, time.Millisecond*100)
|
|
|
|
defer cancel2()
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-04-08 15:26:18 +08:00
|
|
|
st, err := core.CreateCollection(ctx2, &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
MsgID: 1000,
|
|
|
|
Timestamp: 1000,
|
|
|
|
SourceID: 1000,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropCollection(ctx2, &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
|
|
|
MsgID: 1001,
|
|
|
|
Timestamp: 1001,
|
|
|
|
SourceID: 1001,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp1, err := core.HasCollection(ctx2, &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_HasCollection,
|
|
|
|
MsgID: 1002,
|
|
|
|
Timestamp: 1002,
|
|
|
|
SourceID: 1002,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp1.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp2, err := core.DescribeCollection(ctx2, &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 1003,
|
|
|
|
Timestamp: 1003,
|
|
|
|
SourceID: 1003,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp2.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp3, err := core.ShowCollections(ctx2, &milvuspb.ShowCollectionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowCollections,
|
|
|
|
MsgID: 1004,
|
|
|
|
Timestamp: 1004,
|
|
|
|
SourceID: 1004,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp3.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreatePartition(ctx2, &milvuspb.CreatePartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreatePartition,
|
|
|
|
MsgID: 1005,
|
|
|
|
Timestamp: 1005,
|
|
|
|
SourceID: 1005,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropPartition(ctx2, &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropPartition,
|
|
|
|
MsgID: 1006,
|
|
|
|
Timestamp: 1006,
|
|
|
|
SourceID: 1006,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp4, err := core.HasPartition(ctx2, &milvuspb.HasPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_HasPartition,
|
|
|
|
MsgID: 1007,
|
|
|
|
Timestamp: 1007,
|
|
|
|
SourceID: 1007,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp4.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp5, err := core.ShowPartitions(ctx2, &milvuspb.ShowPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowPartitions,
|
|
|
|
MsgID: 1008,
|
|
|
|
Timestamp: 1008,
|
|
|
|
SourceID: 1008,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp5.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreateIndex(ctx2, &milvuspb.CreateIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateIndex,
|
|
|
|
MsgID: 1009,
|
|
|
|
Timestamp: 1009,
|
|
|
|
SourceID: 1009,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp6, err := core.DescribeIndex(ctx2, &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
|
|
|
MsgID: 1010,
|
|
|
|
Timestamp: 1010,
|
|
|
|
SourceID: 1010,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp6.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropIndex(ctx2, &milvuspb.DropIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropIndex,
|
|
|
|
MsgID: 1011,
|
|
|
|
Timestamp: 1011,
|
|
|
|
SourceID: 1011,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp7, err := core.DescribeSegment(ctx2, &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeSegment,
|
|
|
|
MsgID: 1012,
|
|
|
|
Timestamp: 1012,
|
|
|
|
SourceID: 1012,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp7.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp8, err := core.ShowSegments(ctx2, &milvuspb.ShowSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowSegments,
|
|
|
|
MsgID: 1013,
|
|
|
|
Timestamp: 1013,
|
|
|
|
SourceID: 1013,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp8.Status.ErrorCode)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(1 * time.Second)
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
t.Run("undefined req type", func(t *testing.T) {
|
2021-04-08 15:26:18 +08:00
|
|
|
st, err := core.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2000,
|
|
|
|
Timestamp: 2000,
|
|
|
|
SourceID: 2000,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2001,
|
|
|
|
Timestamp: 2001,
|
|
|
|
SourceID: 2001,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp1, err := core.HasCollection(ctx, &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2002,
|
|
|
|
Timestamp: 2002,
|
|
|
|
SourceID: 2002,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp1.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp2, err := core.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2003,
|
|
|
|
Timestamp: 2003,
|
|
|
|
SourceID: 2003,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp2.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp3, err := core.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2004,
|
|
|
|
Timestamp: 2004,
|
|
|
|
SourceID: 2004,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp3.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2005,
|
|
|
|
Timestamp: 2005,
|
|
|
|
SourceID: 2005,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropPartition(ctx, &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2006,
|
|
|
|
Timestamp: 2006,
|
|
|
|
SourceID: 2006,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp4, err := core.HasPartition(ctx, &milvuspb.HasPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2007,
|
|
|
|
Timestamp: 2007,
|
|
|
|
SourceID: 2007,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp4.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp5, err := core.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2008,
|
|
|
|
Timestamp: 2008,
|
|
|
|
SourceID: 2008,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp5.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreateIndex(ctx, &milvuspb.CreateIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2009,
|
|
|
|
Timestamp: 2009,
|
|
|
|
SourceID: 2009,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp6, err := core.DescribeIndex(ctx, &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2010,
|
|
|
|
Timestamp: 2010,
|
|
|
|
SourceID: 2010,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp6.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropIndex(ctx, &milvuspb.DropIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2011,
|
|
|
|
Timestamp: 2011,
|
|
|
|
SourceID: 2011,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp7, err := core.DescribeSegment(ctx, &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2012,
|
|
|
|
Timestamp: 2012,
|
|
|
|
SourceID: 2012,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp7.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp8, err := core.ShowSegments(ctx, &milvuspb.ShowSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 2013,
|
|
|
|
Timestamp: 2013,
|
|
|
|
SourceID: 2013,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp8.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("alloc time tick", func(t *testing.T) {
|
2021-06-22 16:14:09 +08:00
|
|
|
req := &rootcoordpb.AllocTimestampRequest{
|
2021-04-08 15:26:18 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 3000,
|
|
|
|
Timestamp: 3000,
|
|
|
|
SourceID: 3000,
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
}
|
|
|
|
rsp, err := core.AllocTimestamp(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, uint32(1), rsp.Count)
|
|
|
|
assert.NotZero(t, rsp.Timestamp)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("alloc id", func(t *testing.T) {
|
2021-06-22 16:14:09 +08:00
|
|
|
req := &rootcoordpb.AllocIDRequest{
|
2021-04-08 15:26:18 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 3001,
|
|
|
|
Timestamp: 3001,
|
|
|
|
SourceID: 3001,
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
}
|
|
|
|
rsp, err := core.AllocID(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, uint32(1), rsp.Count)
|
|
|
|
assert.NotZero(t, rsp.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get_channels", func(t *testing.T) {
|
|
|
|
_, err := core.GetTimeTickChannel(ctx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
_, err = core.GetStatisticsChannel(ctx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
2021-05-21 16:08:12 +08:00
|
|
|
t.Run("channel timetick", func(t *testing.T) {
|
|
|
|
const (
|
2021-06-22 19:08:03 +08:00
|
|
|
proxyIDInvalid = 102
|
|
|
|
proxyName0 = "proxy_0"
|
|
|
|
proxyName1 = "proxy_1"
|
|
|
|
chanName0 = "c0"
|
|
|
|
chanName1 = "c1"
|
|
|
|
chanName2 = "c2"
|
|
|
|
ts0 = uint64(100)
|
|
|
|
ts1 = uint64(120)
|
|
|
|
ts2 = uint64(150)
|
2021-05-21 16:08:12 +08:00
|
|
|
)
|
2021-06-26 09:22:11 +08:00
|
|
|
numChan := core.chanTimeTick.GetChanNum()
|
2021-05-21 16:08:12 +08:00
|
|
|
p1 := sessionutil.Session{
|
|
|
|
ServerID: 100,
|
|
|
|
}
|
|
|
|
p2 := sessionutil.Session{
|
|
|
|
ServerID: 101,
|
|
|
|
}
|
|
|
|
ctx2, cancel2 := context.WithTimeout(ctx, RequestTimeout)
|
|
|
|
defer cancel2()
|
|
|
|
s1, err := json.Marshal(&p1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
s2, err := json.Marshal(&p2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-09-07 11:16:37 +08:00
|
|
|
proxy1 := path.Join(sessKey, typeutil.ProxyRole) + "-1"
|
|
|
|
proxy2 := path.Join(sessKey, typeutil.ProxyRole) + "-2"
|
|
|
|
_, err = core.etcdCli.Put(ctx2, proxy1, string(s1))
|
2021-05-21 16:08:12 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
_, err = core.etcdCli.Put(ctx2, proxy2, string(s2))
|
2021-05-21 16:08:12 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
2021-09-10 13:00:00 +08:00
|
|
|
core.dmlChannels.AddProducerChannels("c0", "c1", "c2")
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-05-21 16:08:12 +08:00
|
|
|
msg0 := &internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
SourceID: 100,
|
|
|
|
},
|
|
|
|
ChannelNames: []string{chanName0, chanName1},
|
|
|
|
Timestamps: []uint64{ts0, ts2},
|
|
|
|
}
|
|
|
|
s, _ := core.UpdateChannelTimeTick(ctx, msg0)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, s.ErrorCode)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-06-04 15:00:34 +08:00
|
|
|
//t.Log(core.chanTimeTick.proxyTimeTick)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
|
|
|
msg1 := &internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
SourceID: 101,
|
|
|
|
},
|
|
|
|
ChannelNames: []string{chanName1, chanName2},
|
|
|
|
Timestamps: []uint64{ts1, ts2},
|
|
|
|
}
|
|
|
|
s, _ = core.UpdateChannelTimeTick(ctx, msg1)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, s.ErrorCode)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
msgInvalid := &internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-06-22 19:08:03 +08:00
|
|
|
SourceID: proxyIDInvalid,
|
2021-05-21 16:08:12 +08:00
|
|
|
},
|
2021-06-11 16:39:29 +08:00
|
|
|
ChannelNames: []string{"test"},
|
|
|
|
Timestamps: []uint64{0},
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
|
|
|
s, _ = core.UpdateChannelTimeTick(ctx, msgInvalid)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, s.ErrorCode)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
2021-06-25 10:24:11 +08:00
|
|
|
// 2 proxy, 1 rootcoord
|
2021-06-22 19:08:03 +08:00
|
|
|
assert.Equal(t, 3, core.chanTimeTick.GetProxyNum())
|
2021-06-04 15:00:34 +08:00
|
|
|
|
2021-06-26 09:22:11 +08:00
|
|
|
// add 3 proxy channels
|
|
|
|
assert.Equal(t, 3, core.chanTimeTick.GetChanNum()-numChan)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
_, err = core.etcdCli.Delete(ctx2, proxy1)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
_, err = core.etcdCli.Delete(ctx2, proxy2)
|
|
|
|
assert.Nil(t, err)
|
2021-05-21 16:08:12 +08:00
|
|
|
})
|
|
|
|
|
2021-08-31 11:45:59 +08:00
|
|
|
t.Run("get metrics", func(t *testing.T) {
|
|
|
|
// not healthy
|
|
|
|
stateSave := core.stateCode.Load().(internalpb.StateCode)
|
|
|
|
core.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
resp, err := core.GetMetrics(ctx, &milvuspb.GetMetricsRequest{})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
core.UpdateStateCode(stateSave)
|
|
|
|
|
|
|
|
// failed to parse metric type
|
|
|
|
invalidRequest := "invalid request"
|
|
|
|
resp, err = core.GetMetrics(ctx, &milvuspb.GetMetricsRequest{
|
|
|
|
Request: invalidRequest,
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// unsupported metric type
|
|
|
|
unsupportedMetricType := "unsupported"
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(unsupportedMetricType)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
resp, err = core.GetMetrics(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// normal case
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err = metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
resp, err = core.GetMetrics(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get system info", func(t *testing.T) {
|
|
|
|
// normal case
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
resp, err := core.getSystemInfoMetrics(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
err = core.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
st, err := core.GetComponentStates(ctx)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, st.Status.ErrorCode)
|
|
|
|
assert.NotEqual(t, internalpb.StateCode_Healthy, st.State.StateCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("state_not_healthy", func(t *testing.T) {
|
|
|
|
st, err := core.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
MsgID: 4000,
|
|
|
|
Timestamp: 4000,
|
|
|
|
SourceID: 4000,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
|
|
|
MsgID: 4001,
|
|
|
|
Timestamp: 4001,
|
|
|
|
SourceID: 4001,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp1, err := core.HasCollection(ctx, &milvuspb.HasCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_HasCollection,
|
|
|
|
MsgID: 4002,
|
|
|
|
Timestamp: 4002,
|
|
|
|
SourceID: 4002,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp1.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp2, err := core.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 4003,
|
|
|
|
Timestamp: 4003,
|
|
|
|
SourceID: 4003,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp2.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp3, err := core.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowCollections,
|
|
|
|
MsgID: 4004,
|
|
|
|
Timestamp: 4004,
|
|
|
|
SourceID: 4004,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp3.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreatePartition,
|
|
|
|
MsgID: 4005,
|
|
|
|
Timestamp: 4005,
|
|
|
|
SourceID: 4005,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropPartition(ctx, &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropPartition,
|
|
|
|
MsgID: 4006,
|
|
|
|
Timestamp: 4006,
|
|
|
|
SourceID: 4006,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp4, err := core.HasPartition(ctx, &milvuspb.HasPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_HasPartition,
|
|
|
|
MsgID: 4007,
|
|
|
|
Timestamp: 4007,
|
|
|
|
SourceID: 4007,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp4.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp5, err := core.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowPartitions,
|
|
|
|
MsgID: 4008,
|
|
|
|
Timestamp: 4008,
|
|
|
|
SourceID: 4008,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp5.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.CreateIndex(ctx, &milvuspb.CreateIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateIndex,
|
|
|
|
MsgID: 4009,
|
|
|
|
Timestamp: 4009,
|
|
|
|
SourceID: 4009,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp6, err := core.DescribeIndex(ctx, &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
|
|
|
MsgID: 4010,
|
|
|
|
Timestamp: 4010,
|
|
|
|
SourceID: 4010,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp6.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
st, err = core.DropIndex(ctx, &milvuspb.DropIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropIndex,
|
|
|
|
MsgID: 4011,
|
|
|
|
Timestamp: 4011,
|
|
|
|
SourceID: 4011,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, st.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp7, err := core.DescribeSegment(ctx, &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeSegment,
|
|
|
|
MsgID: 4012,
|
|
|
|
Timestamp: 4012,
|
|
|
|
SourceID: 4012,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp7.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
rsp8, err := core.ShowSegments(ctx, &milvuspb.ShowSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ShowSegments,
|
|
|
|
MsgID: 4013,
|
|
|
|
Timestamp: 4013,
|
|
|
|
SourceID: 4013,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp8.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
|
|
|
})
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
t.Run("alloc_error", func(t *testing.T) {
|
2021-06-28 15:08:12 +08:00
|
|
|
core.Stop()
|
2021-05-20 14:14:14 +08:00
|
|
|
core.IDAllocator = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, 0, fmt.Errorf("id allocator error test")
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
core.TSOAllocator = func(count uint32) (typeutil.Timestamp, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, fmt.Errorf("tso allcoator error test")
|
|
|
|
}
|
2021-06-28 15:08:12 +08:00
|
|
|
core.Init()
|
|
|
|
core.Start()
|
2021-06-22 16:14:09 +08:00
|
|
|
r1 := &rootcoordpb.AllocTimestampRequest{
|
2021-04-08 17:31:39 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 5000,
|
|
|
|
Timestamp: 5000,
|
|
|
|
SourceID: 5000,
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
}
|
|
|
|
p1, err := core.AllocTimestamp(ctx, r1)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, p1.Status.ErrorCode)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-06-22 16:14:09 +08:00
|
|
|
r2 := &rootcoordpb.AllocIDRequest{
|
2021-04-08 17:31:39 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Undefined,
|
|
|
|
MsgID: 3001,
|
|
|
|
Timestamp: 3001,
|
|
|
|
SourceID: 3001,
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
}
|
|
|
|
p2, err := core.AllocID(ctx, r2)
|
|
|
|
assert.Nil(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, p2.Status.ErrorCode)
|
2021-04-08 17:31:39 +08:00
|
|
|
})
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 16:14:08 +08:00
|
|
|
func TestRootCoord2(t *testing.T) {
|
2021-05-20 14:14:14 +08:00
|
|
|
const (
|
|
|
|
dbName = "testDb"
|
|
|
|
collName = "testColl"
|
|
|
|
partName = "testPartition"
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
msFactory := msgstream.NewPmsFactory()
|
|
|
|
Params.Init()
|
2021-09-09 17:39:30 +08:00
|
|
|
Params.DmlChannelNum = TestDMLChannelNum
|
2021-05-20 14:14:14 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal := rand.Int()
|
|
|
|
|
2021-06-25 10:24:11 +08:00
|
|
|
Params.TimeTickChannel = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.StatisticsChannel = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2021-05-20 14:14:14 +08:00
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
Params.MsgChannelSubName = fmt.Sprintf("subname-%d", randVal)
|
|
|
|
|
2021-06-03 18:03:33 +08:00
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
dm := &dataMock{randVal: randVal}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetDataCoord(ctx, dm)
|
2021-05-20 14:14:14 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
im := &indexMock{
|
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetIndexCoord(im)
|
2021-05-20 14:14:14 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetQueryCoord(qm)
|
2021-05-20 14:14:14 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
err = core.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = core.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": 1024,
|
|
|
|
"pulsarAddress": Params.PulsarAddress,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err = msFactory.SetParams(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
timeTickStream, _ := msFactory.NewMsgStream(ctx)
|
|
|
|
timeTickStream.AsConsumer([]string{Params.TimeTickChannel}, Params.MsgChannelSubName)
|
|
|
|
timeTickStream.Start()
|
|
|
|
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
|
|
|
t.Run("time tick", func(t *testing.T) {
|
|
|
|
ttmsg, ok := <-timeTickStream.Chan()
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, 1, len(ttmsg.Msgs))
|
|
|
|
ttm, ok := (ttmsg.Msgs[0]).(*msgstream.TimeTickMsg)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Greater(t, ttm.Base.Timestamp, typeutil.Timestamp(0))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("create collection", func(t *testing.T) {
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: collName,
|
|
|
|
}
|
|
|
|
|
|
|
|
sbf, err := proto.Marshal(&schema)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
req := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
Timestamp: 100,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
Schema: sbf,
|
|
|
|
}
|
|
|
|
status, err := core.CreateCollection(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
pChan := core.MetaTable.ListCollectionPhysicalChannels()
|
|
|
|
dmlStream, _ := msFactory.NewMsgStream(ctx)
|
2021-06-24 19:44:08 +08:00
|
|
|
dmlStream.AsConsumer([]string{pChan[0]}, Params.MsgChannelSubName)
|
2021-06-04 15:00:34 +08:00
|
|
|
dmlStream.Start()
|
|
|
|
|
2021-07-06 09:16:03 +08:00
|
|
|
msgs := getNotTtMsg(ctx, 1, dmlStream.Chan())
|
|
|
|
assert.Equal(t, 1, len(msgs))
|
2021-06-04 15:00:34 +08:00
|
|
|
|
|
|
|
m1, ok := (msgs[0]).(*msgstream.CreateCollectionMsg)
|
2021-05-20 14:14:14 +08:00
|
|
|
assert.True(t, ok)
|
|
|
|
t.Log("time tick", m1.Base.Timestamp)
|
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req := &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 120,
|
|
|
|
Timestamp: 120,
|
|
|
|
SourceID: 120,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
}
|
|
|
|
rsp, err := core.DescribeCollection(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, collName, rsp.Schema.Name)
|
|
|
|
assert.Equal(t, collMeta.ID, rsp.CollectionID)
|
2021-09-14 11:59:47 +08:00
|
|
|
assert.Equal(t, common.DefaultShardsNum, int32(len(rsp.VirtualChannelNames)))
|
|
|
|
assert.Equal(t, common.DefaultShardsNum, int32(len(rsp.PhysicalChannelNames)))
|
|
|
|
assert.Equal(t, common.DefaultShardsNum, rsp.ShardsNum)
|
2021-09-08 15:00:00 +08:00
|
|
|
})
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 17:31:39 +08:00
|
|
|
func TestCheckInit(t *testing.T) {
|
|
|
|
c, err := NewCore(context.Background(), nil)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = c.Start()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
c.MetaTable = &metaTable{}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
c.IDAllocator = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, 0, nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
c.IDAllocatorUpdate = func() error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
c.TSOAllocator = func(count uint32) (typeutil.Timestamp, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
c.TSOAllocatorUpdate = func() error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
c.etcdCli = &clientv3.Client{}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
c.kvBase = &etcdkv.EtcdKV{}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdCreateCollectionReq = func(context.Context, *internalpb.CreateCollectionRequest, []string) error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdDropCollectionReq = func(context.Context, *internalpb.DropCollectionRequest, []string) error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdCreatePartitionReq = func(context.Context, *internalpb.CreatePartitionRequest, []string) error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdDropPartitionReq = func(context.Context, *internalpb.DropPartitionRequest, []string) error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-30 16:18:13 +08:00
|
|
|
c.CallGetBinlogFilePathsService = func(ctx context.Context, segID, fieldID typeutil.UniqueID) ([]string, error) {
|
2021-05-25 14:03:06 +08:00
|
|
|
return []string{}, nil
|
|
|
|
}
|
2021-04-08 17:31:39 +08:00
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-30 16:18:13 +08:00
|
|
|
c.CallGetNumRowsService = func(ctx context.Context, segID typeutil.UniqueID, isFromFlushedChan bool) (int64, error) {
|
2021-05-25 14:03:06 +08:00
|
|
|
return 0, nil
|
2021-04-08 17:31:39 +08:00
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
c.CallGetFlushedSegmentsService = func(ctx context.Context, collID, partID typeutil.UniqueID) ([]typeutil.UniqueID, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-25 14:03:06 +08:00
|
|
|
c.CallBuildIndexService = func(ctx context.Context, binlog []string, field *schemapb.FieldSchema, idxInfo *etcdpb.IndexInfo) (typeutil.UniqueID, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-25 14:03:06 +08:00
|
|
|
c.CallDropIndexService = func(ctx context.Context, indexID typeutil.UniqueID) error {
|
|
|
|
return nil
|
2021-04-08 17:31:39 +08:00
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
c.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
return nil, nil
|
2021-04-08 17:31:39 +08:00
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-05-25 14:03:06 +08:00
|
|
|
c.CallReleaseCollectionService = func(ctx context.Context, ts typeutil.Timestamp, dbID, collectionID typeutil.UniqueID) error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
2021-06-22 16:08:08 +08:00
|
|
|
c.CallReleasePartitionService = func(ctx context.Context, ts typeutil.Timestamp, dbID, collectionID typeutil.UniqueID, partitionIDs []typeutil.UniqueID) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
2021-04-08 17:31:39 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-09 17:39:30 +08:00
|
|
|
err = c.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
func TestCheckFlushedSegments(t *testing.T) {
|
|
|
|
const (
|
|
|
|
dbName = "testDb"
|
|
|
|
collName = "testColl"
|
|
|
|
partName = "testPartition"
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
msFactory := msgstream.NewPmsFactory()
|
|
|
|
Params.Init()
|
2021-09-09 17:39:30 +08:00
|
|
|
Params.DmlChannelNum = TestDMLChannelNum
|
2021-08-25 14:41:52 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal := rand.Int()
|
|
|
|
|
|
|
|
Params.TimeTickChannel = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.StatisticsChannel = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
Params.MsgChannelSubName = fmt.Sprintf("subname-%d", randVal)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
dm := &dataMock{randVal: randVal}
|
|
|
|
err = core.SetDataCoord(ctx, dm)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
im := &indexMock{
|
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetIndexCoord(im)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetQueryCoord(qm)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = core.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = core.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": 1024,
|
|
|
|
"pulsarAddress": Params.PulsarAddress,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err = msFactory.SetParams(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
timeTickStream, _ := msFactory.NewMsgStream(ctx)
|
|
|
|
timeTickStream.AsConsumer([]string{Params.TimeTickChannel}, Params.MsgChannelSubName)
|
|
|
|
timeTickStream.Start()
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
t.Run("check flushed segments", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
var collID int64 = 1
|
|
|
|
var partID int64 = 2
|
|
|
|
var segID int64 = 1001
|
|
|
|
var fieldID int64 = 101
|
|
|
|
var indexID int64 = 6001
|
|
|
|
core.MetaTable.segID2IndexMeta[segID] = make(map[int64]etcdpb.SegmentIndexInfo)
|
|
|
|
core.MetaTable.partID2SegID[partID] = make(map[int64]bool)
|
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{ID: collID}
|
|
|
|
// do nothing, since collection has 0 index
|
|
|
|
core.checkFlushedSegments(ctx)
|
|
|
|
|
|
|
|
// get field schema by id fail
|
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
PartitionIDs: []int64{partID},
|
|
|
|
FieldIndexes: []*etcdpb.FieldIndexInfo{
|
|
|
|
{
|
|
|
|
FiledID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Fields: []*schemapb.FieldSchema{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(ctx)
|
|
|
|
|
|
|
|
// fail to get segment id ,dont panic
|
|
|
|
core.CallGetFlushedSegmentsService = func(_ context.Context, collID, partID int64) ([]int64, error) {
|
|
|
|
return []int64{}, errors.New("service not available")
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(core.ctx)
|
|
|
|
// non-exist segID
|
|
|
|
core.CallGetFlushedSegmentsService = func(_ context.Context, collID, partID int64) ([]int64, error) {
|
|
|
|
return []int64{2001}, nil
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(core.ctx)
|
|
|
|
|
|
|
|
// missing index info
|
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
PartitionIDs: []int64{partID},
|
|
|
|
FieldIndexes: []*etcdpb.FieldIndexInfo{
|
|
|
|
{
|
|
|
|
FiledID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: fieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(ctx)
|
|
|
|
// existing segID, buildIndex failed
|
|
|
|
core.CallGetFlushedSegmentsService = func(_ context.Context, cid, pid int64) ([]int64, error) {
|
|
|
|
assert.Equal(t, collID, cid)
|
|
|
|
assert.Equal(t, partID, pid)
|
|
|
|
return []int64{segID}, nil
|
|
|
|
}
|
|
|
|
core.MetaTable.indexID2Meta[indexID] = etcdpb.IndexInfo{
|
|
|
|
IndexID: indexID,
|
|
|
|
}
|
|
|
|
core.CallBuildIndexService = func(_ context.Context, binlog []string, field *schemapb.FieldSchema, idx *etcdpb.IndexInfo) (int64, error) {
|
|
|
|
assert.Equal(t, fieldID, field.FieldID)
|
|
|
|
assert.Equal(t, indexID, idx.IndexID)
|
|
|
|
return -1, errors.New("build index build")
|
|
|
|
}
|
|
|
|
|
|
|
|
core.checkFlushedSegments(ctx)
|
|
|
|
|
|
|
|
var indexBuildID int64 = 10001
|
|
|
|
core.CallBuildIndexService = func(_ context.Context, binlog []string, field *schemapb.FieldSchema, idx *etcdpb.IndexInfo) (int64, error) {
|
|
|
|
return indexBuildID, nil
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(core.ctx)
|
|
|
|
|
|
|
|
})
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
}
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
func TestRootCoord_CheckZeroShardsNum(t *testing.T) {
|
|
|
|
const (
|
|
|
|
dbName = "testDb"
|
|
|
|
collName = "testColl"
|
|
|
|
)
|
|
|
|
|
|
|
|
shardsNum := int32(2)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
msFactory := msgstream.NewPmsFactory()
|
|
|
|
Params.Init()
|
2021-09-09 17:39:30 +08:00
|
|
|
Params.DmlChannelNum = TestDMLChannelNum
|
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
randVal := rand.Int()
|
|
|
|
|
|
|
|
Params.TimeTickChannel = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.StatisticsChannel = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
|
|
|
Params.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.MetaRootPath)
|
|
|
|
Params.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.KvRootPath)
|
|
|
|
Params.MsgChannelSubName = fmt.Sprintf("subname-%d", randVal)
|
|
|
|
|
|
|
|
err = core.Register()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
dm := &dataMock{randVal: randVal}
|
|
|
|
err = core.SetDataCoord(ctx, dm)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
im := &indexMock{
|
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetIndexCoord(im)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetQueryCoord(qm)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = core.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = core.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": 1024,
|
|
|
|
"pulsarAddress": Params.PulsarAddress,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err = msFactory.SetParams(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
timeTickStream, _ := msFactory.NewMsgStream(ctx)
|
|
|
|
timeTickStream.AsConsumer([]string{Params.TimeTickChannel}, Params.MsgChannelSubName)
|
|
|
|
timeTickStream.Start()
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
modifyFunc := func(collInfo *etcdpb.CollectionInfo) {
|
|
|
|
collInfo.ShardsNum = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
createCollectionInMeta(dbName, collName, core, shardsNum, modifyFunc)
|
|
|
|
|
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
req := &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 120,
|
|
|
|
Timestamp: 120,
|
|
|
|
SourceID: 120,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
}
|
|
|
|
rsp, err := core.DescribeCollection(ctx, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, collName, rsp.Schema.Name)
|
|
|
|
assert.Equal(t, collMeta.ID, rsp.CollectionID)
|
|
|
|
assert.Equal(t, shardsNum, int32(len(rsp.VirtualChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, int32(len(rsp.PhysicalChannelNames)))
|
|
|
|
assert.Equal(t, shardsNum, rsp.ShardsNum)
|
|
|
|
})
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
|
|
|
assert.Nil(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|