2021-12-03 19:25:45 +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-09-07 15:45:59 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-03 19:25:45 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-07 15:45:59 +08:00
|
|
|
//
|
2021-12-03 19:25:45 +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-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-09-11 17:22:01 +08:00
|
|
|
"encoding/json"
|
2021-09-07 15:45:59 +08:00
|
|
|
"math/rand"
|
2021-12-29 14:35:21 +08:00
|
|
|
"sync"
|
2021-11-25 15:03:16 +08:00
|
|
|
"sync/atomic"
|
2021-09-07 15:45:59 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-09-24 13:57:54 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-03-30 12:03:27 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-24 13:57:54 +08:00
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2022-04-27 10:41:46 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-09-07 15:45:59 +08:00
|
|
|
queryPb "github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2021-09-11 17:22:01 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-09-07 15:45:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestImpl_GetComponentStates(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-25 15:03:16 +08:00
|
|
|
node.session.UpdateRegistered(true)
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
rsp, err := node.GetComponentStates(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
rsp, err = node.GetComponentStates(ctx)
|
2021-11-25 15:03:16 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
|
|
|
node.stateCode = atomic.Value{}
|
|
|
|
node.stateCode.Store("invalid")
|
|
|
|
rsp, err = node.GetComponentStates(ctx)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, rsp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_GetTimeTickChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rsp, err := node.GetTimeTickChannel(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_GetStatisticsChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rsp, err := node.GetStatisticsChannel(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_WatchDmChannels(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
schema := genTestCollectionSchema()
|
2021-09-07 15:45:59 +08:00
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-11-06 11:02:58 +08:00
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
2021-09-07 15:45:59 +08:00
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
2021-09-07 15:45:59 +08:00
|
|
|
Schema: schema,
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
status, err = node.WatchDmChannels(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_LoadSegments(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
schema := genTestCollectionSchema()
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
req := &queryPb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
2021-12-15 16:53:12 +08:00
|
|
|
DstNodeID: 0,
|
|
|
|
Schema: schema,
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.LoadSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
status, err = node.LoadSegments(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_ReleaseCollection(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.ReleaseCollection(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
status, err = node.ReleaseCollection(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_ReleasePartitions(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleasePartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.ReleasePartitions(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
status, err = node.ReleasePartitions(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_GetSegmentInfo(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-10-20 19:47:35 +08:00
|
|
|
t.Run("test GetSegmentInfo", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-10-20 19:47:35 +08:00
|
|
|
req := &queryPb.GetSegmentInfoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
2022-02-07 15:35:44 +08:00
|
|
|
SegmentIDs: []UniqueID{},
|
2021-10-20 19:47:35 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-10-20 19:47:35 +08:00
|
|
|
rsp, err := node.GetSegmentInfo(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
2022-02-07 15:35:44 +08:00
|
|
|
req.SegmentIDs = []UniqueID{-1}
|
|
|
|
rsp, err = node.GetSegmentInfo(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, 0, len(rsp.GetInfos()))
|
|
|
|
|
2021-10-20 19:47:35 +08:00
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
rsp, err = node.GetSegmentInfo(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, rsp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test no collection in metaReplica", func(t *testing.T) {
|
2021-10-20 19:47:35 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
err = node.metaReplica.removeCollection(defaultCollectionID)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.GetSegmentInfoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp, err := node.GetSegmentInfo(ctx, req)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
2021-10-20 19:47:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test different segment type", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.GetSegmentInfoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
seg, err := node.metaReplica.getSegmentByID(defaultSegmentID, segmentTypeSealed)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
seg.setType(segmentTypeSealed)
|
2022-02-08 21:57:46 +08:00
|
|
|
rsp, err := node.GetSegmentInfo(ctx, req)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
|
|
|
seg.setType(segmentTypeGrowing)
|
|
|
|
rsp, err = node.GetSegmentInfo(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
|
|
|
seg.setType(-100)
|
|
|
|
rsp, err = node.GetSegmentInfo(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test GetSegmentInfo with indexed segment", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
seg, err := node.metaReplica.getSegmentByID(defaultSegmentID, segmentTypeSealed)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
seg.setIndexedFieldInfo(simpleFloatVecField.id, &IndexedFieldInfo{
|
2022-03-30 21:11:28 +08:00
|
|
|
indexInfo: &queryPb.FieldIndexInfo{
|
2022-02-08 21:57:46 +08:00
|
|
|
IndexName: "query-node-test",
|
|
|
|
IndexID: UniqueID(0),
|
|
|
|
BuildID: UniqueID(0),
|
|
|
|
},
|
2021-10-20 19:47:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
req := &queryPb.GetSegmentInfoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp, err := node.GetSegmentInfo(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, rsp.Status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
rsp, err = node.GetSegmentInfo(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-20 19:47:35 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, rsp.Status.ErrorCode)
|
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_isHealthy(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
isHealthy := node.isHealthy()
|
|
|
|
assert.True(t, isHealthy)
|
|
|
|
}
|
|
|
|
|
2022-08-03 01:12:33 +08:00
|
|
|
func TestImpl_ShowConfigurations(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
|
|
|
t.Run("test ShowConfigurations", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.session = sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath, etcdCli)
|
|
|
|
|
|
|
|
pattern := "Cache"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_WatchQueryChannels),
|
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
|
|
|
reqs, err := node.ShowConfigurations(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, reqs.Status.ErrorCode, commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test ShowConfigurations node failed", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.session = sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath, etcdCli)
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
pattern := "Cache"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_WatchQueryChannels),
|
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
|
|
|
reqs, err := node.ShowConfigurations(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, reqs.Status.ErrorCode, commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
func TestImpl_GetMetrics(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
2021-09-11 17:22:01 +08:00
|
|
|
t.Run("test GetMetrics", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-11 17:22:01 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2022-02-07 10:09:45 +08:00
|
|
|
node.session = sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath, etcdCli)
|
2021-09-11 17:22:01 +08:00
|
|
|
|
|
|
|
metricReq := make(map[string]string)
|
|
|
|
metricReq[metricsinfo.MetricTypeKey] = "system_info"
|
|
|
|
mReq, err := json.Marshal(metricReq)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &milvuspb.GetMetricsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
Request: string(mReq),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = node.GetMetrics(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-11 17:22:01 +08:00
|
|
|
t.Run("test ParseMetricType failed", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-11 17:22:01 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &milvuspb.GetMetricsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = node.GetMetrics(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
_, err = node.GetMetrics(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Wait()
|
2021-09-11 17:22:01 +08:00
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-09-11 17:22:01 +08:00
|
|
|
func TestImpl_ReleaseSegments(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
2021-09-11 17:22:01 +08:00
|
|
|
t.Run("test valid", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-11 17:22:01 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments),
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
2022-06-17 17:38:12 +08:00
|
|
|
Scope: queryPb.DataScope_All,
|
2021-09-11 17:22:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2022-06-17 17:38:12 +08:00
|
|
|
|
|
|
|
req.Scope = queryPb.DataScope_Streaming
|
|
|
|
_, err = node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req.Scope = queryPb.DataScope_Historical
|
|
|
|
_, err = node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2021-09-11 17:22:01 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-11 17:22:01 +08:00
|
|
|
t.Run("test invalid query node", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-11 17:22:01 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments),
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
}
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
_, err = node.ReleaseSegments(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-11 17:22:01 +08:00
|
|
|
})
|
|
|
|
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Add(1)
|
2021-09-11 17:22:01 +08:00
|
|
|
t.Run("test segment not exists", func(t *testing.T) {
|
2021-12-29 14:35:21 +08:00
|
|
|
defer wg.Done()
|
2021-09-11 17:22:01 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments),
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
}
|
|
|
|
|
2022-06-01 13:18:02 +08:00
|
|
|
node.metaReplica.removeSegment(defaultSegmentID, segmentTypeSealed)
|
2021-09-11 17:22:01 +08:00
|
|
|
|
|
|
|
status, err := node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2022-06-01 13:18:02 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-09-11 17:22:01 +08:00
|
|
|
})
|
2022-06-22 16:12:14 +08:00
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
t.Run("test no collection", func(t *testing.T) {
|
|
|
|
defer wg.Done()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.metaReplica.removeCollection(defaultCollectionID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments),
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
2021-12-29 14:35:21 +08:00
|
|
|
wg.Wait()
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
2022-03-30 12:03:27 +08:00
|
|
|
|
|
|
|
func TestImpl_Search(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
schema := genTestCollectionSchema()
|
2022-04-29 13:35:49 +08:00
|
|
|
req, err := genSearchRequest(defaultNQ, IndexFaissIDMap, schema)
|
2022-04-20 16:15:41 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
2022-07-06 15:06:21 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
|
|
|
|
// shard cluster not synced
|
|
|
|
_, err = node.Search(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// shard cluster sync segments
|
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
|
|
|
sc.SyncSegments(nil, segmentStateLoaded)
|
2022-04-20 16:15:41 +08:00
|
|
|
|
|
|
|
_, err = node.Search(ctx, &queryPb.SearchRequest{
|
2022-05-23 16:41:58 +08:00
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
2022-07-06 15:06:21 +08:00
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
2022-04-20 16:15:41 +08:00
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-03-30 12:03:27 +08:00
|
|
|
}
|
|
|
|
|
2022-07-06 15:06:21 +08:00
|
|
|
func TestImpl_searchWithDmlChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req, err := genSearchRequest(defaultNQ, IndexFaissIDMap, schema)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
|
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
|
|
|
sc.SyncSegments(nil, segmentStateLoaded)
|
|
|
|
|
|
|
|
_, err = node.searchWithDmlChannel(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// search for wrong dml channel
|
|
|
|
_, err = node.searchWithDmlChannel(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel + "_suffix"},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
func TestImpl_GetCollectionStatistics(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
req, err := genGetCollectionStatisticRequest()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
|
|
|
|
|
|
|
_, err = node.GetStatistics(ctx, &queryPb.GetStatisticsRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_GetPartitionStatistics(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
req, err := genGetPartitionStatisticRequest()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
|
|
|
|
|
|
|
_, err = node.GetStatistics(ctx, &queryPb.GetStatisticsRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-03-30 12:03:27 +08:00
|
|
|
func TestImpl_Query(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-04-27 10:41:46 +08:00
|
|
|
defer node.Stop()
|
2022-03-30 12:03:27 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
schema := genTestCollectionSchema()
|
2022-04-29 13:35:49 +08:00
|
|
|
req, err := genRetrieveRequest(schema)
|
2022-04-20 16:15:41 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
2022-07-06 15:06:21 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
|
|
|
|
// shard cluster not synced
|
|
|
|
_, err = node.Query(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// sync cluster segments
|
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
|
|
|
sc.SyncSegments(nil, segmentStateLoaded)
|
2022-04-20 16:15:41 +08:00
|
|
|
|
|
|
|
_, err = node.Query(ctx, &queryPb.QueryRequest{
|
2022-05-23 16:41:58 +08:00
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
2022-07-06 15:06:21 +08:00
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
2022-04-20 16:15:41 +08:00
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-03-30 12:03:27 +08:00
|
|
|
}
|
2022-04-27 10:41:46 +08:00
|
|
|
|
2022-07-06 15:06:21 +08:00
|
|
|
func TestImpl_queryWithDmlChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req, err := genRetrieveRequest(schema)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
|
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
|
|
|
sc.SyncSegments(nil, segmentStateLoaded)
|
|
|
|
|
|
|
|
_, err = node.queryWithDmlChannel(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// query for wrong dml channel
|
|
|
|
_, err = node.queryWithDmlChannel(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel + "_suffix"},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-04-27 10:41:46 +08:00
|
|
|
func TestImpl_SyncReplicaSegments(t *testing.T) {
|
|
|
|
t.Run("QueryNode not healthy", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
node.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.SyncReplicaSegments(ctx, &querypb.SyncReplicaSegmentsRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Sync non-exist channel", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
resp, err := node.SyncReplicaSegments(ctx, &querypb.SyncReplicaSegmentsRequest{
|
|
|
|
VchannelName: defaultDMLChannel,
|
|
|
|
ReplicaSegments: []*queryPb.ReplicaSegmentsInfo{
|
|
|
|
{
|
|
|
|
NodeId: 1,
|
|
|
|
PartitionId: defaultPartitionID,
|
|
|
|
SegmentIds: []int64{1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Normal sync segments", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
defer node.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
|
|
|
|
|
|
|
|
resp, err := node.SyncReplicaSegments(ctx, &querypb.SyncReplicaSegmentsRequest{
|
|
|
|
VchannelName: defaultDMLChannel,
|
|
|
|
ReplicaSegments: []*queryPb.ReplicaSegmentsInfo{
|
|
|
|
{
|
|
|
|
NodeId: 1,
|
|
|
|
PartitionId: defaultPartitionID,
|
|
|
|
SegmentIds: []int64{1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
t.Log(resp.GetReason())
|
|
|
|
|
|
|
|
cs, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
require.True(t, ok)
|
|
|
|
segment, ok := cs.getSegment(1)
|
|
|
|
require.True(t, ok)
|
|
|
|
assert.Equal(t, int64(1), segment.nodeID)
|
|
|
|
assert.Equal(t, defaultPartitionID, segment.partitionID)
|
|
|
|
assert.Equal(t, segmentStateLoaded, segment.state)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|