2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
import (
|
2021-09-07 15:45:59 +08:00
|
|
|
"context"
|
2020-11-12 12:04:12 +08:00
|
|
|
"encoding/binary"
|
2020-11-12 17:58:05 +08:00
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2020-11-12 12:04:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: start pulsar before test
|
2020-11-19 17:09:22 +08:00
|
|
|
func TestDataSyncService_Start(t *testing.T) {
|
2021-03-22 16:36:10 +08:00
|
|
|
collectionID := UniqueID(0)
|
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2020-11-12 12:04:12 +08:00
|
|
|
// test data generate
|
|
|
|
const msgLength = 10
|
|
|
|
const DIM = 16
|
|
|
|
const N = 10
|
|
|
|
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
// messages generate
|
2020-11-17 14:10:07 +08:00
|
|
|
insertMessages := make([]msgstream.TsMsg, 0)
|
2020-11-12 12:04:12 +08:00
|
|
|
for i := 0; i < msgLength; i++ {
|
|
|
|
var msg msgstream.TsMsg = &msgstream.InsertMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
2020-11-30 19:38:23 +08:00
|
|
|
HashValues: []uint32{
|
|
|
|
uint32(i), uint32(i),
|
2020-11-12 12:04:12 +08:00
|
|
|
},
|
|
|
|
},
|
2021-03-12 14:22:09 +08:00
|
|
|
InsertRequest: internalpb.InsertRequest{
|
2021-01-18 19:32:08 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_Insert,
|
2021-01-18 19:32:08 +08:00
|
|
|
MsgID: 0,
|
2021-09-14 10:25:26 +08:00
|
|
|
Timestamp: Timestamp(i + 1000),
|
2021-01-18 19:32:08 +08:00
|
|
|
SourceID: 0,
|
|
|
|
},
|
2021-03-22 16:36:10 +08:00
|
|
|
CollectionID: collectionID,
|
2021-02-03 18:12:48 +08:00
|
|
|
PartitionID: defaultPartitionID,
|
2021-09-14 10:25:26 +08:00
|
|
|
SegmentID: UniqueID(0),
|
2021-09-27 10:01:59 +08:00
|
|
|
ShardName: "0",
|
2021-09-14 10:25:26 +08:00
|
|
|
Timestamps: []Timestamp{Timestamp(i + 1000), Timestamp(i + 1000)},
|
2021-02-03 18:12:48 +08:00
|
|
|
RowIDs: []int64{int64(i), int64(i)},
|
2020-11-12 12:04:12 +08:00
|
|
|
RowData: []*commonpb.Blob{
|
|
|
|
{Value: rawData},
|
|
|
|
{Value: rawData},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-11-17 14:10:07 +08:00
|
|
|
insertMessages = append(insertMessages, msg)
|
2020-11-12 12:04:12 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
// generate timeTick
|
|
|
|
timeTickMsgPack := msgstream.MsgPack{}
|
|
|
|
baseMsg := msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: 0,
|
|
|
|
EndTimestamp: 0,
|
2020-11-30 19:38:23 +08:00
|
|
|
HashValues: []uint32{0},
|
2020-11-19 17:09:22 +08:00
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
timeTickResult := internalpb.TimeTickMsg{
|
2021-01-18 19:32:08 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-01-18 19:32:08 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: math.MaxUint64,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
2020-11-19 17:09:22 +08:00
|
|
|
}
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
TimeTickMsg: timeTickResult,
|
|
|
|
}
|
|
|
|
timeTickMsgPack.Msgs = append(timeTickMsgPack.Msgs, timeTickMsg)
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
// pulsar produce
|
|
|
|
const receiveBufSize = 1024
|
2020-12-10 16:31:09 +08:00
|
|
|
pulsarURL := Params.PulsarAddress
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2021-04-02 13:48:25 +08:00
|
|
|
msFactory := msgstream.NewPmsFactory()
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": receiveBufSize,
|
|
|
|
"pulsarAddress": pulsarURL,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err := msFactory.SetParams(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-15 20:06:10 +08:00
|
|
|
channels := []Channel{"0"}
|
2021-09-17 11:35:49 +08:00
|
|
|
node.streaming.dataSyncService.addCollectionFlowGraph(collectionID, channels)
|
2021-06-15 12:41:40 +08:00
|
|
|
err = node.streaming.dataSyncService.startCollectionFlowGraph(collectionID, channels)
|
2021-06-09 11:37:55 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
<-node.queryNodeLoopCtx.Done()
|
2021-09-07 15:45:59 +08:00
|
|
|
node.streaming.dataSyncService.close()
|
|
|
|
|
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataSyncService_collectionFlowGraphs(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
streaming, err := genSimpleStreaming(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fac, err := genFactory()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService := newDataSyncService(ctx, streaming.replica, streaming.tSafeReplica, fac)
|
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2021-09-17 11:35:49 +08:00
|
|
|
dataSyncService.addCollectionFlowGraph(defaultCollectionID, []Channel{defaultVChannel})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
fg, err := dataSyncService.getCollectionFlowGraphs(defaultCollectionID, []Channel{defaultVChannel})
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(fg))
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getCollectionFlowGraphs(UniqueID(1000), []Channel{defaultVChannel})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getCollectionFlowGraphs(defaultCollectionID, []Channel{"invalid-vChannel"})
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 0, len(fg))
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getCollectionFlowGraphs(UniqueID(1000), []Channel{"invalid-vChannel"})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startCollectionFlowGraph(defaultCollectionID, []Channel{defaultVChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService.removeCollectionFlowGraph(defaultCollectionID)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getCollectionFlowGraphs(defaultCollectionID, []Channel{defaultVChannel})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataSyncService_partitionFlowGraphs(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
streaming, err := genSimpleStreaming(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fac, err := genFactory()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService := newDataSyncService(ctx, streaming.replica, streaming.tSafeReplica, fac)
|
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
2021-09-17 11:35:49 +08:00
|
|
|
dataSyncService.addPartitionFlowGraph(defaultPartitionID, defaultPartitionID, []Channel{defaultVChannel})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
fg, err := dataSyncService.getPartitionFlowGraphs(defaultPartitionID, []Channel{defaultVChannel})
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(fg))
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getPartitionFlowGraphs(UniqueID(1000), []Channel{defaultVChannel})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getPartitionFlowGraphs(defaultPartitionID, []Channel{"invalid-vChannel"})
|
|
|
|
assert.NotNil(t, fg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 0, len(fg))
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getPartitionFlowGraphs(UniqueID(1000), []Channel{"invalid-vChannel"})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
err = dataSyncService.startPartitionFlowGraph(defaultPartitionID, []Channel{defaultVChannel})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService.removePartitionFlowGraph(defaultPartitionID)
|
|
|
|
|
|
|
|
fg, err = dataSyncService.getPartitionFlowGraphs(defaultPartitionID, []Channel{defaultVChannel})
|
|
|
|
assert.Nil(t, fg)
|
|
|
|
assert.Error(t, err)
|
2020-11-12 12:04:12 +08:00
|
|
|
}
|
2021-09-24 13:57:54 +08:00
|
|
|
|
|
|
|
func TestDataSyncService_removePartitionFlowGraphs(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
t.Run("test no tSafe", func(t *testing.T) {
|
|
|
|
streaming, err := genSimpleStreaming(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fac, err := genFactory()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dataSyncService := newDataSyncService(ctx, streaming.replica, streaming.tSafeReplica, fac)
|
|
|
|
assert.NotNil(t, dataSyncService)
|
|
|
|
|
|
|
|
dataSyncService.addPartitionFlowGraph(defaultPartitionID, defaultPartitionID, []Channel{defaultVChannel})
|
|
|
|
|
|
|
|
err = dataSyncService.tSafeReplica.removeTSafe(defaultVChannel)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
dataSyncService.removePartitionFlowGraph(defaultPartitionID)
|
|
|
|
})
|
|
|
|
}
|