2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
import (
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------- collection
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getCollectionNum(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, node.replica.getCollectionNum(), 1)
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_addCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_removeCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, node.replica.getCollectionNum(), 1)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
err := node.replica.removeCollection(0)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
assert.Equal(t, node.replica.getCollectionNum(), 0)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getCollectionByID(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-08 14:41:04 +08:00
|
|
|
targetCollection, err := node.replica.getCollectionByID(collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, targetCollection)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, targetCollection.ID(), collectionID)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_hasCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
hasCollection := node.replica.hasCollection(collectionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasCollection, true)
|
2020-12-08 14:41:04 +08:00
|
|
|
hasCollection = node.replica.hasCollection(UniqueID(1))
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasCollection, false)
|
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- partition
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getPartitionNum(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-24 15:59:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-24 15:59:51 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
for _, id := range partitionIDs {
|
|
|
|
err := node.replica.addPartition(collectionID, id)
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 10:53:11 +08:00
|
|
|
partition, err := node.replica.getPartitionByID(id)
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
partitionNum := node.replica.getPartitionNum()
|
|
|
|
assert.Equal(t, partitionNum, len(partitionIDs)+1)
|
|
|
|
err := node.Stop()
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_addPartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
for _, id := range partitionIDs {
|
|
|
|
err := node.replica.addPartition(collectionID, id)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 10:53:11 +08:00
|
|
|
partition, err := node.replica.getPartitionByID(id)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_removePartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
for _, id := range partitionIDs {
|
|
|
|
err := node.replica.addPartition(collectionID, id)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 10:53:11 +08:00
|
|
|
partition, err := node.replica.getPartitionByID(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.replica.removePartition(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getPartitionByTag(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
for _, id := range collectionMeta.PartitionIDs {
|
|
|
|
err := node.replica.addPartition(collectionID, id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 10:53:11 +08:00
|
|
|
partition, err := node.replica.getPartitionByID(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NotNil(t, partition)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_hasPartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2021-02-03 18:12:48 +08:00
|
|
|
err := node.replica.addPartition(collectionID, collectionMeta.PartitionIDs[0])
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 10:53:11 +08:00
|
|
|
hasPartition := node.replica.hasPartition(defaultPartitionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasPartition, true)
|
2021-02-05 10:53:11 +08:00
|
|
|
hasPartition = node.replica.hasPartition(defaultPartitionID + 1)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasPartition, false)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- segment
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_addSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-03-10 22:06:22 +08:00
|
|
|
err := node.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, segmentTypeGrowing)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
targetSeg, err := node.replica.getSegmentByID(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_removeSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-03-10 22:06:22 +08:00
|
|
|
err := node.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, segmentTypeGrowing)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
targetSeg, err := node.replica.getSegmentByID(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
2020-12-08 14:41:04 +08:00
|
|
|
err = node.replica.removeSegment(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getSegmentByID(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-24 16:12:39 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-24 16:12:39 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-03-10 22:06:22 +08:00
|
|
|
err := node.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, segmentTypeGrowing)
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
targetSeg, err := node.replica.getSegmentByID(UniqueID(i))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_hasSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-03-10 22:06:22 +08:00
|
|
|
err := node.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, segmentTypeGrowing)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
targetSeg, err := node.replica.getSegmentByID(UniqueID(i))
|
2020-11-13 16:53:55 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
2020-12-08 14:41:04 +08:00
|
|
|
hasSeg := node.replica.hasSegment(UniqueID(i))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.Equal(t, hasSeg, true)
|
2020-12-08 14:41:04 +08:00
|
|
|
hasSeg = node.replica.hasSegment(UniqueID(i + 100))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.Equal(t, hasSeg, false)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_freeAll(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2021-02-07 21:26:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReplaceGrowingSegmentBySealedSegment(t *testing.T) {
|
|
|
|
node := newQueryNodeMock()
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
segmentID := UniqueID(520)
|
|
|
|
initTestMeta(t, node, collectionID, segmentID)
|
|
|
|
|
2021-03-10 22:06:22 +08:00
|
|
|
_, _, segIDs := node.replica.getSegmentsBySegmentType(segmentTypeGrowing)
|
2021-02-07 21:26:03 +08:00
|
|
|
assert.Equal(t, len(segIDs), 1)
|
|
|
|
|
|
|
|
collection, err := node.replica.getCollectionByID(collectionID)
|
|
|
|
assert.NoError(t, err)
|
2021-03-10 22:06:22 +08:00
|
|
|
ns := newSegment(collection, segmentID, defaultPartitionID, collectionID, segmentTypeSealed)
|
2021-02-07 21:26:03 +08:00
|
|
|
err = node.replica.replaceGrowingSegmentBySealedSegment(ns)
|
|
|
|
assert.NoError(t, err)
|
2021-03-10 14:51:00 +08:00
|
|
|
err = node.replica.setSegmentEnableIndex(segmentID, true)
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-07 21:26:03 +08:00
|
|
|
segmentNums := node.replica.getSegmentNum()
|
|
|
|
assert.Equal(t, segmentNums, 1)
|
|
|
|
|
|
|
|
segment, err := node.replica.getSegmentByID(segmentID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-10 22:06:22 +08:00
|
|
|
assert.Equal(t, segment.getType(), segmentTypeSealed)
|
2021-02-07 21:26:03 +08:00
|
|
|
|
2021-03-10 22:06:22 +08:00
|
|
|
_, _, segIDs = node.replica.getSegmentsBySegmentType(segmentTypeGrowing)
|
2021-02-07 21:26:03 +08:00
|
|
|
assert.Equal(t, len(segIDs), 0)
|
2021-03-10 22:06:22 +08:00
|
|
|
_, _, segIDs = node.replica.getSegmentsBySegmentType(segmentTypeSealed)
|
2021-02-07 21:26:03 +08:00
|
|
|
assert.Equal(t, len(segIDs), 1)
|
|
|
|
|
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|