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
|
|
|
"fmt"
|
2021-05-25 15:35:37 +08:00
|
|
|
"math"
|
2021-08-13 10:50:09 +08:00
|
|
|
"math/rand"
|
2021-05-25 15:35:37 +08:00
|
|
|
"os"
|
2022-11-21 10:19:10 +08:00
|
|
|
"path/filepath"
|
2021-09-23 10:53:53 +08:00
|
|
|
"strconv"
|
2021-08-13 10:50:09 +08:00
|
|
|
"strings"
|
2021-09-09 16:40:00 +08:00
|
|
|
"sync"
|
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-09-26 18:06:54 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
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"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2021-11-19 13:57:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2022-01-13 14:21:34 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2022-01-13 14:21:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-12-29 14:35:21 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2022-10-14 15:15:24 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/importutil"
|
2021-09-01 10:13:15 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2022-11-04 14:25:38 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-11-01 11:01:49 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2021-04-21 18:41:37 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-05-25 15:35:37 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-12-02 16:05:16 +08:00
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
"go.uber.org/zap"
|
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 {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.DataNodeCfg.InitAlias("datanode-alias-1")
|
2021-01-19 11:37:16 +08:00
|
|
|
Params.Init()
|
2021-09-23 10:53:53 +08:00
|
|
|
// change to specific channel for test
|
2022-03-04 11:17:56 +08:00
|
|
|
Params.CommonCfg.DataCoordTimeTick = Params.CommonCfg.DataCoordTimeTick + 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) {
|
2022-10-14 15:15:24 +08:00
|
|
|
importutil.ReportImportAttempts = 1
|
|
|
|
|
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())
|
2021-12-29 14:35:21 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
2021-10-09 15:45:15 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node.Start()
|
|
|
|
assert.Nil(t, err)
|
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-11-01 11:01:49 +08:00
|
|
|
t.Run("Test WatchDmChannels ", func(t *testing.T) {
|
|
|
|
emptyNode := &DataNode{}
|
2021-09-23 18:31:55 +08:00
|
|
|
|
2021-11-01 11:01:49 +08:00
|
|
|
status, err := emptyNode.WatchDmChannels(ctx, &datapb.WatchDmChannelsRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-09-23 18:31:55 +08:00
|
|
|
})
|
|
|
|
|
2021-10-11 18:50:30 +08:00
|
|
|
t.Run("Test SetRootCoord", func(t *testing.T) {
|
|
|
|
emptyDN := &DataNode{}
|
|
|
|
tests := []struct {
|
|
|
|
inrc types.RootCoord
|
|
|
|
isvalid bool
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{nil, false, "nil input"},
|
|
|
|
{&RootCoordFactory{}, true, "valid input"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
err := emptyDN.SetRootCoord(test.inrc)
|
|
|
|
if test.isvalid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test SetDataCoord", func(t *testing.T) {
|
|
|
|
emptyDN := &DataNode{}
|
|
|
|
tests := []struct {
|
|
|
|
inrc types.DataCoord
|
|
|
|
isvalid bool
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{nil, false, "nil input"},
|
|
|
|
{&DataCoordFactory{}, true, "valid input"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
err := emptyDN.SetDataCoord(test.inrc)
|
|
|
|
if test.isvalid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-21 18:41:37 +08:00
|
|
|
t.Run("Test GetComponentStates", func(t *testing.T) {
|
|
|
|
stat, err := node.GetComponentStates(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, stat.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-08-23 15:50:52 +08:00
|
|
|
t.Run("Test GetCompactionState", func(t *testing.T) {
|
|
|
|
node.compactionExecutor.executing.Store(int64(3), 0)
|
|
|
|
node.compactionExecutor.executing.Store(int64(2), 0)
|
|
|
|
node.compactionExecutor.completed.Store(int64(1), &datapb.CompactionResult{
|
|
|
|
PlanID: 1,
|
|
|
|
SegmentID: 10,
|
|
|
|
})
|
|
|
|
stat, err := node.GetCompactionState(node.ctx, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, 3, len(stat.GetResults()))
|
|
|
|
|
|
|
|
cnt := 0
|
|
|
|
for _, v := range stat.GetResults() {
|
|
|
|
if v.GetState() == commonpb.CompactionState_Completed {
|
|
|
|
cnt++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1, cnt)
|
|
|
|
|
|
|
|
cnt = 0
|
|
|
|
node.compactionExecutor.completed.Range(func(k, v any) bool {
|
|
|
|
cnt++
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
assert.Equal(t, 0, cnt)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test GetCompactionState unhealthy", func(t *testing.T) {
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-08-23 15:50:52 +08:00
|
|
|
resp, _ := node.GetCompactionState(ctx, nil)
|
|
|
|
assert.Equal(t, "DataNode is unhealthy", resp.GetStatus().GetReason())
|
2022-10-10 15:55:22 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-08-23 15:50:52 +08:00
|
|
|
})
|
|
|
|
|
2021-04-21 18:41:37 +08:00
|
|
|
t.Run("Test FlushSegments", func(t *testing.T) {
|
2021-11-05 11:59:02 +08:00
|
|
|
dmChannelName := "fake-by-dev-rootcoord-dml-channel-test-FlushSegments"
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
node1 := newIDLEDataNodeMock(context.TODO(), schemapb.DataType_Int64)
|
2021-12-29 14:35:21 +08:00
|
|
|
node1.SetEtcdClient(etcdCli)
|
2021-10-09 15:45:15 +08:00
|
|
|
err = node1.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node1.Start()
|
|
|
|
assert.Nil(t, err)
|
2021-09-09 16:40:00 +08:00
|
|
|
defer func() {
|
|
|
|
err := node1.Stop()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
vchan := &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: dmChannelName,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2021-09-09 16:40:00 +08:00
|
|
|
}
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2022-10-10 01:37:21 +08:00
|
|
|
err := node1.flowgraphManager.addAndStart(node1, vchan, nil)
|
2022-01-13 14:21:34 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
fgservice, ok := node1.flowgraphManager.getFlowgraphService(dmChannelName)
|
2021-05-25 15:35:37 +08:00
|
|
|
assert.True(t, ok)
|
2022-01-13 14:21:34 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
err = fgservice.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_New,
|
|
|
|
segID: 0,
|
|
|
|
collID: 1,
|
|
|
|
partitionID: 1,
|
|
|
|
startPos: &internalpb.MsgPosition{},
|
|
|
|
endPos: &internalpb.MsgPosition{},
|
|
|
|
})
|
2021-10-09 15:45:15 +08:00
|
|
|
assert.Nil(t, err)
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2021-04-21 18:41:37 +08:00
|
|
|
req := &datapb.FlushSegmentsRequest{
|
2022-11-03 22:47:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: node1.session.ServerID,
|
|
|
|
},
|
2021-04-21 18:41:37 +08:00
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
2021-05-27 18:45:24 +08:00
|
|
|
SegmentIDs: []int64{0},
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
2021-05-27 18:45:24 +08:00
|
|
|
|
2021-09-09 16:40:00 +08:00
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(2)
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2021-09-09 16:40:00 +08:00
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2021-09-09 16:40:00 +08:00
|
|
|
status, err := node1.FlushSegments(node1.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
|
|
|
}()
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2021-09-09 16:40:00 +08:00
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2021-05-29 18:04:30 +08:00
|
|
|
|
2021-09-09 16:40:00 +08:00
|
|
|
timeTickMsgPack := msgstream.MsgPack{}
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: Timestamp(0),
|
|
|
|
EndTimestamp: Timestamp(0),
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
},
|
|
|
|
TimeTickMsg: internalpb.TimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
MsgID: UniqueID(0),
|
|
|
|
Timestamp: math.MaxUint64,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
timeTickMsgPack.Msgs = append(timeTickMsgPack.Msgs, timeTickMsg)
|
|
|
|
|
|
|
|
// pulsar produce
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
insertStream, err := factory.NewMsgStream(node1.ctx)
|
2021-09-09 16:40:00 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
insertStream.AsProducer([]string{dmChannelName})
|
|
|
|
defer insertStream.Close()
|
|
|
|
|
2022-12-05 20:55:17 +08:00
|
|
|
_, err = insertStream.Broadcast(&timeTickMsgPack)
|
2021-09-09 16:40:00 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-12-05 20:55:17 +08:00
|
|
|
_, err = insertStream.Broadcast(&timeTickMsgPack)
|
2021-09-09 16:40:00 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-27 18:45:24 +08:00
|
|
|
}()
|
2021-09-09 16:40:00 +08:00
|
|
|
|
|
|
|
wg.Wait()
|
2021-10-20 15:02:36 +08:00
|
|
|
// dup call
|
|
|
|
status, err := node1.FlushSegments(node1.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2022-05-06 17:49:51 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-10-20 15:02:36 +08:00
|
|
|
|
|
|
|
// failure call
|
|
|
|
req = &datapb.FlushSegmentsRequest{
|
2022-11-03 22:47:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: -1,
|
|
|
|
},
|
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{1},
|
|
|
|
}
|
|
|
|
status, err = node1.FlushSegments(node1.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_NodeIDNotMatch, status.ErrorCode)
|
|
|
|
|
|
|
|
req = &datapb.FlushSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: node1.session.ServerID,
|
|
|
|
},
|
2021-10-20 15:02:36 +08:00
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{1},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err = node1.FlushSegments(node1.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode)
|
|
|
|
|
|
|
|
req = &datapb.FlushSegmentsRequest{
|
2022-11-03 22:47:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: node1.session.ServerID,
|
|
|
|
},
|
2022-11-10 22:13:04 +08:00
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{},
|
2021-10-20 15:02:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
status, err = node1.FlushSegments(node1.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
2022-11-10 22:13:04 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.ErrorCode)
|
2021-04-21 18:41:37 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test GetTimeTickChannel", func(t *testing.T) {
|
|
|
|
_, err := node.GetTimeTickChannel(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test GetStatisticsChannel", func(t *testing.T) {
|
|
|
|
_, err := node.GetStatisticsChannel(node.ctx)
|
|
|
|
assert.NoError(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{}
|
|
|
|
emptyNode.session = &sessionutil.Session{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{}
|
|
|
|
emptyNode.session = &sessionutil.Session{ServerID: 1}
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
t.Run("Test ShowConfigurations", func(t *testing.T) {
|
|
|
|
pattern := "Port"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
|
|
|
//test closed server
|
|
|
|
node := &DataNode{}
|
|
|
|
node.session = &sessionutil.Session{ServerID: 1}
|
2022-10-10 15:55:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Abnormal)
|
2022-08-12 13:20:39 +08:00
|
|
|
|
|
|
|
resp, err := node.ShowConfigurations(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.Status.ErrorCode)
|
2022-10-10 15:55:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Healthy)
|
2022-08-12 13:20:39 +08:00
|
|
|
|
|
|
|
resp, err = node.ShowConfigurations(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(resp.Configuations))
|
|
|
|
assert.Equal(t, "datanode.port", resp.Configuations[0].Key)
|
|
|
|
})
|
|
|
|
|
2021-09-01 10:13:15 +08:00
|
|
|
t.Run("Test GetMetrics", func(t *testing.T) {
|
2021-11-01 11:01:49 +08:00
|
|
|
node := &DataNode{}
|
|
|
|
node.session = &sessionutil.Session{ServerID: 1}
|
2022-09-16 09:56:47 +08:00
|
|
|
node.flowgraphManager = newFlowgraphManager()
|
2021-09-01 10:13:15 +08:00
|
|
|
// server is closed
|
2022-10-10 15:55:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Abnormal)
|
2021-09-01 10:13:15 +08:00
|
|
|
resp, err := node.GetMetrics(ctx, &milvuspb.GetMetricsRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
2022-10-10 15:55:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Healthy)
|
2021-09-01 10:13:15 +08:00
|
|
|
|
|
|
|
// failed to parse metric type
|
|
|
|
invalidRequest := "invalid request"
|
|
|
|
resp, err = node.GetMetrics(ctx, &milvuspb.GetMetricsRequest{
|
|
|
|
Request: invalidRequest,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// unsupported metric type
|
|
|
|
unsupportedMetricType := "unsupported"
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(unsupportedMetricType)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
resp, err = node.GetMetrics(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
|
|
|
|
// normal case
|
|
|
|
req, err = metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
resp, err = node.GetMetrics(node.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
log.Info("Test DataNode.GetMetrics",
|
|
|
|
zap.String("name", resp.ComponentName),
|
|
|
|
zap.String("response", resp.Response))
|
|
|
|
})
|
|
|
|
|
2022-03-21 15:47:23 +08:00
|
|
|
t.Run("Test Import", func(t *testing.T) {
|
2022-04-20 14:03:40 +08:00
|
|
|
node.rootCoord = &RootCoordFactory{
|
|
|
|
collectionID: 100,
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
|
|
|
content := []byte(`{
|
|
|
|
"rows":[
|
|
|
|
{"bool_field": true, "int8_field": 10, "int16_field": 101, "int32_field": 1001, "int64_field": 10001, "float32_field": 3.14, "float64_field": 1.56, "varChar_field": "hello world", "binary_vector_field": [254, 0, 254, 0], "float_vector_field": [1.1, 1.2]},
|
|
|
|
{"bool_field": false, "int8_field": 11, "int16_field": 102, "int32_field": 1002, "int64_field": 10002, "float32_field": 3.15, "float64_field": 2.56, "varChar_field": "hello world", "binary_vector_field": [253, 0, 253, 0], "float_vector_field": [2.1, 2.2]},
|
|
|
|
{"bool_field": true, "int8_field": 12, "int16_field": 103, "int32_field": 1003, "int64_field": 10003, "float32_field": 3.16, "float64_field": 3.56, "varChar_field": "hello world", "binary_vector_field": [252, 0, 252, 0], "float_vector_field": [3.1, 3.2]},
|
|
|
|
{"bool_field": false, "int8_field": 13, "int16_field": 104, "int32_field": 1004, "int64_field": 10004, "float32_field": 3.17, "float64_field": 4.56, "varChar_field": "hello world", "binary_vector_field": [251, 0, 251, 0], "float_vector_field": [4.1, 4.2]},
|
|
|
|
{"bool_field": true, "int8_field": 14, "int16_field": 105, "int32_field": 1005, "int64_field": 10005, "float32_field": 3.18, "float64_field": 5.56, "varChar_field": "hello world", "binary_vector_field": [250, 0, 250, 0], "float_vector_field": [5.1, 5.2]}
|
|
|
|
]
|
|
|
|
}`)
|
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
chName1 := "fake-by-dev-rootcoord-dml-testimport-1"
|
|
|
|
chName2 := "fake-by-dev-rootcoord-dml-testimport-2"
|
|
|
|
err := node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
|
|
|
CollectionID: 100,
|
|
|
|
ChannelName: chName1,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-09-26 18:06:54 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
err = node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
|
|
|
CollectionID: 100,
|
|
|
|
ChannelName: chName2,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-09-26 18:06:54 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
_, ok := node.flowgraphManager.getFlowgraphService(chName1)
|
|
|
|
assert.True(t, ok)
|
|
|
|
_, ok = node.flowgraphManager.getFlowgraphService(chName2)
|
|
|
|
assert.True(t, ok)
|
|
|
|
|
2022-11-21 10:19:10 +08:00
|
|
|
filePath := filepath.Join(node.chunkManager.RootPath(), "rows_1.json")
|
2022-09-29 16:18:56 +08:00
|
|
|
err = node.chunkManager.Write(ctx, filePath, content)
|
2022-04-20 14:03:40 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
req := &datapb.ImportTaskRequest{
|
|
|
|
ImportTask: &datapb.ImportTask{
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
2022-09-26 18:06:54 +08:00
|
|
|
ChannelNames: []string{chName1, chName2},
|
2022-04-20 14:03:40 +08:00
|
|
|
Files: []string{filePath},
|
|
|
|
RowBased: true,
|
|
|
|
},
|
|
|
|
}
|
2022-09-26 18:06:54 +08:00
|
|
|
node.rootCoord.(*RootCoordFactory).ReportImportErr = true
|
2022-10-14 15:15:24 +08:00
|
|
|
_, err = node.Import(node.ctx, req)
|
2022-09-26 18:06:54 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
node.rootCoord.(*RootCoordFactory).ReportImportErr = false
|
|
|
|
|
|
|
|
node.rootCoord.(*RootCoordFactory).ReportImportNotSuccess = true
|
|
|
|
_, err = node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.rootCoord.(*RootCoordFactory).ReportImportNotSuccess = false
|
|
|
|
|
|
|
|
node.dataCoord.(*DataCoordFactory).AddSegmentError = true
|
|
|
|
_, err = node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.dataCoord.(*DataCoordFactory).AddSegmentError = false
|
|
|
|
|
|
|
|
node.dataCoord.(*DataCoordFactory).AddSegmentNotSuccess = true
|
|
|
|
_, err = node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.dataCoord.(*DataCoordFactory).AddSegmentNotSuccess = false
|
|
|
|
|
2022-04-20 14:03:40 +08:00
|
|
|
stat, err := node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, stat.GetErrorCode())
|
|
|
|
assert.Equal(t, "", stat.GetReason())
|
|
|
|
})
|
|
|
|
|
2022-06-14 16:18:09 +08:00
|
|
|
t.Run("Test Import bad flow graph", func(t *testing.T) {
|
2022-04-25 11:07:47 +08:00
|
|
|
node.rootCoord = &RootCoordFactory{
|
|
|
|
collectionID: 100,
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
|
|
|
|
|
|
|
chName1 := "fake-by-dev-rootcoord-dml-testimport-1"
|
|
|
|
chName2 := "fake-by-dev-rootcoord-dml-testimport-2"
|
|
|
|
err := node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 100,
|
|
|
|
ChannelName: chName1,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-04-25 11:07:47 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
err = node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 999, // wrong collection ID.
|
|
|
|
ChannelName: chName2,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-04-25 11:07:47 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
_, ok := node.flowgraphManager.getFlowgraphService(chName1)
|
|
|
|
assert.True(t, ok)
|
|
|
|
_, ok = node.flowgraphManager.getFlowgraphService(chName2)
|
|
|
|
assert.True(t, ok)
|
|
|
|
|
|
|
|
content := []byte(`{
|
|
|
|
"rows":[
|
|
|
|
{"bool_field": true, "int8_field": 10, "int16_field": 101, "int32_field": 1001, "int64_field": 10001, "float32_field": 3.14, "float64_field": 1.56, "varChar_field": "hello world", "binary_vector_field": [254, 0, 254, 0], "float_vector_field": [1.1, 1.2]},
|
|
|
|
{"bool_field": false, "int8_field": 11, "int16_field": 102, "int32_field": 1002, "int64_field": 10002, "float32_field": 3.15, "float64_field": 2.56, "varChar_field": "hello world", "binary_vector_field": [253, 0, 253, 0], "float_vector_field": [2.1, 2.2]},
|
|
|
|
{"bool_field": true, "int8_field": 12, "int16_field": 103, "int32_field": 1003, "int64_field": 10003, "float32_field": 3.16, "float64_field": 3.56, "varChar_field": "hello world", "binary_vector_field": [252, 0, 252, 0], "float_vector_field": [3.1, 3.2]},
|
|
|
|
{"bool_field": false, "int8_field": 13, "int16_field": 104, "int32_field": 1004, "int64_field": 10004, "float32_field": 3.17, "float64_field": 4.56, "varChar_field": "hello world", "binary_vector_field": [251, 0, 251, 0], "float_vector_field": [4.1, 4.2]},
|
|
|
|
{"bool_field": true, "int8_field": 14, "int16_field": 105, "int32_field": 1005, "int64_field": 10005, "float32_field": 3.18, "float64_field": 5.56, "varChar_field": "hello world", "binary_vector_field": [250, 0, 250, 0], "float_vector_field": [5.1, 5.2]}
|
|
|
|
]
|
|
|
|
}`)
|
|
|
|
|
2022-11-21 10:19:10 +08:00
|
|
|
filePath := filepath.Join(node.chunkManager.RootPath(), "rows_1.json")
|
2022-09-29 16:18:56 +08:00
|
|
|
err = node.chunkManager.Write(ctx, filePath, content)
|
2022-04-25 11:07:47 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
req := &datapb.ImportTaskRequest{
|
|
|
|
ImportTask: &datapb.ImportTask{
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
|
|
|
ChannelNames: []string{chName1, chName2},
|
|
|
|
Files: []string{filePath},
|
|
|
|
RowBased: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stat, err := node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, stat.GetErrorCode())
|
|
|
|
assert.Equal(t, "", stat.GetReason())
|
|
|
|
})
|
|
|
|
|
2022-04-20 14:03:40 +08:00
|
|
|
t.Run("Test Import report import error", func(t *testing.T) {
|
|
|
|
node.rootCoord = &RootCoordFactory{
|
2022-10-14 15:15:24 +08:00
|
|
|
collectionID: 100,
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
ReportImportErr: true,
|
2022-04-20 14:03:40 +08:00
|
|
|
}
|
2022-04-12 22:19:34 +08:00
|
|
|
content := []byte(`{
|
|
|
|
"rows":[
|
|
|
|
{"bool_field": true, "int8_field": 10, "int16_field": 101, "int32_field": 1001, "int64_field": 10001, "float32_field": 3.14, "float64_field": 1.56, "varChar_field": "hello world", "binary_vector_field": [254, 0, 254, 0], "float_vector_field": [1.1, 1.2]},
|
|
|
|
{"bool_field": false, "int8_field": 11, "int16_field": 102, "int32_field": 1002, "int64_field": 10002, "float32_field": 3.15, "float64_field": 2.56, "varChar_field": "hello world", "binary_vector_field": [253, 0, 253, 0], "float_vector_field": [2.1, 2.2]},
|
|
|
|
{"bool_field": true, "int8_field": 12, "int16_field": 103, "int32_field": 1003, "int64_field": 10003, "float32_field": 3.16, "float64_field": 3.56, "varChar_field": "hello world", "binary_vector_field": [252, 0, 252, 0], "float_vector_field": [3.1, 3.2]},
|
|
|
|
{"bool_field": false, "int8_field": 13, "int16_field": 104, "int32_field": 1004, "int64_field": 10004, "float32_field": 3.17, "float64_field": 4.56, "varChar_field": "hello world", "binary_vector_field": [251, 0, 251, 0], "float_vector_field": [4.1, 4.2]},
|
|
|
|
{"bool_field": true, "int8_field": 14, "int16_field": 105, "int32_field": 1005, "int64_field": 10005, "float32_field": 3.18, "float64_field": 5.56, "varChar_field": "hello world", "binary_vector_field": [250, 0, 250, 0], "float_vector_field": [5.1, 5.2]}
|
|
|
|
]
|
|
|
|
}`)
|
|
|
|
|
2022-11-21 10:19:10 +08:00
|
|
|
filePath := filepath.Join(node.chunkManager.RootPath(), "rows_1.json")
|
2022-09-29 16:18:56 +08:00
|
|
|
err = node.chunkManager.Write(ctx, filePath, content)
|
2022-04-12 22:19:34 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-01 11:33:28 +08:00
|
|
|
req := &datapb.ImportTaskRequest{
|
|
|
|
ImportTask: &datapb.ImportTask{
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
2022-04-20 14:03:40 +08:00
|
|
|
ChannelNames: []string{"ch1", "ch2"},
|
2022-04-12 22:19:34 +08:00
|
|
|
Files: []string{filePath},
|
|
|
|
RowBased: true,
|
2022-04-01 11:33:28 +08:00
|
|
|
},
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
2022-10-14 15:15:24 +08:00
|
|
|
stat, err := node.Import(node.ctx, req)
|
2022-03-21 15:47:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-20 14:03:40 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, stat.GetErrorCode())
|
2022-03-21 15:47:23 +08:00
|
|
|
})
|
|
|
|
|
2022-04-12 22:19:34 +08:00
|
|
|
t.Run("Test Import error", func(t *testing.T) {
|
|
|
|
node.rootCoord = &RootCoordFactory{collectionID: -1}
|
|
|
|
req := &datapb.ImportTaskRequest{
|
|
|
|
ImportTask: &datapb.ImportTask{
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
|
|
|
},
|
|
|
|
}
|
2022-04-20 14:03:40 +08:00
|
|
|
stat, err := node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
2022-04-12 22:19:34 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, stat.ErrorCode)
|
2022-04-21 21:37:42 +08:00
|
|
|
|
|
|
|
stat, err = node.Import(context.WithValue(ctx, ctxKey{}, returnError), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, stat.GetErrorCode())
|
|
|
|
|
2022-10-10 15:55:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Abnormal)
|
2022-04-21 21:37:42 +08:00
|
|
|
stat, err = node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, stat.GetErrorCode())
|
2022-04-12 22:19:34 +08:00
|
|
|
})
|
|
|
|
|
2021-11-25 09:43:15 +08:00
|
|
|
t.Run("Test BackGroundGC", func(t *testing.T) {
|
2021-07-15 10:05:55 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
2022-03-25 14:27:25 +08:00
|
|
|
node := newIDLEDataNodeMock(ctx, schemapb.DataType_Int64)
|
2021-07-15 10:05:55 +08:00
|
|
|
|
2021-11-25 09:43:15 +08:00
|
|
|
vchanNameCh := make(chan string)
|
|
|
|
node.clearSignal = vchanNameCh
|
|
|
|
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"},
|
|
|
|
{"fake-by-dev-rootcoord-dml-backgroundgc-3"},
|
|
|
|
{""},
|
|
|
|
{""},
|
2021-07-15 10:05:55 +08:00
|
|
|
}
|
|
|
|
|
2021-11-25 09:43:15 +08:00
|
|
|
for i, test := range testDataSyncs {
|
2021-07-15 10:05:55 +08:00
|
|
|
if i <= 2 {
|
2022-10-10 01:37:21 +08:00
|
|
|
err = node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{CollectionID: 1, ChannelName: test.dmChannelName}, nil)
|
2021-11-25 09:43:15 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
vchanNameCh <- test.dmChannelName
|
|
|
|
}
|
2021-07-15 10:05:55 +08:00
|
|
|
}
|
2021-07-08 15:52:40 +08:00
|
|
|
cancel()
|
|
|
|
})
|
2022-09-23 10:22:52 +08:00
|
|
|
|
|
|
|
t.Run("Test SyncSegments", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
chanName := "fake-by-dev-rootcoord-dml-test-syncsegments-1"
|
|
|
|
|
|
|
|
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())
|
2022-09-23 10:22:52 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer node.Stop()
|
|
|
|
|
|
|
|
err = node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
|
|
|
ChannelName: chanName,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
2022-11-24 10:21:13 +08:00
|
|
|
FlushedSegmentIds: []int64{100, 200, 300},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-09-23 10:22:52 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
fg, ok := node.flowgraphManager.getFlowgraphService(chanName)
|
|
|
|
assert.True(t, ok)
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
s1 := Segment{segmentID: 100}
|
|
|
|
s2 := Segment{segmentID: 200}
|
|
|
|
s3 := Segment{segmentID: 300}
|
|
|
|
s1.setType(datapb.SegmentType_Flushed)
|
|
|
|
s2.setType(datapb.SegmentType_Flushed)
|
|
|
|
s3.setType(datapb.SegmentType_Flushed)
|
|
|
|
fg.channel.(*ChannelMeta).segments = map[UniqueID]*Segment{
|
|
|
|
s1.segmentID: &s1,
|
|
|
|
s2.segmentID: &s2,
|
|
|
|
s3.segmentID: &s3,
|
2022-09-23 10:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("invalid compacted from", func(t *testing.T) {
|
2022-11-24 10:21:13 +08:00
|
|
|
req := &datapb.SyncSegmentsRequest{
|
|
|
|
CompactedTo: 400,
|
|
|
|
NumOfRows: 100,
|
2022-09-23 10:22:52 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 10:21:13 +08:00
|
|
|
req.CompactedFrom = []UniqueID{}
|
|
|
|
status, err := node.SyncSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.GetErrorCode())
|
|
|
|
|
|
|
|
req.CompactedFrom = []UniqueID{101, 201}
|
|
|
|
status, err = node.SyncSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.GetErrorCode())
|
2022-09-23 10:22:52 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid request numRows>0", func(t *testing.T) {
|
|
|
|
req := &datapb.SyncSegmentsRequest{
|
2022-11-24 10:21:13 +08:00
|
|
|
CompactedFrom: []UniqueID{100, 200, 101, 201},
|
|
|
|
CompactedTo: 102,
|
2022-09-23 10:22:52 +08:00
|
|
|
NumOfRows: 100,
|
|
|
|
}
|
|
|
|
status, err := node.SyncSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.GetErrorCode())
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
assert.True(t, fg.channel.hasSegment(req.CompactedTo, true))
|
|
|
|
assert.False(t, fg.channel.hasSegment(req.CompactedFrom[0], true))
|
|
|
|
assert.False(t, fg.channel.hasSegment(req.CompactedFrom[1], true))
|
2022-09-23 10:22:52 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid request numRows=0", func(t *testing.T) {
|
2022-10-18 15:33:26 +08:00
|
|
|
s1.setType(datapb.SegmentType_Flushed)
|
|
|
|
s2.setType(datapb.SegmentType_Flushed)
|
|
|
|
s3.setType(datapb.SegmentType_Flushed)
|
|
|
|
|
|
|
|
fg.channel.(*ChannelMeta).segments = map[UniqueID]*Segment{
|
|
|
|
s1.segmentID: &s1,
|
|
|
|
s2.segmentID: &s2,
|
|
|
|
s3.segmentID: &s3,
|
2022-09-23 10:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
req := &datapb.SyncSegmentsRequest{
|
2022-10-18 15:33:26 +08:00
|
|
|
CompactedFrom: []int64{s1.segmentID, s2.segmentID},
|
|
|
|
CompactedTo: 101,
|
2022-09-23 10:22:52 +08:00
|
|
|
NumOfRows: 0,
|
|
|
|
}
|
|
|
|
status, err := node.SyncSegments(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.GetErrorCode())
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
assert.False(t, fg.channel.hasSegment(req.CompactedTo, true))
|
|
|
|
assert.False(t, fg.channel.hasSegment(req.CompactedFrom[0], true))
|
|
|
|
assert.False(t, fg.channel.hasSegment(req.CompactedFrom[1], true))
|
2022-09-23 10:22:52 +08:00
|
|
|
})
|
|
|
|
})
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
2021-08-13 10:50:09 +08:00
|
|
|
|
2022-06-02 18:54:04 +08:00
|
|
|
func TestDataNode_AddSegment(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
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())
|
2022-06-02 18:54:04 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer node.Stop()
|
|
|
|
|
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)
|
2022-06-02 18:54:04 +08:00
|
|
|
|
|
|
|
t.Run("test AddSegment", func(t *testing.T) {
|
|
|
|
node.rootCoord = &RootCoordFactory{
|
|
|
|
collectionID: 100,
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
|
|
|
|
|
|
|
chName1 := "fake-by-dev-rootcoord-dml-testaddsegment-1"
|
|
|
|
chName2 := "fake-by-dev-rootcoord-dml-testaddsegment-2"
|
|
|
|
err := node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 100,
|
|
|
|
ChannelName: chName1,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-06-02 18:54:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
err = node.flowgraphManager.addAndStart(node, &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 100,
|
|
|
|
ChannelName: chName2,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-10-10 01:37:21 +08:00
|
|
|
}, nil)
|
2022-06-02 18:54:04 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
_, ok := node.flowgraphManager.getFlowgraphService(chName1)
|
|
|
|
assert.True(t, ok)
|
|
|
|
_, ok = node.flowgraphManager.getFlowgraphService(chName2)
|
|
|
|
assert.True(t, ok)
|
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
stat, err := node.AddImportSegment(context.WithValue(ctx, ctxKey{}, ""), &datapb.AddImportSegmentRequest{
|
2022-06-02 18:54:04 +08:00
|
|
|
SegmentId: 100,
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
|
|
|
ChannelName: chName1,
|
|
|
|
RowNum: 500,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-09-26 18:06:54 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, stat.GetStatus().GetErrorCode())
|
|
|
|
assert.Equal(t, "", stat.GetStatus().GetReason())
|
|
|
|
assert.NotEqual(t, nil, stat.GetChannelPos())
|
2022-06-02 18:54:04 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
getFlowGraphServiceAttempts = 3
|
|
|
|
stat, err = node.AddImportSegment(context.WithValue(ctx, ctxKey{}, ""), &datapb.AddImportSegmentRequest{
|
2022-06-02 18:54:04 +08:00
|
|
|
SegmentId: 100,
|
|
|
|
CollectionId: 100,
|
|
|
|
PartitionId: 100,
|
|
|
|
ChannelName: "bad-ch-name",
|
|
|
|
RowNum: 500,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-09-26 18:06:54 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, stat.GetStatus().GetErrorCode())
|
2022-06-02 18:54:04 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-13 10:50:09 +08:00
|
|
|
func TestWatchChannel(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
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())
|
2021-12-29 14:35:21 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
2021-10-09 15:45:15 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node.Start()
|
|
|
|
assert.Nil(t, err)
|
2022-04-13 20:09:34 +08:00
|
|
|
defer node.Stop()
|
2021-10-09 15:45:15 +08:00
|
|
|
err = node.Register()
|
|
|
|
assert.Nil(t, err)
|
2021-08-13 10:50:09 +08:00
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
t.Run("test watch channel", func(t *testing.T) {
|
2022-01-13 14:21:34 +08:00
|
|
|
// GOOSE TODO
|
2022-11-17 18:59:09 +08:00
|
|
|
kv := etcdkv.NewEtcdKV(etcdCli, Params.EtcdCfg.MetaRootPath.GetValue())
|
2021-11-05 11:59:02 +08:00
|
|
|
oldInvalidCh := "datanode-etcd-test-by-dev-rootcoord-dml-channel-invalid"
|
2022-11-04 14:25:38 +08:00
|
|
|
path := fmt.Sprintf("%s/%d/%s", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID(), oldInvalidCh)
|
2021-10-13 17:02:33 +08:00
|
|
|
err = kv.Save(path, string([]byte{23}))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-05 11:59:02 +08:00
|
|
|
ch := fmt.Sprintf("datanode-etcd-test-by-dev-rootcoord-dml-channel_%d", rand.Int31())
|
2022-11-04 14:25:38 +08:00
|
|
|
path = fmt.Sprintf("%s/%d/%s", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID(), ch)
|
2021-08-13 14:00:14 +08:00
|
|
|
c := make(chan struct{})
|
|
|
|
go func() {
|
2022-11-04 14:25:38 +08:00
|
|
|
ec := kv.WatchWithPrefix(fmt.Sprintf("%s/%d", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID()))
|
2021-08-20 17:48:13 +08:00
|
|
|
c <- struct{}{}
|
2021-08-13 14:00:14 +08:00
|
|
|
cnt := 0
|
|
|
|
for {
|
|
|
|
evt := <-ec
|
|
|
|
for _, event := range evt.Events {
|
|
|
|
if strings.Contains(string(event.Kv.Key), ch) {
|
|
|
|
cnt++
|
2021-08-13 10:50:09 +08:00
|
|
|
}
|
|
|
|
}
|
2021-08-13 14:00:14 +08:00
|
|
|
if cnt >= 2 {
|
|
|
|
break
|
|
|
|
}
|
2021-08-13 10:50:09 +08:00
|
|
|
}
|
2021-08-13 14:00:14 +08:00
|
|
|
c <- struct{}{}
|
|
|
|
}()
|
2021-08-20 17:48:13 +08:00
|
|
|
// wait for check goroutine start Watch
|
|
|
|
<-c
|
2021-08-13 14:00:14 +08:00
|
|
|
|
|
|
|
vchan := &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: ch,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
2021-08-13 14:00:14 +08:00
|
|
|
}
|
|
|
|
info := &datapb.ChannelWatchInfo{
|
2022-03-09 15:39:58 +08:00
|
|
|
State: datapb.ChannelWatchState_ToWatch,
|
|
|
|
Vchan: vchan,
|
|
|
|
TimeoutTs: time.Now().Add(time.Minute).UnixNano(),
|
2021-08-13 10:50:09 +08:00
|
|
|
}
|
2021-08-13 14:00:14 +08:00
|
|
|
val, err := proto.Marshal(info)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save(path, string(val))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-08-20 17:48:13 +08:00
|
|
|
// wait for check goroutine received 2 events
|
2021-08-13 14:00:14 +08:00
|
|
|
<-c
|
2022-01-13 14:21:34 +08:00
|
|
|
exist := node.flowgraphManager.exist(ch)
|
|
|
|
assert.True(t, exist)
|
2021-08-13 14:00:14 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
err = kv.RemoveWithPrefix(fmt.Sprintf("%s/%d", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID()))
|
2021-10-09 15:45:15 +08:00
|
|
|
assert.Nil(t, err)
|
2021-08-13 14:00:14 +08:00
|
|
|
//TODO there is not way to sync Release done, use sleep for now
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
2022-01-13 14:21:34 +08:00
|
|
|
exist = node.flowgraphManager.exist(ch)
|
|
|
|
assert.False(t, exist)
|
2021-08-13 10:50:09 +08:00
|
|
|
})
|
2021-09-23 18:31:55 +08:00
|
|
|
|
2022-03-09 15:39:58 +08:00
|
|
|
t.Run("Test release channel", func(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
kv := etcdkv.NewEtcdKV(etcdCli, Params.EtcdCfg.MetaRootPath.GetValue())
|
2022-03-09 15:39:58 +08:00
|
|
|
oldInvalidCh := "datanode-etcd-test-by-dev-rootcoord-dml-channel-invalid"
|
2022-11-04 14:25:38 +08:00
|
|
|
path := fmt.Sprintf("%s/%d/%s", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID(), oldInvalidCh)
|
2022-03-09 15:39:58 +08:00
|
|
|
err = kv.Save(path, string([]byte{23}))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
ch := fmt.Sprintf("datanode-etcd-test-by-dev-rootcoord-dml-channel_%d", rand.Int31())
|
2022-11-04 14:25:38 +08:00
|
|
|
path = fmt.Sprintf("%s/%d/%s", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID(), ch)
|
2022-03-09 15:39:58 +08:00
|
|
|
c := make(chan struct{})
|
|
|
|
go func() {
|
2022-11-04 14:25:38 +08:00
|
|
|
ec := kv.WatchWithPrefix(fmt.Sprintf("%s/%d", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID()))
|
2022-03-09 15:39:58 +08:00
|
|
|
c <- struct{}{}
|
|
|
|
cnt := 0
|
|
|
|
for {
|
|
|
|
evt := <-ec
|
|
|
|
for _, event := range evt.Events {
|
|
|
|
if strings.Contains(string(event.Kv.Key), ch) {
|
|
|
|
cnt++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cnt >= 2 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c <- struct{}{}
|
|
|
|
}()
|
|
|
|
// wait for check goroutine start Watch
|
|
|
|
<-c
|
|
|
|
|
|
|
|
vchan := &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: ch,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
2022-03-09 15:39:58 +08:00
|
|
|
}
|
|
|
|
info := &datapb.ChannelWatchInfo{
|
|
|
|
State: datapb.ChannelWatchState_ToRelease,
|
|
|
|
Vchan: vchan,
|
|
|
|
TimeoutTs: time.Now().Add(time.Minute).UnixNano(),
|
|
|
|
}
|
|
|
|
val, err := proto.Marshal(info)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save(path, string(val))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
// wait for check goroutine received 2 events
|
|
|
|
<-c
|
|
|
|
exist := node.flowgraphManager.exist(ch)
|
|
|
|
assert.False(t, exist)
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
err = kv.RemoveWithPrefix(fmt.Sprintf("%s/%d", Params.DataNodeCfg.ChannelWatchSubPath, paramtable.GetNodeID()))
|
2022-03-09 15:39:58 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
//TODO there is not way to sync Release done, use sleep for now
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
exist = node.flowgraphManager.exist(ch)
|
|
|
|
assert.False(t, exist)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2021-10-13 17:02:33 +08:00
|
|
|
t.Run("handle watch info failed", func(t *testing.T) {
|
2022-01-13 14:21:34 +08:00
|
|
|
e := &event{
|
|
|
|
eventType: putEventType,
|
|
|
|
}
|
2021-10-13 17:02:33 +08:00
|
|
|
|
2022-01-13 14:21:34 +08:00
|
|
|
node.handleWatchInfo(e, "test1", []byte{23})
|
|
|
|
|
|
|
|
exist := node.flowgraphManager.exist("test1")
|
|
|
|
assert.False(t, exist)
|
2021-10-13 17:02:33 +08:00
|
|
|
|
|
|
|
info := datapb.ChannelWatchInfo{
|
|
|
|
Vchan: nil,
|
|
|
|
State: datapb.ChannelWatchState_Uncomplete,
|
|
|
|
}
|
|
|
|
bs, err := proto.Marshal(&info)
|
|
|
|
assert.NoError(t, err)
|
2022-01-13 14:21:34 +08:00
|
|
|
node.handleWatchInfo(e, "test2", bs)
|
2021-10-13 17:02:33 +08:00
|
|
|
|
2022-01-13 14:21:34 +08:00
|
|
|
exist = node.flowgraphManager.exist("test2")
|
|
|
|
assert.False(t, exist)
|
2021-10-13 17:02:33 +08:00
|
|
|
|
2022-03-09 15:39:58 +08:00
|
|
|
chPut := make(chan struct{}, 1)
|
|
|
|
chDel := make(chan struct{}, 1)
|
|
|
|
|
|
|
|
ch := fmt.Sprintf("datanode-etcd-test-by-dev-rootcoord-dml-channel_%d", rand.Int31())
|
|
|
|
m := newChannelEventManager(
|
|
|
|
func(info *datapb.ChannelWatchInfo, version int64) error {
|
|
|
|
r := node.handlePutEvent(info, version)
|
|
|
|
chPut <- struct{}{}
|
|
|
|
return r
|
|
|
|
},
|
2022-07-06 13:54:21 +08:00
|
|
|
func(vChan string) {
|
2022-03-09 15:39:58 +08:00
|
|
|
node.handleDeleteEvent(vChan)
|
|
|
|
chDel <- struct{}{}
|
|
|
|
}, time.Millisecond*100,
|
|
|
|
)
|
|
|
|
node.eventManagerMap.Store(ch, m)
|
|
|
|
m.Run()
|
|
|
|
|
2021-10-13 17:02:33 +08:00
|
|
|
info = datapb.ChannelWatchInfo{
|
2022-03-09 15:39:58 +08:00
|
|
|
Vchan: &datapb.VchannelInfo{ChannelName: ch},
|
|
|
|
State: datapb.ChannelWatchState_Uncomplete,
|
|
|
|
TimeoutTs: time.Now().Add(time.Minute).UnixNano(),
|
2021-10-13 17:02:33 +08:00
|
|
|
}
|
|
|
|
bs, err = proto.Marshal(&info)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory := node.factory
|
|
|
|
defer func() { node.factory = msFactory }()
|
2022-03-09 15:39:58 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
node.factory = &FailMessageStreamFactory{}
|
2022-03-09 15:39:58 +08:00
|
|
|
node.handleWatchInfo(e, ch, bs)
|
|
|
|
<-chPut
|
|
|
|
exist = node.flowgraphManager.exist(ch)
|
2022-01-13 14:21:34 +08:00
|
|
|
assert.False(t, exist)
|
2021-10-13 17:02:33 +08:00
|
|
|
})
|
2022-03-09 15:39:58 +08:00
|
|
|
|
|
|
|
t.Run("handle watchinfo out of date", func(t *testing.T) {
|
|
|
|
chPut := make(chan struct{}, 1)
|
|
|
|
chDel := make(chan struct{}, 1)
|
|
|
|
// inject eventManager
|
|
|
|
ch := fmt.Sprintf("datanode-etcd-test-by-dev-rootcoord-dml-channel_%d", rand.Int31())
|
|
|
|
m := newChannelEventManager(
|
|
|
|
func(info *datapb.ChannelWatchInfo, version int64) error {
|
|
|
|
r := node.handlePutEvent(info, version)
|
|
|
|
chPut <- struct{}{}
|
|
|
|
return r
|
|
|
|
},
|
2022-07-06 13:54:21 +08:00
|
|
|
func(vChan string) {
|
2022-03-09 15:39:58 +08:00
|
|
|
node.handleDeleteEvent(vChan)
|
|
|
|
chDel <- struct{}{}
|
|
|
|
}, time.Millisecond*100,
|
|
|
|
)
|
|
|
|
node.eventManagerMap.Store(ch, m)
|
|
|
|
m.Run()
|
|
|
|
e := &event{
|
|
|
|
eventType: putEventType,
|
|
|
|
version: 10000,
|
|
|
|
}
|
|
|
|
|
|
|
|
info := datapb.ChannelWatchInfo{
|
|
|
|
Vchan: &datapb.VchannelInfo{ChannelName: ch},
|
|
|
|
State: datapb.ChannelWatchState_Uncomplete,
|
|
|
|
TimeoutTs: time.Now().Add(time.Minute).UnixNano(),
|
|
|
|
}
|
|
|
|
bs, err := proto.Marshal(&info)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
node.handleWatchInfo(e, ch, bs)
|
|
|
|
<-chPut
|
|
|
|
exist := node.flowgraphManager.exist("test3")
|
|
|
|
assert.False(t, exist)
|
|
|
|
})
|
2022-07-07 21:58:22 +08:00
|
|
|
|
|
|
|
t.Run("handle watchinfo compatibility", func(t *testing.T) {
|
|
|
|
info := datapb.ChannelWatchInfo{
|
|
|
|
Vchan: &datapb.VchannelInfo{
|
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: "delta-channel1",
|
|
|
|
UnflushedSegments: []*datapb.SegmentInfo{{ID: 1}},
|
|
|
|
FlushedSegments: []*datapb.SegmentInfo{{ID: 2}},
|
|
|
|
DroppedSegments: []*datapb.SegmentInfo{{ID: 3}},
|
|
|
|
UnflushedSegmentIds: []int64{1},
|
|
|
|
},
|
|
|
|
State: datapb.ChannelWatchState_Uncomplete,
|
|
|
|
TimeoutTs: time.Now().Add(time.Minute).UnixNano(),
|
|
|
|
}
|
|
|
|
bs, err := proto.Marshal(&info)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
newWatchInfo, err := parsePutEventData(bs)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, []*datapb.SegmentInfo{}, newWatchInfo.GetVchan().GetUnflushedSegments())
|
|
|
|
assert.Equal(t, []*datapb.SegmentInfo{}, newWatchInfo.GetVchan().GetFlushedSegments())
|
|
|
|
assert.Equal(t, []*datapb.SegmentInfo{}, newWatchInfo.GetVchan().GetDroppedSegments())
|
|
|
|
assert.NotEmpty(t, newWatchInfo.GetVchan().GetUnflushedSegmentIds())
|
|
|
|
assert.NotEmpty(t, newWatchInfo.GetVchan().GetFlushedSegmentIds())
|
|
|
|
assert.NotEmpty(t, newWatchInfo.GetVchan().GetDroppedSegmentIds())
|
|
|
|
})
|
2021-08-13 10:50:09 +08:00
|
|
|
}
|
2021-11-19 13:57:12 +08:00
|
|
|
|
|
|
|
func TestDataNode_GetComponentStates(t *testing.T) {
|
|
|
|
n := &DataNode{}
|
2022-10-10 15:55:22 +08:00
|
|
|
n.stateCode.Store(commonpb.StateCode_Healthy)
|
2021-11-19 13:57:12 +08:00
|
|
|
resp, err := n.GetComponentStates(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
assert.Equal(t, common.NotRegisteredID, resp.State.NodeID)
|
|
|
|
n.session = &sessionutil.Session{}
|
|
|
|
n.session.UpdateRegistered(true)
|
|
|
|
resp, err = n.GetComponentStates(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
2022-05-25 14:34:00 +08:00
|
|
|
|
|
|
|
func TestDataNode_ResendSegmentStats(t *testing.T) {
|
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-05-25 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
dmChannelName := "fake-by-dev-rootcoord-dml-channel-test-ResendSegmentStats"
|
|
|
|
|
|
|
|
node := newIDLEDataNodeMock(context.TODO(), schemapb.DataType_Int64)
|
|
|
|
node.SetEtcdClient(etcdCli)
|
|
|
|
err = node.Init()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = node.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer func() {
|
|
|
|
err := node.Stop()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
vChan := &datapb.VchannelInfo{
|
2022-06-16 12:00:10 +08:00
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: dmChannelName,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
2022-05-25 14:34:00 +08:00
|
|
|
}
|
|
|
|
|
2022-10-10 01:37:21 +08:00
|
|
|
err = node.flowgraphManager.addAndStart(node, vChan, nil)
|
2022-05-25 14:34:00 +08:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
fgService, ok := node.flowgraphManager.getFlowgraphService(dmChannelName)
|
|
|
|
assert.True(t, ok)
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
err = fgService.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_New,
|
|
|
|
segID: 0,
|
|
|
|
collID: 1,
|
|
|
|
partitionID: 1,
|
|
|
|
startPos: &internalpb.MsgPosition{},
|
|
|
|
endPos: &internalpb.MsgPosition{},
|
|
|
|
})
|
2022-05-25 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
2022-10-18 15:33:26 +08:00
|
|
|
err = fgService.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_New,
|
|
|
|
segID: 1,
|
|
|
|
collID: 1,
|
|
|
|
partitionID: 2,
|
|
|
|
startPos: &internalpb.MsgPosition{},
|
|
|
|
endPos: &internalpb.MsgPosition{},
|
|
|
|
})
|
2022-05-25 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
2022-10-18 15:33:26 +08:00
|
|
|
err = fgService.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_New,
|
|
|
|
segID: 2,
|
|
|
|
collID: 1,
|
|
|
|
partitionID: 3,
|
|
|
|
startPos: &internalpb.MsgPosition{},
|
|
|
|
endPos: &internalpb.MsgPosition{},
|
|
|
|
})
|
2022-05-25 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
req := &datapb.ResendSegmentStatsRequest{
|
|
|
|
Base: &commonpb.MsgBase{},
|
|
|
|
}
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(2)
|
|
|
|
|
|
|
|
resp, err := node.ResendSegmentStats(node.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
assert.ElementsMatch(t, []UniqueID{0, 1, 2}, resp.GetSegResent())
|
|
|
|
|
|
|
|
// Duplicate call.
|
|
|
|
resp, err = node.ResendSegmentStats(node.ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
assert.ElementsMatch(t, []UniqueID{0, 1, 2}, resp.GetSegResent())
|
|
|
|
}
|