diff --git a/internal/indexcoord/index_coord.go b/internal/indexcoord/index_coord.go index 32deb9f658..a5d407064c 100644 --- a/internal/indexcoord/index_coord.go +++ b/internal/indexcoord/index_coord.go @@ -361,6 +361,17 @@ func (i *IndexCoord) BuildIndex(ctx context.Context, req *indexpb.BuildIndexRequ zap.Strings("DataPath = ", req.DataPaths), zap.Any("TypeParams", req.TypeParams), zap.Any("IndexParams", req.IndexParams)) + if !i.isHealthy() { + errMsg := "IndexCoord is not healthy" + err := errors.New(errMsg) + log.Warn(errMsg) + return &indexpb.BuildIndexResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_UnexpectedError, + Reason: errMsg, + }, + }, err + } sp, ctx := trace.StartSpanFromContextWithOperationName(ctx, "IndexCoord-BuildIndex") defer sp.Finish() hasIndex, indexBuildID := i.metaTable.HasSameReq(req) diff --git a/internal/indexcoord/index_coord_test.go b/internal/indexcoord/index_coord_test.go index 6ec39568d1..0f2c44d360 100644 --- a/internal/indexcoord/index_coord_test.go +++ b/internal/indexcoord/index_coord_test.go @@ -247,3 +247,12 @@ func TestIndexCoord_GetComponentStates(t *testing.T) { assert.NoError(t, err) assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode) } + +func TestIndexCoord_NotHealthy(t *testing.T) { + ic := &IndexCoord{} + ic.stateCode.Store(internalpb.StateCode_Abnormal) + req := &indexpb.BuildIndexRequest{} + resp, err := ic.BuildIndex(context.Background(), req) + assert.Error(t, err) + assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.Status.ErrorCode) +}