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-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)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.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)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.replica.getCollectionNum(), 1)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.removeCollection(0)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.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)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetCollection, err := node.historical.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
|
|
|
|
2021-05-28 10:26:30 +08:00
|
|
|
hasCollection := node.historical.replica.hasCollection(collectionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasCollection, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasCollection = node.historical.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 {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.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-05-28 10:26:30 +08:00
|
|
|
partitionNum := node.historical.replica.getPartitionNum()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, partitionNum, len(partitionIDs))
|
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_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 {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.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 {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.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-05-28 10:26:30 +08:00
|
|
|
err = node.historical.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 {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.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-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, collectionMeta.PartitionIDs[0])
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasPartition := node.historical.replica.hasPartition(defaultPartitionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasPartition, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasPartition = node.historical.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-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.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-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.replica.getSegmentByID(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
2021-05-28 10:26:30 +08:00
|
|
|
err = node.historical.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-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.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-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.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))
|
2021-05-28 10:26:30 +08:00
|
|
|
hasSeg := node.historical.replica.hasSegment(UniqueID(i))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.Equal(t, hasSeg, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasSeg = node.historical.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
|
|
|
}
|
|
|
|
|
2021-09-10 09:33:43 +08:00
|
|
|
func TestCollectionReplica_statistic(t *testing.T) {
|
|
|
|
t.Run("test getCollectionIDs", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
ids := replica.getCollectionIDs()
|
|
|
|
assert.Len(t, ids, 1)
|
|
|
|
assert.Equal(t, defaultCollectionID, ids[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test getCollectionIDs", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
num := replica.getSegmentNum()
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
})
|
|
|
|
}
|