From 961e9379c6090f260d2dfd7060dbafb424896b7e Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Thu, 9 Dec 2021 11:43:09 +0800 Subject: [PATCH] Check the indexcoord state before get index state (#12452) Signed-off-by: Cai.Zhang --- internal/indexcoord/index_coord.go | 10 ++++++++++ internal/indexcoord/index_coord_test.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/internal/indexcoord/index_coord.go b/internal/indexcoord/index_coord.go index 4c070c7f1e..3f04a46f29 100644 --- a/internal/indexcoord/index_coord.go +++ b/internal/indexcoord/index_coord.go @@ -435,6 +435,16 @@ func (i *IndexCoord) BuildIndex(ctx context.Context, req *indexpb.BuildIndexRequ // GetIndexStates gets the index states from IndexCoord. func (i *IndexCoord) GetIndexStates(ctx context.Context, req *indexpb.GetIndexStatesRequest) (*indexpb.GetIndexStatesResponse, error) { log.Debug("IndexCoord get index states", zap.Int64s("IndexBuildIDs", req.IndexBuildIDs)) + if !i.isHealthy() { + errMsg := "IndexCoord is not healthy" + log.Warn(errMsg) + return &indexpb.GetIndexStatesResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_UnexpectedError, + Reason: errMsg, + }, + }, nil + } sp, _ := trace.StartSpanFromContextWithOperationName(ctx, "IndexCoord-BuildIndex") defer sp.Finish() var ( diff --git a/internal/indexcoord/index_coord_test.go b/internal/indexcoord/index_coord_test.go index 6ffe6693ad..f01093a427 100644 --- a/internal/indexcoord/index_coord_test.go +++ b/internal/indexcoord/index_coord_test.go @@ -260,4 +260,9 @@ func TestIndexCoord_NotHealthy(t *testing.T) { status, err := ic.DropIndex(context.Background(), req2) assert.Nil(t, err) assert.Equal(t, commonpb.ErrorCode_UnexpectedError, status.ErrorCode) + + req3 := &indexpb.GetIndexStatesRequest{} + resp2, err := ic.GetIndexStates(context.Background(), req3) + assert.Nil(t, err) + assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp2.Status.ErrorCode) }