@@ -1947,37 +1947,21 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx,
1947
1947
final RemotingCommand response = RemotingCommand .createResponseCommand (null );
1948
1948
try {
1949
1949
final GetConsumeStatsRequestHeader requestHeader = request .decodeCommandCustomHeader (GetConsumeStatsRequestHeader .class );
1950
- ConsumeStats consumeStats = new ConsumeStats ();
1950
+ List <String > topicListProvided = requestHeader .fetchTopicList ();
1951
+ String topicProvided = requestHeader .getTopic ();
1952
+ String group = requestHeader .getConsumerGroup ();
1951
1953
1952
- Set <String > topics = new HashSet <>();
1953
- if (UtilAll .isBlank (requestHeader .getTopic ())) {
1954
- topics = this .brokerController .getConsumerOffsetManager ().whichTopicByConsumer (requestHeader .getConsumerGroup ());
1955
- } else {
1956
- topics .add (requestHeader .getTopic ());
1957
- }
1954
+ ConsumeStats consumeStats = new ConsumeStats ();
1955
+ Set <String > topicsForCollecting = getTopicsForCollecting (topicListProvided , topicProvided , group );
1958
1956
1959
- for (String topic : topics ) {
1957
+ for (String topic : topicsForCollecting ) {
1960
1958
TopicConfig topicConfig = this .brokerController .getTopicConfigManager ().selectTopicConfig (topic );
1961
1959
if (null == topicConfig ) {
1962
1960
LOGGER .warn ("AdminBrokerProcessor#getConsumeStats: topic config does not exist, topic={}" , topic );
1963
1961
continue ;
1964
1962
}
1965
1963
1966
1964
TopicQueueMappingDetail mappingDetail = this .brokerController .getTopicQueueMappingManager ().getTopicQueueMapping (topic );
1967
-
1968
- {
1969
- SubscriptionData findSubscriptionData =
1970
- this .brokerController .getConsumerManager ().findSubscriptionData (requestHeader .getConsumerGroup (), topic );
1971
-
1972
- if (null == findSubscriptionData
1973
- && this .brokerController .getConsumerManager ().findSubscriptionDataCount (requestHeader .getConsumerGroup ()) > 0 ) {
1974
- LOGGER .warn (
1975
- "AdminBrokerProcessor#getConsumeStats: topic does not exist in consumer group's subscription, "
1976
- + "topic={}, consumer group={}" , topic , requestHeader .getConsumerGroup ());
1977
- continue ;
1978
- }
1979
- }
1980
-
1981
1965
for (int i = 0 ; i < topicConfig .getReadQueueNums (); i ++) {
1982
1966
MessageQueue mq = new MessageQueue ();
1983
1967
mq .setTopic (topic );
@@ -2038,6 +2022,37 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx,
2038
2022
return response ;
2039
2023
}
2040
2024
2025
+ private Set <String > getTopicsForCollecting (List <String > topicListProvided , String topicProvided , String group ) {
2026
+ Set <String > topicsForCollecting = new HashSet <>();
2027
+ if (!topicListProvided .isEmpty ()) {
2028
+ // if topic list is provided, only collect the topics in the list
2029
+ // and ignore subscription check
2030
+ topicsForCollecting .addAll (topicListProvided );
2031
+ } else {
2032
+ // In order to be compatible with the old logic,
2033
+ // even if the topic has been provided here, the subscription will be checked.
2034
+ if (UtilAll .isBlank (topicProvided )) {
2035
+ topicsForCollecting .addAll (
2036
+ this .brokerController .getConsumerOffsetManager ().whichTopicByConsumer (group ));
2037
+ } else {
2038
+ topicsForCollecting .add (topicProvided );
2039
+ }
2040
+ int subscriptionCount = this .brokerController .getConsumerManager ().findSubscriptionDataCount (group );
2041
+ Iterator <String > iterator = topicsForCollecting .iterator ();
2042
+ while (iterator .hasNext ()) {
2043
+ String topic = iterator .next ();
2044
+ SubscriptionData findSubscriptionData = this .brokerController .getConsumerManager ().findSubscriptionData (group , topic );
2045
+ if (findSubscriptionData == null && subscriptionCount > 0 ) {
2046
+ LOGGER .warn (
2047
+ "AdminBrokerProcessor#getConsumeStats: topic does not exist in consumer group's subscription, topic={}, consumer group={}" ,
2048
+ topic , group );
2049
+ iterator .remove ();
2050
+ }
2051
+ }
2052
+ }
2053
+ return topicsForCollecting ;
2054
+ }
2055
+
2041
2056
private RemotingCommand getAllConsumerOffset (ChannelHandlerContext ctx , RemotingCommand request ) {
2042
2057
final RemotingCommand response = RemotingCommand .createResponseCommand (null );
2043
2058
0 commit comments