From 5c98329f7c17a1d048d411495117c3637ad0f39a Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 10 May 2022 19:47:53 +0800 Subject: [PATCH] Return error when no replica available (#16886) Signed-off-by: Congqi Xia --- internal/querycoord/impl.go | 10 ++++++++++ internal/querycoord/impl_test.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/querycoord/impl.go b/internal/querycoord/impl.go index 11bdd2d95..eb77c61fd 100644 --- a/internal/querycoord/impl.go +++ b/internal/querycoord/impl.go @@ -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), diff --git a/internal/querycoord/impl_test.go b/internal/querycoord/impl_test.go index bc794eaf2..bd78d60e5 100644 --- a/internal/querycoord/impl_test.go +++ b/internal/querycoord/impl_test.go @@ -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 -- GitLab