2021-10-15 18:01:38 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 15:16:33 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-15 18:01:38 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 15:16:33 +08:00
|
|
|
//
|
2021-10-15 18:01:38 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 15:16:33 +08:00
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
2021-06-11 17:53:37 +08:00
|
|
|
"context"
|
2021-08-13 10:50:09 +08:00
|
|
|
"math/rand"
|
2021-05-25 15:35:37 +08:00
|
|
|
"os"
|
2021-09-23 10:53:53 +08:00
|
|
|
"strconv"
|
2021-08-13 10:50:09 +08:00
|
|
|
"strings"
|
2021-01-19 11:37:16 +08:00
|
|
|
"testing"
|
2021-06-07 11:25:37 +08:00
|
|
|
"time"
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2022-12-12 10:57:22 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-10-13 09:55:34 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2022-12-12 10:57:22 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-10-13 09:55:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/broker"
|
2022-01-13 14:21:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-11-01 11:01:49 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2024-03-19 01:33:05 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/etcd"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
2022-04-20 14:03:40 +08:00
|
|
|
const returnError = "ReturnError"
|
|
|
|
|
|
|
|
type ctxKey struct{}
|
|
|
|
|
2021-05-18 19:45:00 +08:00
|
|
|
func TestMain(t *testing.M) {
|
2021-08-13 10:50:09 +08:00
|
|
|
rand.Seed(time.Now().Unix())
|
2022-12-02 16:05:16 +08:00
|
|
|
// init embed etcd
|
|
|
|
embedetcdServer, tempDir, err := etcd.StartTestEmbedEtcdServer()
|
|
|
|
if err != nil {
|
2023-09-01 13:09:01 +08:00
|
|
|
log.Fatal("failed to start embed etcd server", zap.Error(err))
|
2022-12-02 16:05:16 +08:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
defer embedetcdServer.Close()
|
|
|
|
|
|
|
|
addrs := etcd.GetEmbedEtcdEndpoints(embedetcdServer)
|
|
|
|
// setup env for etcd endpoint
|
|
|
|
os.Setenv("etcd.endpoints", strings.Join(addrs, ","))
|
|
|
|
|
2022-03-14 19:22:01 +08:00
|
|
|
path := "/tmp/milvus_ut/rdb_data"
|
|
|
|
os.Setenv("ROCKSMQ_PATH", path)
|
|
|
|
defer os.RemoveAll(path)
|
|
|
|
|
2023-09-05 10:31:48 +08:00
|
|
|
paramtable.Init()
|
2021-09-23 10:53:53 +08:00
|
|
|
// change to specific channel for test
|
2023-02-20 21:14:25 +08:00
|
|
|
paramtable.Get().Save(Params.EtcdCfg.Endpoints.Key, strings.Join(addrs, ","))
|
2022-12-07 18:01:19 +08:00
|
|
|
paramtable.Get().Save(Params.CommonCfg.DataCoordTimeTick.Key, Params.CommonCfg.DataCoordTimeTick.GetValue()+strconv.Itoa(rand.Int()))
|
2022-03-14 19:22:01 +08:00
|
|
|
|
2022-09-16 09:56:47 +08:00
|
|
|
rateCol, err = newRateCollector()
|
|
|
|
if err != nil {
|
|
|
|
panic("init test failed, err = " + err.Error())
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
code := t.Run()
|
|
|
|
os.Exit(code)
|
2021-05-18 19:45:00 +08:00
|
|
|
}
|
2021-02-03 17:30:10 +08:00
|
|
|
|
2021-05-18 19:45:00 +08:00
|
|
|
func TestDataNode(t *testing.T) {
|
2021-06-11 17:53:37 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
2022-01-13 14:21:34 +08:00
|
|
|
defer cancel()
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
node := newIDLEDataNodeMock(ctx, schemapb.DataType_Int64)
|
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())
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-29 14:35:21 +08:00
|
|
|
defer etcdCli.Close()
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-09 15:45:15 +08:00
|
|
|
err = node.Start()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-01-12 19:49:40 +08:00
|
|
|
assert.Empty(t, node.GetAddress())
|
|
|
|
node.SetAddress("address")
|
|
|
|
assert.Equal(t, "address", node.GetAddress())
|
2023-10-13 09:55:34 +08:00
|
|
|
|
|
|
|
broker := &broker.MockBroker{}
|
|
|
|
broker.EXPECT().ReportTimeTick(mock.Anything, mock.Anything).Return(nil).Maybe()
|
|
|
|
broker.EXPECT().GetSegmentInfo(mock.Anything, mock.Anything).Return([]*datapb.SegmentInfo{}, nil).Maybe()
|
|
|
|
|
|
|
|
node.broker = broker
|
|
|
|
|
2022-04-13 20:09:34 +08:00
|
|
|
defer node.Stop()
|
2021-09-23 18:31:55 +08:00
|
|
|
|
2022-11-21 10:19:10 +08:00
|
|
|
node.chunkManager = storage.NewLocalChunkManager(storage.RootPath("/tmp/milvus_test/datanode"))
|
2022-11-04 14:25:38 +08:00
|
|
|
paramtable.SetNodeID(1)
|
2021-09-23 18:31:55 +08:00
|
|
|
|
2023-02-22 10:28:26 +08:00
|
|
|
defer cancel()
|
2023-09-26 09:57:25 +08:00
|
|
|
t.Run("Test SetRootCoordClient", func(t *testing.T) {
|
2021-10-11 18:50:30 +08:00
|
|
|
emptyDN := &DataNode{}
|
|
|
|
tests := []struct {
|
2023-09-26 09:57:25 +08:00
|
|
|
inrc types.RootCoordClient
|
2021-10-11 18:50:30 +08:00
|
|
|
isvalid bool
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{nil, false, "nil input"},
|
|
|
|
{&RootCoordFactory{}, true, "valid input"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
err := emptyDN.SetRootCoordClient(test.inrc)
|
2021-10-11 18:50:30 +08:00
|
|
|
if test.isvalid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
t.Run("Test SetDataCoordClient", func(t *testing.T) {
|
2021-10-11 18:50:30 +08:00
|
|
|
emptyDN := &DataNode{}
|
|
|
|
tests := []struct {
|
2023-09-26 09:57:25 +08:00
|
|
|
inrc types.DataCoordClient
|
2021-10-11 18:50:30 +08:00
|
|
|
isvalid bool
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{nil, false, "nil input"},
|
|
|
|
{&DataCoordFactory{}, true, "valid input"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
err := emptyDN.SetDataCoordClient(test.inrc)
|
2021-10-11 18:50:30 +08:00
|
|
|
if test.isvalid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-09-01 10:13:15 +08:00
|
|
|
t.Run("Test getSystemInfoMetrics", func(t *testing.T) {
|
2021-11-01 11:01:49 +08:00
|
|
|
emptyNode := &DataNode{}
|
2023-10-01 10:33:30 +08:00
|
|
|
emptyNode.SetSession(&sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}})
|
2022-09-16 09:56:47 +08:00
|
|
|
emptyNode.flowgraphManager = newFlowgraphManager()
|
2021-11-01 11:01:49 +08:00
|
|
|
|
2021-09-01 10:13:15 +08:00
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
assert.NoError(t, err)
|
2021-11-01 11:01:49 +08:00
|
|
|
resp, err := emptyNode.getSystemInfoMetrics(context.TODO(), req)
|
2021-09-01 10:13:15 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-16 09:56:47 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-09-01 10:13:15 +08:00
|
|
|
log.Info("Test DataNode.getSystemInfoMetrics",
|
|
|
|
zap.String("name", resp.ComponentName),
|
|
|
|
zap.String("response", resp.Response))
|
|
|
|
})
|
|
|
|
|
2022-09-16 09:56:47 +08:00
|
|
|
t.Run("Test getSystemInfoMetrics with quotaMetric error", func(t *testing.T) {
|
|
|
|
emptyNode := &DataNode{}
|
2023-10-01 10:33:30 +08:00
|
|
|
emptyNode.SetSession(&sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}})
|
2022-09-16 09:56:47 +08:00
|
|
|
emptyNode.flowgraphManager = newFlowgraphManager()
|
|
|
|
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
rateCol.Deregister(metricsinfo.InsertConsumeThroughput)
|
|
|
|
resp, err := emptyNode.getSystemInfoMetrics(context.TODO(), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
rateCol.Register(metricsinfo.InsertConsumeThroughput)
|
|
|
|
})
|
|
|
|
|
2021-11-25 09:43:15 +08:00
|
|
|
t.Run("Test BackGroundGC", func(t *testing.T) {
|
|
|
|
vchanNameCh := make(chan string)
|
|
|
|
node.clearSignal = vchanNameCh
|
2023-09-19 15:27:38 +08:00
|
|
|
node.stopWaiter.Add(1)
|
2021-11-25 09:43:15 +08:00
|
|
|
go node.BackGroundGC(vchanNameCh)
|
2021-07-15 10:05:55 +08:00
|
|
|
|
|
|
|
testDataSyncs := []struct {
|
|
|
|
dmChannelName string
|
|
|
|
}{
|
2021-11-25 09:43:15 +08:00
|
|
|
{"fake-by-dev-rootcoord-dml-backgroundgc-1"},
|
|
|
|
{"fake-by-dev-rootcoord-dml-backgroundgc-2"},
|
2021-07-15 10:05:55 +08:00
|
|
|
}
|
|
|
|
|
2023-02-22 10:28:26 +08:00
|
|
|
for _, test := range testDataSyncs {
|
2024-03-19 01:33:05 +08:00
|
|
|
err = node.flowgraphManager.AddandStartWithEtcdTickler(node, &datapb.VchannelInfo{
|
|
|
|
CollectionID: 1, ChannelName: test.dmChannelName,
|
|
|
|
}, &schemapb.CollectionSchema{
|
|
|
|
Name: "test_collection",
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.RowIDField, Name: common.RowIDFieldName, DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: common.TimeStampField, Name: common.TimeStampFieldName, DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 100, Name: "pk", DataType: schemapb.DataType_Int64, IsPrimaryKey: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 101, Name: "vector", DataType: schemapb.DataType_FloatVector,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{Key: common.DimKey, Value: "128"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, genTestTickler())
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-02-22 10:28:26 +08:00
|
|
|
vchanNameCh <- test.dmChannelName
|
2021-07-15 10:05:55 +08:00
|
|
|
}
|
2023-02-22 10:28:26 +08:00
|
|
|
|
|
|
|
assert.Eventually(t, func() bool {
|
|
|
|
for _, test := range testDataSyncs {
|
2023-11-30 18:42:32 +08:00
|
|
|
if node.flowgraphManager.HasFlowgraph(test.dmChannelName) {
|
2023-02-22 10:28:26 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}, 2*time.Second, 10*time.Millisecond)
|
2021-07-08 15:52:40 +08:00
|
|
|
})
|
2021-08-13 10:50:09 +08:00
|
|
|
}
|