Return error when no replica available (#16886)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2022-05-10 19:47:53 +08:00 committed by GitHub
parent 000c5ff3de
commit 5c98329f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -1200,6 +1200,16 @@ func (qc *QueryCoord) GetShardLeaders(ctx context.Context, req *querypb.GetShard
shardLeaderLists = append(shardLeaderLists, shard)
}
// all replicas are not available
if len(shardLeaderLists) == 0 {
return &querypb.GetShardLeadersResponse{
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: "no replica available",
},
}, nil
}
log.Info("GetShardLeaders finished",
zap.String("role", typeutil.QueryCoordRole),
zap.Int64("collectionID", req.CollectionID),

View File

@ -1683,6 +1683,14 @@ func TestGetShardLeaders(t *testing.T) {
}
assert.Equal(t, 0, totalLeaders%3)
// mock replica all down, without triggering load balance
queryCoord.cluster.stopNode(node1.queryNodeID)
queryCoord.cluster.stopNode(node2.queryNodeID)
queryCoord.cluster.stopNode(node3.queryNodeID)
resp, err = queryCoord.GetShardLeaders(ctx, getShardLeadersReq)
assert.NoError(t, err)
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.Status.ErrorCode)
// TODO(yah01): Disable the unit test case for now,
// restore it after the rebalance between replicas feature is implemented