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-08-25 11:41:52 +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-08-25 11:41:52 +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-08-25 11:41:52 +08:00
|
|
|
|
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
2021-10-11 16:31:44 +08:00
|
|
|
"context"
|
2021-08-25 11:41:52 +08:00
|
|
|
"testing"
|
2021-10-11 16:31:44 +08:00
|
|
|
"time"
|
2021-08-25 11:41:52 +08:00
|
|
|
|
2021-08-28 10:12:00 +08:00
|
|
|
"github.com/bits-and-blooms/bloom/v3"
|
2022-09-23 10:22:52 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2021-11-02 18:16:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2022-10-18 15:33:26 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-03-17 18:03:23 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2021-10-11 16:31:44 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
2022-09-23 10:22:52 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
2021-08-25 11:41:52 +08:00
|
|
|
)
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
var deleteNodeTestDir = "/tmp/milvus_test/deleteNode"
|
|
|
|
|
2021-09-08 10:41:59 +08:00
|
|
|
func TestFlowGraphDeleteNode_newDeleteNode(te *testing.T) {
|
|
|
|
tests := []struct {
|
2021-10-13 11:16:32 +08:00
|
|
|
ctx context.Context
|
|
|
|
config *nodeConfig
|
2021-09-08 10:41:59 +08:00
|
|
|
|
|
|
|
description string
|
|
|
|
}{
|
2022-10-18 15:33:26 +08:00
|
|
|
{context.Background(), &nodeConfig{}, "pointer of channel"},
|
2021-09-08 10:41:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
te.Run(test.description, func(t *testing.T) {
|
2021-11-25 09:43:15 +08:00
|
|
|
dn, err := newDeleteNode(test.ctx, nil, make(chan string, 1), test.config)
|
2021-10-11 16:31:44 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-08 10:41:59 +08:00
|
|
|
|
2021-09-09 15:36:01 +08:00
|
|
|
assert.NotNil(t, dn)
|
2021-12-30 10:33:46 +08:00
|
|
|
assert.Equal(t, "deleteNode-"+dn.channelName, dn.Name())
|
2021-09-09 15:36:01 +08:00
|
|
|
dn.Close()
|
2021-09-08 10:41:59 +08:00
|
|
|
})
|
|
|
|
}
|
2021-08-25 11:41:52 +08:00
|
|
|
}
|
2021-08-28 10:12:00 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
func genMockChannel(segIDs []int64, pks []primaryKey, chanName string) *ChannelMeta {
|
2021-08-28 10:12:00 +08:00
|
|
|
buf := make([]byte, 8)
|
2021-10-11 16:31:44 +08:00
|
|
|
filter0 := bloom.NewWithEstimates(1000000, 0.01)
|
2021-08-28 10:12:00 +08:00
|
|
|
for i := 0; i < 3; i++ {
|
2022-04-02 17:43:29 +08:00
|
|
|
switch pks[i].Type() {
|
|
|
|
case schemapb.DataType_Int64:
|
|
|
|
common.Endian.PutUint64(buf, uint64(pks[i].(*int64PrimaryKey).Value))
|
|
|
|
filter0.Add(buf)
|
|
|
|
case schemapb.DataType_VarChar:
|
|
|
|
filter0.AddString(pks[i].(*varCharPrimaryKey).Value)
|
|
|
|
}
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
2021-10-11 16:31:44 +08:00
|
|
|
|
|
|
|
filter1 := bloom.NewWithEstimates(1000000, 0.01)
|
2021-08-28 10:12:00 +08:00
|
|
|
for i := 3; i < 5; i++ {
|
2022-04-02 17:43:29 +08:00
|
|
|
switch pks[i].Type() {
|
|
|
|
case schemapb.DataType_Int64:
|
|
|
|
common.Endian.PutUint64(buf, uint64(pks[i].(*int64PrimaryKey).Value))
|
|
|
|
filter1.Add(buf)
|
|
|
|
case schemapb.DataType_VarChar:
|
|
|
|
filter1.AddString(pks[i].(*varCharPrimaryKey).Value)
|
|
|
|
}
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
2021-10-11 16:31:44 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
segTypes := []datapb.SegmentType{
|
|
|
|
datapb.SegmentType_New,
|
|
|
|
datapb.SegmentType_New,
|
|
|
|
datapb.SegmentType_Normal,
|
|
|
|
datapb.SegmentType_Normal,
|
|
|
|
datapb.SegmentType_Flushed,
|
|
|
|
datapb.SegmentType_Flushed,
|
2021-10-11 16:31:44 +08:00
|
|
|
}
|
2022-10-18 15:33:26 +08:00
|
|
|
|
|
|
|
channel := &ChannelMeta{
|
2021-10-11 16:31:44 +08:00
|
|
|
channelName: chanName,
|
2022-10-18 15:33:26 +08:00
|
|
|
segments: make(map[UniqueID]*Segment),
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
2022-10-18 15:33:26 +08:00
|
|
|
for i := range segIDs {
|
|
|
|
seg := Segment{
|
|
|
|
segmentID: segIDs[i],
|
|
|
|
}
|
|
|
|
seg.setType(segTypes[i])
|
|
|
|
if i < 3 {
|
2022-10-20 14:33:27 +08:00
|
|
|
seg.pkStat.pkFilter = filter0
|
2022-10-18 15:33:26 +08:00
|
|
|
} else {
|
2022-10-20 14:33:27 +08:00
|
|
|
seg.pkStat.pkFilter = filter1
|
2022-10-18 15:33:26 +08:00
|
|
|
}
|
|
|
|
channel.segments[segIDs[i]] = &seg
|
2021-09-27 14:38:00 +08:00
|
|
|
}
|
2021-10-11 16:31:44 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
return channel
|
2021-10-11 16:31:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFlowGraphDeleteNode_Operate(t *testing.T) {
|
2022-09-29 16:18:56 +08:00
|
|
|
ctx := context.Background()
|
2021-10-11 16:31:44 +08:00
|
|
|
t.Run("Test deleteNode Operate invalid Msg", func(te *testing.T) {
|
|
|
|
invalidInTests := []struct {
|
|
|
|
in []Msg
|
|
|
|
desc string
|
|
|
|
}{
|
|
|
|
{[]Msg{},
|
|
|
|
"Invalid input length == 0"},
|
|
|
|
{[]Msg{&flowGraphMsg{}, &flowGraphMsg{}, &flowGraphMsg{}},
|
|
|
|
"Invalid input length == 3"},
|
2022-05-24 21:11:59 +08:00
|
|
|
{[]Msg{&flowgraph.MsgStreamMsg{}},
|
|
|
|
"Invalid input length == 1 but input message is not flowGraphMsg"},
|
2021-10-11 16:31:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range invalidInTests {
|
|
|
|
te.Run(test.desc, func(t *testing.T) {
|
2021-10-18 12:34:34 +08:00
|
|
|
dn := deleteNode{}
|
2021-10-11 16:31:44 +08:00
|
|
|
rt := dn.Operate(test.in)
|
|
|
|
assert.Empty(t, rt)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const (
|
|
|
|
chanName = "channel-test"
|
|
|
|
)
|
|
|
|
var (
|
2022-04-02 17:43:29 +08:00
|
|
|
segIDs = []int64{11, 22, 33, 44, 55}
|
|
|
|
int64Pks = []primaryKey{
|
|
|
|
newInt64PrimaryKey(3),
|
|
|
|
newInt64PrimaryKey(17),
|
|
|
|
newInt64PrimaryKey(44),
|
|
|
|
newInt64PrimaryKey(190),
|
|
|
|
newInt64PrimaryKey(425),
|
|
|
|
}
|
|
|
|
varCharPks = []primaryKey{
|
|
|
|
newVarCharPrimaryKey("ab"),
|
|
|
|
newVarCharPrimaryKey("ac"),
|
|
|
|
newVarCharPrimaryKey("bcd"),
|
|
|
|
newVarCharPrimaryKey("gggg"),
|
|
|
|
newVarCharPrimaryKey("milvus"),
|
|
|
|
}
|
|
|
|
tss = []uint64{1, 1, 1, 1, 1}
|
2021-10-11 16:31:44 +08:00
|
|
|
)
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(deleteNodeTestDir))
|
2022-09-29 16:18:56 +08:00
|
|
|
defer cm.RemoveWithPrefix(ctx, "")
|
2022-04-02 17:43:29 +08:00
|
|
|
|
|
|
|
t.Run("Test get segment by varChar primary keys", func(te *testing.T) {
|
2022-10-18 15:33:26 +08:00
|
|
|
channel := genMockChannel(segIDs, varCharPks, chanName)
|
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, channel, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2022-04-02 17:43:29 +08:00
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2022-04-02 17:43:29 +08:00
|
|
|
allocator: &allocator{},
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
|
|
|
|
dn, err := newDeleteNode(context.Background(), fm, make(chan string, 1), c)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
segID2Pks, _ := dn.filterSegmentByPK(0, varCharPks, tss)
|
|
|
|
expected := map[int64][]primaryKey{
|
|
|
|
segIDs[0]: varCharPks[0:3],
|
|
|
|
segIDs[1]: varCharPks[0:3],
|
|
|
|
segIDs[2]: varCharPks[0:3],
|
|
|
|
segIDs[3]: varCharPks[3:5],
|
|
|
|
segIDs[4]: varCharPks[3:5],
|
|
|
|
}
|
|
|
|
for segmentID, expectedPks := range expected {
|
|
|
|
filterPks := segID2Pks[segmentID]
|
|
|
|
assert.Equal(t, len(expectedPks), len(filterPks))
|
|
|
|
for index, pk := range expectedPks {
|
|
|
|
assert.Equal(t, true, pk.EQ(filterPks[index]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
channel := genMockChannel(segIDs, int64Pks, chanName)
|
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, channel, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2022-04-02 17:43:29 +08:00
|
|
|
t.Run("Test get segment by int64 primary keys", func(te *testing.T) {
|
2021-10-13 11:16:32 +08:00
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: &allocator{},
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
|
2021-11-25 09:43:15 +08:00
|
|
|
dn, err := newDeleteNode(context.Background(), fm, make(chan string, 1), c)
|
2021-10-11 16:31:44 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-04-02 17:43:29 +08:00
|
|
|
segID2Pks, _ := dn.filterSegmentByPK(0, int64Pks, tss)
|
|
|
|
expected := map[int64][]primaryKey{
|
|
|
|
segIDs[0]: int64Pks[0:3],
|
|
|
|
segIDs[1]: int64Pks[0:3],
|
|
|
|
segIDs[2]: int64Pks[0:3],
|
|
|
|
segIDs[3]: int64Pks[3:5],
|
|
|
|
segIDs[4]: int64Pks[3:5],
|
2021-10-11 16:31:44 +08:00
|
|
|
}
|
2022-04-02 17:43:29 +08:00
|
|
|
for segmentID, expectedPks := range expected {
|
|
|
|
filterPks := segID2Pks[segmentID]
|
|
|
|
assert.Equal(t, len(expectedPks), len(filterPks))
|
|
|
|
for index, pk := range expectedPks {
|
|
|
|
assert.Equal(t, true, pk.EQ(filterPks[index]))
|
|
|
|
}
|
2021-10-11 16:31:44 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-19 11:04:34 +08:00
|
|
|
t.Run("Test deleteNode Operate valid Msg with failure", func(te *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-operate"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-10-19 11:04:34 +08:00
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2021-10-19 11:04:34 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
2021-11-25 09:43:15 +08:00
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
2021-10-19 11:04:34 +08:00
|
|
|
assert.Nil(te, err)
|
|
|
|
|
2022-04-02 17:43:29 +08:00
|
|
|
msg := genFlowGraphDeleteMsg(int64Pks, chanName)
|
2021-10-19 11:04:34 +08:00
|
|
|
msg.segmentsToFlush = segIDs
|
|
|
|
// this will fail since ts = 0 will trigger mocked error
|
|
|
|
var fgMsg flowgraph.Msg = &msg
|
|
|
|
delNode.Operate([]flowgraph.Msg{fgMsg})
|
|
|
|
})
|
|
|
|
t.Run("Test deleteNode Operate valid Msg with failure", func(te *testing.T) {
|
2021-10-11 16:31:44 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-operate"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-10-11 16:31:44 +08:00
|
|
|
|
2021-10-13 11:16:32 +08:00
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2021-10-13 11:16:32 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
2021-11-25 09:43:15 +08:00
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
2021-10-11 16:31:44 +08:00
|
|
|
assert.Nil(te, err)
|
|
|
|
|
2022-04-02 17:43:29 +08:00
|
|
|
msg := genFlowGraphDeleteMsg(int64Pks, chanName)
|
2021-10-18 12:34:34 +08:00
|
|
|
msg.segmentsToFlush = segIDs
|
2021-10-19 11:04:34 +08:00
|
|
|
|
|
|
|
msg.endPositions[0].Timestamp = 100 // set to normal timestamp
|
2021-10-11 16:31:44 +08:00
|
|
|
var fgMsg flowgraph.Msg = &msg
|
|
|
|
delNode.Operate([]flowgraph.Msg{fgMsg})
|
2021-10-19 11:04:34 +08:00
|
|
|
|
|
|
|
msg.deleteMessages = []*msgstream.DeleteMsg{}
|
|
|
|
// send again shall trigger empty buffer flush
|
|
|
|
delNode.Operate([]flowgraph.Msg{fgMsg})
|
2021-10-11 16:31:44 +08:00
|
|
|
})
|
2022-08-17 17:08:49 +08:00
|
|
|
|
2021-12-02 16:39:33 +08:00
|
|
|
t.Run("Test deleteNode Operate valid with dropCollection", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-operate"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
2021-12-02 16:39:33 +08:00
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2021-12-02 16:39:33 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
sig := make(chan string, 1)
|
|
|
|
delNode, err := newDeleteNode(ctx, fm, sig, c)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-04-02 17:43:29 +08:00
|
|
|
msg := genFlowGraphDeleteMsg(int64Pks, chanName)
|
2021-12-02 16:39:33 +08:00
|
|
|
msg.segmentsToFlush = segIDs
|
|
|
|
|
|
|
|
msg.endPositions[0].Timestamp = 100 // set to normal timestamp
|
|
|
|
msg.dropCollection = true
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
fm.startDropping()
|
|
|
|
delNode.Operate([]flowgraph.Msg{&msg})
|
|
|
|
})
|
|
|
|
timer := time.NewTimer(time.Millisecond)
|
|
|
|
select {
|
|
|
|
case <-timer.C:
|
|
|
|
t.FailNow()
|
|
|
|
case <-sig:
|
|
|
|
}
|
|
|
|
})
|
2022-05-24 21:11:59 +08:00
|
|
|
|
|
|
|
t.Run("Test deleteNode Operate flushDelData failed", func(te *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-operate"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: nil,
|
2022-05-24 21:11:59 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
|
|
|
assert.Nil(te, err)
|
|
|
|
|
|
|
|
msg := genFlowGraphDeleteMsg(int64Pks, chanName)
|
|
|
|
msg.segmentsToFlush = []UniqueID{-1}
|
|
|
|
delNode.delBuf.Store(UniqueID(-1), &DelDataBuf{})
|
|
|
|
delNode.flushManager = &mockFlushManager{
|
|
|
|
returnError: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
var fgMsg flowgraph.Msg = &msg
|
|
|
|
|
2022-09-13 14:12:31 +08:00
|
|
|
setFlowGraphRetryOpt(retry.Attempts(1))
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.Panics(te, func() {
|
|
|
|
delNode.Operate([]flowgraph.Msg{fgMsg})
|
|
|
|
})
|
|
|
|
})
|
2022-08-17 17:08:49 +08:00
|
|
|
|
|
|
|
t.Run("Test issue#18565", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-issue18565"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
channel := &ChannelMeta{
|
|
|
|
segments: make(map[UniqueID]*Segment),
|
2022-08-17 17:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2022-08-17 17:08:49 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
compactedSegment := UniqueID(10020987)
|
2022-10-18 15:33:26 +08:00
|
|
|
seg := Segment{
|
2022-08-17 17:08:49 +08:00
|
|
|
segmentID: compactedSegment,
|
|
|
|
compactedTo: 100,
|
|
|
|
}
|
2022-10-18 15:33:26 +08:00
|
|
|
seg.setType(datapb.SegmentType_Compacted)
|
|
|
|
channel.segments[compactedSegment] = &seg
|
2022-08-17 17:08:49 +08:00
|
|
|
|
|
|
|
msg := genFlowGraphDeleteMsg(int64Pks, chanName)
|
|
|
|
msg.deleteMessages = []*msgstream.DeleteMsg{}
|
|
|
|
msg.segmentsToFlush = []UniqueID{compactedSegment}
|
|
|
|
|
|
|
|
delNode.delBuf.Store(compactedSegment, &DelDataBuf{delData: &DeleteData{}})
|
2022-10-18 15:33:26 +08:00
|
|
|
delNode.flushManager = NewRendezvousFlushManager(&allocator{}, cm, channel, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2022-08-17 17:08:49 +08:00
|
|
|
|
|
|
|
var fgMsg flowgraph.Msg = &msg
|
2022-09-13 14:12:31 +08:00
|
|
|
setFlowGraphRetryOpt(retry.Attempts(1))
|
2022-08-17 17:08:49 +08:00
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
delNode.Operate([]flowgraph.Msg{fgMsg})
|
|
|
|
})
|
|
|
|
|
|
|
|
_, ok := delNode.delBuf.Load(100)
|
|
|
|
assert.False(t, ok)
|
|
|
|
_, ok = delNode.delBuf.Load(compactedSegment)
|
|
|
|
assert.False(t, ok)
|
|
|
|
})
|
2021-08-28 10:12:00 +08:00
|
|
|
}
|
2022-08-15 16:28:48 +08:00
|
|
|
|
|
|
|
func TestFlowGraphDeleteNode_showDelBuf(t *testing.T) {
|
2022-09-29 16:18:56 +08:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2022-08-15 16:28:48 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(deleteNodeTestDir))
|
2022-09-29 16:18:56 +08:00
|
|
|
defer cm.RemoveWithPrefix(ctx, "")
|
2022-08-15 16:28:48 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, nil, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2022-08-15 16:28:48 +08:00
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-showDelBuf"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: nil,
|
2022-08-15 16:28:48 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
seg UniqueID
|
|
|
|
numRows int64
|
|
|
|
}{
|
|
|
|
{111, 10},
|
|
|
|
{112, 10},
|
|
|
|
{113, 1},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
delBuf := newDelDataBuf()
|
|
|
|
delBuf.updateSize(test.numRows)
|
|
|
|
delNode.delBuf.Store(test.seg, delBuf)
|
|
|
|
}
|
|
|
|
|
|
|
|
delNode.showDelBuf([]UniqueID{111, 112, 113}, 100)
|
|
|
|
}
|
2022-08-17 17:08:49 +08:00
|
|
|
|
|
|
|
func TestFlowGraphDeleteNode_updateCompactedSegments(t *testing.T) {
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
2022-09-29 16:18:56 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(deleteNodeTestDir))
|
|
|
|
defer cm.RemoveWithPrefix(ctx, "")
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
fm := NewRendezvousFlushManager(NewAllocatorFactory(), cm, nil, func(*segmentFlushPack) {}, emptyFlushAndDropFunc)
|
2022-08-17 17:08:49 +08:00
|
|
|
|
|
|
|
chanName := "datanode-test-FlowGraphDeletenode-showDelBuf"
|
|
|
|
testPath := "/test/datanode/root/meta"
|
|
|
|
assert.NoError(t, clearEtcd(testPath))
|
|
|
|
Params.EtcdCfg.MetaRootPath = testPath
|
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
channel := ChannelMeta{
|
|
|
|
segments: make(map[UniqueID]*Segment),
|
2022-08-17 17:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c := &nodeConfig{
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: &channel,
|
2022-08-17 17:08:49 +08:00
|
|
|
allocator: NewAllocatorFactory(),
|
|
|
|
vChannelName: chanName,
|
|
|
|
}
|
|
|
|
delNode, err := newDeleteNode(ctx, fm, make(chan string, 1), c)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tests := []struct {
|
2022-09-23 10:22:52 +08:00
|
|
|
description string
|
|
|
|
compactToExist bool
|
|
|
|
segIDsInBuffer []UniqueID
|
|
|
|
|
2022-08-17 17:08:49 +08:00
|
|
|
compactedToIDs []UniqueID
|
|
|
|
compactedFromIDs []UniqueID
|
|
|
|
|
|
|
|
expectedSegsRemain []UniqueID
|
|
|
|
}{
|
2022-09-23 10:22:52 +08:00
|
|
|
{"zero segments", false,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{}, []UniqueID{}, []UniqueID{}, []UniqueID{}},
|
2022-09-23 10:22:52 +08:00
|
|
|
{"segment no compaction", false,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{100, 101}, []UniqueID{}, []UniqueID{}, []UniqueID{100, 101}},
|
2022-09-23 10:22:52 +08:00
|
|
|
{"segment compacted not in buffer", true,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{100, 101}, []UniqueID{200}, []UniqueID{103}, []UniqueID{100, 101}},
|
2022-09-23 10:22:52 +08:00
|
|
|
{"segment compacted in buffer 100>201", true,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{100, 101}, []UniqueID{201}, []UniqueID{100}, []UniqueID{101, 201}},
|
2022-09-23 10:22:52 +08:00
|
|
|
{"segment compacted in buffer 100+101>201", true,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{100, 101}, []UniqueID{201, 201}, []UniqueID{100, 101}, []UniqueID{201}},
|
2022-09-23 10:22:52 +08:00
|
|
|
{"segment compacted in buffer 100>201, 101>202", true,
|
2022-08-17 17:08:49 +08:00
|
|
|
[]UniqueID{100, 101}, []UniqueID{201, 202}, []UniqueID{100, 101}, []UniqueID{201, 202}},
|
2022-09-23 10:22:52 +08:00
|
|
|
// false
|
|
|
|
{"segment compacted in buffer 100>201", false,
|
|
|
|
[]UniqueID{100, 101}, []UniqueID{201}, []UniqueID{100}, []UniqueID{101}},
|
|
|
|
{"segment compacted in buffer 100+101>201", false,
|
|
|
|
[]UniqueID{100, 101}, []UniqueID{201, 201}, []UniqueID{100, 101}, []UniqueID{}},
|
|
|
|
{"segment compacted in buffer 100>201, 101>202", false,
|
|
|
|
[]UniqueID{100, 101}, []UniqueID{201, 202}, []UniqueID{100, 101}, []UniqueID{}},
|
2022-08-17 17:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
for _, seg := range test.segIDsInBuffer {
|
|
|
|
delBuf := newDelDataBuf()
|
2022-09-23 10:22:52 +08:00
|
|
|
delBuf.updateSize(100)
|
2022-08-17 17:08:49 +08:00
|
|
|
delNode.delBuf.Store(seg, delBuf)
|
|
|
|
}
|
|
|
|
|
2022-09-23 10:22:52 +08:00
|
|
|
if test.compactToExist {
|
2022-10-18 15:33:26 +08:00
|
|
|
for _, segID := range test.compactedToIDs {
|
|
|
|
seg := Segment{
|
|
|
|
segmentID: segID,
|
2022-09-23 10:22:52 +08:00
|
|
|
numRows: 10,
|
|
|
|
}
|
2022-10-18 15:33:26 +08:00
|
|
|
seg.setType(datapb.SegmentType_Flushed)
|
|
|
|
channel.segments[segID] = &seg
|
|
|
|
}
|
|
|
|
} else { // clear all segments in channel
|
|
|
|
channel.segments = make(map[UniqueID]*Segment)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, segID := range test.compactedFromIDs {
|
|
|
|
seg := Segment{
|
|
|
|
segmentID: segID,
|
|
|
|
compactedTo: test.compactedToIDs[i],
|
2022-09-23 10:22:52 +08:00
|
|
|
}
|
2022-10-18 15:33:26 +08:00
|
|
|
seg.setType(datapb.SegmentType_Compacted)
|
|
|
|
channel.segments[segID] = &seg
|
2022-09-23 10:22:52 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 17:08:49 +08:00
|
|
|
delNode.updateCompactedSegments()
|
|
|
|
|
|
|
|
for _, remain := range test.expectedSegsRemain {
|
|
|
|
_, ok := delNode.delBuf.Load(remain)
|
|
|
|
assert.True(t, ok)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|