2023-06-21 03:36:46 +00: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
|
|
|
|
// 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 crossclusterrouting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2023-09-06 09:43:14 +00:00
|
|
|
"strconv"
|
2023-06-21 03:36:46 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-06-26 06:48:44 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-06-21 03:36:46 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2025-01-10 02:49:01 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/pkg/proto/proxypb"
|
|
|
|
"github.com/milvus-io/milvus/pkg/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/pkg/proto/workerpb"
|
2023-09-21 01:45:27 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2024-01-11 06:00:52 +00:00
|
|
|
"github.com/milvus-io/milvus/tests/integration"
|
2023-06-21 03:36:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type CrossClusterRoutingSuite struct {
|
2024-01-11 06:00:52 +00:00
|
|
|
integration.MiniClusterSuite
|
2023-06-21 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CrossClusterRoutingSuite) SetupSuite() {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
2024-01-11 06:00:52 +00:00
|
|
|
s.Require().NoError(s.SetupEmbedEtcd())
|
2023-06-21 03:36:46 +00:00
|
|
|
|
2023-09-05 02:31:48 +00:00
|
|
|
paramtable.Init()
|
2023-09-06 09:43:14 +00:00
|
|
|
paramtable.Get().Save("grpc.client.maxMaxAttempts", "1")
|
2023-06-21 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CrossClusterRoutingSuite) TearDownSuite() {
|
2024-01-11 06:00:52 +00:00
|
|
|
s.TearDownEmbedEtcd()
|
2023-09-06 09:43:14 +00:00
|
|
|
paramtable.Get().Save("grpc.client.maxMaxAttempts", strconv.FormatInt(paramtable.DefaultMaxAttempts, 10))
|
2023-06-21 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
2024-01-11 06:00:52 +00:00
|
|
|
func (s *CrossClusterRoutingSuite) TestCrossClusterRouting() {
|
2023-06-21 03:36:46 +00:00
|
|
|
const (
|
|
|
|
waitFor = time.Second * 10
|
|
|
|
duration = time.Millisecond * 10
|
|
|
|
)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
2024-01-11 06:00:52 +00:00
|
|
|
case <-time.After(15 * time.Second):
|
2023-06-21 03:36:46 +00:00
|
|
|
return
|
|
|
|
default:
|
|
|
|
err := paramtable.Get().Save(paramtable.Get().CommonCfg.ClusterPrefix.Key, fmt.Sprintf("%d", rand.Int()))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// test rootCoord
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.RootCoordClient.ShowCollections(s.Cluster.GetContext(), &milvuspb.ShowCollectionsRequest{
|
2023-06-26 06:48:44 +00:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_ShowCollections),
|
|
|
|
),
|
|
|
|
DbName: "fake_db_name",
|
|
|
|
})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test dataCoord
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.DataCoordClient.GetRecoveryInfoV2(s.Cluster.GetContext(), &datapb.GetRecoveryInfoRequestV2{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test queryCoord
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.QueryCoordClient.LoadCollection(s.Cluster.GetContext(), &querypb.LoadCollectionRequest{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test proxy
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.ProxyClient.InvalidateCollectionMetaCache(s.Cluster.GetContext(), &proxypb.InvalidateCollMetaCacheRequest{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test dataNode
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.DataNodeClient.FlushSegments(s.Cluster.GetContext(), &datapb.FlushSegmentsRequest{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test queryNode
|
|
|
|
s.Eventually(func() bool {
|
2024-01-11 06:00:52 +00:00
|
|
|
resp, err := s.Cluster.QueryNodeClient.Search(s.Cluster.GetContext(), &querypb.SearchRequest{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
|
|
|
|
// test indexNode
|
|
|
|
s.Eventually(func() bool {
|
2024-09-02 06:19:03 +00:00
|
|
|
resp, err := s.Cluster.IndexNodeClient.CreateJob(s.Cluster.GetContext(), &workerpb.CreateJobRequest{})
|
2023-06-21 03:36:46 +00:00
|
|
|
s.Suite.T().Logf("resp: %s, err: %s", resp, err)
|
|
|
|
if err != nil {
|
|
|
|
return strings.Contains(err.Error(), merr.ErrServiceUnavailable.Error())
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, waitFor, duration)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCrossClusterRoutingSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(CrossClusterRoutingSuite))
|
|
|
|
}
|