2021-11-29 20:15:45 +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-11-06 11:02:58 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-29 20:15:45 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-11-06 11:02:58 +08:00
|
|
|
//
|
2021-11-29 20:15:45 +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-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
2022-04-02 17:43:29 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-11-06 11:02:58 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFlowGraphDeleteNode_delete(t *testing.T) {
|
|
|
|
t.Run("test delete", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
deleteData, err := genFlowGraphDeleteData()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
2022-05-24 21:11:59 +08:00
|
|
|
err = deleteNode.delete(deleteData, defaultSegmentID, wg)
|
|
|
|
assert.NoError(t, err)
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test segment delete error", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
deleteData, err := genFlowGraphDeleteData()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
|
|
|
deleteData.deleteTimestamps[defaultSegmentID] = deleteData.deleteTimestamps[defaultSegmentID][:len(deleteData.deleteTimestamps)/2]
|
2022-05-24 21:11:59 +08:00
|
|
|
err = deleteNode.delete(deleteData, defaultSegmentID, wg)
|
|
|
|
assert.Error(t, err)
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test no target segment", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
2022-05-24 21:11:59 +08:00
|
|
|
err = deleteNode.delete(nil, defaultSegmentID, wg)
|
|
|
|
assert.Error(t, err)
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid segmentType", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeGrowing)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
2022-05-24 21:11:59 +08:00
|
|
|
err = deleteNode.delete(&deleteData{}, defaultSegmentID, wg)
|
|
|
|
assert.Error(t, err)
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFlowGraphDeleteNode_operate(t *testing.T) {
|
|
|
|
t.Run("test operate", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
msgDeleteMsg := genDeleteMsg(defaultCollectionID, schemapb.DataType_Int64, defaultDelLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
dMsg := deleteMsg{
|
|
|
|
deleteMessages: []*msgstream.DeleteMsg{
|
|
|
|
msgDeleteMsg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msg := []flowgraph.Msg{&dMsg}
|
|
|
|
deleteNode.Operate(msg)
|
2022-05-31 13:42:03 +08:00
|
|
|
s, err := historical.getSegmentByID(defaultSegmentID, segmentTypeSealed)
|
2022-04-02 17:43:29 +08:00
|
|
|
pks := make([]primaryKey, defaultMsgLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
for i := 0; i < defaultMsgLength; i++ {
|
2022-04-02 17:43:29 +08:00
|
|
|
pks[i] = newInt64PrimaryKey(int64(i))
|
2021-11-06 11:02:58 +08:00
|
|
|
}
|
|
|
|
s.updateBloomFilter(pks)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
buf := make([]byte, 8)
|
|
|
|
for i := 0; i < defaultMsgLength; i++ {
|
|
|
|
common.Endian.PutUint64(buf, uint64(i))
|
|
|
|
assert.True(t, s.pkFilter.Test(buf))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid partitionID", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
msgDeleteMsg := genDeleteMsg(defaultCollectionID, schemapb.DataType_Int64, defaultDelLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
msgDeleteMsg.PartitionID = common.InvalidPartitionID
|
|
|
|
assert.NoError(t, err)
|
|
|
|
dMsg := deleteMsg{
|
|
|
|
deleteMessages: []*msgstream.DeleteMsg{
|
|
|
|
msgDeleteMsg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msg := []flowgraph.Msg{&dMsg}
|
|
|
|
deleteNode.Operate(msg)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test collection partition not exist", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
msgDeleteMsg := genDeleteMsg(defaultCollectionID, schemapb.DataType_Int64, defaultDelLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
msgDeleteMsg.CollectionID = 9999
|
|
|
|
msgDeleteMsg.PartitionID = -1
|
|
|
|
assert.NoError(t, err)
|
|
|
|
dMsg := deleteMsg{
|
|
|
|
deleteMessages: []*msgstream.DeleteMsg{
|
|
|
|
msgDeleteMsg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msg := []flowgraph.Msg{&dMsg}
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.Panics(t, func() {
|
|
|
|
deleteNode.Operate(msg)
|
|
|
|
})
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test partition not exist", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
msgDeleteMsg := genDeleteMsg(defaultCollectionID, schemapb.DataType_Int64, defaultDelLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
msgDeleteMsg.PartitionID = 9999
|
|
|
|
assert.NoError(t, err)
|
|
|
|
dMsg := deleteMsg{
|
|
|
|
deleteMessages: []*msgstream.DeleteMsg{
|
|
|
|
msgDeleteMsg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msg := []flowgraph.Msg{&dMsg}
|
2022-05-24 21:11:59 +08:00
|
|
|
assert.Panics(t, func() {
|
|
|
|
deleteNode.Operate(msg)
|
|
|
|
})
|
2021-11-06 11:02:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid input length", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
2022-06-15 21:04:10 +08:00
|
|
|
deleteNode := newDeleteNode(historical, defaultCollectionID, defaultChannelName)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2022-05-23 16:41:58 +08:00
|
|
|
segmentTypeSealed)
|
2021-11-06 11:02:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
msgDeleteMsg := genDeleteMsg(defaultCollectionID, schemapb.DataType_Int64, defaultDelLength)
|
2021-11-06 11:02:58 +08:00
|
|
|
dMsg := deleteMsg{
|
|
|
|
deleteMessages: []*msgstream.DeleteMsg{
|
|
|
|
msgDeleteMsg,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msg := []flowgraph.Msg{&dMsg, &dMsg}
|
|
|
|
deleteNode.Operate(msg)
|
|
|
|
})
|
|
|
|
}
|