Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix load index with empty file list #26236

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/querycoordv2/checkers/index_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/querycoordv2/checkers/index_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion internal/querynodev2/segments/segment_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 20 additions & 0 deletions internal/querynodev2/segments/segment_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down