2021-12-20 17:45:37 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 11:12:56 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-20 17:45:37 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:12:56 +08:00
|
|
|
//
|
2021-12-20 17:45:37 +08:00
|
|
|
// 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-04-19 11:12:56 +08:00
|
|
|
|
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"
|
2022-06-10 13:10:08 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
|
|
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"
|
2022-04-01 11:33:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-06-10 13:10: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-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"
|
2022-04-21 19:57:42 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util"
|
2022-04-07 22:05:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2022-03-28 16:41:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
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
|
|
|
)
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
const (
|
|
|
|
TestDMLChannelNum = 32
|
|
|
|
returnError = "ReturnError"
|
|
|
|
returnUnsuccessfulStatus = "ReturnUnsuccessfulStatus"
|
|
|
|
)
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
var disabledIndexBuildID []int64
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
type ctxKey struct{}
|
2021-09-09 17:39:30 +08:00
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
type proxyMock struct {
|
|
|
|
types.Proxy
|
2021-05-26 20:14:30 +08:00
|
|
|
collArray []string
|
2022-05-19 10:13:56 +08:00
|
|
|
collIDs []UniqueID
|
2021-05-26 20:14:30 +08:00
|
|
|
mutex sync.Mutex
|
2022-05-19 10:13:56 +08:00
|
|
|
|
|
|
|
returnError bool
|
|
|
|
returnGrpcError bool
|
2021-05-26 20:14:30 +08:00
|
|
|
}
|
|
|
|
|
2021-11-29 17:33:41 +08:00
|
|
|
func (p *proxyMock) Stop() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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()
|
2022-05-19 10:13:56 +08:00
|
|
|
if p.returnError {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
if p.returnGrpcError {
|
|
|
|
return nil, fmt.Errorf("grpc error")
|
|
|
|
}
|
2021-01-24 20:26:35 +08:00
|
|
|
p.collArray = append(p.collArray, request.CollectionName)
|
2022-05-19 10:13:56 +08:00
|
|
|
p.collIDs = append(p.collIDs, request.CollectionID)
|
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
|
|
|
}
|
2022-05-19 10:13:56 +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
|
|
|
|
}
|
|
|
|
|
2022-05-19 10:13:56 +08:00
|
|
|
func (p *proxyMock) GetCollIDs() []UniqueID {
|
|
|
|
p.mutex.Lock()
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
ret := p.collIDs
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:16:37 +08:00
|
|
|
func (p *proxyMock) ReleaseDQLMessageStream(ctx context.Context, request *proxypb.ReleaseDQLMessageStreamRequest) (*commonpb.Status, error) {
|
2022-05-19 10:13:56 +08:00
|
|
|
if p.returnError {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
if p.returnGrpcError {
|
|
|
|
return nil, fmt.Errorf("grpc error")
|
|
|
|
}
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *proxyMock) InvalidateCredentialCache(ctx context.Context, request *proxypb.InvalidateCredCacheRequest) (*commonpb.Status, error) {
|
|
|
|
if p.returnError {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
if p.returnGrpcError {
|
|
|
|
return nil, fmt.Errorf("grpc error")
|
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
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-12-23 18:39:11 +08:00
|
|
|
NumOfRows: Params.RootCoordCfg.MinSegmentSizeToEnableIndex,
|
2021-06-04 11:45:45 +08:00
|
|
|
State: commonpb.SegmentState_Flushed,
|
2021-03-08 15:46:51 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:36:03 +08:00
|
|
|
func (d *dataMock) GetRecoveryInfo(ctx context.Context, req *datapb.GetRecoveryInfoRequest) (*datapb.GetRecoveryInfoResponse, error) {
|
|
|
|
var fieldBinlog []*datapb.FieldBinlog
|
|
|
|
for i := 0; i < 200; i++ {
|
|
|
|
binlog := &datapb.FieldBinlog{
|
|
|
|
FieldID: int64(i),
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: fmt.Sprintf("file0-%d", i),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LogPath: fmt.Sprintf("file1-%d", i),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LogPath: fmt.Sprintf("file2-%d", i),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
fieldBinlog = append(fieldBinlog, binlog)
|
|
|
|
}
|
|
|
|
|
|
|
|
d.mu.Lock()
|
|
|
|
segmentBinlogs := make([]*datapb.SegmentBinlogs, 0, len(d.segs))
|
|
|
|
for _, segID := range d.segs {
|
|
|
|
segmentBinlog := &datapb.SegmentBinlogs{
|
|
|
|
SegmentID: segID,
|
|
|
|
NumOfRows: Params.RootCoordCfg.MinSegmentSizeToEnableIndex,
|
|
|
|
FieldBinlogs: fieldBinlog,
|
|
|
|
}
|
|
|
|
segmentBinlogs = append(segmentBinlogs, segmentBinlog)
|
|
|
|
}
|
|
|
|
d.mu.Unlock()
|
|
|
|
|
|
|
|
return &datapb.GetRecoveryInfoResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Binlogs: segmentBinlogs,
|
|
|
|
}, 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-11-11 00:54:45 +08:00
|
|
|
func (d *dataMock) WatchChannels(ctx context.Context, req *datapb.WatchChannelsRequest) (*datapb.WatchChannelsResponse, error) {
|
|
|
|
return &datapb.WatchChannelsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
func (d *dataMock) SetSegmentState(ctx context.Context, req *datapb.SetSegmentStateRequest) (*datapb.SetSegmentStateResponse, error) {
|
|
|
|
if req.GetSegmentId() == 999 /* intended failure seg ID */ {
|
|
|
|
return &datapb.SetSegmentStateResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return &datapb.SetSegmentStateResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-01 11:33:28 +08:00
|
|
|
func (d *dataMock) Import(ctx context.Context, req *datapb.ImportTaskRequest) (*datapb.ImportTaskResponse, error) {
|
2022-03-22 15:11:24 +08:00
|
|
|
return &datapb.ImportTaskResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
2022-03-21 15:47:23 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-25 11:07:47 +08:00
|
|
|
func (d *dataMock) Flush(ctx context.Context, req *datapb.FlushRequest) (*datapb.FlushResponse, error) {
|
|
|
|
return &datapb.FlushResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:20:10 +08:00
|
|
|
func (d *dataMock) AcquireSegmentLock(context.Context, *datapb.AcquireSegmentLockRequest) (*commonpb.Status, error) {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataMock) ReleaseSegmentLock(context.Context, *datapb.ReleaseSegmentLockRequest) (*commonpb.Status, error) {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
func (idx *indexMock) GetIndexStates(ctx context.Context, req *indexpb.GetIndexStatesRequest) (*indexpb.GetIndexStatesResponse, error) {
|
|
|
|
v := ctx.Value(ctxKey{}).(string)
|
|
|
|
if v == returnError {
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("(testing) simulating injected error")
|
2022-03-28 16:41:28 +08:00
|
|
|
return nil, fmt.Errorf("injected error")
|
|
|
|
} else if v == returnUnsuccessfulStatus {
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("(testing) simulating unsuccessful status")
|
2022-03-28 16:41:28 +08:00
|
|
|
return &indexpb.GetIndexStatesResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: 100,
|
|
|
|
Reason: "not so good",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
resp := &indexpb.GetIndexStatesResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: 0,
|
|
|
|
Reason: "all good",
|
|
|
|
},
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug(fmt.Sprint("(testing) getting index state for index build IDs:", req.IndexBuildIDs))
|
|
|
|
log.Debug(fmt.Sprint("(testing) banned index build IDs:", disabledIndexBuildID))
|
|
|
|
for _, id := range req.IndexBuildIDs {
|
|
|
|
ban := false
|
|
|
|
for _, disabled := range disabledIndexBuildID {
|
|
|
|
if disabled == id {
|
|
|
|
ban = true
|
|
|
|
resp.States = append(resp.States, &indexpb.IndexInfo{
|
|
|
|
State: commonpb.IndexState_InProgress,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !ban {
|
|
|
|
resp.States = append(resp.States, &indexpb.IndexInfo{
|
|
|
|
State: commonpb.IndexState_Finished,
|
|
|
|
})
|
|
|
|
}
|
2022-03-28 16:41:28 +08:00
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
func createCollectionInMeta(dbName, collName string, core *Core, shardsNum int32, modifyFunc func(*etcdpb.CollectionInfo)) error {
|
2021-09-08 15:00:00 +08:00
|
|
|
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-11-25 10:07:15 +08:00
|
|
|
vchanNames[i] = fmt.Sprintf("%s_%dv%d", core.chanTimeTick.getDmlChannelName(), collID, i)
|
2022-03-15 21:51:21 +08:00
|
|
|
chanNames[i] = funcutil.ToPhysicalChannel(vchanNames[i])
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
collInfo := etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
Schema: &schema,
|
|
|
|
PartitionIDs: []typeutil.UniqueID{partID},
|
|
|
|
PartitionNames: []string{Params.CommonCfg.DefaultPartitionName},
|
|
|
|
FieldIndexes: make([]*etcdpb.FieldIndexInfo, 0, 16),
|
|
|
|
VirtualChannelNames: vchanNames,
|
|
|
|
PhysicalChannelNames: chanNames,
|
|
|
|
ShardsNum: 0, // intend to set zero
|
|
|
|
PartitionCreatedTimestamps: []uint64{0},
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if modifyFunc != nil {
|
|
|
|
modifyFunc(&collInfo)
|
|
|
|
}
|
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
idxInfo := make([]*etcdpb.IndexInfo, 0, 16)
|
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
// 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,
|
2022-01-10 19:03:35 +08:00
|
|
|
PartitionName: Params.CommonCfg.DefaultPartitionName,
|
2021-09-08 15:00:00 +08:00
|
|
|
DbID: 0, //TODO,not used
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
Schema: schemaBytes,
|
|
|
|
VirtualChannelNames: vchanNames,
|
|
|
|
PhysicalChannelNames: chanNames,
|
|
|
|
}
|
|
|
|
|
|
|
|
reason := fmt.Sprintf("create collection %d", collID)
|
|
|
|
ts, err := core.TSOAllocator(1)
|
|
|
|
if err != nil {
|
2021-12-10 10:17:30 +08:00
|
|
|
return fmt.Errorf("tso alloc fail, error = %w", err)
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|
|
|
|
|
2021-10-13 15:54:33 +08:00
|
|
|
// build DdOperation and save it into etcd, when ddmsg send fail,
|
|
|
|
// system can restore ddmsg from etcd and re-send
|
|
|
|
ddCollReq.Base.Timestamp = ts
|
|
|
|
ddOpStr, err := EncodeDdOperation(&ddCollReq, CreateCollectionDDType)
|
|
|
|
if err != nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("encodeDdOperation fail, error = %w", err)
|
2021-10-13 15:54:33 +08:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
// 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()
|
|
|
|
|
2021-11-25 10:07:15 +08:00
|
|
|
core.chanTimeTick.addDdlTimeTick(ts, reason)
|
2021-09-08 15:00:00 +08:00
|
|
|
// clear ddl timetick in all conditions
|
2021-11-25 10:07:15 +08:00
|
|
|
defer core.chanTimeTick.removeDdlTimeTick(ts, reason)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
err = core.MetaTable.AddCollection(&collInfo, ts, idxInfo, ddOpStr)
|
2021-09-08 15:00:00 +08:00
|
|
|
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) {
|
2021-09-18 10:49:51 +08:00
|
|
|
return []string{}, []string{}, retry.Unrecoverable(errors.New("mocked fail"))
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRootCoordInit(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
coreFactory := dependency.NewDefaultFactory(true)
|
2021-09-15 22:05:49 +08:00
|
|
|
Params.Init()
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
2021-12-29 14:35:21 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2021-12-29 14:35:21 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
core, err := NewCore(ctx, coreFactory)
|
|
|
|
require.Nil(t, err)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-15 22:05:49 +08:00
|
|
|
randVal := rand.Int()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
// inject kvBaseCreate fail
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-15 22:05:49 +08:00
|
|
|
require.Nil(t, err)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
randVal = rand.Int()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
2021-09-18 10:49:51 +08:00
|
|
|
return nil, retry.Unrecoverable(errors.New("injected"))
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
core.metaKVCreate = func(root string) (kv.MetaKv, error) {
|
|
|
|
return nil, retry.Unrecoverable(errors.New("injected"))
|
|
|
|
}
|
2021-09-15 22:05:49 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
// inject metaKV create fail
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-15 22:05:49 +08:00
|
|
|
require.Nil(t, err)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
randVal = rand.Int()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
|
|
|
core.kvBaseCreate = func(root string) (kv.TxnKV, error) {
|
2022-02-07 10:09:45 +08:00
|
|
|
if root == Params.EtcdCfg.MetaRootPath {
|
2021-09-18 10:49:51 +08:00
|
|
|
return nil, retry.Unrecoverable(errors.New("injected"))
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
|
|
|
return memkv.NewMemoryKV(), nil
|
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
core.metaKVCreate = func(root string) (kv.MetaKv, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2021-09-15 22:05:49 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
// inject newSuffixSnapshot failure
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-15 22:05:49 +08:00
|
|
|
require.Nil(t, err)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
randVal = rand.Int()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
core.metaKVCreate = func(root string) (kv.MetaKv, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2021-09-15 22:05:49 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
// inject newMetaTable failure
|
|
|
|
core, err = NewCore(ctx, coreFactory)
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-15 22:05:49 +08:00
|
|
|
require.Nil(t, err)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
randVal = rand.Int()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
|
|
|
core.kvBaseCreate = func(string) (kv.TxnKV, error) {
|
|
|
|
kv := memkv.NewMemoryKV()
|
|
|
|
return &loadPrefixFailKV{TxnKV: kv}, nil
|
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
core.metaKVCreate = func(root string) (kv.MetaKv, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2021-09-15 22:05:49 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
|
|
|
|
2022-04-21 19:57:42 +08:00
|
|
|
func TestRootCoordInitData(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
coreFactory := dependency.NewDefaultFactory(true)
|
|
|
|
Params.Init()
|
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
|
|
|
|
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
|
|
|
core, err := NewCore(ctx, coreFactory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
core.SetEtcdClient(etcdCli)
|
|
|
|
|
|
|
|
randVal := rand.Int()
|
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
|
|
|
|
|
|
|
// 1. normal init
|
|
|
|
err = core.Init()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// 2. mock init data error
|
|
|
|
// firstly delete data
|
|
|
|
err = core.MetaTable.DeleteCredential(util.UserRoot)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
snapshotKV, err := newMetaSnapshot(etcdCli, Params.EtcdCfg.MetaRootPath, TimestampPrefix, 7)
|
2022-04-21 19:57:42 +08:00
|
|
|
assert.NotNil(t, snapshotKV)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
txnKV := etcdkv.NewEtcdKV(etcdCli, Params.EtcdCfg.MetaRootPath)
|
2022-06-10 13:10:08 +08:00
|
|
|
mt, err := NewMetaTable(txnKV, snapshotKV)
|
2022-04-21 19:57:42 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
mockTxnKV := &mockTestTxnKV{
|
2022-06-10 13:10:08 +08:00
|
|
|
TxnKV: mt.txn,
|
|
|
|
save: func(key, value string) error { return txnKV.Save(key, value) },
|
2022-04-21 19:57:42 +08:00
|
|
|
remove: func(key string) error { return txnKV.Remove(key) },
|
|
|
|
}
|
2022-06-10 13:10:08 +08:00
|
|
|
mt.txn = mockTxnKV
|
|
|
|
// mock save data error
|
|
|
|
mockTxnKV.save = func(key, value string) error {
|
|
|
|
return fmt.Errorf("save error")
|
|
|
|
}
|
2022-04-21 19:57:42 +08:00
|
|
|
core.MetaTable = mt
|
|
|
|
err = core.initData()
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
func TestRootCoord_Base(t *testing.T) {
|
2021-05-17 19:15:01 +08:00
|
|
|
const (
|
2021-09-18 11:13:51 +08:00
|
|
|
dbName = "testDb"
|
|
|
|
collName = "testColl"
|
|
|
|
collName2 = "testColl2"
|
|
|
|
aliasName = "alias1"
|
|
|
|
partName = "testPartition"
|
|
|
|
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()
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
coreFactory := dependency.NewDefaultFactory(true)
|
2021-02-23 11:40:30 +08:00
|
|
|
Params.Init()
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
2022-04-03 11:37:29 +08:00
|
|
|
Params.RootCoordCfg.ImportIndexCheckInterval = 0.1
|
|
|
|
Params.RootCoordCfg.ImportIndexWaitLimit = 0.2
|
2022-05-05 21:17:50 +08:00
|
|
|
Params.RootCoordCfg.ImportSegmentStateCheckInterval = 0.1
|
|
|
|
Params.RootCoordCfg.ImportSegmentStateWaitLimit = 0.2
|
|
|
|
core, err := NewCore(context.WithValue(ctx, ctxKey{}, ""), coreFactory)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
randVal := rand.Int()
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordTimeTick = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordStatistics = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordSubName = fmt.Sprintf("subname-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordDml = fmt.Sprintf("rootcoord-dml-test-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordDelta = fmt.Sprintf("rootcoord-delta-test-%d", randVal)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2021-12-29 14:35:21 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
sessKey := path.Join(Params.EtcdCfg.MetaRootPath, sessionutil.DefaultServiceRoot)
|
2021-05-26 20:14:30 +08:00
|
|
|
_, err = etcdCli.Delete(ctx, sessKey, clientv3.WithPrefix())
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-21 16:08:12 +08:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-22 14:40:07 +08:00
|
|
|
_, err = etcdCli.Put(ctx, path.Join(sessKey, typeutil.ProxyRole+"-100"), string(pnb))
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-26 20:14:30 +08:00
|
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
tmpFactory := dependency.NewDefaultFactory(true)
|
2021-02-08 14:30:54 +08:00
|
|
|
|
2021-06-04 15:00:34 +08:00
|
|
|
dmlStream, _ := tmpFactory.NewMsgStream(ctx)
|
2022-04-12 19:47:33 +08:00
|
|
|
defer dmlStream.Close()
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
|
|
|
|
2021-06-02 22:36:41 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-02 22:36:41 +08:00
|
|
|
|
2021-12-14 15:31:07 +08:00
|
|
|
var localTSO uint64
|
2021-06-03 18:03:33 +08:00
|
|
|
localTSOLock := sync.RWMutex{}
|
|
|
|
core.TSOAllocator = func(c uint32) (uint64, error) {
|
|
|
|
localTSOLock.Lock()
|
|
|
|
defer localTSOLock.Unlock()
|
|
|
|
localTSO += uint64(c)
|
|
|
|
return localTSO, nil
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:20:10 +08:00
|
|
|
expireOldTasksInterval = 500
|
2021-06-02 22:36:41 +08:00
|
|
|
err = core.Start()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-02 22:36:41 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
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-12-29 14:35:21 +08:00
|
|
|
var wg sync.WaitGroup
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("create collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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-11-25 10:07:15 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(core.chanTimeTick.getDmlChannelNum()))
|
2021-02-03 20:04:29 +08:00
|
|
|
|
2021-11-02 15:50:30 +08:00
|
|
|
createMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-04 11:17:56 +08:00
|
|
|
dmlStream.AsConsumer([]string{createMeta.PhysicalChannelNames[0]}, Params.CommonCfg.RootCoordSubName)
|
2021-06-04 15:00:34 +08:00
|
|
|
dmlStream.Start()
|
|
|
|
|
2021-11-02 15:50:30 +08:00
|
|
|
pChanMap := core.MetaTable.ListCollectionPhysicalChannels()
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Greater(t, len(pChanMap[createMeta.ID]), 0)
|
2021-11-02 15:50:30 +08:00
|
|
|
vChanMap := core.MetaTable.ListCollectionVirtualChannels()
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Greater(t, len(vChanMap[createMeta.ID]), 0)
|
2021-11-02 15:50:30 +08:00
|
|
|
|
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)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, createMeta.ID, createMsg.CollectionID)
|
|
|
|
assert.Equal(t, 1, len(createMeta.PartitionIDs))
|
|
|
|
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]
|
2022-03-15 21:51:21 +08:00
|
|
|
assert.Equal(t, createMeta.PhysicalChannelNames[0], funcutil.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()
|
2022-01-18 14:47:36 +08:00
|
|
|
assert.Equal(t, len(core.chanTimeTick.sess2ChanTsMap), 2)
|
|
|
|
pt, ok := core.chanTimeTick.sess2ChanTsMap[core.session.ServerID]
|
2021-06-04 15:00:34 +08:00
|
|
|
assert.True(t, ok)
|
2022-01-18 14:47:36 +08:00
|
|
|
assert.Equal(t, shardsNum, int32(len(pt.chanTsMap)))
|
|
|
|
for chanName, ts := range pt.chanTsMap {
|
2021-11-27 13:57:16 +08:00
|
|
|
assert.Contains(t, createMeta.PhysicalChannelNames, chanName)
|
|
|
|
assert.Equal(t, pt.defaultTs, ts)
|
|
|
|
}
|
2021-06-11 16:39:29 +08:00
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
|
|
|
|
// check DD operation info
|
2021-10-21 14:04:36 +08:00
|
|
|
flag, err := core.MetaTable.txn.Load(DDMsgSendPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-11 16:39:29 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-10-21 14:04:36 +08:00
|
|
|
ddOpStr, err := core.MetaTable.txn.Load(DDOperationPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-11 16:39:29 +08:00
|
|
|
var ddOp DdOperation
|
|
|
|
err = DecodeDdOperation(ddOpStr, &ddOp)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-11 16:39:29 +08:00
|
|
|
assert.Equal(t, CreateCollectionDDType, ddOp.Type)
|
|
|
|
|
|
|
|
var ddCollReq = internalpb.CreateCollectionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
err = proto.Unmarshal(ddOp.Body, &ddCollReq)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, createMeta.ID, ddCollReq.CollectionID)
|
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("has collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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: 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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-06-10 13:10:08 +08:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("show collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("create partition", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, 2, len(collMeta.PartitionIDs))
|
|
|
|
partNameIdx1, err := core.MetaTable.GetPartitionNameByID(collMeta.ID, collMeta.PartitionIDs[1], 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, partMsg.CollectionID)
|
|
|
|
assert.Equal(t, collMeta.PartitionIDs[1], partMsg.PartitionID)
|
2021-03-22 16:36:10 +08:00
|
|
|
|
2022-05-19 10:13:56 +08:00
|
|
|
assert.Equal(t, 1, len(pnm.GetCollIDs()))
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, pnm.GetCollIDs()[0])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-10-21 14:04:36 +08:00
|
|
|
flag, err := core.MetaTable.txn.Load(DDMsgSendPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-10-21 14:04:36 +08:00
|
|
|
ddOpStr, err := core.MetaTable.txn.Load(DDOperationPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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{}
|
2021-09-23 10:37:54 +08:00
|
|
|
err = proto.Unmarshal(ddOp.Body, &ddReq)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
|
|
|
assert.Equal(t, collMeta.PartitionIDs[1], ddReq.PartitionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("has partition", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("show partition", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: coll.ID,
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.ShowPartitions(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("show segment", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
partID := coll.PartitionIDs[1]
|
2021-07-03 14:36:18 +08:00
|
|
|
dm.mu.Lock()
|
2022-03-31 13:51:28 +08:00
|
|
|
dm.segs = []typeutil.UniqueID{1000, 1001, 1002, 1003, 1004, 1005}
|
2021-07-03 14:36:18 +08:00
|
|
|
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,
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: coll.GetID(),
|
2021-01-24 20:26:35 +08:00
|
|
|
PartitionID: partID,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.ShowSegments(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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])
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.Equal(t, int64(1001), rsp.SegmentIDs[1])
|
|
|
|
assert.Equal(t, int64(1002), rsp.SegmentIDs[2])
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.Equal(t, int64(1003), rsp.SegmentIDs[3])
|
|
|
|
assert.Equal(t, int64(1004), rsp.SegmentIDs[4])
|
|
|
|
assert.Equal(t, int64(1005), rsp.SegmentIDs[5])
|
|
|
|
assert.Equal(t, 6, len(rsp.SegmentIDs))
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("create index", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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()
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.Equal(t, 6*3, len(files))
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.ElementsMatch(t, files,
|
|
|
|
[]string{"file0-100", "file1-100", "file2-100",
|
2022-03-31 13:51:28 +08:00
|
|
|
"file0-100", "file1-100", "file2-100",
|
|
|
|
"file0-100", "file1-100", "file2-100",
|
|
|
|
"file0-100", "file1-100", "file2-100",
|
2022-03-28 16:41:28 +08:00
|
|
|
"file0-100", "file1-100", "file2-100",
|
|
|
|
"file0-100", "file1-100", "file2-100"})
|
2021-05-18 14:18:02 +08:00
|
|
|
collMeta, err = core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-01-10 19:03:35 +08:00
|
|
|
assert.Equal(t, Params.CommonCfg.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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("describe segment", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: coll.ID,
|
2021-01-24 20:26:35 +08:00
|
|
|
SegmentID: 1000,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := core.DescribeSegment(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("describe index", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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: 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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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))
|
2022-01-10 19:03:35 +08:00
|
|
|
assert.Equal(t, Params.CommonCfg.DefaultIndexName, rsp.IndexDescriptions[0].IndexName)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, "vector", rsp.IndexDescriptions[0].FieldName)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-03-05 20:41:34 +08:00
|
|
|
t.Run("describe index not exist", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-03-05 20:41:34 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("count complete index", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
// Normal case.
|
2022-06-15 12:20:10 +08:00
|
|
|
done, err := core.CountCompleteIndex(context.WithValue(ctx, ctxKey{}, ""),
|
2022-06-10 13:10:08 +08:00
|
|
|
collName, coll.ID, []UniqueID{1000, 1001, 1002})
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-15 12:20:10 +08:00
|
|
|
assert.Equal(t, true, done)
|
2022-03-28 16:41:28 +08:00
|
|
|
// Case with an empty result.
|
2022-06-15 12:20:10 +08:00
|
|
|
done, err = core.CountCompleteIndex(ctx, collName, coll.ID, []UniqueID{})
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-15 12:20:10 +08:00
|
|
|
assert.Equal(t, true, done)
|
2022-03-28 16:41:28 +08:00
|
|
|
// Case where GetIndexStates failed with error.
|
|
|
|
_, err = core.CountCompleteIndex(context.WithValue(ctx, ctxKey{}, returnError),
|
2022-06-10 13:10:08 +08:00
|
|
|
collName, coll.ID, []UniqueID{1000, 1001, 1002})
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
// Case where GetIndexStates failed with bad status.
|
|
|
|
_, err = core.CountCompleteIndex(context.WithValue(ctx, ctxKey{}, returnUnsuccessfulStatus),
|
2022-06-10 13:10:08 +08:00
|
|
|
collName, coll.ID, []UniqueID{1000, 1001, 1002})
|
2022-03-28 16:41:28 +08:00
|
|
|
assert.Error(t, err)
|
2022-06-15 12:20:10 +08:00
|
|
|
// Case where describing segment fails, which is not considered as an error.
|
|
|
|
_, err = core.CountCompleteIndex(context.WithValue(ctx, ctxKey{}, ""),
|
|
|
|
collName, coll.ID, []UniqueID{9000, 9001, 9002})
|
|
|
|
assert.NoError(t, err)
|
2022-03-28 16:41:28 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("flush segment", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-18 14:18:02 +08:00
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
partID := coll.PartitionIDs[1]
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
flushMsg := datapb.SegmentFlushCompletedMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_SegmentFlushDone,
|
|
|
|
},
|
|
|
|
Segment: &datapb.SegmentInfo{
|
|
|
|
ID: segID,
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: coll.ID,
|
2021-07-03 14:36:18 +08:00
|
|
|
PartitionID: partID,
|
|
|
|
},
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-07-03 14:36:18 +08:00
|
|
|
st, err := core.SegmentFlushCompleted(ctx, &flushMsg)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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))
|
2022-01-10 19:03:35 +08:00
|
|
|
assert.Equal(t, Params.CommonCfg.DefaultIndexName, rsp.IndexDescriptions[0].IndexName)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("import", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
2022-04-24 11:29:45 +08:00
|
|
|
tID := typeutil.UniqueID(0)
|
|
|
|
core.importManager.idAllocator = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
|
|
|
tID++
|
|
|
|
return tID, 0, nil
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
req := &milvuspb.ImportRequest{
|
|
|
|
CollectionName: collName,
|
|
|
|
PartitionName: partName,
|
|
|
|
RowBased: true,
|
|
|
|
Files: []string{"f1", "f2", "f3"},
|
|
|
|
}
|
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.collName2ID[collName] = coll.GetID()
|
2022-03-31 13:51:28 +08:00
|
|
|
rsp, err := core.Import(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
wg.Add(1)
|
2022-05-09 20:47:52 +08:00
|
|
|
t.Run("import with collection ID not found", func(t *testing.T) {
|
2022-03-31 13:51:28 +08:00
|
|
|
defer wg.Done()
|
|
|
|
req := &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "bad name",
|
|
|
|
PartitionName: partName,
|
|
|
|
RowBased: true,
|
|
|
|
Files: []string{"f1", "f2", "f3"},
|
|
|
|
}
|
|
|
|
_, err := core.Import(ctx, req)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
t.Run("get import state", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
req := &milvuspb.GetImportStateRequest{
|
2022-04-24 11:29:45 +08:00
|
|
|
Task: 1,
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
|
|
|
rsp, err := core.GetImportState(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-04-25 17:37:46 +08:00
|
|
|
wg.Add(1)
|
2022-05-05 21:17:50 +08:00
|
|
|
t.Run("list import tasks", func(t *testing.T) {
|
2022-04-25 17:37:46 +08:00
|
|
|
defer wg.Done()
|
|
|
|
req := &milvuspb.ListImportTasksRequest{}
|
|
|
|
rsp, err := core.ListImportTasks(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import task timeout", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
coll, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-31 13:51:28 +08:00
|
|
|
req := &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 1,
|
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{1003, 1004, 1005},
|
2022-05-05 21:17:50 +08:00
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, segmentID := range []int64{1003, 1004, 1005} {
|
|
|
|
describeSegmentRequest := &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeSegment,
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: coll.ID,
|
2022-03-31 13:51:28 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
}
|
|
|
|
segDesc, err := core.DescribeSegment(ctx, describeSegmentRequest)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
disabledIndexBuildID = append(disabledIndexBuildID, segDesc.BuildID)
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
})
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import update import task fail", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
// Case where report import request is nil.
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UpdateImportTaskFailure, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import collection name not found", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
2022-04-24 11:29:45 +08:00
|
|
|
var tID = typeutil.UniqueID(100)
|
|
|
|
core.importManager.idAllocator = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
|
|
|
tID++
|
|
|
|
return tID, 0, nil
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
|
|
|
core.MetaTable.collName2ID["new"+collName] = 123
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.collID2Meta[123] = etcdpb.CollectionInfo{
|
|
|
|
ID: 123,
|
|
|
|
PartitionIDs: []int64{456},
|
|
|
|
PartitionNames: []string{"testPartition"}}
|
2022-04-24 11:29:45 +08:00
|
|
|
req := &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "new" + collName,
|
|
|
|
PartitionName: partName,
|
|
|
|
RowBased: true,
|
|
|
|
Files: []string{"f1", "f2", "f3"},
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
rsp, err := core.Import(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
delete(core.MetaTable.collName2ID, "new"+collName)
|
2022-04-20 14:03:40 +08:00
|
|
|
delete(core.MetaTable.collID2Meta, 123)
|
2022-03-31 13:51:28 +08:00
|
|
|
|
|
|
|
reqIR := &rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 101,
|
2022-03-31 13:51:28 +08:00
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{1003, 1004, 1005},
|
2022-05-05 21:17:50 +08:00
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), reqIR)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_CollectionNameNotFound, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import with transitional state", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
req := &rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 1,
|
2022-04-03 11:37:29 +08:00
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{1000, 1001, 1002},
|
|
|
|
State: commonpb.ImportState_ImportDownloaded,
|
|
|
|
}
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
})
|
|
|
|
|
2022-06-15 12:20:10 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import with alloc seg state", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
req := &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 1,
|
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{1000, 1001, 1002},
|
|
|
|
State: commonpb.ImportState_ImportAllocSegment,
|
|
|
|
}
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
})
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
wg.Add(1)
|
2022-05-12 19:23:53 +08:00
|
|
|
t.Run("report import wait for index", func(t *testing.T) {
|
2022-03-31 13:51:28 +08:00
|
|
|
defer wg.Done()
|
2022-05-12 19:23:53 +08:00
|
|
|
core.CallGetSegmentInfoService = func(ctx context.Context, collectionID int64,
|
|
|
|
segIDs []int64) (*querypb.GetSegmentInfoResponse, error) {
|
|
|
|
return &querypb.GetSegmentInfoResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
|
|
|
Infos: []*querypb.SegmentInfo{
|
|
|
|
{SegmentID: 1000},
|
|
|
|
{SegmentID: 1001},
|
|
|
|
{SegmentID: 1002},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
req := &rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 1,
|
2022-03-31 13:51:28 +08:00
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{1000, 1001, 1002},
|
2022-05-05 21:17:50 +08:00
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
})
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import bring segments online with set segment state fail", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
req := &rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 1,
|
2022-04-06 15:33:32 +08:00
|
|
|
RowCount: 100,
|
|
|
|
Segments: []int64{999}, /* pre-injected failure for segment ID = 999 */
|
2022-05-05 21:17:50 +08:00
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
2022-04-06 15:33:32 +08:00
|
|
|
}
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
wg.Add(1)
|
|
|
|
t.Run("report import segments update already failed task", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
// Mark task 0 as failed.
|
|
|
|
core.importManager.updateTaskState(
|
|
|
|
&rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 1,
|
2022-04-03 11:37:29 +08:00
|
|
|
RowCount: 100,
|
|
|
|
State: commonpb.ImportState_ImportFailed,
|
|
|
|
Segments: []int64{1000, 1001, 1002},
|
|
|
|
})
|
|
|
|
// Now try to update this task with a complete status.
|
|
|
|
resp, err := core.ReportImport(context.WithValue(ctx, ctxKey{}, ""),
|
|
|
|
&rootcoordpb.ImportResult{
|
2022-04-24 11:29:45 +08:00
|
|
|
TaskId: 1,
|
2022-04-03 11:37:29 +08:00
|
|
|
RowCount: 100,
|
2022-05-05 21:17:50 +08:00
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
2022-04-03 11:37:29 +08:00
|
|
|
Segments: []int64{1000, 1001, 1002},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UpdateImportTaskFailure, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-03-10 16:21:49 +08:00
|
|
|
t.Run("over ride index", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-03-10 16:21:49 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
|
|
|
|
rsp, err := core.CreateIndex(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-05 21:33:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, rsp.ErrorCode)
|
2021-03-10 16:21:49 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-02-20 15:38:44 +08:00
|
|
|
t.Run("drop index", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-02-20 15:38:44 +08:00
|
|
|
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",
|
2022-01-10 19:03:35 +08:00
|
|
|
IndexName: Params.CommonCfg.DefaultIndexName,
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2022-01-10 19:03:35 +08:00
|
|
|
_, idx, err := core.MetaTable.GetIndexByName(collName, Params.CommonCfg.DefaultIndexName)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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()
|
|
|
|
|
2022-01-10 19:03:35 +08:00
|
|
|
_, idx, err = core.MetaTable.GetIndexByName(collName, Params.CommonCfg.DefaultIndexName)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("drop partition", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-01-24 20:26:35 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
dropPartID := collMeta.PartitionIDs[1]
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.DropPartition(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, 1, len(collMeta.PartitionIDs))
|
|
|
|
partName, err := core.MetaTable.GetPartitionNameByID(collMeta.ID, collMeta.PartitionIDs[0], 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-01-10 19:03:35 +08:00
|
|
|
assert.Equal(t, Params.CommonCfg.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)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, dmsg.CollectionID)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, dropPartID, dmsg.PartitionID)
|
2021-03-22 16:36:10 +08:00
|
|
|
|
2022-05-19 10:13:56 +08:00
|
|
|
assert.Equal(t, 2, len(pnm.GetCollIDs()))
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, pnm.GetCollIDs()[1])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-10-21 14:04:36 +08:00
|
|
|
flag, err := core.MetaTable.txn.Load(DDMsgSendPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-10-21 14:04:36 +08:00
|
|
|
ddOpStr, err := core.MetaTable.txn.Load(DDOperationPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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{}
|
2021-09-23 10:37:54 +08:00
|
|
|
err = proto.Unmarshal(ddOp.Body, &ddReq)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, dropPartID, ddReq.PartitionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-07 11:16:37 +08:00
|
|
|
t.Run("remove DQL msgstream", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-07 11:16:37 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
req := &proxypb.ReleaseDQLMessageStreamRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_RemoveQueryChannels,
|
|
|
|
SourceID: core.session.ServerID,
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
CollectionID: collMeta.ID,
|
2021-09-07 11:16:37 +08:00
|
|
|
}
|
|
|
|
status, err := core.ReleaseDQLMessageStream(core.ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
t.Run("drop collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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: 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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-26 17:44:24 +08:00
|
|
|
status, err := core.DropCollection(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-17 19:15:01 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
vChanName := collMeta.VirtualChannelNames[0]
|
2022-03-15 21:51:21 +08:00
|
|
|
assert.Equal(t, collMeta.PhysicalChannelNames[0], funcutil.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)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, dmsg.CollectionID)
|
2022-05-19 10:13:56 +08:00
|
|
|
collIDs := pnm.GetCollIDs()
|
|
|
|
assert.Equal(t, 3, len(collIDs))
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, collIDs[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))
|
2022-06-10 13:10:08 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-05-19 10:13:56 +08:00
|
|
|
collIDs = pnm.GetCollIDs()
|
|
|
|
assert.Equal(t, 3, len(collIDs))
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, collIDs[2])
|
2021-05-12 15:33:53 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
// check DD operation info
|
2021-10-21 14:04:36 +08:00
|
|
|
flag, err := core.MetaTable.txn.Load(DDMsgSendPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, "true", flag)
|
2021-10-21 14:04:36 +08:00
|
|
|
ddOpStr, err := core.MetaTable.txn.Load(DDOperationPrefix)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-14 21:26:06 +08:00
|
|
|
assert.Equal(t, DropCollectionDDType, ddOp.Type)
|
|
|
|
|
|
|
|
var ddReq = internalpb.DropCollectionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
err = proto.Unmarshal(ddOp.Body, &ddReq)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-06-10 13:10:08 +08:00
|
|
|
assert.Equal(t, collMeta.ID, ddReq.CollectionID)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
err = core.reSendDdMsg(core.ctx, true)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("context_cancel", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-04-08 15:26:18 +08:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-06-11 16:39:29 +08:00
|
|
|
t.Run("undefined req type", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("alloc time tick", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
assert.Equal(t, uint32(1), rsp.Count)
|
|
|
|
assert.NotZero(t, rsp.Timestamp)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("alloc id", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
assert.Equal(t, uint32(1), rsp.Count)
|
|
|
|
assert.NotZero(t, rsp.ID)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("get_channels", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-04-08 15:26:18 +08:00
|
|
|
_, err := core.GetTimeTickChannel(ctx)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
_, err = core.GetStatisticsChannel(ctx)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-05-21 16:08:12 +08:00
|
|
|
t.Run("channel timetick", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-21 16:08:12 +08:00
|
|
|
const (
|
2021-06-22 19:08:03 +08:00
|
|
|
proxyIDInvalid = 102
|
2022-04-17 23:47:36 +08:00
|
|
|
ts0 = uint64(20)
|
|
|
|
ts1 = uint64(40)
|
|
|
|
ts2 = uint64(60)
|
2021-05-21 16:08:12 +08:00
|
|
|
)
|
2021-11-25 10:07:15 +08:00
|
|
|
numChan := core.chanTimeTick.getDmlChannelNum()
|
2021-05-21 16:08:12 +08:00
|
|
|
p1 := sessionutil.Session{
|
|
|
|
ServerID: 100,
|
|
|
|
}
|
|
|
|
p2 := sessionutil.Session{
|
|
|
|
ServerID: 101,
|
|
|
|
}
|
2022-06-10 13:10:08 +08:00
|
|
|
ctx2, cancel2 := context.WithTimeout(ctx, RequestTimeout)
|
2021-05-21 16:08:12 +08:00
|
|
|
defer cancel2()
|
|
|
|
s1, err := json.Marshal(&p1)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-21 16:08:12 +08:00
|
|
|
s2, err := json.Marshal(&p2)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
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))
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
_, err = core.etcdCli.Put(ctx2, proxy2, string(s2))
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
2021-11-25 10:07:15 +08:00
|
|
|
cn0 := core.chanTimeTick.getDmlChannelName()
|
|
|
|
cn1 := core.chanTimeTick.getDmlChannelName()
|
|
|
|
cn2 := core.chanTimeTick.getDmlChannelName()
|
|
|
|
core.chanTimeTick.addDmlChannels(cn0, cn1, cn2)
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-11-25 10:07:15 +08:00
|
|
|
dn0 := core.chanTimeTick.getDeltaChannelName()
|
|
|
|
dn1 := core.chanTimeTick.getDeltaChannelName()
|
|
|
|
dn2 := core.chanTimeTick.getDeltaChannelName()
|
|
|
|
core.chanTimeTick.addDeltaChannels(dn0, dn1, dn2)
|
2021-11-03 21:04:14 +08:00
|
|
|
|
2022-04-17 23:47:36 +08:00
|
|
|
// wait for local channel reported
|
|
|
|
for {
|
|
|
|
core.chanTimeTick.lock.Lock()
|
|
|
|
_, ok := core.chanTimeTick.sess2ChanTsMap[core.session.ServerID].chanTsMap[cn0]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, ok = core.chanTimeTick.sess2ChanTsMap[core.session.ServerID].chanTsMap[cn1]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, ok = core.chanTimeTick.sess2ChanTsMap[core.session.ServerID].chanTsMap[cn2]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
core.chanTimeTick.lock.Unlock()
|
|
|
|
break
|
|
|
|
}
|
2021-05-21 16:08:12 +08:00
|
|
|
msg0 := &internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
SourceID: 100,
|
|
|
|
},
|
2022-04-17 23:47:36 +08:00
|
|
|
ChannelNames: []string{cn0, cn1},
|
2021-05-21 16:08:12 +08:00
|
|
|
Timestamps: []uint64{ts0, ts2},
|
|
|
|
}
|
|
|
|
s, _ := core.UpdateChannelTimeTick(ctx, msg0)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, s.ErrorCode)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2022-01-18 14:47:36 +08:00
|
|
|
//t.Log(core.chanTimeTick.sess2ChanTsMap)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
|
|
|
msg1 := &internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
SourceID: 101,
|
|
|
|
},
|
2022-04-17 23:47:36 +08:00
|
|
|
ChannelNames: []string{cn1, cn2},
|
2021-05-21 16:08:12 +08:00
|
|
|
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
|
2022-01-18 14:47:36 +08:00
|
|
|
assert.Equal(t, 3, core.chanTimeTick.getSessionNum())
|
2021-06-04 15:00:34 +08:00
|
|
|
|
2021-06-26 09:22:11 +08:00
|
|
|
// add 3 proxy channels
|
2021-11-25 10:07:15 +08:00
|
|
|
assert.Equal(t, 3, core.chanTimeTick.getDmlChannelNum()-numChan)
|
2021-09-07 11:16:37 +08:00
|
|
|
|
|
|
|
_, err = core.etcdCli.Delete(ctx2, proxy1)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 11:16:37 +08:00
|
|
|
_, err = core.etcdCli.Delete(ctx2, proxy2)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-21 16:08:12 +08:00
|
|
|
})
|
|
|
|
|
2021-09-18 11:13:51 +08:00
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: collName,
|
|
|
|
}
|
|
|
|
sbf, err := proto.Marshal(&schema)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
req := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
MsgID: 3011,
|
|
|
|
Timestamp: 3011,
|
|
|
|
SourceID: 3011,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
Schema: sbf,
|
|
|
|
}
|
|
|
|
status, err := core.CreateCollection(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-18 11:13:51 +08:00
|
|
|
t.Run("create alias", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-18 11:13:51 +08:00
|
|
|
req := &milvuspb.CreateAliasRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateAlias,
|
|
|
|
MsgID: 3012,
|
|
|
|
Timestamp: 3012,
|
|
|
|
SourceID: 3012,
|
|
|
|
},
|
|
|
|
CollectionName: collName,
|
|
|
|
Alias: aliasName,
|
|
|
|
}
|
|
|
|
rsp, err := core.CreateAlias(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-22 16:20:48 +08:00
|
|
|
t.Run("describe collection2", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-22 16:20:48 +08:00
|
|
|
req := &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 3013,
|
|
|
|
Timestamp: 3013,
|
|
|
|
SourceID: 3013,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
}
|
|
|
|
rsp, err := core.DescribeCollection(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-22 16:20:48 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, rsp.Aliases, []string{aliasName})
|
|
|
|
})
|
|
|
|
|
2021-09-18 11:13:51 +08:00
|
|
|
// temporarily create collName2
|
|
|
|
schema = schemapb.CollectionSchema{
|
|
|
|
Name: collName2,
|
|
|
|
}
|
|
|
|
sbf, err = proto.Marshal(&schema)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
req2 := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
2021-09-22 16:20:48 +08:00
|
|
|
MsgID: 3014,
|
|
|
|
Timestamp: 3014,
|
|
|
|
SourceID: 3014,
|
2021-09-18 11:13:51 +08:00
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName2,
|
|
|
|
Schema: sbf,
|
|
|
|
}
|
|
|
|
status, err = core.CreateCollection(ctx, req2)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-18 11:13:51 +08:00
|
|
|
t.Run("alter alias", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-18 11:13:51 +08:00
|
|
|
req := &milvuspb.AlterAliasRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_AlterAlias,
|
2021-09-22 16:20:48 +08:00
|
|
|
MsgID: 3015,
|
|
|
|
Timestamp: 3015,
|
|
|
|
SourceID: 3015,
|
2021-09-18 11:13:51 +08:00
|
|
|
},
|
|
|
|
CollectionName: collName2,
|
|
|
|
Alias: aliasName,
|
|
|
|
}
|
|
|
|
rsp, err := core.AlterAlias(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-10-08 17:37:53 +08:00
|
|
|
t.Run("drop collection with alias", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-10-08 17:37:53 +08:00
|
|
|
req := &milvuspb.DropCollectionRequest{
|
2021-09-18 11:13:51 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropAlias,
|
2021-09-22 16:20:48 +08:00
|
|
|
MsgID: 3016,
|
|
|
|
Timestamp: 3016,
|
|
|
|
SourceID: 3016,
|
2021-09-18 11:13:51 +08:00
|
|
|
},
|
2021-10-08 17:37:53 +08:00
|
|
|
CollectionName: aliasName,
|
|
|
|
}
|
|
|
|
rsp, err := core.DropCollection(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-08 17:37:53 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-10-08 17:37:53 +08:00
|
|
|
t.Run("drop alias", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-10-08 17:37:53 +08:00
|
|
|
req := &milvuspb.DropAliasRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropAlias,
|
|
|
|
MsgID: 3017,
|
|
|
|
Timestamp: 3017,
|
|
|
|
SourceID: 3017,
|
|
|
|
},
|
2021-09-18 11:13:51 +08:00
|
|
|
Alias: aliasName,
|
|
|
|
}
|
|
|
|
rsp, err := core.DropAlias(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
2021-10-08 17:37:53 +08:00
|
|
|
MsgID: 3018,
|
|
|
|
Timestamp: 3018,
|
|
|
|
SourceID: 3018,
|
2021-09-18 11:13:51 +08:00
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DropCollection,
|
2021-10-08 17:37:53 +08:00
|
|
|
MsgID: 3019,
|
|
|
|
Timestamp: 3019,
|
|
|
|
SourceID: 3019,
|
2021-09-18 11:13:51 +08:00
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName2,
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-18 11:13:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-08-31 11:45:59 +08:00
|
|
|
t.Run("get metrics", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-08-31 11:45:59 +08:00
|
|
|
// not healthy
|
|
|
|
stateSave := core.stateCode.Load().(internalpb.StateCode)
|
|
|
|
core.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
resp, err := core.GetMetrics(ctx, &milvuspb.GetMetricsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
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,
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// unsupported metric type
|
|
|
|
unsupportedMetricType := "unsupported"
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(unsupportedMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
resp, err = core.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// normal case
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err = metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
resp, err = core.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-08-31 11:45:59 +08:00
|
|
|
t.Run("get system info", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-08-31 11:45:59 +08:00
|
|
|
// normal case
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
resp, err := core.getSystemInfoMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
err = core.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 15:26:18 +08:00
|
|
|
st, err := core.GetComponentStates(ctx)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 15:26:18 +08:00
|
|
|
t.Run("state_not_healthy", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-04-08 15:26:18 +08:00
|
|
|
st, err := core.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
MsgID: 4000,
|
|
|
|
Timestamp: 4000,
|
|
|
|
SourceID: 4000,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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,
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
|
2022-03-21 15:47:23 +08:00
|
|
|
rsp9, err := core.Import(ctx, &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "c1",
|
|
|
|
PartitionName: "p1",
|
|
|
|
RowBased: true,
|
|
|
|
Files: []string{"f1", "f2", "f3"},
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-21 15:47:23 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp9.Status.ErrorCode)
|
|
|
|
|
|
|
|
rsp10, err := core.GetImportState(ctx, &milvuspb.GetImportStateRequest{
|
|
|
|
Task: 0,
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-21 15:47:23 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp10.Status.ErrorCode)
|
|
|
|
|
|
|
|
rsp11, err := core.ReportImport(ctx, &rootcoordpb.ImportResult{
|
|
|
|
RowCount: 0,
|
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-21 15:47:23 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp11.ErrorCode)
|
2022-04-25 17:37:46 +08:00
|
|
|
|
|
|
|
rsp12, err := core.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp12.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-04-08 17:31:39 +08:00
|
|
|
t.Run("alloc_error", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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
|
|
|
})
|
2022-03-31 13:51:28 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Wait()
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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()
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory := dependency.NewDefaultFactory(true)
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
Params.Init()
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
2021-05-20 14:14:14 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
defer etcdCli.Close()
|
|
|
|
|
2021-05-20 14:14:14 +08:00
|
|
|
randVal := rand.Int()
|
|
|
|
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordTimeTick = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordStatistics = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordSubName = fmt.Sprintf("subname-%d", randVal)
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
2021-06-17 16:47:57 +08:00
|
|
|
err = core.SetQueryCoord(qm)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
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-12-29 14:35:21 +08:00
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-05-20 14:14:14 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
|
|
|
err = core.Start()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-07-06 09:16:03 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
2021-05-20 14:14:14 +08:00
|
|
|
t.Run("create collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-05-20 14:14:14 +08:00
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: collName,
|
|
|
|
}
|
|
|
|
|
|
|
|
sbf, err := proto.Marshal(&schema)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
|
|
|
|
req := &milvuspb.CreateCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_CreateCollection,
|
|
|
|
Timestamp: 100,
|
|
|
|
},
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collName,
|
|
|
|
Schema: sbf,
|
|
|
|
}
|
|
|
|
status, err := core.CreateCollection(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-20 14:14:14 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
2021-11-02 15:50:30 +08:00
|
|
|
collInfo, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-04 15:00:34 +08:00
|
|
|
dmlStream, _ := msFactory.NewMsgStream(ctx)
|
2022-03-04 11:17:56 +08:00
|
|
|
dmlStream.AsConsumer([]string{collInfo.PhysicalChannelNames[0]}, Params.CommonCfg.RootCoordSubName)
|
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
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-08 15:00:00 +08:00
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-08 15:00:00 +08:00
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, collName, rsp.Schema.Name)
|
2022-06-10 13:10:08 +08:00
|
|
|
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-12-29 14:35:21 +08:00
|
|
|
wg.Wait()
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
err = c.Start()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
c.MetaTable = &MetaTable{}
|
2021-04-08 17:31:39 +08:00
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
c.etcdCli = &clientv3.Client{}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
c.kvBase = &etcdkv.EtcdKV{}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2022-03-25 11:03:25 +08:00
|
|
|
c.impTaskKv = &etcdkv.EtcdKV{}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2022-03-25 11:03:25 +08:00
|
|
|
|
2021-09-27 18:10:00 +08:00
|
|
|
c.SendDdCreateCollectionReq = func(context.Context, *internalpb.CreateCollectionRequest, []string) (map[string][]byte, error) {
|
|
|
|
return map[string][]byte{}, nil
|
2021-04-08 17:31:39 +08:00
|
|
|
}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2022-05-31 16:36:03 +08:00
|
|
|
c.CallGetFlushedSegmentsService = func(ctx context.Context, collID, partID typeutil.UniqueID) ([]typeutil.UniqueID, error) {
|
|
|
|
return nil, nil
|
2021-05-25 14:03:06 +08:00
|
|
|
}
|
2021-04-08 17:31:39 +08:00
|
|
|
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2022-05-31 16:36:03 +08:00
|
|
|
c.CallGetRecoveryInfoService = func(ctx context.Context, collID, partID UniqueID) ([]*datapb.SegmentBinlogs, error) {
|
2021-07-03 14:36:18 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
2022-05-31 16:36:03 +08:00
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-07-03 14:36:18 +08:00
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
c.CallBuildIndexService = func(ctx context.Context, segID UniqueID, binlog []string, field *schemapb.FieldSchema, idxInfo *etcdpb.IndexInfo, numRows int64) (typeutil.UniqueID, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-04-08 17:31:39 +08:00
|
|
|
|
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()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.Error(t, err)
|
2021-11-11 00:54:45 +08:00
|
|
|
|
|
|
|
c.CallWatchChannels = func(ctx context.Context, collectionID int64, channelNames []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-06 15:33:32 +08:00
|
|
|
err = c.checkInit()
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
2022-04-01 11:33:28 +08:00
|
|
|
c.CallImportService = func(ctx context.Context, req *datapb.ImportTaskRequest) *datapb.ImportTaskResponse {
|
2022-03-22 15:11:24 +08:00
|
|
|
return &datapb.ImportTaskResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-11 00:54:45 +08:00
|
|
|
err = c.checkInit()
|
2022-06-15 12:20:10 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
c.CallAddSegRefLock = func(context.Context, []int64) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
c.CallReleaseSegRefLock = func(context.Context, []int64) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = c.checkInit()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-11 00:54:45 +08:00
|
|
|
|
2021-09-09 17:39:30 +08:00
|
|
|
err = c.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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()
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory := dependency.NewDefaultFactory(true)
|
2021-08-25 14:41:52 +08:00
|
|
|
Params.Init()
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
2021-08-25 14:41:52 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
randVal := rand.Int()
|
|
|
|
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordTimeTick = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordStatistics = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordSubName = fmt.Sprintf("subname-%d", randVal)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
dm := &dataMock{randVal: randVal}
|
|
|
|
err = core.SetDataCoord(ctx, dm)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
im := &indexMock{
|
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetIndexCoord(im)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetQueryCoord(qm)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
defer etcdCli.Close()
|
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-08-25 14:41:52 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
|
|
|
err = core.Start()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-25 14:41:52 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-08-25 14:41:52 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2021-12-29 14:35:21 +08:00
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
2021-08-25 14:41:52 +08:00
|
|
|
t.Run("check flushed segments", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-08-25 14:41:52 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
var collID int64 = 1
|
|
|
|
var partID int64 = 2
|
|
|
|
var segID int64 = 1001
|
|
|
|
var fieldID int64 = 101
|
|
|
|
var indexID int64 = 6001
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.segID2IndexMeta[segID] = make(map[int64]etcdpb.SegmentIndexInfo)
|
2021-08-25 14:41:52 +08:00
|
|
|
core.MetaTable.partID2SegID[partID] = make(map[int64]bool)
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{ID: collID}
|
2021-08-25 14:41:52 +08:00
|
|
|
// do nothing, since collection has 0 index
|
|
|
|
core.checkFlushedSegments(ctx)
|
|
|
|
|
|
|
|
// get field schema by id fail
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
PartitionIDs: []int64{partID},
|
|
|
|
FieldIndexes: []*etcdpb.FieldIndexInfo{
|
2021-08-25 14:41:52 +08:00
|
|
|
{
|
2022-06-10 13:10:08 +08:00
|
|
|
FiledID: fieldID,
|
2022-06-07 12:00:07 +08:00
|
|
|
IndexID: indexID,
|
|
|
|
},
|
2021-08-25 14:41:52 +08:00
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Fields: []*schemapb.FieldSchema{},
|
|
|
|
},
|
2021-08-25 14:41:52 +08:00
|
|
|
}
|
|
|
|
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
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.collID2Meta[collID] = etcdpb.CollectionInfo{
|
|
|
|
ID: collID,
|
|
|
|
PartitionIDs: []int64{partID},
|
|
|
|
FieldIndexes: []*etcdpb.FieldIndexInfo{
|
2021-08-25 14:41:52 +08:00
|
|
|
{
|
2022-06-10 13:10:08 +08:00
|
|
|
FiledID: fieldID,
|
2021-08-25 14:41:52 +08:00
|
|
|
IndexID: indexID,
|
|
|
|
},
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: fieldID,
|
|
|
|
},
|
2021-08-25 14:41:52 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2022-06-10 13:10:08 +08:00
|
|
|
core.MetaTable.indexID2Meta[indexID] = etcdpb.IndexInfo{
|
2021-08-25 14:41:52 +08:00
|
|
|
IndexID: indexID,
|
|
|
|
}
|
2022-06-10 13:10:08 +08:00
|
|
|
core.CallBuildIndexService = func(_ context.Context, segID UniqueID, binlog []string, field *schemapb.FieldSchema, idx *etcdpb.IndexInfo, numRows int64) (int64, error) {
|
2021-08-25 14:41:52 +08:00
|
|
|
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
|
2022-06-10 13:10:08 +08:00
|
|
|
core.CallBuildIndexService = func(_ context.Context, segID UniqueID, binlog []string, field *schemapb.FieldSchema, idx *etcdpb.IndexInfo, numRows int64) (int64, error) {
|
2021-08-25 14:41:52 +08:00
|
|
|
return indexBuildID, nil
|
|
|
|
}
|
|
|
|
core.checkFlushedSegments(core.ctx)
|
|
|
|
|
|
|
|
})
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Wait()
|
2021-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(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()
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory := dependency.NewDefaultFactory(true)
|
2021-09-08 15:00:00 +08:00
|
|
|
Params.Init()
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.DmlChannelNum = TestDMLChannelNum
|
2021-09-09 17:39:30 +08:00
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
core, err := NewCore(ctx, msFactory)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
randVal := rand.Int()
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordTimeTick = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordStatistics = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.MetaRootPath)
|
|
|
|
Params.EtcdCfg.KvRootPath = fmt.Sprintf("/%d/%s", randVal, Params.EtcdCfg.KvRootPath)
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.RootCoordSubName = fmt.Sprintf("subname-%d", randVal)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
dm := &dataMock{randVal: randVal}
|
|
|
|
err = core.SetDataCoord(ctx, dm)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
im := &indexMock{
|
|
|
|
fileArray: []string{},
|
|
|
|
idxBuildID: []int64{},
|
|
|
|
idxID: []int64{},
|
|
|
|
idxDropID: []int64{},
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetIndexCoord(im)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
qm := &queryMock{
|
|
|
|
collID: nil,
|
|
|
|
mutex: sync.Mutex{},
|
|
|
|
}
|
|
|
|
err = core.SetQueryCoord(qm)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
core.NewProxyClient = func(*sessionutil.Session) (types.Proxy, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
2021-12-29 14:35:21 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
|
|
|
core.SetEtcdClient(etcdCli)
|
2021-09-08 15:00:00 +08:00
|
|
|
err = core.Init()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
|
|
|
err = core.Start()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
core.session.TriggerKill = false
|
2021-12-15 11:47:10 +08:00
|
|
|
err = core.Register()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2021-09-08 15:00:00 +08:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
2022-06-10 13:10:08 +08:00
|
|
|
modifyFunc := func(collInfo *etcdpb.CollectionInfo) {
|
2021-09-08 15:00:00 +08:00
|
|
|
collInfo.ShardsNum = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
createCollectionInMeta(dbName, collName, core, shardsNum, modifyFunc)
|
|
|
|
|
|
|
|
t.Run("describe collection", func(t *testing.T) {
|
|
|
|
collMeta, err := core.MetaTable.GetCollectionByName(collName, 0)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
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)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, collName, rsp.Schema.Name)
|
2022-06-10 13:10:08 +08:00
|
|
|
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-09-09 17:39:30 +08:00
|
|
|
err = core.Stop()
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|
2021-11-19 13:57:12 +08:00
|
|
|
|
|
|
|
func TestCore_GetComponentStates(t *testing.T) {
|
|
|
|
n := &Core{}
|
|
|
|
n.stateCode.Store(internalpb.StateCode_Healthy)
|
|
|
|
resp, err := n.GetComponentStates(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, common.NotRegisteredID, resp.State.NodeID)
|
|
|
|
n.session = &sessionutil.Session{}
|
|
|
|
n.session.UpdateRegistered(true)
|
|
|
|
resp, err = n.GetComponentStates(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
func TestCore_DescribeSegments(t *testing.T) {
|
|
|
|
collID := typeutil.UniqueID(1)
|
|
|
|
partID := typeutil.UniqueID(2)
|
|
|
|
segID := typeutil.UniqueID(100)
|
|
|
|
fieldID := typeutil.UniqueID(3)
|
|
|
|
buildID := typeutil.UniqueID(4)
|
|
|
|
indexID := typeutil.UniqueID(1000)
|
|
|
|
indexName := "test_describe_segments_index"
|
|
|
|
|
|
|
|
c := &Core{
|
|
|
|
ctx: context.Background(),
|
|
|
|
}
|
|
|
|
|
|
|
|
// not healthy.
|
|
|
|
c.stateCode.Store(internalpb.StateCode_Abnormal)
|
|
|
|
got1, err := c.DescribeSegments(context.Background(), &rootcoordpb.DescribeSegmentsRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, got1.GetStatus().GetErrorCode())
|
|
|
|
|
|
|
|
// failed to be executed.
|
|
|
|
c.CallGetFlushedSegmentsService = func(ctx context.Context, collID, partID typeutil.UniqueID) ([]typeutil.UniqueID, error) {
|
|
|
|
return []typeutil.UniqueID{segID}, nil
|
|
|
|
}
|
|
|
|
c.stateCode.Store(internalpb.StateCode_Healthy)
|
|
|
|
shortDuration := time.Nanosecond
|
|
|
|
shortCtx, cancel := context.WithTimeout(c.ctx, shortDuration)
|
|
|
|
defer cancel()
|
|
|
|
time.Sleep(shortDuration)
|
|
|
|
got2, err := c.DescribeSegments(shortCtx, &rootcoordpb.DescribeSegmentsRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, got2.GetStatus().GetErrorCode())
|
|
|
|
|
|
|
|
// success.
|
|
|
|
c.MetaTable = &MetaTable{
|
2022-06-10 13:10:08 +08:00
|
|
|
segID2IndexMeta: map[typeutil.UniqueID]map[typeutil.UniqueID]etcdpb.SegmentIndexInfo{
|
2022-03-30 21:11:28 +08:00
|
|
|
segID: {
|
|
|
|
indexID: {
|
|
|
|
CollectionID: collID,
|
2022-06-10 13:10:08 +08:00
|
|
|
PartitionID: partID,
|
|
|
|
SegmentID: segID,
|
2022-03-30 21:11:28 +08:00
|
|
|
FieldID: fieldID,
|
|
|
|
IndexID: indexID,
|
2022-06-10 13:10:08 +08:00
|
|
|
BuildID: buildID,
|
|
|
|
EnableIndex: true,
|
2022-03-30 21:11:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-10 13:10:08 +08:00
|
|
|
indexID2Meta: map[typeutil.UniqueID]etcdpb.IndexInfo{
|
2022-03-30 21:11:28 +08:00
|
|
|
indexID: {
|
|
|
|
IndexName: indexName,
|
|
|
|
IndexID: indexID,
|
|
|
|
IndexParams: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
infos, err := c.DescribeSegments(context.Background(), &rootcoordpb.DescribeSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeSegments,
|
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: 0,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
|
|
|
CollectionID: collID,
|
|
|
|
SegmentIDs: []typeutil.UniqueID{segID},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, infos.GetStatus().GetErrorCode())
|
|
|
|
assert.Equal(t, 1, len(infos.GetSegmentInfos()))
|
|
|
|
segmentInfo, ok := infos.GetSegmentInfos()[segID]
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, 1, len(segmentInfo.GetIndexInfos()))
|
|
|
|
assert.Equal(t, collID, segmentInfo.GetIndexInfos()[0].GetCollectionID())
|
|
|
|
assert.Equal(t, partID, segmentInfo.GetIndexInfos()[0].GetPartitionID())
|
|
|
|
assert.Equal(t, segID, segmentInfo.GetIndexInfos()[0].GetSegmentID())
|
|
|
|
assert.Equal(t, fieldID, segmentInfo.GetIndexInfos()[0].GetFieldID())
|
|
|
|
assert.Equal(t, indexID, segmentInfo.GetIndexInfos()[0].GetIndexID())
|
|
|
|
assert.Equal(t, buildID, segmentInfo.GetIndexInfos()[0].GetBuildID())
|
|
|
|
assert.Equal(t, true, segmentInfo.GetIndexInfos()[0].GetEnableIndex())
|
|
|
|
|
|
|
|
indexInfo, ok := segmentInfo.GetExtraIndexInfos()[indexID]
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, indexName, indexInfo.IndexName)
|
|
|
|
assert.Equal(t, indexID, indexInfo.IndexID)
|
|
|
|
}
|
2022-06-14 16:18:09 +08:00
|
|
|
|
|
|
|
func TestCore_getCollectionName(t *testing.T) {
|
|
|
|
mt := &MetaTable{
|
|
|
|
ddLock: sync.RWMutex{},
|
|
|
|
collID2Meta: make(map[int64]etcdpb.CollectionInfo),
|
|
|
|
}
|
|
|
|
|
|
|
|
core := &Core{
|
|
|
|
MetaTable: mt,
|
|
|
|
}
|
|
|
|
|
|
|
|
collName, partName, err := core.getCollectionName(1, 2)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, collName)
|
|
|
|
assert.Empty(t, partName)
|
|
|
|
|
|
|
|
ids := make([]int64, 0)
|
|
|
|
names := make([]string, 0)
|
|
|
|
mt.collID2Meta[1] = etcdpb.CollectionInfo{
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "dummy",
|
|
|
|
},
|
|
|
|
PartitionIDs: ids,
|
|
|
|
PartitionNames: names,
|
|
|
|
}
|
|
|
|
|
|
|
|
collName, partName, err = core.getCollectionName(1, 2)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, "dummy", collName)
|
|
|
|
assert.Empty(t, partName)
|
|
|
|
|
|
|
|
ids = append(ids, 2)
|
|
|
|
names = append(names, "p2")
|
|
|
|
mt.collID2Meta[1] = etcdpb.CollectionInfo{
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "dummy",
|
|
|
|
},
|
|
|
|
PartitionIDs: ids,
|
|
|
|
PartitionNames: names,
|
|
|
|
}
|
|
|
|
|
|
|
|
collName, partName, err = core.getCollectionName(1, 2)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "dummy", collName)
|
|
|
|
assert.Equal(t, "p2", partName)
|
|
|
|
}
|