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-09-07 15:45:59 +08:00
|
|
|
"testing"
|
|
|
|
|
2023-03-20 14:55:57 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
2022-09-02 10:42:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2022-09-15 18:48:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-09-07 15:45:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
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"
|
2023-02-28 14:19:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/conc"
|
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"
|
2023-03-20 14:55:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-09-11 17:22:01 +08:00
|
|
|
"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)
|
2023-01-29 17:45:49 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2021-11-25 15:03:16 +08:00
|
|
|
|
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)
|
2023-01-29 17:45:49 +08:00
|
|
|
assert.Equal(t, commonpb.StateCode_Healthy, rsp.GetState().GetStateCode())
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-09-07 15:45:59 +08:00
|
|
|
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)
|
2023-01-29 17:45:49 +08:00
|
|
|
assert.Equal(t, commonpb.StateCode_Abnormal, rsp.GetState().GetStateCode())
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-08 20:26:57 +08:00
|
|
|
t.Run("normal_run", func(t *testing.T) {
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
2023-01-12 19:49:40 +08:00
|
|
|
TargetID: node.GetSession().ServerID,
|
2022-09-15 18:48:32 +08:00
|
|
|
},
|
2022-10-08 20:26:57 +08:00
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
Schema: schema,
|
|
|
|
Infos: []*datapb.VchannelInfo{
|
|
|
|
{
|
|
|
|
CollectionID: 1000,
|
|
|
|
ChannelName: "1000-dmc0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2022-12-28 10:19:31 +08:00
|
|
|
|
|
|
|
originPool := node.taskPool
|
|
|
|
defer func() {
|
|
|
|
node.taskPool = originPool
|
|
|
|
}()
|
2023-02-28 14:19:47 +08:00
|
|
|
node.taskPool = conc.NewDefaultPool()
|
2022-12-28 10:19:31 +08:00
|
|
|
node.taskPool.Release()
|
|
|
|
status, err = node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
2022-10-08 20:26:57 +08:00
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
t.Run("target not match", func(t *testing.T) {
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
TargetID: -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("server unhealthy", func(t *testing.T) {
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
}
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-11-15 19:03:08 +08:00
|
|
|
defer node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-10-08 20:26:57 +08:00
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
2022-11-15 19:03:08 +08:00
|
|
|
|
2022-12-06 22:59:19 +08:00
|
|
|
t.Run("server stopping", func(t *testing.T) {
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Stopping)
|
|
|
|
defer node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-11-15 19:03:08 +08:00
|
|
|
t.Run("mock release after loaded", func(t *testing.T) {
|
|
|
|
|
|
|
|
mockTSReplica := &MockTSafeReplicaInterface{}
|
|
|
|
|
|
|
|
oldTSReplica := node.tSafeReplica
|
|
|
|
defer func() {
|
|
|
|
node.tSafeReplica = oldTSReplica
|
|
|
|
}()
|
|
|
|
node.tSafeReplica = mockTSReplica
|
|
|
|
mockTSReplica.On("addTSafe", mock.Anything).Run(func(_ mock.Arguments) {
|
|
|
|
node.ShardClusterService.releaseShardCluster("1001-dmc0")
|
|
|
|
})
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
2023-01-12 19:49:40 +08:00
|
|
|
TargetID: node.GetSession().ServerID,
|
2022-11-15 19:03:08 +08:00
|
|
|
},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
Schema: schema,
|
|
|
|
Infos: []*datapb.VchannelInfo{
|
|
|
|
{
|
|
|
|
CollectionID: 1001,
|
|
|
|
ChannelName: "1001-dmc0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
2022-10-08 20:26:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestImpl_UnsubDmChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-08 20:26:57 +08:00
|
|
|
|
2023-01-02 16:39:32 +08:00
|
|
|
t.Run("normal run", func(t *testing.T) {
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req := &queryPb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
MsgID: rand.Int63(),
|
2023-01-12 19:49:40 +08:00
|
|
|
TargetID: node.GetSession().ServerID,
|
2023-01-02 16:39:32 +08:00
|
|
|
},
|
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
Schema: schema,
|
|
|
|
Infos: []*datapb.VchannelInfo{
|
|
|
|
{
|
|
|
|
CollectionID: 1000,
|
2023-01-18 17:45:44 +08:00
|
|
|
ChannelName: Params.CommonCfg.RootCoordDml.GetValue() + "-dmc0",
|
2023-01-02 16:39:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.WatchDmChannels(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
{
|
|
|
|
req := &queryPb.UnsubDmChannelRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_UnsubDmChannel,
|
|
|
|
MsgID: rand.Int63(),
|
2023-01-12 19:49:40 +08:00
|
|
|
TargetID: node.GetSession().ServerID,
|
2023-01-02 16:39:32 +08:00
|
|
|
},
|
|
|
|
NodeID: 0,
|
|
|
|
CollectionID: defaultCollectionID,
|
2023-01-18 17:45:44 +08:00
|
|
|
ChannelName: Params.CommonCfg.RootCoordDml.GetValue() + "-dmc0",
|
2023-01-02 16:39:32 +08:00
|
|
|
}
|
|
|
|
originMetaReplica := node.metaReplica
|
|
|
|
node.metaReplica = newMockReplicaInterface()
|
|
|
|
status, err := node.UnsubDmChannel(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
|
|
|
|
node.metaReplica = originMetaReplica
|
|
|
|
status, err = node.UnsubDmChannel(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
t.Run("target not match", func(t *testing.T) {
|
|
|
|
req := &queryPb.UnsubDmChannelRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_UnsubDmChannel,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
TargetID: -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
status, err := node.UnsubDmChannel(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("server unhealthy", func(t *testing.T) {
|
|
|
|
req := &queryPb.UnsubDmChannelRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_UnsubDmChannel,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
}
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-10-08 20:26:57 +08:00
|
|
|
status, err := node.UnsubDmChannel(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2022-10-08 20:26:57 +08:00
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
2023-01-12 19:49:40 +08:00
|
|
|
TargetID: node.GetSession().ServerID,
|
2021-09-07 15:45:59 +08:00
|
|
|
},
|
2021-12-15 16:53:12 +08:00
|
|
|
DstNodeID: 0,
|
|
|
|
Schema: schema,
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
t.Run("normal run", func(t *testing.T) {
|
|
|
|
status, err := node.LoadSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
t.Run("target not match", func(t *testing.T) {
|
|
|
|
req := &queryPb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
TargetID: -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
status, err := node.LoadSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("server unhealthy", func(t *testing.T) {
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-12-06 22:59:19 +08:00
|
|
|
defer node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
status, err := node.LoadSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("server stopping", func(t *testing.T) {
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Stopping)
|
|
|
|
defer node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-10-08 20:26:57 +08:00
|
|
|
status, err := node.LoadSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
})
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-09-07 15:45:59 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:55:57 +08:00
|
|
|
func TestImpl_LoadPartitions(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.LoadPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: paramtable.GetNodeID(),
|
|
|
|
},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.LoadPartitions(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
status, err = node.LoadPartitions(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
req.Base.TargetID = -1
|
|
|
|
status, err = node.LoadPartitions(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
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{
|
2023-03-20 14:55:57 +08:00
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
TargetID: paramtable.GetNodeID(),
|
2021-09-07 15:45:59 +08:00
|
|
|
},
|
|
|
|
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)
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-09-07 15:45:59 +08:00
|
|
|
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)
|
2023-03-20 14:55:57 +08:00
|
|
|
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
req.Base.TargetID = -1
|
|
|
|
status, err = node.ReleasePartitions(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()))
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-10-20 19:47:35 +08:00
|
|
|
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)
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-10-20 19:47:35 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-03 01:12:33 +08:00
|
|
|
func TestImpl_ShowConfigurations(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-11-30 18:23:15 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(
|
|
|
|
Params.EtcdCfg.UseEmbedEtcd.GetAsBool(),
|
|
|
|
Params.EtcdCfg.EtcdUseSSL.GetAsBool(),
|
|
|
|
Params.EtcdCfg.Endpoints.GetAsStrings(),
|
|
|
|
Params.EtcdCfg.EtcdTLSCert.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSKey.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSCACert.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSMinVersion.GetValue())
|
2022-08-03 01:12:33 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
|
|
|
|
t.Run("test ShowConfigurations", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2023-01-12 19:49:40 +08:00
|
|
|
node.SetSession(sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), etcdCli))
|
2022-08-03 01:12:33 +08:00
|
|
|
|
|
|
|
pattern := "Cache"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_WatchQueryChannels, node.GetSession().ServerID),
|
2022-08-03 01:12:33 +08:00
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
resp, err := node.ShowConfigurations(ctx, req)
|
2022-08-03 01:12:33 +08:00
|
|
|
assert.NoError(t, err)
|
2022-08-12 13:20:39 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
2022-08-03 01:12:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test ShowConfigurations node failed", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2023-01-12 19:49:40 +08:00
|
|
|
node.SetSession(sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), etcdCli))
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-08-03 01:12:33 +08:00
|
|
|
|
|
|
|
pattern := "Cache"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_WatchQueryChannels, node.GetSession().ServerID),
|
2022-08-03 01:12:33 +08:00
|
|
|
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-11-30 18:23:15 +08:00
|
|
|
etcdCli, err := etcd.GetEtcdClient(
|
|
|
|
Params.EtcdCfg.UseEmbedEtcd.GetAsBool(),
|
|
|
|
Params.EtcdCfg.EtcdUseSSL.GetAsBool(),
|
|
|
|
Params.EtcdCfg.Endpoints.GetAsStrings(),
|
|
|
|
Params.EtcdCfg.EtcdTLSCert.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSKey.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSCACert.GetValue(),
|
|
|
|
Params.EtcdCfg.EtcdTLSMinVersion.GetValue())
|
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)
|
2023-01-12 19:49:40 +08:00
|
|
|
node.SetSession(sessionutil.NewSession(node.queryNodeLoopCtx, Params.EtcdCfg.MetaRootPath.GetValue(), 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)
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-09-11 17:22:01 +08:00
|
|
|
_, 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-09-11 17:22:01 +08:00
|
|
|
t.Run("test valid", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer node.Stop()
|
2021-09-11 17:22:01 +08:00
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments, node.GetSession().ServerID),
|
2021-09-11 17:22:01 +08:00
|
|
|
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
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid query node", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer node.Stop()
|
2021-09-11 17:22:01 +08:00
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments, node.GetSession().ServerID),
|
2021-09-11 17:22:01 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
}
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-10-08 20:26:57 +08:00
|
|
|
resp, err := node.ReleaseSegments(ctx, req)
|
2021-12-01 22:13:37 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-08 20:26:57 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test target not matched", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer node.Stop()
|
2022-10-08 20:26:57 +08:00
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments, -1),
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, resp.GetErrorCode())
|
2021-09-11 17:22:01 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test segment not exists", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer node.Stop()
|
2021-09-11 17:22:01 +08:00
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments, node.GetSession().ServerID),
|
2021-09-11 17:22:01 +08:00
|
|
|
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
|
|
|
|
|
|
|
t.Run("test no collection", func(t *testing.T) {
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer node.Stop()
|
2022-06-22 16:12:14 +08:00
|
|
|
err = node.metaReplica.removeCollection(defaultCollectionID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
req := &queryPb.ReleaseSegmentsRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: genCommonMsgBase(commonpb.MsgType_ReleaseSegments, node.GetSession().ServerID),
|
2022-06-22 16:12:14 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.ReleaseSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2022-09-15 18:48:32 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2022-06-22 16:12:14 +08:00
|
|
|
})
|
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-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-03-30 12:03:27 +08:00
|
|
|
|
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-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-07-06 15:06:21 +08:00
|
|
|
// 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)
|
2022-10-20 16:35:28 +08:00
|
|
|
sc.SetupFirstVersion()
|
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-12-04 20:05:17 +08:00
|
|
|
|
|
|
|
req.GetBase().TargetID = -1
|
|
|
|
ret, err := node.Search(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, ret.GetStatus().GetErrorCode())
|
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)
|
2022-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-07-06 15:06:21 +08:00
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req, err := genSearchRequest(defaultNQ, IndexFaissIDMap, schema)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
2022-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-07-06 15:06:21 +08:00
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
2022-10-20 16:35:28 +08:00
|
|
|
sc.SetupFirstVersion()
|
2022-07-06 15:06:21 +08:00
|
|
|
|
|
|
|
_, err = node.searchWithDmlChannel(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
2023-02-22 17:31:46 +08:00
|
|
|
// search with ignore growing segment
|
|
|
|
req.IgnoreGrowing = true
|
|
|
|
_, err = node.searchWithDmlChannel(ctx, &queryPb.SearchRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
req.IgnoreGrowing = false
|
2022-07-06 15:06:21 +08:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
require.NoError(t, err)
|
2022-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-07-18 09:58:28 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
require.NoError(t, err)
|
2022-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-07-18 09:58:28 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
require.NoError(t, err)
|
2022-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-03-30 12:03:27 +08:00
|
|
|
|
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-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-07-06 15:06:21 +08:00
|
|
|
// 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)
|
2022-10-20 16:35:28 +08:00
|
|
|
sc.SetupFirstVersion()
|
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-12-04 20:05:17 +08:00
|
|
|
|
|
|
|
req.GetBase().TargetID = -1
|
|
|
|
ret, err := node.Query(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, ret.GetStatus().GetErrorCode())
|
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)
|
|
|
|
require.NoError(t, err)
|
2022-11-17 14:23:08 +08:00
|
|
|
defer node.Stop()
|
2022-07-06 15:06:21 +08:00
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
req, err := genRetrieveRequest(schema)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
node.queryShardService.addQueryShard(defaultCollectionID, defaultDMLChannel, defaultReplicaID)
|
2022-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-07-06 15:06:21 +08:00
|
|
|
sc, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
assert.True(t, ok)
|
2022-10-20 16:35:28 +08:00
|
|
|
sc.SetupFirstVersion()
|
2022-07-06 15:06:21 +08:00
|
|
|
|
|
|
|
_, err = node.queryWithDmlChannel(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2023-02-22 17:31:46 +08:00
|
|
|
// query with ignore growing
|
|
|
|
req.IgnoreGrowing = true
|
|
|
|
_, err = node.queryWithDmlChannel(ctx, &queryPb.QueryRequest{
|
|
|
|
Req: req,
|
|
|
|
FromShardLeader: false,
|
|
|
|
DmlChannels: []string{defaultDMLChannel},
|
|
|
|
}, defaultDMLChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
req.IgnoreGrowing = false
|
|
|
|
|
2022-07-06 15:06:21 +08:00
|
|
|
// 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)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-04-27 10:41:46 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-04-27 10:41:46 +08:00
|
|
|
|
|
|
|
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)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-04-27 10:41:46 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
|
|
|
resp, err := node.SyncReplicaSegments(ctx, &querypb.SyncReplicaSegmentsRequest{
|
|
|
|
VchannelName: defaultDMLChannel,
|
|
|
|
ReplicaSegments: []*queryPb.ReplicaSegmentsInfo{
|
|
|
|
{
|
|
|
|
NodeId: 1,
|
|
|
|
PartitionId: defaultPartitionID,
|
|
|
|
SegmentIds: []int64{1},
|
2022-09-28 12:10:54 +08:00
|
|
|
Versions: []int64{1},
|
2022-04-27 10:41:46 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-04-27 10:41:46 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
2022-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-10-20 16:35:28 +08:00
|
|
|
cs, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
require.True(t, ok)
|
|
|
|
cs.SetupFirstVersion()
|
2022-04-27 10:41:46 +08:00
|
|
|
|
|
|
|
resp, err := node.SyncReplicaSegments(ctx, &querypb.SyncReplicaSegmentsRequest{
|
|
|
|
VchannelName: defaultDMLChannel,
|
|
|
|
ReplicaSegments: []*queryPb.ReplicaSegmentsInfo{
|
|
|
|
{
|
|
|
|
NodeId: 1,
|
|
|
|
PartitionId: defaultPartitionID,
|
|
|
|
SegmentIds: []int64{1},
|
2022-09-28 12:10:54 +08:00
|
|
|
Versions: []int64{1},
|
2022-04-27 10:41:46 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
t.Log(resp.GetReason())
|
|
|
|
|
|
|
|
segment, ok := cs.getSegment(1)
|
|
|
|
require.True(t, ok)
|
2022-09-02 10:42:59 +08:00
|
|
|
assert.Equal(t, common.InvalidNodeID, segment.nodeID)
|
2022-04-27 10:41:46 +08:00
|
|
|
assert.Equal(t, defaultPartitionID, segment.partitionID)
|
|
|
|
assert.Equal(t, segmentStateLoaded, segment.state)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
2022-09-22 13:18:50 +08:00
|
|
|
|
|
|
|
func TestSyncDistribution(t *testing.T) {
|
|
|
|
t.Run("QueryNode not healthy", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-09-22 13:18:50 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-09-22 13:18:50 +08:00
|
|
|
|
|
|
|
resp, err := node.SyncDistribution(ctx, &querypb.SyncDistributionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
2022-10-08 20:26:57 +08:00
|
|
|
t.Run("Target not match", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-10-08 20:26:57 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
|
|
|
resp, err := node.SyncDistribution(ctx, &querypb.SyncDistributionRequest{
|
|
|
|
Base: &commonpb.MsgBase{TargetID: -1},
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
Channel: defaultDMLChannel,
|
|
|
|
Actions: []*querypb.SyncAction{
|
|
|
|
{
|
|
|
|
Type: querypb.SyncType_Set,
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
NodeID: 99,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
2022-09-22 13:18:50 +08:00
|
|
|
t.Run("Sync non-exist channel", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-09-22 13:18:50 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
|
|
|
resp, err := node.SyncDistribution(ctx, &querypb.SyncDistributionRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: &commonpb.MsgBase{TargetID: node.GetSession().ServerID},
|
2022-09-22 13:18:50 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
Channel: defaultDMLChannel,
|
|
|
|
Actions: []*querypb.SyncAction{
|
|
|
|
{
|
|
|
|
Type: querypb.SyncType_Set,
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
NodeID: 99,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-09-22 13:18:50 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
2022-11-15 13:21:07 +08:00
|
|
|
node.ShardClusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel, defaultVersion)
|
2022-10-20 16:35:28 +08:00
|
|
|
cs, ok := node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
require.True(t, ok)
|
|
|
|
cs.SetupFirstVersion()
|
2022-09-22 13:18:50 +08:00
|
|
|
|
|
|
|
resp, err := node.SyncDistribution(ctx, &querypb.SyncDistributionRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: &commonpb.MsgBase{TargetID: node.GetSession().ServerID},
|
2022-09-22 13:18:50 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
Channel: defaultDMLChannel,
|
|
|
|
Actions: []*querypb.SyncAction{
|
|
|
|
{
|
|
|
|
Type: querypb.SyncType_Set,
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
NodeID: 99,
|
2022-09-28 12:10:54 +08:00
|
|
|
Version: 1,
|
2022-09-22 13:18:50 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
|
|
|
|
segment, ok := cs.getSegment(defaultSegmentID)
|
|
|
|
require.True(t, ok)
|
|
|
|
assert.Equal(t, common.InvalidNodeID, segment.nodeID)
|
|
|
|
assert.Equal(t, defaultPartitionID, segment.partitionID)
|
|
|
|
assert.Equal(t, segmentStateLoaded, segment.state)
|
2022-09-28 12:10:54 +08:00
|
|
|
assert.EqualValues(t, 1, segment.version)
|
2022-09-27 19:22:54 +08:00
|
|
|
resp, err = node.SyncDistribution(ctx, &querypb.SyncDistributionRequest{
|
2023-01-12 19:49:40 +08:00
|
|
|
Base: &commonpb.MsgBase{TargetID: node.GetSession().ServerID},
|
2022-09-27 19:22:54 +08:00
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
Channel: defaultDMLChannel,
|
|
|
|
Actions: []*querypb.SyncAction{
|
|
|
|
{
|
|
|
|
Type: querypb.SyncType_Remove,
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
NodeID: 99,
|
2022-09-28 12:10:54 +08:00
|
|
|
Version: 1,
|
2022-09-27 19:22:54 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
|
|
|
|
cs, ok = node.ShardClusterService.getShardCluster(defaultDMLChannel)
|
|
|
|
require.True(t, ok)
|
|
|
|
_, ok = cs.getSegment(defaultSegmentID)
|
|
|
|
require.False(t, ok)
|
2022-09-22 13:18:50 +08:00
|
|
|
})
|
|
|
|
}
|
2022-10-08 20:26:57 +08:00
|
|
|
|
|
|
|
func TestGetDataDistribution(t *testing.T) {
|
|
|
|
t.Run("QueryNode not healthy", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-10-08 20:26:57 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-10-08 20:26:57 +08:00
|
|
|
|
|
|
|
resp, err := node.GetDataDistribution(ctx, &querypb.GetDataDistributionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Target not match", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2022-11-17 14:23:08 +08:00
|
|
|
require.NoError(t, err)
|
2022-10-08 20:26:57 +08:00
|
|
|
defer node.Stop()
|
|
|
|
|
|
|
|
resp, err := node.GetDataDistribution(ctx, &querypb.GetDataDistributionRequest{
|
|
|
|
Base: &commonpb.MsgBase{TargetID: -1},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|