diff --git a/internal/querycoordv2/checkers/index_checker.go b/internal/querycoordv2/checkers/index_checker.go index a8d95b384f2c9833ecca2e83733736d5f5337a3a..fd935ee4ebb715931c9accdf480e6fe039e5e8a0 100644 --- a/internal/querycoordv2/checkers/index_checker.go +++ b/internal/querycoordv2/checkers/index_checker.go @@ -102,7 +102,9 @@ func (c *IndexChecker) checkReplica(ctx context.Context, collection *meta.Collec continue } for _, info := range infos { - if missingFields.Contain(info.GetFieldID()) && info.GetEnableIndex() { + if missingFields.Contain(info.GetFieldID()) && + info.GetEnableIndex() && + len(info.GetIndexFilePaths()) > 0 { segmentsToUpdate.Insert(segment) } } diff --git a/internal/querycoordv2/checkers/index_checker_test.go b/internal/querycoordv2/checkers/index_checker_test.go index fd140a869f8854dc79f31ceacb185e560073a8e0..8eb66df2d407ea46f8b2466d7c1182655c5ec9b8 100644 --- a/internal/querycoordv2/checkers/index_checker_test.go +++ b/internal/querycoordv2/checkers/index_checker_test.go @@ -97,9 +97,10 @@ func (suite *IndexCheckerSuite) TestLoadIndex() { suite.broker.EXPECT().GetIndexInfo(mock.Anything, int64(1), int64(2)). Return([]*querypb.FieldIndexInfo{ { - FieldID: 101, - IndexID: 1000, - EnableIndex: true, + FieldID: 101, + IndexID: 1000, + EnableIndex: true, + IndexFilePaths: []string{"index"}, }, }, nil) diff --git a/internal/querynodev2/segments/segment_loader.go b/internal/querynodev2/segments/segment_loader.go index dcb6c206a9876485de4edf906f35cd1c150ce0dc..f3c477a27b66d2c109997eea5dd265d7affe065b 100644 --- a/internal/querynodev2/segments/segment_loader.go +++ b/internal/querynodev2/segments/segment_loader.go @@ -470,7 +470,7 @@ func (loader *segmentLoader) loadSegment(ctx context.Context, if segment.Type() == SegmentTypeSealed { fieldID2IndexInfo := make(map[int64]*querypb.FieldIndexInfo) for _, indexInfo := range loadInfo.IndexInfos { - if len(indexInfo.IndexFilePaths) > 0 { + if len(indexInfo.GetIndexFilePaths()) > 0 { fieldID := indexInfo.FieldID fieldID2IndexInfo[fieldID] = indexInfo } @@ -947,6 +947,11 @@ func (loader *segmentLoader) LoadIndex(ctx context.Context, segment *LocalSegmen func(info *datapb.FieldBinlog) (int64, *datapb.FieldBinlog) { return info.GetFieldID(), info }) for _, info := range loadInfo.GetIndexInfos() { + if len(info.GetIndexFilePaths()) == 0 { + log.Warn("failed to add index for segment, index file list is empty, the segment may be too small") + return merr.WrapErrIndexNotFound("index file list empty") + } + fieldInfo, ok := fieldInfos[info.GetFieldID()] if !ok { return merr.WrapErrParameterInvalid("index info with corresponding field info", "missing field info", strconv.FormatInt(fieldInfo.GetFieldID(), 10)) diff --git a/internal/querynodev2/segments/segment_loader_test.go b/internal/querynodev2/segments/segment_loader_test.go index cba0d14332cdc4eb81e66772bac80203046ccc8d..6e276088a6339fa022380fe5e0a0154f3187de7c 100644 --- a/internal/querynodev2/segments/segment_loader_test.go +++ b/internal/querynodev2/segments/segment_loader_test.go @@ -28,6 +28,7 @@ import ( "github.com/milvus-io/milvus/internal/storage" "github.com/milvus-io/milvus/internal/util/initcore" "github.com/milvus-io/milvus/pkg/util/funcutil" + "github.com/milvus-io/milvus/pkg/util/merr" "github.com/milvus-io/milvus/pkg/util/metric" "github.com/milvus-io/milvus/pkg/util/paramtable" ) @@ -352,6 +353,25 @@ func (suite *SegmentLoaderSuite) TestLoadDeltaLogs() { } } +func (suite *SegmentLoaderSuite) TestLoadIndex() { + ctx := context.Background() + segment := &LocalSegment{} + loadInfo := &querypb.SegmentLoadInfo{ + SegmentID: 1, + PartitionID: suite.partitionID, + CollectionID: suite.collectionID, + IndexInfos: []*querypb.FieldIndexInfo{ + { + IndexFilePaths: []string{}, + }, + }, + } + + err := suite.loader.LoadIndex(ctx, segment, loadInfo) + suite.ErrorIs(err, merr.ErrIndexNotFound) + +} + func (suite *SegmentLoaderSuite) TestLoadWithMmap() { key := paramtable.Get().QueryNodeCfg.MmapDirPath.Key paramtable.Get().Save(key, "/tmp/mmap-test")