diff --git a/internal/querynode/index_loader.go b/internal/querynode/index_loader.go index 43c1ea3f3e..0256813eda 100644 --- a/internal/querynode/index_loader.go +++ b/internal/querynode/index_loader.go @@ -205,6 +205,9 @@ func (loader *indexLoader) setIndexInfo(collectionID UniqueID, segment *Segment, if len(pathResponse.FilePaths) <= 0 { return errors.New("illegal index file paths") } + if len(pathResponse.FilePaths[0].IndexFilePaths) == 0 { + return errors.New("empty index paths") + } info := &indexInfo{ indexID: response.IndexID, diff --git a/internal/querynode/index_loader_test.go b/internal/querynode/index_loader_test.go index c2e47c96ab..4bd83825ef 100644 --- a/internal/querynode/index_loader_test.go +++ b/internal/querynode/index_loader_test.go @@ -111,6 +111,24 @@ func TestIndexLoader_loadIndex(t *testing.T) { assert.NoError(t, err) }) + t.Run("test set indexinfo with empty indexFilePath", func(t *testing.T) { + historical, err := genSimpleHistorical(ctx) + assert.NoError(t, err) + + segment, err := genSimpleSealedSegment() + assert.NoError(t, err) + + historical.loader.indexLoader.rootCoord = newMockRootCoord() + ic := newMockIndexCoord() + ic.idxFileInfo.IndexFilePaths = []string{} + + historical.loader.indexLoader.indexCoord = ic + + err = historical.loader.indexLoader.setIndexInfo(defaultCollectionID, segment, simpleVecField.id) + assert.Error(t, err) + + }) + //t.Run("test get index failed", func(t *testing.T) { // historical, err := genSimpleHistorical(ctx) // assert.NoError(t, err) diff --git a/internal/querynode/mock_components_test.go b/internal/querynode/mock_components_test.go index 05f4f36a1d..a1bcbd6867 100644 --- a/internal/querynode/mock_components_test.go +++ b/internal/querynode/mock_components_test.go @@ -177,10 +177,22 @@ func (m *mockRootCoord) GetMetrics(ctx context.Context, req *milvuspb.GetMetrics type mockIndexCoord struct { types.Component types.TimeTickProvider + + idxFileInfo *indexpb.IndexFilePathInfo } func newMockIndexCoord() *mockIndexCoord { - return &mockIndexCoord{} + paths, _ := generateIndex(defaultSegmentID) + return &mockIndexCoord{ + idxFileInfo: &indexpb.IndexFilePathInfo{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + }, + IndexBuildID: buildID, + IndexFilePaths: paths, + }, + } + } func (m *mockIndexCoord) BuildIndex(ctx context.Context, req *indexpb.BuildIndexRequest) (*indexpb.BuildIndexResponse, error) { @@ -196,27 +208,11 @@ func (m *mockIndexCoord) GetIndexStates(ctx context.Context, req *indexpb.GetInd } func (m *mockIndexCoord) GetIndexFilePaths(ctx context.Context, req *indexpb.GetIndexFilePathsRequest) (*indexpb.GetIndexFilePathsResponse, error) { - paths, err := generateIndex(defaultSegmentID) - if err != nil { - return &indexpb.GetIndexFilePathsResponse{ - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_UnexpectedError, - }, - }, nil - } return &indexpb.GetIndexFilePathsResponse{ Status: &commonpb.Status{ ErrorCode: commonpb.ErrorCode_Success, }, - FilePaths: []*indexpb.IndexFilePathInfo{ - { - Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, - }, - IndexBuildID: buildID, - IndexFilePaths: paths, - }, - }, + FilePaths: []*indexpb.IndexFilePathInfo{m.idxFileInfo}, }, nil }