Fix panic if channel not watched while getting shard leaders (#25820)

Signed-off-by: yah01 <yang.cen@zilliz.com>
pull/25718/head
yah01 2023-07-24 14:13:02 +08:00 committed by GitHub
parent f4e72cb170
commit dc37b4587e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

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

View File

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