2023-03-27 00:42:00 +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
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package segments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-05-07 19:13:35 +08:00
|
|
|
"fmt"
|
2023-03-27 00:42:00 +08:00
|
|
|
"math/rand"
|
|
|
|
"testing"
|
2023-09-08 16:41:16 +08:00
|
|
|
"time"
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-09-08 16:41:16 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/stretchr/testify/suite"
|
2024-05-06 20:29:30 +08:00
|
|
|
"go.uber.org/atomic"
|
2023-04-06 19:14:32 +08:00
|
|
|
|
2023-09-08 16:41:16 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2024-02-23 10:00:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2023-03-27 00:42:00 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2023-06-25 14:38:44 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/initcore"
|
2023-11-02 23:52:16 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2024-05-10 19:17:30 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/contextutil"
|
2023-04-20 11:32:31 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
2024-05-10 11:53:30 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/indexparamcheck"
|
2023-08-09 18:39:16 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-07-19 16:16:58 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/metric"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-03-27 00:42:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type SegmentLoaderSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
loader Loader
|
|
|
|
|
|
|
|
// Dependencies
|
2023-05-11 15:33:24 +08:00
|
|
|
manager *Manager
|
2023-08-01 10:33:04 +08:00
|
|
|
rootPath string
|
2023-05-11 15:33:24 +08:00
|
|
|
chunkManager storage.ChunkManager
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
// Data
|
|
|
|
collectionID int64
|
|
|
|
partitionID int64
|
|
|
|
segmentID int64
|
|
|
|
schema *schemapb.CollectionSchema
|
2023-06-25 14:38:44 +08:00
|
|
|
segmentNum int
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderSuite) SetupSuite() {
|
|
|
|
paramtable.Init()
|
2023-08-01 10:33:04 +08:00
|
|
|
suite.rootPath = suite.T().Name()
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.collectionID = rand.Int63()
|
|
|
|
suite.partitionID = rand.Int63()
|
|
|
|
suite.segmentID = rand.Int63()
|
2023-06-25 14:38:44 +08:00
|
|
|
suite.segmentNum = 5
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderSuite) SetupTest() {
|
|
|
|
// Dependencies
|
2023-05-11 15:33:24 +08:00
|
|
|
suite.manager = NewManager()
|
2023-06-25 14:38:44 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
// TODO:: cpp chunk manager not support local chunk manager
|
2023-09-21 09:45:27 +08:00
|
|
|
// suite.chunkManager = storage.NewLocalChunkManager(storage.RootPath(
|
2023-06-25 14:38:44 +08:00
|
|
|
// fmt.Sprintf("/tmp/milvus-ut/%d", rand.Int63())))
|
2024-03-22 13:57:06 +08:00
|
|
|
chunkManagerFactory := storage.NewTestChunkManagerFactory(paramtable.Get(), suite.rootPath)
|
2023-06-25 14:38:44 +08:00
|
|
|
suite.chunkManager, _ = chunkManagerFactory.NewPersistentStorageChunkManager(ctx)
|
2023-05-11 15:33:24 +08:00
|
|
|
suite.loader = NewLoader(suite.manager, suite.chunkManager)
|
2023-06-25 14:38:44 +08:00
|
|
|
initcore.InitRemoteChunkManager(paramtable.Get())
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
// Data
|
2024-03-14 05:32:54 +08:00
|
|
|
suite.schema = GenTestCollectionSchema("test", schemapb.DataType_Int64, false)
|
2023-11-02 23:52:16 +08:00
|
|
|
indexMeta := GenTestIndexMeta(suite.collectionID, suite.schema)
|
2023-03-27 00:42:00 +08:00
|
|
|
loadMeta := &querypb.LoadMetaInfo{
|
|
|
|
LoadType: querypb.LoadType_LoadCollection,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
PartitionIDs: []int64{suite.partitionID},
|
|
|
|
}
|
2023-11-02 23:52:16 +08:00
|
|
|
suite.manager.Collection.PutOrRef(suite.collectionID, suite.schema, indexMeta, loadMeta)
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TearDownTest() {
|
|
|
|
ctx := context.Background()
|
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
2024-05-06 20:29:30 +08:00
|
|
|
suite.manager.Segment.Remove(context.Background(), suite.segmentID+int64(i), querypb.DataScope_All)
|
2023-06-25 14:38:44 +08:00
|
|
|
}
|
2023-08-01 10:33:04 +08:00
|
|
|
suite.chunkManager.RemoveWithPrefix(ctx, suite.rootPath)
|
2023-06-25 14:38:44 +08:00
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoad() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 4
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
// Load sealed
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Load growing
|
|
|
|
binlogs, statsLogs, err = SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID+1,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID + 1,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
}
|
|
|
|
|
2023-12-26 00:46:46 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadFail() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
msgLength := 4
|
|
|
|
|
|
|
|
// Load sealed
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID,
|
|
|
|
msgLength,
|
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// make file & binlog mismatch
|
|
|
|
for _, binlog := range binlogs {
|
|
|
|
for _, log := range binlog.GetBinlogs() {
|
|
|
|
log.LogPath = log.LogPath + "-suffix"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-12-26 00:46:46 +08:00
|
|
|
})
|
|
|
|
suite.Error(err)
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadMultipleSegments() {
|
|
|
|
ctx := context.Background()
|
2023-06-25 14:38:44 +08:00
|
|
|
loadInfos := make([]*querypb.SegmentLoadInfo, 0, suite.segmentNum)
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-03-27 00:42:00 +08:00
|
|
|
// Load sealed
|
2023-06-25 14:38:44 +08:00
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
2023-03-27 00:42:00 +08:00
|
|
|
segmentID := suite.segmentID + int64(i)
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err := suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Won't load bloom filter with sealed segments
|
|
|
|
for _, segment := range segments {
|
|
|
|
for pk := 0; pk < 100; pk++ {
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
lc := storage.NewLocationsCache(storage.NewInt64PrimaryKey(int64(pk)))
|
|
|
|
exist := segment.MayPkExist(lc)
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.Require().False(exist)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load growing
|
|
|
|
loadInfos = loadInfos[:0]
|
2023-06-25 14:38:44 +08:00
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
|
|
|
segmentID := suite.segmentID + int64(suite.segmentNum) + int64(i)
|
2023-03-27 00:42:00 +08:00
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
// Should load bloom filter with growing segments
|
|
|
|
for _, segment := range segments {
|
|
|
|
for pk := 0; pk < 100; pk++ {
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
lc := storage.NewLocationsCache(storage.NewInt64PrimaryKey(int64(pk)))
|
|
|
|
exist := segment.MayPkExist(lc)
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.True(exist)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderSuite) TestLoadWithIndex() {
|
|
|
|
ctx := context.Background()
|
2023-06-25 14:38:44 +08:00
|
|
|
loadInfos := make([]*querypb.SegmentLoadInfo, 0, suite.segmentNum)
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-03-27 00:42:00 +08:00
|
|
|
// Load sealed
|
2023-06-25 14:38:44 +08:00
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
2023-03-27 00:42:00 +08:00
|
|
|
segmentID := suite.segmentID + int64(i)
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
2023-04-20 11:32:31 +08:00
|
|
|
vecFields := funcutil.GetVecFieldIDs(suite.schema)
|
2023-03-27 00:42:00 +08:00
|
|
|
indexInfo, err := GenAndSaveIndex(
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-04-20 11:32:31 +08:00
|
|
|
vecFields[0],
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
IndexFaissIVFFlat,
|
2023-07-19 16:16:58 +08:00
|
|
|
metric.L2,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
IndexInfos: []*querypb.FieldIndexInfo{indexInfo},
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err := suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
2023-04-20 11:32:31 +08:00
|
|
|
vecFields := funcutil.GetVecFieldIDs(suite.schema)
|
2023-03-27 00:42:00 +08:00
|
|
|
for _, segment := range segments {
|
2023-04-20 11:32:31 +08:00
|
|
|
suite.True(segment.ExistIndex(vecFields[0]))
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderSuite) TestLoadBloomFilter() {
|
|
|
|
ctx := context.Background()
|
2023-06-25 14:38:44 +08:00
|
|
|
loadInfos := make([]*querypb.SegmentLoadInfo, 0, suite.segmentNum)
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-03-27 00:42:00 +08:00
|
|
|
// Load sealed
|
2023-06-25 14:38:44 +08:00
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
2023-03-27 00:42:00 +08:00
|
|
|
segmentID := suite.segmentID + int64(i)
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
bfs, err := suite.loader.LoadBloomFilterSet(ctx, suite.collectionID, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
for _, bf := range bfs {
|
|
|
|
for pk := 0; pk < 100; pk++ {
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
lc := storage.NewLocationsCache(storage.NewInt64PrimaryKey(int64(pk)))
|
|
|
|
exist := bf.MayPkExist(lc)
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.Require().True(exist)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderSuite) TestLoadDeltaLogs() {
|
|
|
|
ctx := context.Background()
|
2023-06-25 14:38:44 +08:00
|
|
|
loadInfos := make([]*querypb.SegmentLoadInfo, 0, suite.segmentNum)
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-03-27 00:42:00 +08:00
|
|
|
// Load sealed
|
2023-06-25 14:38:44 +08:00
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
2023-03-27 00:42:00 +08:00
|
|
|
segmentID := suite.segmentID + int64(i)
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Delete PKs 1, 2
|
|
|
|
deltaLogs, err := SaveDeltaLog(suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
Deltalogs: deltaLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-27 00:42:00 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err := suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
for _, segment := range segments {
|
|
|
|
suite.Equal(int64(100-2), segment.RowNum())
|
|
|
|
for pk := 0; pk < 100; pk++ {
|
|
|
|
if pk == 1 || pk == 2 {
|
|
|
|
continue
|
|
|
|
}
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
lc := storage.NewLocationsCache(storage.NewInt64PrimaryKey(int64(pk)))
|
|
|
|
exist := segment.MayPkExist(lc)
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.Require().True(exist)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 16:21:23 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadDupDeltaLogs() {
|
|
|
|
ctx := context.Background()
|
|
|
|
loadInfos := make([]*querypb.SegmentLoadInfo, 0, suite.segmentNum)
|
|
|
|
|
|
|
|
msgLength := 100
|
|
|
|
// Load sealed
|
|
|
|
for i := 0; i < suite.segmentNum; i++ {
|
|
|
|
segmentID := suite.segmentID + int64(i)
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
|
|
|
msgLength,
|
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Delete PKs 1, 2
|
|
|
|
deltaLogs, err := SaveDeltaLog(suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
loadInfos = append(loadInfos, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
Deltalogs: deltaLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-09-19 16:21:23 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err := suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, loadInfos...)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
for i, segment := range segments {
|
|
|
|
suite.Equal(int64(100-2), segment.RowNum())
|
|
|
|
for pk := 0; pk < 100; pk++ {
|
|
|
|
if pk == 1 || pk == 2 {
|
|
|
|
continue
|
|
|
|
}
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
lc := storage.NewLocationsCache(storage.NewInt64PrimaryKey(int64(pk)))
|
|
|
|
exist := segment.MayPkExist(lc)
|
2023-09-19 16:21:23 +08:00
|
|
|
suite.Require().True(exist)
|
|
|
|
}
|
|
|
|
|
|
|
|
seg := segment.(*LocalSegment)
|
|
|
|
// nothing would happen as the delta logs have been all applied,
|
|
|
|
// so the released segment won't cause error
|
2024-05-06 20:29:30 +08:00
|
|
|
seg.Release(ctx)
|
2023-09-19 16:21:23 +08:00
|
|
|
loadInfos[i].Deltalogs[0].Binlogs[0].TimestampTo--
|
|
|
|
err := suite.loader.LoadDeltaLogs(ctx, seg, loadInfos[i].GetDeltalogs())
|
|
|
|
suite.NoError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 18:39:16 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadIndex() {
|
|
|
|
ctx := context.Background()
|
|
|
|
loadInfo := &querypb.SegmentLoadInfo{
|
|
|
|
SegmentID: 1,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
IndexInfos: []*querypb.FieldIndexInfo{
|
|
|
|
{
|
|
|
|
IndexFilePaths: []string{},
|
|
|
|
},
|
|
|
|
},
|
2024-05-07 19:13:35 +08:00
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-08-09 18:39:16 +08:00
|
|
|
}
|
2024-05-06 20:29:30 +08:00
|
|
|
segment := &LocalSegment{
|
|
|
|
baseSegment: baseSegment{
|
|
|
|
loadInfo: atomic.NewPointer[querypb.SegmentLoadInfo](loadInfo),
|
|
|
|
},
|
|
|
|
}
|
2023-08-09 18:39:16 +08:00
|
|
|
|
2023-08-11 11:21:32 +08:00
|
|
|
err := suite.loader.LoadIndex(ctx, segment, loadInfo, 0)
|
2023-08-09 18:39:16 +08:00
|
|
|
suite.ErrorIs(err, merr.ErrIndexNotFound)
|
|
|
|
}
|
|
|
|
|
2024-05-10 11:53:30 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadIndexWithLimitedResource() {
|
|
|
|
ctx := context.Background()
|
|
|
|
loadInfo := &querypb.SegmentLoadInfo{
|
|
|
|
SegmentID: 1,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
IndexInfos: []*querypb.FieldIndexInfo{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
IndexFilePaths: []string{},
|
|
|
|
IndexParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: common.IndexTypeKey,
|
|
|
|
Value: indexparamcheck.IndexINVERTED,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BinlogPaths: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
2024-05-15 12:59:34 +08:00
|
|
|
LogSize: 1000000000,
|
|
|
|
MemorySize: 1000000000,
|
2024-05-10 11:53:30 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
segment := &LocalSegment{
|
|
|
|
baseSegment: baseSegment{
|
|
|
|
loadInfo: atomic.NewPointer[querypb.SegmentLoadInfo](loadInfo),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
paramtable.Get().QueryNodeCfg.DiskCapacityLimit.SwapTempValue("100000")
|
|
|
|
err := suite.loader.LoadIndex(ctx, segment, loadInfo, 0)
|
|
|
|
suite.Error(err)
|
|
|
|
}
|
|
|
|
|
2023-03-28 21:30:05 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestLoadWithMmap() {
|
|
|
|
key := paramtable.Get().QueryNodeCfg.MmapDirPath.Key
|
|
|
|
paramtable.Get().Save(key, "/tmp/mmap-test")
|
|
|
|
defer paramtable.Get().Reset(key)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2023-11-02 23:52:16 +08:00
|
|
|
collection := suite.manager.Collection.Get(suite.collectionID)
|
|
|
|
for _, field := range collection.Schema().GetFields() {
|
|
|
|
field.TypeParams = append(field.TypeParams, &commonpb.KeyValuePair{
|
|
|
|
Key: common.MmapEnabledKey,
|
|
|
|
Value: "true",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-03-28 21:30:05 +08:00
|
|
|
// Load sealed
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-03-28 21:30:05 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-03-28 21:30:05 +08:00
|
|
|
})
|
|
|
|
suite.NoError(err)
|
|
|
|
}
|
|
|
|
|
2023-05-06 14:24:39 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestPatchEntryNum() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength := 100
|
2023-05-06 14:24:39 +08:00
|
|
|
segmentID := suite.segmentID
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-05-06 14:24:39 +08:00
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
vecFields := funcutil.GetVecFieldIDs(suite.schema)
|
|
|
|
indexInfo, err := GenAndSaveIndex(
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
segmentID,
|
|
|
|
vecFields[0],
|
2023-06-25 14:38:44 +08:00
|
|
|
msgLength,
|
2023-05-06 14:24:39 +08:00
|
|
|
IndexFaissIVFFlat,
|
2023-07-19 16:16:58 +08:00
|
|
|
metric.L2,
|
2023-05-06 14:24:39 +08:00
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
loadInfo := &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
IndexInfos: []*querypb.FieldIndexInfo{indexInfo},
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-05-06 14:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// mock legacy binlog entry num is zero case
|
|
|
|
for _, fieldLog := range binlogs {
|
|
|
|
for _, binlog := range fieldLog.GetBinlogs() {
|
|
|
|
binlog.EntriesNum = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
segments, err := suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, loadInfo)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
suite.Require().Equal(1, len(segments))
|
|
|
|
|
|
|
|
segment := segments[0]
|
|
|
|
info := segment.GetIndex(vecFields[0])
|
|
|
|
suite.Require().NotNil(info)
|
|
|
|
|
|
|
|
for _, binlog := range info.FieldBinlog.GetBinlogs() {
|
|
|
|
suite.Greater(binlog.EntriesNum, int64(0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 17:41:01 +08:00
|
|
|
func (suite *SegmentLoaderSuite) TestRunOutMemory() {
|
|
|
|
ctx := context.Background()
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.OverloadedMemoryThresholdPercentage.Key, "0")
|
2024-01-12 18:10:51 +08:00
|
|
|
defer paramtable.Get().Reset(paramtable.Get().QueryNodeCfg.OverloadedMemoryThresholdPercentage.Key)
|
2023-07-25 17:41:01 +08:00
|
|
|
|
|
|
|
msgLength := 4
|
|
|
|
|
|
|
|
// Load sealed
|
|
|
|
binlogs, statsLogs, err := SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID,
|
|
|
|
msgLength,
|
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-07-25 17:41:01 +08:00
|
|
|
})
|
|
|
|
suite.Error(err)
|
|
|
|
|
|
|
|
// Load growing
|
|
|
|
binlogs, statsLogs, err = SaveBinLog(ctx,
|
|
|
|
suite.collectionID,
|
|
|
|
suite.partitionID,
|
|
|
|
suite.segmentID+1,
|
|
|
|
msgLength,
|
|
|
|
suite.schema,
|
|
|
|
suite.chunkManager,
|
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID + 1,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-07-25 17:41:01 +08:00
|
|
|
})
|
|
|
|
suite.Error(err)
|
|
|
|
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.MmapDirPath.Key, "./mmap")
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeSealed, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-07-25 17:41:01 +08:00
|
|
|
})
|
|
|
|
suite.Error(err)
|
|
|
|
_, err = suite.loader.Load(ctx, suite.collectionID, SegmentTypeGrowing, 0, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID + 1,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
Statslogs: statsLogs,
|
|
|
|
NumOfRows: int64(msgLength),
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-07-25 17:41:01 +08:00
|
|
|
})
|
|
|
|
suite.Error(err)
|
|
|
|
}
|
|
|
|
|
2023-09-08 16:41:16 +08:00
|
|
|
type SegmentLoaderDetailSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
loader *segmentLoader
|
|
|
|
manager *Manager
|
|
|
|
segmentManager *MockSegmentManager
|
|
|
|
collectionManager *MockCollectionManager
|
|
|
|
|
|
|
|
rootPath string
|
|
|
|
chunkManager storage.ChunkManager
|
|
|
|
|
|
|
|
// Data
|
|
|
|
collectionID int64
|
|
|
|
partitionID int64
|
|
|
|
segmentID int64
|
|
|
|
schema *schemapb.CollectionSchema
|
|
|
|
segmentNum int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderDetailSuite) SetupSuite() {
|
|
|
|
paramtable.Init()
|
|
|
|
suite.rootPath = suite.T().Name()
|
|
|
|
suite.collectionID = rand.Int63()
|
|
|
|
suite.partitionID = rand.Int63()
|
|
|
|
suite.segmentID = rand.Int63()
|
|
|
|
suite.segmentNum = 5
|
2024-03-14 05:32:54 +08:00
|
|
|
suite.schema = GenTestCollectionSchema("test", schemapb.DataType_Int64, false)
|
2023-09-08 16:41:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderDetailSuite) SetupTest() {
|
|
|
|
// Dependencies
|
|
|
|
suite.collectionManager = NewMockCollectionManager(suite.T())
|
|
|
|
suite.segmentManager = NewMockSegmentManager(suite.T())
|
|
|
|
suite.manager = &Manager{
|
|
|
|
Segment: suite.segmentManager,
|
|
|
|
Collection: suite.collectionManager,
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2024-03-22 13:57:06 +08:00
|
|
|
chunkManagerFactory := storage.NewTestChunkManagerFactory(paramtable.Get(), suite.rootPath)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.chunkManager, _ = chunkManagerFactory.NewPersistentStorageChunkManager(ctx)
|
|
|
|
suite.loader = NewLoader(suite.manager, suite.chunkManager)
|
|
|
|
initcore.InitRemoteChunkManager(paramtable.Get())
|
|
|
|
|
|
|
|
// Data
|
2024-03-14 05:32:54 +08:00
|
|
|
schema := GenTestCollectionSchema("test", schemapb.DataType_Int64, false)
|
2023-09-08 16:41:16 +08:00
|
|
|
|
|
|
|
indexMeta := GenTestIndexMeta(suite.collectionID, schema)
|
|
|
|
loadMeta := &querypb.LoadMetaInfo{
|
|
|
|
LoadType: querypb.LoadType_LoadCollection,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
PartitionIDs: []int64{suite.partitionID},
|
|
|
|
}
|
|
|
|
|
2024-03-21 11:59:12 +08:00
|
|
|
collection := NewCollection(suite.collectionID, schema, indexMeta, loadMeta)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.collectionManager.EXPECT().Get(suite.collectionID).Return(collection).Maybe()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SegmentLoaderDetailSuite) TestWaitSegmentLoadDone() {
|
|
|
|
suite.Run("wait_success", func() {
|
|
|
|
idx := 0
|
|
|
|
|
|
|
|
var infos []*querypb.SegmentLoadInfo
|
2024-06-14 15:35:56 +08:00
|
|
|
suite.segmentManager.EXPECT().Exist(mock.Anything, mock.Anything).Return(false)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.segmentManager.EXPECT().GetWithType(suite.segmentID, SegmentTypeSealed).RunAndReturn(func(segmentID int64, segmentType commonpb.SegmentState) Segment {
|
|
|
|
defer func() { idx++ }()
|
|
|
|
if idx == 0 {
|
|
|
|
go func() {
|
|
|
|
<-time.After(time.Second)
|
|
|
|
suite.loader.notifyLoadFinish(infos...)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2024-03-01 14:21:10 +08:00
|
|
|
suite.segmentManager.EXPECT().UpdateBy(mock.Anything, mock.Anything, mock.Anything).Return(0)
|
2024-03-13 10:01:07 +08:00
|
|
|
infos = suite.loader.prepare(context.Background(), SegmentTypeSealed, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
NumOfRows: 100,
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-09-08 16:41:16 +08:00
|
|
|
})
|
|
|
|
|
2024-03-01 14:21:10 +08:00
|
|
|
err := suite.loader.waitSegmentLoadDone(context.Background(), SegmentTypeSealed, []int64{suite.segmentID}, 0)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.Run("wait_failure", func() {
|
|
|
|
suite.SetupTest()
|
|
|
|
|
|
|
|
var idx int
|
|
|
|
var infos []*querypb.SegmentLoadInfo
|
2024-06-14 15:35:56 +08:00
|
|
|
suite.segmentManager.EXPECT().Exist(mock.Anything, mock.Anything).Return(false)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.segmentManager.EXPECT().GetWithType(suite.segmentID, SegmentTypeSealed).RunAndReturn(func(segmentID int64, segmentType commonpb.SegmentState) Segment {
|
|
|
|
defer func() { idx++ }()
|
|
|
|
if idx == 0 {
|
|
|
|
go func() {
|
|
|
|
<-time.After(time.Second)
|
|
|
|
suite.loader.unregister(infos...)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2024-03-13 10:01:07 +08:00
|
|
|
infos = suite.loader.prepare(context.Background(), SegmentTypeSealed, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
NumOfRows: 100,
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-09-08 16:41:16 +08:00
|
|
|
})
|
|
|
|
|
2024-03-01 14:21:10 +08:00
|
|
|
err := suite.loader.waitSegmentLoadDone(context.Background(), SegmentTypeSealed, []int64{suite.segmentID}, 0)
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.Error(err)
|
|
|
|
})
|
2023-09-10 07:41:18 +08:00
|
|
|
|
|
|
|
suite.Run("wait_timeout", func() {
|
|
|
|
suite.SetupTest()
|
|
|
|
|
2024-06-14 15:35:56 +08:00
|
|
|
suite.segmentManager.EXPECT().Exist(mock.Anything, mock.Anything).Return(false)
|
2023-09-10 07:41:18 +08:00
|
|
|
suite.segmentManager.EXPECT().GetWithType(suite.segmentID, SegmentTypeSealed).RunAndReturn(func(segmentID int64, segmentType commonpb.SegmentState) Segment {
|
|
|
|
return nil
|
|
|
|
})
|
2024-03-13 10:01:07 +08:00
|
|
|
suite.loader.prepare(context.Background(), SegmentTypeSealed, &querypb.SegmentLoadInfo{
|
2024-05-07 19:13:35 +08:00
|
|
|
SegmentID: suite.segmentID,
|
|
|
|
PartitionID: suite.partitionID,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
NumOfRows: 100,
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
2023-09-10 07:41:18 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
|
2024-03-01 14:21:10 +08:00
|
|
|
err := suite.loader.waitSegmentLoadDone(ctx, SegmentTypeSealed, []int64{suite.segmentID}, 0)
|
2023-09-10 07:41:18 +08:00
|
|
|
suite.Error(err)
|
|
|
|
suite.True(merr.IsCanceledOrTimeout(err))
|
|
|
|
})
|
2023-09-08 16:41:16 +08:00
|
|
|
}
|
|
|
|
|
2024-02-20 14:34:51 +08:00
|
|
|
func (suite *SegmentLoaderDetailSuite) TestRequestResource() {
|
|
|
|
suite.Run("out_of_memory_zero_info", func() {
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.OverloadedMemoryThresholdPercentage.Key, "0")
|
|
|
|
defer paramtable.Get().Reset(paramtable.Get().QueryNodeCfg.OverloadedMemoryThresholdPercentage.Key)
|
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
_, err := suite.loader.requestResource(context.Background())
|
2024-02-20 14:34:51 +08:00
|
|
|
suite.NoError(err)
|
|
|
|
})
|
2024-02-23 10:00:54 +08:00
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
loadInfo := &querypb.SegmentLoadInfo{
|
|
|
|
SegmentID: 100,
|
|
|
|
CollectionID: suite.collectionID,
|
|
|
|
Level: datapb.SegmentLevel_L0,
|
|
|
|
Deltalogs: []*datapb.FieldBinlog{
|
|
|
|
{
|
|
|
|
Binlogs: []*datapb.Binlog{
|
2024-05-15 12:59:34 +08:00
|
|
|
{LogSize: 10000, MemorySize: 10000},
|
|
|
|
{LogSize: 12000, MemorySize: 12000},
|
2024-05-10 19:17:30 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InsertChannel: fmt.Sprintf("by-dev-rootcoord-dml_0_%dv0", suite.collectionID),
|
|
|
|
}
|
|
|
|
|
2024-02-23 10:00:54 +08:00
|
|
|
suite.Run("l0_segment_deltalog", func() {
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.DeltaDataExpansionRate.Key, "50")
|
|
|
|
defer paramtable.Get().Reset(paramtable.Get().QueryNodeCfg.DeltaDataExpansionRate.Key)
|
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
resource, err := suite.loader.requestResource(context.Background(), loadInfo)
|
|
|
|
|
|
|
|
suite.NoError(err)
|
|
|
|
suite.EqualValues(1100000, resource.Resource.MemorySize)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.Run("request_resource_with_timeout", func() {
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.DeltaDataExpansionRate.Key, "50")
|
|
|
|
defer paramtable.Get().Reset(paramtable.Get().QueryNodeCfg.DeltaDataExpansionRate.Key)
|
2024-02-23 10:00:54 +08:00
|
|
|
|
2024-05-10 19:17:30 +08:00
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.LazyLoadRequestResourceTimeout.Key, "500")
|
|
|
|
paramtable.Get().Save(paramtable.Get().QueryNodeCfg.LazyLoadRequestResourceRetryInterval.Key, "100")
|
|
|
|
resource, err := suite.loader.requestResourceWithTimeout(context.Background(), loadInfo)
|
2024-02-23 10:00:54 +08:00
|
|
|
suite.NoError(err)
|
|
|
|
suite.EqualValues(1100000, resource.MemorySize)
|
2024-05-10 19:17:30 +08:00
|
|
|
|
|
|
|
suite.loader.committedResource.Add(LoadResource{
|
|
|
|
MemorySize: 1024 * 1024 * 1024 * 1024,
|
|
|
|
})
|
|
|
|
|
|
|
|
timeoutErr := errors.New("timeout")
|
|
|
|
ctx, cancel := contextutil.WithTimeoutCause(context.Background(), 1000*time.Millisecond, timeoutErr)
|
|
|
|
defer cancel()
|
|
|
|
resource, err = suite.loader.requestResourceWithTimeout(ctx, loadInfo)
|
|
|
|
suite.Error(err)
|
|
|
|
suite.ErrorIs(err, timeoutErr)
|
2024-02-23 10:00:54 +08:00
|
|
|
})
|
2024-02-20 14:34:51 +08:00
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func TestSegmentLoader(t *testing.T) {
|
|
|
|
suite.Run(t, &SegmentLoaderSuite{})
|
2023-09-08 16:41:16 +08:00
|
|
|
suite.Run(t, &SegmentLoaderDetailSuite{})
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|