Check the indexcoord state before building index (#12451)

Signed-off-by: Cai.Zhang <cai.zhang@zilliz.com>
pull/12666/head
cai.zhang 2021-12-02 23:11:35 +08:00 committed by GitHub
parent 567c657310
commit ed546d0a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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)

View File

@ -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)
}