2021-08-17 10:06:11 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
|
|
|
package querycoord
|
|
|
|
|
|
|
|
import (
|
2021-08-26 14:17:54 +08:00
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-08-17 10:06:11 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-08-17 10:06:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-08-26 14:17:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-09-15 20:40:07 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-08-17 10:06:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestQueryNodeCluster_getMetrics(t *testing.T) {
|
|
|
|
log.Info("TestQueryNodeCluster_getMetrics, todo")
|
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
|
|
|
|
func TestReloadClusterFromKV(t *testing.T) {
|
2021-09-15 20:40:07 +08:00
|
|
|
t.Run("Test LoadOnlineNodes", func(t *testing.T) {
|
|
|
|
refreshParams()
|
|
|
|
baseCtx := context.Background()
|
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
clusterSession := sessionutil.NewSession(context.Background(), Params.MetaRootPath, Params.EtcdEndpoints)
|
|
|
|
clusterSession.Init(typeutil.QueryCoordRole, Params.Address, true)
|
|
|
|
cluster := &queryNodeCluster{
|
|
|
|
ctx: baseCtx,
|
|
|
|
client: kv,
|
|
|
|
nodes: make(map[int64]Node),
|
|
|
|
newNodeFn: newQueryNodeTest,
|
|
|
|
session: clusterSession,
|
|
|
|
}
|
|
|
|
|
|
|
|
queryNode, err := startQueryNodeServer(baseCtx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
cluster.reloadFromKV()
|
|
|
|
|
|
|
|
nodeID := queryNode.queryNodeID
|
|
|
|
for {
|
|
|
|
_, err = cluster.getNodeByID(nodeID)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queryNode.stop()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test LoadOfflineNodes", func(t *testing.T) {
|
|
|
|
refreshParams()
|
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
clusterSession := sessionutil.NewSession(context.Background(), Params.MetaRootPath, Params.EtcdEndpoints)
|
|
|
|
clusterSession.Init(typeutil.QueryCoordRole, Params.Address, true)
|
|
|
|
cluster := &queryNodeCluster{
|
|
|
|
client: kv,
|
|
|
|
nodes: make(map[int64]Node),
|
|
|
|
newNodeFn: newQueryNodeTest,
|
|
|
|
session: clusterSession,
|
|
|
|
}
|
|
|
|
|
|
|
|
kvs := make(map[string]string)
|
|
|
|
session := &sessionutil.Session{
|
|
|
|
ServerID: 100,
|
|
|
|
Address: "localhost",
|
|
|
|
}
|
|
|
|
sessionBlob, err := json.Marshal(session)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
sessionKey := fmt.Sprintf("%s/%d", queryNodeInfoPrefix, 100)
|
|
|
|
kvs[sessionKey] = string(sessionBlob)
|
|
|
|
|
|
|
|
collectionInfo := &querypb.CollectionInfo{
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
collectionBlobs := proto.MarshalTextString(collectionInfo)
|
|
|
|
nodeKey := fmt.Sprintf("%s/%d", queryNodeMetaPrefix, 100)
|
|
|
|
kvs[nodeKey] = collectionBlobs
|
|
|
|
|
|
|
|
err = kv.MultiSave(kvs)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
cluster.reloadFromKV()
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(cluster.nodes))
|
|
|
|
collection := cluster.getCollectionInfosByID(context.Background(), 100)
|
|
|
|
assert.Equal(t, defaultCollectionID, collection[0].CollectionID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGrpcRequest(t *testing.T) {
|
2021-08-26 14:17:54 +08:00
|
|
|
refreshParams()
|
2021-09-15 20:40:07 +08:00
|
|
|
baseCtx, cancel := context.WithCancel(context.Background())
|
2021-08-26 14:17:54 +08:00
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
assert.Nil(t, err)
|
2021-09-15 20:40:07 +08:00
|
|
|
clusterSession := sessionutil.NewSession(context.Background(), Params.MetaRootPath, Params.EtcdEndpoints)
|
|
|
|
clusterSession.Init(typeutil.QueryCoordRole, Params.Address, true)
|
|
|
|
meta, err := newMeta(kv)
|
|
|
|
assert.Nil(t, err)
|
2021-08-26 14:17:54 +08:00
|
|
|
cluster := &queryNodeCluster{
|
2021-09-15 20:40:07 +08:00
|
|
|
ctx: baseCtx,
|
|
|
|
cancel: cancel,
|
|
|
|
client: kv,
|
|
|
|
clusterMeta: meta,
|
|
|
|
nodes: make(map[int64]Node),
|
|
|
|
newNodeFn: newQueryNodeTest,
|
|
|
|
session: clusterSession,
|
2021-08-26 14:17:54 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
node, err := startQueryNodeServer(baseCtx)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-15 20:40:07 +08:00
|
|
|
nodeSession := node.session
|
|
|
|
nodeID := node.queryNodeID
|
|
|
|
cluster.registerNode(baseCtx, nodeSession, nodeID, disConnect)
|
2021-08-26 14:17:54 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
for {
|
|
|
|
online, err := cluster.isOnline(nodeID)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
if online {
|
|
|
|
break
|
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
t.Run("Test GetComponentInfos", func(t *testing.T) {
|
|
|
|
_, err := cluster.getComponentInfos(baseCtx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test LoadSegments", func(t *testing.T) {
|
|
|
|
segmentLoadInfo := &querypb.SegmentLoadInfo{
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
loadSegmentReq := &querypb.LoadSegmentsRequest{
|
|
|
|
NodeID: nodeID,
|
|
|
|
Infos: []*querypb.SegmentLoadInfo{segmentLoadInfo},
|
|
|
|
}
|
|
|
|
err := cluster.loadSegments(baseCtx, nodeID, loadSegmentReq)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test ReleaseSegments", func(t *testing.T) {
|
|
|
|
releaseSegmentReq := &querypb.ReleaseSegmentsRequest{
|
|
|
|
NodeID: nodeID,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
PartitionIDs: []UniqueID{defaultPartitionID},
|
|
|
|
SegmentIDs: []UniqueID{defaultSegmentID},
|
|
|
|
}
|
|
|
|
err := cluster.releaseSegments(baseCtx, nodeID, releaseSegmentReq)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test AddQueryChannel", func(t *testing.T) {
|
|
|
|
reqChannel, resChannel := cluster.clusterMeta.GetQueryChannel(defaultCollectionID)
|
|
|
|
addQueryChannelReq := &querypb.AddQueryChannelRequest{
|
|
|
|
NodeID: nodeID,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
RequestChannelID: reqChannel,
|
|
|
|
ResultChannelID: resChannel,
|
|
|
|
}
|
|
|
|
err := cluster.addQueryChannel(baseCtx, nodeID, addQueryChannelReq)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
2021-08-26 14:17:54 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
t.Run("Test RemoveQueryChannel", func(t *testing.T) {
|
|
|
|
reqChannel, resChannel := cluster.clusterMeta.GetQueryChannel(defaultCollectionID)
|
|
|
|
removeQueryChannelReq := &querypb.RemoveQueryChannelRequest{
|
|
|
|
NodeID: nodeID,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
RequestChannelID: reqChannel,
|
|
|
|
ResultChannelID: resChannel,
|
|
|
|
}
|
|
|
|
err := cluster.removeQueryChannel(baseCtx, nodeID, removeQueryChannelReq)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
2021-08-26 14:17:54 +08:00
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
node.stop()
|
2021-08-26 14:17:54 +08:00
|
|
|
}
|