This is an automated email from the ASF dual-hosted git repository.
lizhimin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 652f5bbba9 [ISSUE #6627] Fix ConsumerLagCalculator NPE if group or
topic is null (#6632)
652f5bbba9 is described below
commit 652f5bbba951e5b61dc1493751c44ceae3e5318e
Author: lizhimins <[email protected]>
AuthorDate: Tue Apr 25 10:25:13 2023 +0800
[ISSUE #6627] Fix ConsumerLagCalculator NPE if group or topic is null
(#6632)
Co-authored-by: 斜阳 <[email protected]>
---
.../rocketmq/broker/metrics/ConsumerLagCalculator.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git
a/broker/src/main/java/org/apache/rocketmq/broker/metrics/ConsumerLagCalculator.java
b/broker/src/main/java/org/apache/rocketmq/broker/metrics/ConsumerLagCalculator.java
index a1afe7e57e..7a5f1f765e 100644
---
a/broker/src/main/java/org/apache/rocketmq/broker/metrics/ConsumerLagCalculator.java
+++
b/broker/src/main/java/org/apache/rocketmq/broker/metrics/ConsumerLagCalculator.java
@@ -194,6 +194,10 @@ public class ConsumerLagCalculator {
public void calculateLag(Consumer<CalculateLagResult> lagRecorder) {
processAllGroup(info -> {
+ if (info.group == null || info.topic == null) {
+ return;
+ }
+
CalculateLagResult result = new CalculateLagResult(info.group,
info.topic, false);
Pair<Long, Long> lag = getConsumerLagStats(info.group, info.topic,
info.isPop);
@@ -260,6 +264,10 @@ public class ConsumerLagCalculator {
long total = 0L;
long earliestUnconsumedTimestamp = Long.MAX_VALUE;
+ if (group == null || topic == null) {
+ return new Pair<>(total, earliestUnconsumedTimestamp);
+ }
+
TopicConfig topicConfig = topicConfigManager.selectTopicConfig(topic);
if (topicConfig != null) {
for (int queueId = 0; queueId < topicConfig.getWriteQueueNums();
queueId++) {
@@ -313,6 +321,10 @@ public class ConsumerLagCalculator {
long total = 0L;
long earliestUnPulledTimestamp = Long.MAX_VALUE;
+ if (group == null || topic == null) {
+ return new Pair<>(total, earliestUnPulledTimestamp);
+ }
+
TopicConfig topicConfig = topicConfigManager.selectTopicConfig(topic);
if (topicConfig != null) {
for (int queueId = 0; queueId < topicConfig.getWriteQueueNums();
queueId++) {
@@ -363,6 +375,10 @@ public class ConsumerLagCalculator {
public long getAvailableMsgCount(String group, String topic, boolean
isPop) {
long total = 0L;
+ if (group == null || topic == null) {
+ return total;
+ }
+
TopicConfig topicConfig = topicConfigManager.selectTopicConfig(topic);
if (topicConfig != null) {
for (int queueId = 0; queueId < topicConfig.getWriteQueueNums();
queueId++) {