2021-10-15 18:07:09 +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:07:09 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 15:16:33 +08:00
|
|
|
//
|
2021-10-15 18:07:09 +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 (
|
|
|
|
"context"
|
2021-08-30 10:03:58 +08:00
|
|
|
"errors"
|
2021-05-20 18:38:45 +08:00
|
|
|
"sync"
|
2021-01-19 11:37:16 +08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-05-24 21:11:59 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
|
|
|
|
2021-05-20 18:38:45 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-01-19 11:37:16 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
|
|
|
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2021-09-23 16:03:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
|
|
|
|
2021-05-20 18:38:45 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-09-09 15:00:00 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-05-20 18:38:45 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
var insertNodeTestDir = "/tmp/milvus_test/insert_node"
|
|
|
|
|
2021-08-30 10:03:58 +08:00
|
|
|
// CDFMsFactory count down fails msg factory
|
|
|
|
type CDFMsFactory struct {
|
|
|
|
msgstream.Factory
|
|
|
|
cd int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *CDFMsFactory) NewMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
f.cd--
|
|
|
|
if f.cd < 0 {
|
|
|
|
return nil, errors.New("fail")
|
|
|
|
}
|
|
|
|
return f.Factory.NewMsgStream(ctx)
|
|
|
|
}
|
|
|
|
|
2021-09-09 15:00:00 +08:00
|
|
|
func TestFlowGraphInsertBufferNodeCreate(t *testing.T) {
|
2021-08-30 10:03:58 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(insertNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix("")
|
2021-08-30 10:03:58 +08:00
|
|
|
insertChannelName := "datanode-01-test-flowgraphinsertbuffernode-create"
|
|
|
|
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
err := clearEtcd(testPath)
|
|
|
|
require.NoError(t, err)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-08-30 10:03:58 +08:00
|
|
|
|
|
|
|
Factory := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
collMeta := Factory.GetCollectionMeta(UniqueID(0), "coll1", schemapb.DataType_Int64)
|
|
|
|
mockRootCoord := &RootCoordFactory{
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
2021-08-30 10:03:58 +08:00
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
replica, err := newReplica(ctx, mockRootCoord, cm, collMeta.ID)
|
2021-10-14 10:24:33 +08:00
|
|
|
assert.Nil(t, err)
|
2021-08-30 10:03:58 +08:00
|
|
|
|
|
|
|
err = replica.addNewSegment(1, collMeta.ID, 0, insertChannelName, &internalpb.MsgPosition{}, &internalpb.MsgPosition{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
2021-08-30 10:03:58 +08:00
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
fm := NewRendezvousFlushManager(&allocator{}, cm, replica, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2021-08-30 10:03:58 +08:00
|
|
|
|
2021-10-18 12:34:34 +08:00
|
|
|
flushChan := make(chan flushMsg, 100)
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTChan := make(chan resendTTMsg, 100)
|
2021-10-13 11:16:32 +08:00
|
|
|
|
|
|
|
c := &nodeConfig{
|
|
|
|
replica: replica,
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory: factory,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: "string",
|
|
|
|
}
|
|
|
|
|
2022-05-25 14:34:00 +08:00
|
|
|
iBNode, err := newInsertBufferNode(ctx, collMeta.ID, flushChan, resendTTChan, fm, newCache(), c)
|
2021-08-30 10:03:58 +08:00
|
|
|
assert.NotNil(t, iBNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
/*ctxDone, cancel := context.WithCancel(ctx)
|
2021-08-30 10:03:58 +08:00
|
|
|
cancel() // cancel now to make context done
|
2021-10-19 11:04:34 +08:00
|
|
|
_, err = newInsertBufferNode(ctxDone, flushChan, fm, newCache(), c)
|
|
|
|
assert.Error(t, err)*/
|
2021-08-30 10:03:58 +08:00
|
|
|
|
2021-10-13 11:16:32 +08:00
|
|
|
c.msFactory = &CDFMsFactory{
|
2022-04-07 22:05:32 +08:00
|
|
|
Factory: factory,
|
2021-08-30 10:03:58 +08:00
|
|
|
cd: 0,
|
|
|
|
}
|
|
|
|
|
2022-05-25 14:34:00 +08:00
|
|
|
_, err = newInsertBufferNode(ctx, collMeta.ID, flushChan, resendTTChan, fm, newCache(), c)
|
2021-08-30 10:03:58 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
2021-09-17 16:27:56 +08:00
|
|
|
type mockMsg struct{}
|
|
|
|
|
|
|
|
func (*mockMsg) TimeTick() Timestamp {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:55:25 +08:00
|
|
|
func TestFlowGraphInsertBufferNode_Operate(t *testing.T) {
|
2021-09-17 16:27:56 +08:00
|
|
|
t.Run("Test iBNode Operate invalid Msg", func(te *testing.T) {
|
|
|
|
invalidInTests := []struct {
|
|
|
|
in []Msg
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{[]Msg{},
|
|
|
|
"Invalid input length == 0"},
|
2021-09-26 10:43:57 +08:00
|
|
|
{[]Msg{&flowGraphMsg{}, &flowGraphMsg{}, &flowGraphMsg{}},
|
2021-09-17 16:27:56 +08:00
|
|
|
"Invalid input length == 3"},
|
|
|
|
{[]Msg{&mockMsg{}},
|
2021-09-26 10:43:57 +08:00
|
|
|
"Invalid input length == 1 but input message is not flowGraphMsg"},
|
2021-09-17 16:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range invalidInTests {
|
|
|
|
te.Run(test.description, func(t0 *testing.T) {
|
2021-11-05 14:59:32 +08:00
|
|
|
ibn := &insertBufferNode{
|
2021-12-15 10:53:16 +08:00
|
|
|
ttMerger: newMergedTimeTickerSender(func(Timestamp, []int64) error { return nil }),
|
2021-11-05 14:59:32 +08:00
|
|
|
}
|
2021-09-17 16:27:56 +08:00
|
|
|
rt := ibn.Operate(test.in)
|
|
|
|
assert.Empty(t0, rt)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-04 16:31:34 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-06-08 19:25:37 +08:00
|
|
|
insertChannelName := "datanode-01-test-flowgraphinsertbuffernode-operate"
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(insertNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix("")
|
2021-01-19 11:37:16 +08:00
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
err := clearEtcd(testPath)
|
|
|
|
require.NoError(t, err)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-01-24 21:20:11 +08:00
|
|
|
Factory := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
collMeta := Factory.GetCollectionMeta(UniqueID(0), "coll1", schemapb.DataType_Int64)
|
|
|
|
mockRootCoord := &RootCoordFactory{
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
replica, err := newReplica(ctx, mockRootCoord, cm, collMeta.ID)
|
2021-10-14 10:24:33 +08:00
|
|
|
assert.Nil(t, err)
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
err = replica.addNewSegment(1, collMeta.ID, 0, insertChannelName, &internalpb.MsgPosition{}, &internalpb.MsgPosition{})
|
2021-03-30 09:47:27 +08:00
|
|
|
require.NoError(t, err)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
2021-02-08 14:30:54 +08:00
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, replica, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2021-06-04 16:31:34 +08:00
|
|
|
|
2021-10-18 12:34:34 +08:00
|
|
|
flushChan := make(chan flushMsg, 100)
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTChan := make(chan resendTTMsg, 100)
|
2021-10-13 11:16:32 +08:00
|
|
|
c := &nodeConfig{
|
|
|
|
replica: replica,
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory: factory,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: "string",
|
|
|
|
}
|
|
|
|
|
2022-05-25 14:34:00 +08:00
|
|
|
iBNode, err := newInsertBufferNode(ctx, collMeta.ID, flushChan, resendTTChan, fm, newCache(), c)
|
2021-08-30 10:03:58 +08:00
|
|
|
require.NoError(t, err)
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2021-11-04 15:40:14 +08:00
|
|
|
// trigger log ts
|
|
|
|
iBNode.ttLogger.counter.Store(999)
|
|
|
|
|
2021-10-18 12:34:34 +08:00
|
|
|
flushChan <- flushMsg{
|
2021-06-02 15:58:33 +08:00
|
|
|
msgID: 1,
|
|
|
|
timestamp: 2000,
|
|
|
|
segmentID: UniqueID(1),
|
|
|
|
collectionID: UniqueID(1),
|
|
|
|
}
|
|
|
|
|
2021-11-04 15:36:19 +08:00
|
|
|
inMsg := genFlowGraphInsertMsg(insertChannelName)
|
2021-12-02 16:39:33 +08:00
|
|
|
assert.NotPanics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTChan <- resendTTMsg{
|
|
|
|
segmentIDs: []int64{0, 1, 2},
|
|
|
|
}
|
|
|
|
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
assert.NotPanics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
|
2021-12-02 16:39:33 +08:00
|
|
|
// test drop collection operate
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
inMsg.dropCollection = true
|
|
|
|
assert.NotPanics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
2022-05-24 21:11:59 +08:00
|
|
|
|
|
|
|
// test consume old message
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
timestampBak := iBNode.lastTimestamp
|
|
|
|
iBNode.lastTimestamp = typeutil.MaxTimestamp
|
|
|
|
assert.Panics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
iBNode.lastTimestamp = timestampBak
|
|
|
|
|
|
|
|
// test updateSegStatesInReplica failed
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
inMsg.insertMessages[0].CollectionID = UniqueID(-1)
|
|
|
|
inMsg.insertMessages[0].SegmentID = UniqueID(-1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Panics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
|
|
|
|
// test bufferInsertMsg failed
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
inMsg.insertMessages[0].Timestamps = []Timestamp{1, 2}
|
|
|
|
inMsg.insertMessages[0].RowIDs = []int64{1}
|
|
|
|
assert.Panics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
|
|
|
|
// test flushBufferData failed
|
|
|
|
flowGraphRetryOpt = retry.Attempts(1)
|
|
|
|
inMsg = genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
iBNode.flushManager = &mockFlushManager{returnError: true}
|
|
|
|
iBNode.insertBuffer.Store(inMsg.insertMessages[0].SegmentID, &BufferData{})
|
|
|
|
assert.Panics(t, func() { iBNode.Operate([]flowgraph.Msg{&inMsg}) })
|
|
|
|
iBNode.flushManager = fm
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
/*
|
2021-05-28 14:54:31 +08:00
|
|
|
func TestFlushSegment(t *testing.T) {
|
2021-06-06 00:59:36 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
2021-05-20 18:38:45 +08:00
|
|
|
idAllocMock := NewAllocatorFactory(1)
|
|
|
|
mockMinIO := memkv.NewMemoryKV()
|
2021-06-08 19:25:37 +08:00
|
|
|
insertChannelName := "datanode-02-test-flushsegment"
|
2021-05-20 18:38:45 +08:00
|
|
|
|
|
|
|
segmentID, _ := idAllocMock.allocID()
|
|
|
|
partitionID, _ := idAllocMock.allocID()
|
|
|
|
collectionID, _ := idAllocMock.allocID()
|
|
|
|
fmt.Printf("generate segmentID, partitionID, collectionID: %v, %v, %v\n",
|
|
|
|
segmentID, partitionID, collectionID)
|
|
|
|
|
|
|
|
collMeta := genCollectionMeta(collectionID, "test_flush_segment_txn")
|
|
|
|
flushMap := sync.Map{}
|
2021-06-21 17:28:03 +08:00
|
|
|
mockRootCoord := &RootCoordFactory{}
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-10-14 10:24:33 +08:00
|
|
|
replica, err := newReplica(ctx, mockRootCoord, collMeta.ID)
|
|
|
|
assert.Nil(t, err)
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-10-14 10:24:33 +08:00
|
|
|
err = replica.addNewSegment(segmentID, collMeta.ID, 0, insertChannelName, &internalpb.MsgPosition{}, &internalpb.MsgPosition{})
|
2021-06-06 13:21:37 +08:00
|
|
|
require.NoError(t, err)
|
2021-06-21 16:00:22 +08:00
|
|
|
replica.updateSegmentEndPosition(segmentID, &internalpb.MsgPosition{ChannelName: "TestChannel"})
|
2021-05-20 18:38:45 +08:00
|
|
|
|
2021-06-06 13:21:37 +08:00
|
|
|
finishCh := make(chan segmentFlushUnit, 1)
|
2021-05-20 18:38:45 +08:00
|
|
|
|
|
|
|
insertData := &InsertData{
|
|
|
|
Data: make(map[storage.FieldID]storage.FieldData),
|
|
|
|
}
|
|
|
|
insertData.Data[0] = &storage.Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{10},
|
2021-05-20 18:38:45 +08:00
|
|
|
Data: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
|
|
|
|
}
|
|
|
|
insertData.Data[1] = &storage.Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{10},
|
2021-05-20 18:38:45 +08:00
|
|
|
Data: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
|
|
|
}
|
|
|
|
insertData.Data[107] = &storage.FloatFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{10},
|
2021-05-20 18:38:45 +08:00
|
|
|
Data: make([]float32, 10),
|
|
|
|
}
|
|
|
|
flushMap.Store(segmentID, insertData)
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := msgstream.NewPmsFactory()
|
2021-06-06 00:59:36 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": 1024,
|
|
|
|
"pulsarAddress": Params.PulsarAddress,
|
|
|
|
"pulsarBufSize": 1024}
|
2022-04-07 22:05:32 +08:00
|
|
|
err = factory.SetParams(m)
|
2021-06-06 00:59:36 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-18 12:34:34 +08:00
|
|
|
flushChan := make(chan flushMsg, 100)
|
2021-10-19 11:04:34 +08:00
|
|
|
|
|
|
|
memkv := memkv.NewMemoryKV()
|
|
|
|
|
|
|
|
fm := NewRendezvousFlushManager(&allocator{}, memkv, replica, func(*segmentFlushPack) error {
|
2021-06-06 00:59:36 +08:00
|
|
|
return nil
|
2021-10-19 11:04:34 +08:00
|
|
|
})
|
2021-10-13 11:16:32 +08:00
|
|
|
|
|
|
|
c := &nodeConfig{
|
|
|
|
replica: replica,
|
2022-04-07 22:05:32 +08:00
|
|
|
factory: factory,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: "string",
|
|
|
|
}
|
2021-10-19 11:04:34 +08:00
|
|
|
ibNode, err := newInsertBufferNode(ctx, flushChan, fm, newCache(), c)
|
2021-08-30 10:03:58 +08:00
|
|
|
require.NoError(t, err)
|
2021-06-06 00:59:36 +08:00
|
|
|
|
2021-05-20 18:38:45 +08:00
|
|
|
flushSegment(collMeta,
|
|
|
|
segmentID,
|
|
|
|
partitionID,
|
|
|
|
collectionID,
|
|
|
|
&flushMap,
|
|
|
|
mockMinIO,
|
|
|
|
finishCh,
|
2021-06-04 16:31:34 +08:00
|
|
|
nil,
|
2021-06-06 00:59:36 +08:00
|
|
|
ibNode,
|
2021-05-20 18:38:45 +08:00
|
|
|
idAllocMock)
|
|
|
|
|
2021-06-04 16:31:34 +08:00
|
|
|
fu := <-finishCh
|
|
|
|
assert.NotNil(t, fu.field2Path)
|
|
|
|
assert.Equal(t, fu.segID, segmentID)
|
|
|
|
|
2021-12-09 11:09:06 +08:00
|
|
|
k := JoinIDPath(collectionID, partitionID, segmentID, 0)
|
2021-05-20 18:38:45 +08:00
|
|
|
key := path.Join(Params.StatsBinlogRootPath, k)
|
|
|
|
_, values, _ := mockMinIO.LoadWithPrefix(key)
|
|
|
|
assert.Equal(t, len(values), 1)
|
2021-10-19 11:04:34 +08:00
|
|
|
}*/
|
2021-05-20 18:38:45 +08:00
|
|
|
|
|
|
|
func genCollectionMeta(collectionID UniqueID, collectionName string) *etcdpb.CollectionMeta {
|
|
|
|
sch := schemapb.CollectionSchema{
|
|
|
|
Name: collectionName,
|
|
|
|
Description: "test collection by meta factory",
|
|
|
|
AutoID: true,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: 0,
|
|
|
|
Name: "RowID",
|
|
|
|
Description: "RowID field",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "f0_tk1",
|
|
|
|
Value: "f0_tv1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Name: "Timestamp",
|
|
|
|
Description: "Timestamp field",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "f1_tk1",
|
|
|
|
Value: "f1_tv1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 107,
|
|
|
|
Name: "float32_field",
|
|
|
|
Description: "field 107",
|
|
|
|
DataType: schemapb.DataType_Float,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{},
|
|
|
|
IndexParams: []*commonpb.KeyValuePair{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
collection := etcdpb.CollectionMeta{
|
|
|
|
ID: collectionID,
|
|
|
|
Schema: &sch,
|
|
|
|
CreateTime: Timestamp(1),
|
|
|
|
SegmentIDs: make([]UniqueID, 0),
|
|
|
|
PartitionIDs: []UniqueID{0},
|
|
|
|
}
|
|
|
|
return &collection
|
|
|
|
}
|
2021-06-05 18:18:34 +08:00
|
|
|
|
|
|
|
func TestFlowGraphInsertBufferNode_AutoFlush(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
err := clearEtcd(testPath)
|
|
|
|
require.NoError(t, err)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-06-05 18:18:34 +08:00
|
|
|
|
|
|
|
Factory := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
collMeta := Factory.GetCollectionMeta(UniqueID(0), "coll1", schemapb.DataType_Int64)
|
2021-06-05 18:18:34 +08:00
|
|
|
dataFactory := NewDataFactory()
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
mockRootCoord := &RootCoordFactory{
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
colRep := &SegmentReplica{
|
|
|
|
collectionID: collMeta.ID,
|
|
|
|
newSegments: make(map[UniqueID]*Segment),
|
|
|
|
normalSegments: make(map[UniqueID]*Segment),
|
|
|
|
flushedSegments: make(map[UniqueID]*Segment),
|
2021-06-05 18:18:34 +08:00
|
|
|
}
|
2021-06-08 19:25:37 +08:00
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
colRep.metaService = newMetaService(mockRootCoord, collMeta.ID)
|
2021-06-05 18:18:34 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
2021-06-05 18:18:34 +08:00
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
flushPacks := []*segmentFlushPack{}
|
2021-10-25 18:03:42 +08:00
|
|
|
fpMut := sync.Mutex{}
|
2021-10-19 11:04:34 +08:00
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(insertNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix("")
|
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, colRep, func(pack *segmentFlushPack) {
|
2021-10-25 18:03:42 +08:00
|
|
|
fpMut.Lock()
|
2021-10-19 11:04:34 +08:00
|
|
|
flushPacks = append(flushPacks, pack)
|
2021-10-25 18:03:42 +08:00
|
|
|
fpMut.Unlock()
|
2021-10-19 11:04:34 +08:00
|
|
|
colRep.listNewSegmentsStartPositions()
|
|
|
|
colRep.listSegmentsCheckPoints()
|
2021-11-12 17:31:11 +08:00
|
|
|
if pack.flushed || pack.dropped {
|
|
|
|
colRep.segmentFlushed(pack.segmentID)
|
|
|
|
}
|
2021-10-19 11:04:34 +08:00
|
|
|
wg.Done()
|
2021-12-01 10:11:39 +08:00
|
|
|
}, emptyFlushAndDropFunc)
|
2021-06-05 18:18:34 +08:00
|
|
|
|
2021-10-18 12:34:34 +08:00
|
|
|
flushChan := make(chan flushMsg, 100)
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTChan := make(chan resendTTMsg, 100)
|
2021-10-13 11:16:32 +08:00
|
|
|
c := &nodeConfig{
|
|
|
|
replica: colRep,
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory: factory,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: "string",
|
|
|
|
}
|
2022-05-25 14:34:00 +08:00
|
|
|
iBNode, err := newInsertBufferNode(ctx, collMeta.ID, flushChan, resendTTChan, fm, newCache(), c)
|
2021-08-30 10:03:58 +08:00
|
|
|
require.NoError(t, err)
|
2021-06-05 18:18:34 +08:00
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
// Auto flush number of rows set to 2
|
2021-06-05 18:18:34 +08:00
|
|
|
|
2021-11-04 15:36:19 +08:00
|
|
|
inMsg := genFlowGraphInsertMsg("datanode-03-test-autoflush")
|
2021-06-21 16:00:22 +08:00
|
|
|
inMsg.insertMessages = dataFactory.GetMsgStreamInsertMsgs(2)
|
2021-06-05 18:18:34 +08:00
|
|
|
var iMsg flowgraph.Msg = &inMsg
|
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
t.Run("Pure auto flush", func(t *testing.T) {
|
2021-09-26 20:55:59 +08:00
|
|
|
// iBNode.insertBuffer.maxSize = 2
|
2021-12-23 18:39:11 +08:00
|
|
|
tmp := Params.DataNodeCfg.FlushInsertBufferSize
|
|
|
|
Params.DataNodeCfg.FlushInsertBufferSize = 4 * 4
|
2021-09-26 20:55:59 +08:00
|
|
|
defer func() {
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.DataNodeCfg.FlushInsertBufferSize = tmp
|
2021-09-26 20:55:59 +08:00
|
|
|
}()
|
2021-06-21 16:00:22 +08:00
|
|
|
|
|
|
|
for i := range inMsg.insertMessages {
|
|
|
|
inMsg.insertMessages[i].SegmentID = int64(i%2) + 1
|
|
|
|
}
|
|
|
|
inMsg.startPositions = []*internalpb.MsgPosition{{Timestamp: 100}}
|
|
|
|
inMsg.endPositions = []*internalpb.MsgPosition{{Timestamp: 123}}
|
|
|
|
|
|
|
|
type Test struct {
|
|
|
|
expectedSegID UniqueID
|
|
|
|
expectedNumOfRows int64
|
|
|
|
expectedStartPosTs Timestamp
|
|
|
|
expectedEndPosTs Timestamp
|
|
|
|
expectedCpNumOfRows int64
|
|
|
|
expectedCpPosTs Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeAutoFlushTests := []Test{
|
|
|
|
// segID, numOfRow, startTs, endTs, cp.numOfRow, cp.Ts
|
|
|
|
{1, 1, 100, 123, 0, 100},
|
|
|
|
{2, 1, 100, 123, 0, 100},
|
|
|
|
}
|
|
|
|
iBNode.Operate([]flowgraph.Msg{iMsg})
|
2021-10-19 11:04:34 +08:00
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
require.Equal(t, 2, len(colRep.newSegments))
|
|
|
|
require.Equal(t, 0, len(colRep.normalSegments))
|
2021-10-19 11:04:34 +08:00
|
|
|
assert.Equal(t, 0, len(flushPacks))
|
2021-06-21 16:00:22 +08:00
|
|
|
|
|
|
|
for i, test := range beforeAutoFlushTests {
|
2021-10-25 18:03:42 +08:00
|
|
|
colRep.segMu.Lock()
|
2021-06-21 16:00:22 +08:00
|
|
|
seg, ok := colRep.newSegments[UniqueID(i+1)]
|
2021-10-25 18:03:42 +08:00
|
|
|
colRep.segMu.Unlock()
|
2021-06-21 16:00:22 +08:00
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, test.expectedSegID, seg.segmentID)
|
|
|
|
assert.Equal(t, test.expectedNumOfRows, seg.numRows)
|
|
|
|
assert.Equal(t, test.expectedStartPosTs, seg.startPos.GetTimestamp())
|
|
|
|
assert.Equal(t, test.expectedCpNumOfRows, seg.checkPoint.numRows)
|
|
|
|
assert.Equal(t, test.expectedCpPosTs, seg.checkPoint.pos.GetTimestamp())
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range inMsg.insertMessages {
|
|
|
|
inMsg.insertMessages[i].SegmentID = int64(i%2) + 2
|
|
|
|
}
|
|
|
|
inMsg.startPositions = []*internalpb.MsgPosition{{Timestamp: 200}}
|
|
|
|
inMsg.endPositions = []*internalpb.MsgPosition{{Timestamp: 234}}
|
|
|
|
iMsg = &inMsg
|
|
|
|
|
|
|
|
// Triger auto flush
|
2021-10-19 11:04:34 +08:00
|
|
|
output := iBNode.Operate([]flowgraph.Msg{iMsg})
|
|
|
|
fgm := output[0].(*flowGraphMsg)
|
|
|
|
wg.Add(len(fgm.segmentsToFlush))
|
|
|
|
t.Log("segments to flush", fgm.segmentsToFlush)
|
|
|
|
|
|
|
|
for _, im := range fgm.segmentsToFlush {
|
|
|
|
// send del done signal
|
2022-05-24 21:11:59 +08:00
|
|
|
err = fm.flushDelData(nil, im, fgm.endPositions[0])
|
|
|
|
assert.NoError(t, err)
|
2021-10-19 11:04:34 +08:00
|
|
|
}
|
|
|
|
wg.Wait()
|
2021-06-21 16:00:22 +08:00
|
|
|
require.Equal(t, 0, len(colRep.newSegments))
|
|
|
|
require.Equal(t, 3, len(colRep.normalSegments))
|
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
assert.Equal(t, 1, len(flushPacks))
|
|
|
|
// assert.Equal(t, 3, len(flushUnit[0].checkPoint))
|
|
|
|
assert.Less(t, 0, len(flushPacks[0].insertLogs))
|
|
|
|
assert.False(t, flushPacks[0].flushed)
|
2021-06-21 16:00:22 +08:00
|
|
|
|
|
|
|
afterAutoFlushTests := []Test{
|
|
|
|
// segID, numOfRow, startTs, endTs, cp.numOfRow, cp.Ts
|
|
|
|
{1, 1, 100, 123, 0, 100},
|
|
|
|
{2, 2, 100, 234, 2, 234},
|
|
|
|
{3, 1, 200, 234, 0, 200},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range afterAutoFlushTests {
|
|
|
|
seg, ok := colRep.normalSegments[UniqueID(i+1)]
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, test.expectedSegID, seg.segmentID)
|
|
|
|
assert.Equal(t, test.expectedNumOfRows, seg.numRows)
|
|
|
|
assert.Equal(t, test.expectedStartPosTs, seg.startPos.GetTimestamp())
|
|
|
|
assert.Equal(t, test.expectedCpNumOfRows, seg.checkPoint.numRows)
|
|
|
|
assert.Equal(t, test.expectedCpPosTs, seg.checkPoint.pos.GetTimestamp())
|
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
// assert.Equal(t, test.expectedCpNumOfRows, flushPacks[0].checkPoint[UniqueID(i+1)].numRows)
|
|
|
|
// assert.Equal(t, test.expectedCpPosTs, flushPacks[0].checkPoint[UniqueID(i+1)].pos.Timestamp)
|
2021-06-21 16:00:22 +08:00
|
|
|
|
|
|
|
if i == 1 {
|
2021-10-19 11:04:34 +08:00
|
|
|
assert.Equal(t, test.expectedSegID, flushPacks[0].segmentID)
|
2021-09-26 20:55:59 +08:00
|
|
|
// assert.Equal(t, int64(0), iBNode.insertBuffer.size(UniqueID(i+1)))
|
2021-06-21 16:00:22 +08:00
|
|
|
}
|
2021-09-26 20:55:59 +08:00
|
|
|
// else {
|
|
|
|
// // assert.Equal(t, int64(1), iBNode.insertBuffer.size(UniqueID(i+1)))
|
|
|
|
// }
|
2021-06-21 16:00:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2021-10-08 17:45:35 +08:00
|
|
|
t.Run("Auto with manual flush", func(t *testing.T) {
|
2021-12-23 18:39:11 +08:00
|
|
|
tmp := Params.DataNodeCfg.FlushInsertBufferSize
|
|
|
|
Params.DataNodeCfg.FlushInsertBufferSize = 4 * 4
|
2021-10-25 18:03:42 +08:00
|
|
|
defer func() {
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.DataNodeCfg.FlushInsertBufferSize = tmp
|
2021-10-25 18:03:42 +08:00
|
|
|
}()
|
2021-09-23 16:03:54 +08:00
|
|
|
|
2021-10-25 18:03:42 +08:00
|
|
|
fpMut.Lock()
|
|
|
|
flushPacks = flushPacks[:0]
|
|
|
|
fpMut.Unlock()
|
|
|
|
|
2021-11-04 15:36:19 +08:00
|
|
|
inMsg := genFlowGraphInsertMsg("datanode-03-test-autoflush")
|
2021-10-25 18:03:42 +08:00
|
|
|
inMsg.insertMessages = dataFactory.GetMsgStreamInsertMsgs(2)
|
|
|
|
|
|
|
|
for i := range inMsg.insertMessages {
|
|
|
|
inMsg.insertMessages[i].SegmentID = UniqueID(10 + i)
|
|
|
|
}
|
|
|
|
inMsg.startPositions = []*internalpb.MsgPosition{{Timestamp: 300}}
|
|
|
|
inMsg.endPositions = []*internalpb.MsgPosition{{Timestamp: 323}}
|
|
|
|
var iMsg flowgraph.Msg = &inMsg
|
|
|
|
|
|
|
|
type Test struct {
|
|
|
|
expectedSegID UniqueID
|
|
|
|
expectedNumOfRows int64
|
|
|
|
expectedStartPosTs Timestamp
|
|
|
|
expectedEndPosTs Timestamp
|
|
|
|
expectedCpNumOfRows int64
|
|
|
|
expectedCpPosTs Timestamp
|
|
|
|
}
|
2021-06-21 16:00:22 +08:00
|
|
|
|
2021-10-25 18:03:42 +08:00
|
|
|
beforeAutoFlushTests := []Test{
|
|
|
|
// segID, numOfRow, startTs, endTs, cp.numOfRow, cp.Ts
|
|
|
|
{10, 1, 300, 323, 0, 300},
|
|
|
|
{11, 1, 300, 323, 0, 300},
|
|
|
|
}
|
|
|
|
iBNode.Operate([]flowgraph.Msg{iMsg})
|
|
|
|
|
|
|
|
require.Equal(t, 2, len(colRep.newSegments))
|
|
|
|
require.Equal(t, 3, len(colRep.normalSegments))
|
|
|
|
assert.Equal(t, 0, len(flushPacks))
|
|
|
|
|
|
|
|
for _, test := range beforeAutoFlushTests {
|
|
|
|
colRep.segMu.Lock()
|
|
|
|
seg, ok := colRep.newSegments[test.expectedSegID]
|
|
|
|
colRep.segMu.Unlock()
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, test.expectedSegID, seg.segmentID)
|
|
|
|
assert.Equal(t, test.expectedNumOfRows, seg.numRows)
|
|
|
|
assert.Equal(t, test.expectedStartPosTs, seg.startPos.GetTimestamp())
|
|
|
|
assert.Equal(t, test.expectedCpNumOfRows, seg.checkPoint.numRows)
|
|
|
|
assert.Equal(t, test.expectedCpPosTs, seg.checkPoint.pos.GetTimestamp())
|
|
|
|
}
|
|
|
|
|
|
|
|
inMsg.startPositions = []*internalpb.MsgPosition{{Timestamp: 400}}
|
|
|
|
inMsg.endPositions = []*internalpb.MsgPosition{{Timestamp: 434}}
|
|
|
|
|
|
|
|
// trigger manual flush
|
|
|
|
flushChan <- flushMsg{
|
|
|
|
segmentID: 10,
|
|
|
|
flushed: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger auto flush since buffer full
|
|
|
|
output := iBNode.Operate([]flowgraph.Msg{iMsg})
|
|
|
|
fgm := output[0].(*flowGraphMsg)
|
|
|
|
wg.Add(len(fgm.segmentsToFlush))
|
|
|
|
for _, im := range fgm.segmentsToFlush {
|
|
|
|
// send del done signal
|
2022-05-24 21:11:59 +08:00
|
|
|
err = fm.flushDelData(nil, im, fgm.endPositions[0])
|
|
|
|
assert.NoError(t, err)
|
2021-10-25 18:03:42 +08:00
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
require.Equal(t, 0, len(colRep.newSegments))
|
|
|
|
require.Equal(t, 4, len(colRep.normalSegments))
|
|
|
|
require.Equal(t, 1, len(colRep.flushedSegments))
|
|
|
|
|
|
|
|
assert.Equal(t, 2, len(flushPacks))
|
|
|
|
for _, pack := range flushPacks {
|
|
|
|
if pack.segmentID == 10 {
|
|
|
|
assert.Equal(t, true, pack.flushed)
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, false, pack.flushed)
|
2021-10-19 11:04:34 +08:00
|
|
|
}
|
2021-10-25 18:03:42 +08:00
|
|
|
}
|
|
|
|
|
2021-06-21 16:00:22 +08:00
|
|
|
})
|
2021-06-05 18:18:34 +08:00
|
|
|
}
|
2021-09-09 15:00:00 +08:00
|
|
|
|
|
|
|
// CompactedRootCoord has meta info compacted at ts
|
|
|
|
type CompactedRootCoord struct {
|
|
|
|
types.RootCoord
|
|
|
|
compactTs Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *CompactedRootCoord) DescribeCollection(ctx context.Context, in *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2022-03-25 14:27:25 +08:00
|
|
|
if in.TimeStamp != 0 && in.GetTimeStamp() <= m.compactTs {
|
2021-09-09 15:00:00 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "meta compacted",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return m.RootCoord.DescribeCollection(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInsertBufferNode_bufferInsertMsg(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
insertChannelName := "datanode-01-test-flowgraphinsertbuffernode-operate"
|
|
|
|
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
err := clearEtcd(testPath)
|
|
|
|
require.NoError(t, err)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-09-09 15:00:00 +08:00
|
|
|
|
|
|
|
Factory := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
tests := []struct {
|
|
|
|
collID UniqueID
|
|
|
|
pkType schemapb.DataType
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{0, schemapb.DataType_Int64, "int64PrimaryData"},
|
|
|
|
{0, schemapb.DataType_VarChar, "varCharPrimaryData"},
|
2021-09-09 15:00:00 +08:00
|
|
|
}
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(insertNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix("")
|
2022-03-25 14:27:25 +08:00
|
|
|
for _, test := range tests {
|
|
|
|
collMeta := Factory.GetCollectionMeta(test.collID, "collection", test.pkType)
|
|
|
|
rcf := &RootCoordFactory{
|
|
|
|
pkType: test.pkType,
|
|
|
|
}
|
|
|
|
mockRootCoord := &CompactedRootCoord{
|
|
|
|
RootCoord: rcf,
|
|
|
|
compactTs: 100,
|
|
|
|
}
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
replica, err := newReplica(ctx, mockRootCoord, cm, collMeta.ID)
|
|
|
|
assert.Nil(t, err)
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
err = replica.addNewSegment(1, collMeta.ID, 0, insertChannelName, &internalpb.MsgPosition{}, &internalpb.MsgPosition{Timestamp: 101})
|
|
|
|
require.NoError(t, err)
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
fm := NewRendezvousFlushManager(&allocator{}, cm, replica, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
flushChan := make(chan flushMsg, 100)
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTChan := make(chan resendTTMsg, 100)
|
2022-03-25 14:27:25 +08:00
|
|
|
c := &nodeConfig{
|
|
|
|
replica: replica,
|
2022-04-07 22:05:32 +08:00
|
|
|
msFactory: factory,
|
2022-03-25 14:27:25 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: "string",
|
|
|
|
}
|
2022-05-25 14:34:00 +08:00
|
|
|
iBNode, err := newInsertBufferNode(ctx, collMeta.ID, flushChan, resendTTChan, fm, newCache(), c)
|
2022-03-25 14:27:25 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
inMsg := genFlowGraphInsertMsg(insertChannelName)
|
|
|
|
for _, msg := range inMsg.insertMessages {
|
|
|
|
msg.EndTimestamp = 101 // ts valid
|
|
|
|
err = iBNode.bufferInsertMsg(msg, &internalpb.MsgPosition{})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
2021-09-09 15:00:00 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
for _, msg := range inMsg.insertMessages {
|
|
|
|
msg.EndTimestamp = 101 // ts valid
|
|
|
|
msg.RowIDs = []int64{} //misaligned data
|
|
|
|
err = iBNode.bufferInsertMsg(msg, &internalpb.MsgPosition{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
2021-09-09 15:00:00 +08:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 16:27:56 +08:00
|
|
|
|
|
|
|
func TestInsertBufferNode_updateSegStatesInReplica(te *testing.T) {
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(insertNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix("")
|
2021-09-17 16:27:56 +08:00
|
|
|
invalideTests := []struct {
|
|
|
|
replicaCollID UniqueID
|
|
|
|
|
|
|
|
inCollID UniqueID
|
|
|
|
segID UniqueID
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{1, 9, 100, "collectionID mismatch"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range invalideTests {
|
2022-03-25 14:27:25 +08:00
|
|
|
replica, err := newReplica(context.Background(), &RootCoordFactory{pkType: schemapb.DataType_Int64}, cm, test.replicaCollID)
|
2021-10-14 10:24:33 +08:00
|
|
|
assert.Nil(te, err)
|
|
|
|
|
2021-09-17 16:27:56 +08:00
|
|
|
ibNode := &insertBufferNode{
|
2021-10-14 10:24:33 +08:00
|
|
|
replica: replica,
|
2021-09-17 16:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
im := []*msgstream.InsertMsg{
|
|
|
|
{
|
|
|
|
InsertRequest: internalpb.InsertRequest{
|
|
|
|
CollectionID: test.inCollID,
|
|
|
|
SegmentID: test.segID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
seg, err := ibNode.updateSegStatesInReplica(im, &internalpb.MsgPosition{}, &internalpb.MsgPosition{})
|
|
|
|
|
|
|
|
assert.Error(te, err)
|
|
|
|
assert.Empty(te, seg)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-09-18 14:25:50 +08:00
|
|
|
|
|
|
|
func TestInsertBufferNode_BufferData(te *testing.T) {
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.DataNodeCfg.FlushInsertBufferSize = 16 * (1 << 20) // 16 MB
|
2021-09-18 14:25:50 +08:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
isValid bool
|
|
|
|
|
|
|
|
indim int64
|
|
|
|
expectedLimit int64
|
|
|
|
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{true, 1, 4194304, "Smallest of the DIM"},
|
|
|
|
{true, 128, 32768, "Normal DIM"},
|
|
|
|
{true, 32768, 128, "Largest DIM"},
|
|
|
|
{false, 0, 0, "Illegal DIM"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
te.Run(test.description, func(t *testing.T) {
|
|
|
|
idata, err := newBufferData(test.indim)
|
|
|
|
|
|
|
|
if test.isValid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, idata)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expectedLimit, idata.limit)
|
|
|
|
assert.Zero(t, idata.size)
|
2021-09-26 20:55:59 +08:00
|
|
|
|
|
|
|
capacity := idata.effectiveCap()
|
|
|
|
assert.Equal(t, test.expectedLimit, capacity)
|
2021-09-18 14:25:50 +08:00
|
|
|
} else {
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, idata)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|