diff --git a/internal/querycoordv2/services.go b/internal/querycoordv2/services.go index 28eaed08d6..d76ccb8d72 100644 --- a/internal/querycoordv2/services.go +++ b/internal/querycoordv2/services.go @@ -894,6 +894,9 @@ func (s *Server) GetShardLeaders(ctx context.Context, req *querypb.GetShardLeade addrs := make([]string, 0, len(leaders)) var channelErr error + if len(leaders) == 0 { + channelErr = merr.WrapErrChannelLack("channel not subscribed") + } // In a replica, a shard is available, if and only if: // 1. The leader is online diff --git a/internal/querycoordv2/services_test.go b/internal/querycoordv2/services_test.go index 28daee919c..ae9a02c820 100644 --- a/internal/querycoordv2/services_test.go +++ b/internal/querycoordv2/services_test.go @@ -1533,6 +1533,19 @@ func (suite *ServiceSuite) TestGetShardLeadersFailed() { suite.Equal(commonpb.ErrorCode_NoReplicaAvailable, resp.GetStatus().GetErrorCode()) } + // channel not subscribed + for _, node := range suite.nodes { + suite.dist.LeaderViewManager.Update(node) + } + for _, collection := range suite.collections { + req := &querypb.GetShardLeadersRequest{ + CollectionID: collection, + } + resp, err := server.GetShardLeaders(ctx, req) + suite.NoError(err) + suite.ErrorIs(merr.Error(resp.GetStatus()), merr.ErrChannelNotAvailable) + } + // collection not loaded req := &querypb.GetShardLeadersRequest{ CollectionID: -1,