2021-11-29 20:13:50 +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 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-11-29 20:13:50 +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 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
import (
|
2022-08-09 16:34:37 +08:00
|
|
|
"runtime"
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-08-09 16:34:37 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-02-08 21:57:46 +08:00
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
2022-02-08 21:57:46 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2022-08-09 16:34:37 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/concurrency"
|
2020-11-12 11:18:23 +08:00
|
|
|
)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
func TestMetaReplica_collection(t *testing.T) {
|
|
|
|
t.Run("test getCollectionNum", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
assert.Equal(t, 1, replica.getCollectionNum())
|
|
|
|
})
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test addCollection", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
replica.addCollection(defaultCollectionID+1, genTestCollectionSchema())
|
|
|
|
assert.Equal(t, 2, replica.getCollectionNum())
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test removeCollection", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
err = replica.removeCollection(defaultCollectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
})
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test getCollectionByID", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
targetCollection, err := replica.getCollectionByID(defaultCollectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.NotNil(t, targetCollection)
|
|
|
|
assert.Equal(t, defaultCollectionID, targetCollection.ID())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test hasCollection", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
hasCollection := replica.hasCollection(defaultCollectionID)
|
|
|
|
assert.Equal(t, true, hasCollection)
|
|
|
|
hasCollection = replica.hasCollection(defaultCollectionID + 1)
|
|
|
|
assert.Equal(t, false, hasCollection)
|
|
|
|
})
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test getCollectionIDs", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
ids := replica.getCollectionIDs()
|
|
|
|
assert.Len(t, ids, 1)
|
|
|
|
assert.Equal(t, defaultCollectionID, ids[0])
|
|
|
|
})
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
func TestMetaReplica_partition(t *testing.T) {
|
|
|
|
t.Run("test addPartition, getPartitionNum and getPartitionByID", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
for _, id := range partitionIDs {
|
|
|
|
err := replica.addPartition(defaultCollectionID, id)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
partition, err := replica.getPartitionByID(id)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, id, partition.ID())
|
|
|
|
}
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
partitionNum := replica.getPartitionNum()
|
|
|
|
assert.Equal(t, len(partitionIDs), partitionNum)
|
|
|
|
})
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test removePartition", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
|
|
|
|
for _, id := range partitionIDs {
|
|
|
|
err := replica.addPartition(defaultCollectionID, id)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
partition, err := replica.getPartitionByID(id)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, id, partition.ID())
|
|
|
|
err = replica.removePartition(id)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = replica.getPartitionByID(id)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
})
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test hasPartition", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
collection, err := replica.getCollectionByID(defaultCollectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
err = replica.addPartition(defaultCollectionID, collection.partitionIDs[0])
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
hasPartition := replica.hasPartition(defaultPartitionID)
|
|
|
|
assert.Equal(t, true, hasPartition)
|
|
|
|
hasPartition = replica.hasPartition(defaultPartitionID + 1)
|
|
|
|
assert.Equal(t, false, hasPartition)
|
|
|
|
})
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
func TestMetaReplica_segment(t *testing.T) {
|
|
|
|
t.Run("test addSegment and getSegmentByID", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
const segmentNum = 3
|
|
|
|
for i := 0; i < segmentNum; i++ {
|
2022-11-07 19:37:04 +08:00
|
|
|
err := replica.addSegment(UniqueID(i), defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, segmentTypeGrowing)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
targetSeg, err := replica.getSegmentByID(UniqueID(i), segmentTypeGrowing)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, UniqueID(i), targetSeg.segmentID)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test removeSegment", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
const segmentNum = 3
|
|
|
|
for i := 0; i < segmentNum; i++ {
|
2022-11-07 19:37:04 +08:00
|
|
|
err := replica.addSegment(UniqueID(i), defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, segmentTypeGrowing)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
targetSeg, err := replica.getSegmentByID(UniqueID(i), segmentTypeGrowing)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, UniqueID(i), targetSeg.segmentID)
|
2022-06-01 13:18:02 +08:00
|
|
|
replica.removeSegment(UniqueID(i), segmentTypeGrowing)
|
2022-05-31 13:42:03 +08:00
|
|
|
}
|
|
|
|
})
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test hasSegment", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
const segmentNum = 3
|
|
|
|
for i := 0; i < segmentNum; i++ {
|
2022-11-07 19:37:04 +08:00
|
|
|
err := replica.addSegment(UniqueID(i), defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, segmentTypeGrowing)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
targetSeg, err := replica.getSegmentByID(UniqueID(i), segmentTypeGrowing)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, UniqueID(i), targetSeg.segmentID)
|
|
|
|
hasSeg, err := replica.hasSegment(UniqueID(i), segmentTypeGrowing)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, true, hasSeg)
|
|
|
|
hasSeg, err = replica.hasSegment(UniqueID(i+100), segmentTypeGrowing)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, hasSeg)
|
|
|
|
}
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-07-19 20:58:28 +08:00
|
|
|
t.Run("test add duplicated segment", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
err = replica.addSegment(defaultSegmentID, defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, segmentTypeGrowing)
|
2022-07-19 20:58:28 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
err = replica.addSegment(defaultSegmentID, defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, segmentTypeGrowing)
|
2022-07-19 20:58:28 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test invalid segment type", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
|
|
|
|
invalidType := commonpb.SegmentState_NotExist
|
2022-11-07 19:37:04 +08:00
|
|
|
err = replica.addSegment(defaultSegmentID, defaultPartitionID, defaultCollectionID, "", defaultSegmentVersion, defaultSegmentStartPosition, invalidType)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
_, err = replica.getSegmentByID(defaultSegmentID, invalidType)
|
|
|
|
assert.Error(t, err)
|
|
|
|
_, err = replica.getSegmentIDs(defaultPartitionID, invalidType)
|
|
|
|
assert.Error(t, err)
|
2022-06-01 13:18:02 +08:00
|
|
|
assert.Panics(t, func() { replica.removeSegment(defaultSegmentID, invalidType) })
|
2022-05-31 13:42:03 +08:00
|
|
|
_, err = replica.hasSegment(defaultSegmentID, invalidType)
|
|
|
|
assert.Error(t, err)
|
|
|
|
num := replica.getSegmentNum(invalidType)
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
})
|
2022-02-08 21:57:46 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
t.Run("test getSegmentInfosByColID", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
2022-02-08 21:57:46 +08:00
|
|
|
|
2022-08-09 16:34:37 +08:00
|
|
|
pool, err := concurrency.NewPool(runtime.GOMAXPROCS(0))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
collection := replica.addCollection(defaultCollectionID, schema)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID)
|
2021-11-05 16:00:55 +08:00
|
|
|
|
2022-05-31 13:42:03 +08:00
|
|
|
// test get indexed segment info
|
|
|
|
vectorFieldIDDs, err := replica.getVecFieldIDsByCollectionID(defaultCollectionID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(vectorFieldIDDs))
|
|
|
|
fieldID := vectorFieldIDDs[0]
|
|
|
|
|
|
|
|
indexID := UniqueID(10000)
|
|
|
|
indexInfo := &IndexedFieldInfo{
|
|
|
|
indexInfo: &querypb.FieldIndexInfo{
|
|
|
|
IndexName: "test-index-name",
|
|
|
|
IndexID: indexID,
|
|
|
|
EnableIndex: true,
|
|
|
|
},
|
2022-02-08 21:57:46 +08:00
|
|
|
}
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment1, err := newSegment(collection, UniqueID(1), defaultPartitionID, defaultCollectionID, "", segmentTypeGrowing, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-05-31 13:42:03 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment1)
|
|
|
|
assert.NoError(t, err)
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment2, err := newSegment(collection, UniqueID(2), defaultPartitionID, defaultCollectionID, "", segmentTypeSealed, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
segment2.setIndexedFieldInfo(fieldID, indexInfo)
|
|
|
|
err = replica.setSegment(segment2)
|
2020-11-13 16:53:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
|
|
|
|
targetSegs := replica.getSegmentInfosByColID(defaultCollectionID)
|
|
|
|
assert.Equal(t, 2, len(targetSegs))
|
|
|
|
for _, segment := range targetSegs {
|
|
|
|
if segment.GetSegmentState() == segmentTypeGrowing {
|
|
|
|
assert.Equal(t, UniqueID(0), segment.IndexID)
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, indexID, segment.IndexID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-07-04 15:10:20 +08:00
|
|
|
|
|
|
|
t.Run("test getSegmentIDsByVChannel", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer replica.freeAll()
|
|
|
|
|
2022-08-09 16:34:37 +08:00
|
|
|
pool, err := concurrency.NewPool(runtime.GOMAXPROCS(0))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-04 15:10:20 +08:00
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
collection := replica.addCollection(defaultCollectionID, schema)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID+1)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment1, err := newSegment(collection, UniqueID(1), defaultPartitionID, defaultCollectionID, "channel1", segmentTypeGrowing, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-07-04 15:10:20 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment2, err := newSegment(collection, UniqueID(2), defaultPartitionID+1, defaultCollectionID, "channel2", segmentTypeGrowing, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-07-04 15:10:20 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment3, err := newSegment(collection, UniqueID(3), defaultPartitionID+1, defaultCollectionID, "channel2", segmentTypeGrowing, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-07-04 15:10:20 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment3)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment4, err := newSegment(collection, UniqueID(4), defaultPartitionID, defaultCollectionID, "channel1", segmentTypeSealed, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-07-04 15:10:20 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment4)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
seg1, err := replica.getSegmentIDsByVChannel([]UniqueID{defaultPartitionID}, "channel1", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg1, err = replica.getSegmentIDsByVChannel([]UniqueID{}, "channel1", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg1, err = replica.getSegmentIDsByVChannel([]UniqueID{}, "channel1", segmentTypeSealed)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg1, err = replica.getSegmentIDsByVChannel(nil, "channel1", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg1, err = replica.getSegmentIDsByVChannel([]UniqueID{defaultPartitionID}, "channel1", segmentTypeSealed)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg1, err = replica.getSegmentIDsByVChannel(nil, "channel1", segmentTypeSealed)
|
|
|
|
assert.Equal(t, 1, len(seg1))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
seg0, err := replica.getSegmentIDsByVChannel([]UniqueID{defaultPartitionID}, "channel2", segmentTypeSealed)
|
|
|
|
assert.Equal(t, 0, len(seg0))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg0, err = replica.getSegmentIDsByVChannel([]UniqueID{defaultPartitionID}, "channel2", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 0, len(seg0))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
seg2, err := replica.getSegmentIDsByVChannel([]UniqueID{defaultPartitionID + 1}, "channel2", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 2, len(seg2))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg2, err = replica.getSegmentIDsByVChannel([]UniqueID{}, "channel2", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 2, len(seg2))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg2, err = replica.getSegmentIDsByVChannel(nil, "channel2", segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 2, len(seg2))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 21:30:51 +08:00
|
|
|
func TestMetaReplica_BlackList(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
collection := replica.addCollection(defaultCollectionID, schema)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID+1)
|
|
|
|
|
|
|
|
pool, err := concurrency.NewPool(runtime.GOMAXPROCS(0))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment1, err := newSegment(collection, UniqueID(1), defaultPartitionID, defaultCollectionID, "channel1", segmentTypeSealed, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-09-21 21:30:51 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment2, err := newSegment(collection, UniqueID(2), defaultPartitionID, defaultCollectionID, "channel2", segmentTypeSealed, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-09-21 21:30:51 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-07 19:37:04 +08:00
|
|
|
segment3, err := newSegment(collection, UniqueID(3), defaultPartitionID, defaultCollectionID, "channel2", segmentTypeGrowing, defaultSegmentVersion, defaultSegmentStartPosition, pool)
|
2022-09-21 21:30:51 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
replica.addSegmentsLoadingList([]UniqueID{1, 2, 3})
|
|
|
|
|
|
|
|
segments := replica.getSealedSegments()
|
|
|
|
assert.Equal(t, 0, len(segments))
|
|
|
|
|
|
|
|
segments = replica.getGrowingSegments()
|
|
|
|
assert.Equal(t, 0, len(segments))
|
|
|
|
|
|
|
|
// add segments
|
|
|
|
|
|
|
|
err = replica.setSegment(segment1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = replica.setSegment(segment3)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// no segments since all in black list
|
|
|
|
segments = replica.getSealedSegments()
|
|
|
|
assert.Equal(t, 0, len(segments))
|
|
|
|
|
|
|
|
// affect sealed segment only
|
|
|
|
segments = replica.getGrowingSegments()
|
|
|
|
assert.Equal(t, 1, len(segments))
|
|
|
|
|
|
|
|
replica.removeSegmentsLoadingList([]UniqueID{1, 2, 3})
|
|
|
|
|
|
|
|
segments = replica.getSealedSegments()
|
|
|
|
assert.Equal(t, 2, len(segments))
|
|
|
|
|
|
|
|
segments = replica.getGrowingSegments()
|
|
|
|
assert.Equal(t, 1, len(segments))
|
|
|
|
|
|
|
|
// try add black list, shall fail since all loaded before
|
|
|
|
replica.addSegmentsLoadingList([]UniqueID{1, 2, 3})
|
|
|
|
|
|
|
|
segments = replica.getSealedSegments()
|
|
|
|
assert.Equal(t, 2, len(segments))
|
|
|
|
|
|
|
|
segments = replica.getGrowingSegments()
|
|
|
|
assert.Equal(t, 1, len(segments))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-29 18:31:33 +08:00
|
|
|
func TestMetaReplica_removeCollectionVDeltaChannel(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// remove when collection not exists
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
replica.removeCollectionVDeltaChannel(-1, defaultDeltaChannel)
|
|
|
|
})
|
|
|
|
|
|
|
|
schema := genTestCollectionSchema()
|
|
|
|
collection := replica.addCollection(defaultCollectionID, schema)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID)
|
|
|
|
replica.addPartition(defaultCollectionID, defaultPartitionID+1)
|
|
|
|
|
|
|
|
collection.addVDeltaChannels([]string{defaultDeltaChannel})
|
|
|
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
replica.removeCollectionVDeltaChannel(defaultCollectionID, defaultDeltaChannel)
|
|
|
|
})
|
|
|
|
|
|
|
|
channels := collection.getVDeltaChannels()
|
|
|
|
assert.Equal(t, 0, len(channels))
|
|
|
|
}
|
|
|
|
|
2022-05-16 18:23:55 +08:00
|
|
|
func TestMetaReplica_freeAll(t *testing.T) {
|
2022-05-31 13:42:03 +08:00
|
|
|
replica, err := genSimpleReplica()
|
2021-02-05 10:53:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-05-31 13:42:03 +08:00
|
|
|
replica.freeAll()
|
|
|
|
num := replica.getCollectionNum()
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
num = replica.getPartitionNum()
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
num = replica.getSegmentNum(segmentTypeGrowing)
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
num = replica.getSegmentNum(segmentTypeSealed)
|
|
|
|
assert.Equal(t, 0, num)
|
2021-09-10 09:33:43 +08:00
|
|
|
}
|