From 2ef2228ad03b9d872a7e3d26d8c28afc9c63c9d4 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Fri, 17 Dec 2021 23:10:42 +0800 Subject: [PATCH] Check component state before get index files (#13578) Signed-off-by: Cai.Zhang --- internal/indexcoord/index_coord.go | 11 +++++++++++ internal/indexcoord/index_coord_test.go | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/internal/indexcoord/index_coord.go b/internal/indexcoord/index_coord.go index de04cd3871..fca5fe48cb 100644 --- a/internal/indexcoord/index_coord.go +++ b/internal/indexcoord/index_coord.go @@ -541,6 +541,17 @@ func (i *IndexCoord) DropIndex(ctx context.Context, req *indexpb.DropIndexReques // GetIndexFilePaths gets the index file paths from IndexCoord. func (i *IndexCoord) GetIndexFilePaths(ctx context.Context, req *indexpb.GetIndexFilePathsRequest) (*indexpb.GetIndexFilePathsResponse, error) { log.Debug("IndexCoord GetIndexFilePaths", zap.Int64s("IndexBuildIds", req.IndexBuildIDs)) + if !i.isHealthy() { + errMsg := "IndexCoord is not healthy" + log.Warn(errMsg) + return &indexpb.GetIndexFilePathsResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_UnexpectedError, + Reason: errMsg, + }, + FilePaths: nil, + }, nil + } sp, _ := trace.StartSpanFromContextWithOperationName(ctx, "IndexCoord-BuildIndex") defer sp.Finish() var indexPaths []*indexpb.IndexFilePathInfo diff --git a/internal/indexcoord/index_coord_test.go b/internal/indexcoord/index_coord_test.go index dad2126bae..8d1cb42cd2 100644 --- a/internal/indexcoord/index_coord_test.go +++ b/internal/indexcoord/index_coord_test.go @@ -277,4 +277,11 @@ func TestIndexCoord_NotHealthy(t *testing.T) { resp2, err := ic.GetIndexStates(context.Background(), req3) assert.Nil(t, err) assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp2.Status.ErrorCode) + + req4 := &indexpb.GetIndexFilePathsRequest{ + IndexBuildIDs: []UniqueID{1, 2}, + } + resp4, err := ic.GetIndexFilePaths(context.Background(), req4) + assert.Nil(t, err) + assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp4.Status.ErrorCode) }