2022-12-12 10:57:22 +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
|
|
|
|
// 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 datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/rand"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-23 19:43:57 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2023-03-04 23:21:50 +08:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
|
"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/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-03-23 19:43:57 +08:00
|
|
|
allocator2 "github.com/milvus-io/milvus/internal/allocator"
|
|
|
|
"github.com/milvus-io/milvus/internal/datanode/allocator"
|
2023-10-13 09:55:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/broker"
|
2024-05-23 09:53:40 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/compaction"
|
2023-11-15 15:24:18 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/metacache"
|
2022-12-12 10:57:22 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/etcd"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2022-12-12 10:57:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type DataNodeServicesSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2023-10-13 09:55:34 +08:00
|
|
|
broker *broker.MockBroker
|
2022-12-12 10:57:22 +08:00
|
|
|
node *DataNode
|
|
|
|
etcdCli *clientv3.Client
|
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataNodeServicesSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(DataNodeServicesSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) SetupSuite() {
|
|
|
|
s.ctx, s.cancel = context.WithCancel(context.Background())
|
|
|
|
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())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.etcdCli = etcdCli
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) SetupTest() {
|
|
|
|
s.node = newIDLEDataNodeMock(s.ctx, schemapb.DataType_Int64)
|
|
|
|
s.node.SetEtcdClient(s.etcdCli)
|
|
|
|
|
|
|
|
err := s.node.Init()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
alloc := allocator.NewMockAllocator(s.T())
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc.EXPECT().Start().Return(nil).Maybe()
|
|
|
|
alloc.EXPECT().Close().Maybe()
|
|
|
|
alloc.EXPECT().GetIDAlloactor().Return(&allocator2.IDAllocator{}).Maybe()
|
|
|
|
alloc.EXPECT().Alloc(mock.Anything).Call.Return(int64(22222),
|
|
|
|
func(count uint32) int64 {
|
|
|
|
return int64(22222 + count)
|
|
|
|
}, nil).Maybe()
|
|
|
|
s.node.allocator = alloc
|
|
|
|
|
2023-10-13 09:55:34 +08:00
|
|
|
broker := broker.NewMockBroker(s.T())
|
|
|
|
broker.EXPECT().GetSegmentInfo(mock.Anything, mock.Anything).
|
|
|
|
Return([]*datapb.SegmentInfo{}, nil).Maybe()
|
|
|
|
broker.EXPECT().ReportTimeTick(mock.Anything, mock.Anything).Return(nil).Maybe()
|
|
|
|
broker.EXPECT().SaveBinlogPaths(mock.Anything, mock.Anything).Return(nil).Maybe()
|
2024-03-07 20:39:02 +08:00
|
|
|
broker.EXPECT().UpdateChannelCheckpoint(mock.Anything, mock.Anything).Return(nil).Maybe()
|
2023-10-13 09:55:34 +08:00
|
|
|
|
|
|
|
s.broker = broker
|
|
|
|
s.node.broker = broker
|
|
|
|
|
2022-12-12 10:57:22 +08:00
|
|
|
err = s.node.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.node.chunkManager = storage.NewLocalChunkManager(storage.RootPath("/tmp/milvus_test/datanode"))
|
|
|
|
paramtable.SetNodeID(1)
|
|
|
|
}
|
|
|
|
|
2022-12-28 20:11:30 +08:00
|
|
|
func (s *DataNodeServicesSuite) TearDownTest() {
|
2023-10-13 09:55:34 +08:00
|
|
|
if s.broker != nil {
|
|
|
|
s.broker.AssertExpectations(s.T())
|
|
|
|
s.broker = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.node != nil {
|
|
|
|
s.node.Stop()
|
|
|
|
s.node = nil
|
|
|
|
}
|
2022-12-28 20:11:30 +08:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:57:22 +08:00
|
|
|
func (s *DataNodeServicesSuite) TearDownSuite() {
|
|
|
|
s.cancel()
|
|
|
|
err := s.etcdCli.Close()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestNotInUseAPIs() {
|
|
|
|
s.Run("WatchDmChannels", func() {
|
|
|
|
status, err := s.node.WatchDmChannels(s.ctx, &datapb.WatchDmChannelsRequest{})
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().True(merr.Ok(status))
|
2022-12-12 10:57:22 +08:00
|
|
|
})
|
|
|
|
s.Run("GetTimeTickChannel", func() {
|
2023-09-26 09:57:25 +08:00
|
|
|
_, err := s.node.GetTimeTickChannel(s.ctx, nil)
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("GetStatisticsChannel", func() {
|
2023-09-26 09:57:25 +08:00
|
|
|
_, err := s.node.GetStatisticsChannel(s.ctx, nil)
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestGetComponentStates() {
|
2023-09-26 09:57:25 +08:00
|
|
|
resp, err := s.node.GetComponentStates(s.ctx, nil)
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().True(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().Equal(common.NotRegisteredID, resp.State.NodeID)
|
|
|
|
|
2023-01-12 19:49:40 +08:00
|
|
|
s.node.SetSession(&sessionutil.Session{})
|
2022-12-12 10:57:22 +08:00
|
|
|
s.node.session.UpdateRegistered(true)
|
2023-09-26 09:57:25 +08:00
|
|
|
resp, err = s.node.GetComponentStates(context.Background(), nil)
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().True(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestGetCompactionState() {
|
|
|
|
s.Run("success", func() {
|
2024-05-23 09:53:40 +08:00
|
|
|
mockC := compaction.NewMockCompactor(s.T())
|
|
|
|
s.node.compactionExecutor.executing.Insert(int64(3), mockC)
|
|
|
|
|
|
|
|
mockC2 := compaction.NewMockCompactor(s.T())
|
|
|
|
s.node.compactionExecutor.executing.Insert(int64(2), mockC2)
|
|
|
|
|
2023-11-14 15:56:19 +08:00
|
|
|
s.node.compactionExecutor.completed.Insert(int64(1), &datapb.CompactionPlanResult{
|
|
|
|
PlanID: 1,
|
|
|
|
State: commonpb.CompactionState_Completed,
|
|
|
|
Segments: []*datapb.CompactionSegment{
|
|
|
|
{SegmentID: 10},
|
|
|
|
},
|
2022-12-12 10:57:22 +08:00
|
|
|
})
|
2024-05-23 09:53:40 +08:00
|
|
|
|
|
|
|
s.node.compactionExecutor.completed.Insert(int64(4), &datapb.CompactionPlanResult{
|
|
|
|
PlanID: 4,
|
|
|
|
Type: datapb.CompactionType_Level0DeleteCompaction,
|
|
|
|
State: commonpb.CompactionState_Completed,
|
|
|
|
})
|
|
|
|
|
2022-12-12 10:57:22 +08:00
|
|
|
stat, err := s.node.GetCompactionState(s.ctx, nil)
|
|
|
|
s.Assert().NoError(err)
|
2024-05-23 09:53:40 +08:00
|
|
|
s.Assert().Equal(4, len(stat.GetResults()))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
var mu sync.RWMutex
|
|
|
|
cnt := 0
|
|
|
|
for _, v := range stat.GetResults() {
|
|
|
|
if v.GetState() == commonpb.CompactionState_Completed {
|
|
|
|
mu.Lock()
|
|
|
|
cnt++
|
|
|
|
mu.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mu.Lock()
|
2024-05-23 09:53:40 +08:00
|
|
|
s.Assert().Equal(2, cnt)
|
2022-12-12 10:57:22 +08:00
|
|
|
mu.Unlock()
|
|
|
|
|
2023-07-24 10:23:01 +08:00
|
|
|
s.Assert().Equal(1, s.node.compactionExecutor.completed.Len())
|
2022-12-12 10:57:22 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("unhealthy", func() {
|
|
|
|
node := &DataNode{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
resp, _ := node.GetCompactionState(s.ctx, nil)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().Equal(merr.Code(merr.ErrServiceNotReady), resp.GetStatus().GetCode())
|
2022-12-12 10:57:22 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-04 19:06:40 +08:00
|
|
|
func (s *DataNodeServicesSuite) TestCompaction() {
|
|
|
|
dmChannelName := "by-dev-rootcoord-dml_0_100v0"
|
|
|
|
|
|
|
|
s.Run("service_not_ready", func() {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node := &DataNode{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
req := &datapb.CompactionPlan{
|
|
|
|
PlanID: 1000,
|
|
|
|
Channel: dmChannelName,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.Compaction(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp))
|
|
|
|
})
|
|
|
|
|
2024-05-24 09:07:41 +08:00
|
|
|
s.Run("unknown CompactionType", func() {
|
2023-12-04 19:06:40 +08:00
|
|
|
node := s.node
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
req := &datapb.CompactionPlan{
|
|
|
|
PlanID: 1000,
|
|
|
|
Channel: dmChannelName,
|
|
|
|
SegmentBinlogs: []*datapb.CompactionSegmentBinlogs{
|
|
|
|
{SegmentID: 102, Level: datapb.SegmentLevel_L0},
|
2024-05-24 09:07:41 +08:00
|
|
|
{SegmentID: 103, Level: datapb.SegmentLevel_L1},
|
2023-12-04 19:06:40 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.Compaction(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-12 10:57:22 +08:00
|
|
|
func (s *DataNodeServicesSuite) TestFlushSegments() {
|
|
|
|
dmChannelName := "fake-by-dev-rootcoord-dml-channel-test-FlushSegments"
|
2023-11-15 15:24:18 +08:00
|
|
|
schema := &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: common.StartOfUserFieldID, DataType: schemapb.DataType_Int64, IsPrimaryKey: true, Name: "pk"},
|
|
|
|
{FieldID: common.StartOfUserFieldID + 1, DataType: schemapb.DataType_FloatVector, TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{Key: common.DimKey, Value: "128"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
segmentID := int64(100)
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
vchan := &datapb.VchannelInfo{
|
|
|
|
CollectionID: 1,
|
|
|
|
ChannelName: dmChannelName,
|
|
|
|
UnflushedSegmentIds: []int64{},
|
|
|
|
FlushedSegmentIds: []int64{},
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
err := s.node.flowgraphManager.AddandStartWithEtcdTickler(s.node, vchan, schema, genTestTickler())
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2023-11-30 18:42:32 +08:00
|
|
|
fgservice, ok := s.node.flowgraphManager.GetFlowgraphService(dmChannelName)
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Require().True(ok)
|
|
|
|
|
2023-11-17 21:46:20 +08:00
|
|
|
metaCache := metacache.NewMockMetaCache(s.T())
|
|
|
|
metaCache.EXPECT().Collection().Return(1).Maybe()
|
|
|
|
metaCache.EXPECT().Schema().Return(schema).Maybe()
|
2023-11-23 17:26:24 +08:00
|
|
|
s.node.writeBufferManager.Register(dmChannelName, metaCache, nil)
|
2023-11-17 21:46:20 +08:00
|
|
|
|
|
|
|
fgservice.metacache.AddSegment(&datapb.SegmentInfo{
|
|
|
|
ID: segmentID,
|
|
|
|
CollectionID: 1,
|
|
|
|
PartitionID: 2,
|
2024-05-28 14:19:42 +08:00
|
|
|
State: commonpb.SegmentState_Growing,
|
2023-11-17 21:46:20 +08:00
|
|
|
StartPosition: &msgpb.MsgPosition{},
|
|
|
|
}, func(_ *datapb.SegmentInfo) *metacache.BloomFilterSet { return metacache.NewBloomFilterSet() })
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
s.Run("service_not_ready", func() {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node := &DataNode{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
req := &datapb.FlushSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: s.node.GetSession().ServerID,
|
|
|
|
},
|
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{0},
|
|
|
|
}
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
resp, err := node.FlushSegments(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp))
|
|
|
|
})
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
s.Run("node_id_not_match", func() {
|
|
|
|
node := s.node
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
req := &datapb.FlushSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: s.node.GetSession().ServerID + 1,
|
2022-12-12 10:57:22 +08:00
|
|
|
},
|
2023-11-15 15:24:18 +08:00
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{0},
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
resp, err := node.FlushSegments(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp))
|
|
|
|
})
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
s.Run("channel_not_found", func() {
|
|
|
|
node := s.node
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
req := &datapb.FlushSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: s.node.GetSession().ServerID,
|
|
|
|
},
|
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{segmentID},
|
|
|
|
}
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
resp, err := node.FlushSegments(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp))
|
|
|
|
})
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
s.Run("normal_flush", func() {
|
|
|
|
node := s.node
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
req := &datapb.FlushSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
TargetID: s.node.GetSession().ServerID,
|
|
|
|
},
|
|
|
|
DbID: 0,
|
|
|
|
CollectionID: 1,
|
|
|
|
SegmentIDs: []int64{segmentID},
|
|
|
|
ChannelName: dmChannelName,
|
|
|
|
}
|
2022-12-12 10:57:22 +08:00
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
resp, err := node.FlushSegments(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.True(merr.Ok(resp))
|
|
|
|
})
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestShowConfigurations() {
|
|
|
|
pattern := "datanode.Port"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
MsgID: rand.Int63(),
|
|
|
|
},
|
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
// test closed server
|
2022-12-12 10:57:22 +08:00
|
|
|
node := &DataNode{}
|
2023-10-01 10:33:30 +08:00
|
|
|
node.SetSession(&sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}})
|
2022-12-12 10:57:22 +08:00
|
|
|
node.stateCode.Store(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.ShowConfigurations(s.ctx, req)
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().False(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
node.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
resp, err = node.ShowConfigurations(s.ctx, req)
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().True(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
s.Assert().Equal(1, len(resp.Configuations))
|
|
|
|
s.Assert().Equal("datanode.port", resp.Configuations[0].Key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestGetMetrics() {
|
|
|
|
node := &DataNode{}
|
2023-10-01 10:33:30 +08:00
|
|
|
node.SetSession(&sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}})
|
2022-12-12 10:57:22 +08:00
|
|
|
node.flowgraphManager = newFlowgraphManager()
|
|
|
|
// server is closed
|
|
|
|
node.stateCode.Store(commonpb.StateCode_Abnormal)
|
|
|
|
resp, err := node.GetMetrics(s.ctx, &milvuspb.GetMetricsRequest{})
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().False(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
node.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
// failed to parse metric type
|
|
|
|
invalidRequest := "invalid request"
|
|
|
|
resp, err = node.GetMetrics(s.ctx, &milvuspb.GetMetricsRequest{
|
|
|
|
Request: invalidRequest,
|
|
|
|
})
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().False(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
// unsupported metric type
|
|
|
|
unsupportedMetricType := "unsupported"
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(unsupportedMetricType)
|
|
|
|
s.Assert().NoError(err)
|
|
|
|
resp, err = node.GetMetrics(s.ctx, req)
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().False(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
|
|
|
|
// normal case
|
|
|
|
req, err = metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
|
|
|
s.Assert().NoError(err)
|
|
|
|
resp, err = node.GetMetrics(node.ctx, req)
|
|
|
|
s.Assert().NoError(err)
|
2023-03-28 19:04:00 +08:00
|
|
|
s.Assert().True(merr.Ok(resp.GetStatus()))
|
2022-12-12 10:57:22 +08:00
|
|
|
log.Info("Test DataNode.GetMetrics",
|
|
|
|
zap.String("name", resp.ComponentName),
|
|
|
|
zap.String("response", resp.Response))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestResendSegmentStats() {
|
|
|
|
req := &datapb.ResendSegmentStatsRequest{
|
|
|
|
Base: &commonpb.MsgBase{},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.node.ResendSegmentStats(s.ctx, req)
|
2023-11-15 15:24:18 +08:00
|
|
|
s.Assert().NoError(err, "empty call, no error")
|
|
|
|
s.Assert().True(merr.Ok(resp.GetStatus()), "empty call, status shall be OK")
|
2022-12-12 10:57:22 +08:00
|
|
|
}
|
2023-09-12 21:07:19 +08:00
|
|
|
|
2023-09-25 14:05:27 +08:00
|
|
|
func (s *DataNodeServicesSuite) TestRPCWatch() {
|
2023-12-27 16:00:48 +08:00
|
|
|
s.Run("node not healthy", func() {
|
|
|
|
s.SetupTest()
|
|
|
|
s.node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
status, err := s.node.NotifyChannelOperation(ctx, nil)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(status))
|
|
|
|
s.ErrorIs(merr.Error(status), merr.ErrServiceNotReady)
|
|
|
|
|
|
|
|
resp, err := s.node.CheckChannelOperationProgress(ctx, nil)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp.GetStatus()))
|
|
|
|
s.ErrorIs(merr.Error(status), merr.ErrServiceNotReady)
|
|
|
|
})
|
|
|
|
|
2024-05-07 15:49:30 +08:00
|
|
|
s.Run("submit error", func() {
|
2023-12-27 16:00:48 +08:00
|
|
|
s.SetupTest()
|
|
|
|
ctx := context.Background()
|
|
|
|
status, err := s.node.NotifyChannelOperation(ctx, &datapb.ChannelOperationsRequest{Infos: []*datapb.ChannelWatchInfo{{OpID: 19530}}})
|
|
|
|
s.NoError(err)
|
2024-05-07 15:49:30 +08:00
|
|
|
s.False(merr.Ok(status))
|
|
|
|
s.NotErrorIs(merr.Error(status), merr.ErrServiceNotReady)
|
2023-12-27 16:00:48 +08:00
|
|
|
|
|
|
|
resp, err := s.node.CheckChannelOperationProgress(ctx, nil)
|
|
|
|
s.NoError(err)
|
2024-05-07 15:49:30 +08:00
|
|
|
s.False(merr.Ok(resp.GetStatus()))
|
2023-12-27 16:00:48 +08:00
|
|
|
})
|
2023-09-25 14:05:27 +08:00
|
|
|
}
|
2024-05-17 18:19:38 +08:00
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestQuerySlot() {
|
|
|
|
s.Run("node not healthy", func() {
|
|
|
|
s.SetupTest()
|
|
|
|
s.node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := s.node.QuerySlot(ctx, nil)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(resp.GetStatus()))
|
|
|
|
s.ErrorIs(merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("normal case", func() {
|
|
|
|
s.SetupTest()
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := s.node.QuerySlot(ctx, nil)
|
|
|
|
s.NoError(err)
|
|
|
|
s.True(merr.Ok(resp.GetStatus()))
|
|
|
|
s.NoError(merr.Error(resp.GetStatus()))
|
|
|
|
})
|
|
|
|
}
|
2024-05-30 13:37:44 +08:00
|
|
|
|
|
|
|
func (s *DataNodeServicesSuite) TestSyncSegments() {
|
|
|
|
s.Run("node not healthy", func() {
|
|
|
|
s.SetupTest()
|
|
|
|
s.node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
status, err := s.node.SyncSegments(ctx, nil)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(status))
|
|
|
|
s.ErrorIs(merr.Error(status), merr.ErrServiceNotReady)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("normal case", func() {
|
|
|
|
s.SetupTest()
|
|
|
|
ctx := context.Background()
|
|
|
|
req := &datapb.SyncSegmentsRequest{
|
|
|
|
ChannelName: "channel1",
|
|
|
|
PartitionId: 2,
|
|
|
|
CollectionId: 1,
|
|
|
|
SegmentInfos: map[int64]*datapb.SyncSegmentInfo{
|
|
|
|
3: {
|
|
|
|
SegmentId: 3,
|
|
|
|
PkStatsLog: nil,
|
|
|
|
State: commonpb.SegmentState_Dropped,
|
|
|
|
Level: 2,
|
|
|
|
NumOfRows: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := s.node.SyncSegments(ctx, req)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(merr.Ok(status))
|
|
|
|
})
|
|
|
|
}
|