This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 2db6015fb fix(litetopic): sum sharded parent counts and per-broker
group backlog across masters (#7344)
2db6015fb is described below
commit 2db6015fb73b312198672d51dac20c0dd0b8ed8e
Author: bob <[email protected]>
AuthorDate: Fri Nov 27 11:59:33 2026 +0800
fix(litetopic): sum sharded parent counts and per-broker group backlog
across masters (#7344)
---
.../provider/apache/RocketMQLiteTopicProvider.java | 44 ++++++++++++++++------
.../apache/RocketMQLiteTopicProviderTest.java | 28 ++++++++++++++
2 files changed, 60 insertions(+), 12 deletions(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProvider.java
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProvider.java
index 9be5f5473..6496ee51d 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProvider.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProvider.java
@@ -195,9 +195,10 @@ public class RocketMQLiteTopicProvider implements
LiteTopicProvider {
return;
}
// A parent topic can be sharded across brokers; the group
binding is reported
- // by whichever broker owns the lite topic, so union
across masters.
+ // by whichever broker owns the lite topic, so union
across masters and remember
+ // which master reported each group for the per-broker
backlog lookups.
parents.computeIfAbsent(parent, key -> new
ParentTopicAccumulator(key, master))
- .groups.addAll(groups);
+ .recordGroups(master, groups);
});
}
}
@@ -215,13 +216,21 @@ public class RocketMQLiteTopicProvider implements
LiteTopicProvider {
summary.setMaxTTL(ttlMillis);
int topicCount = 0;
- try {
- GetParentTopicInfoResponseBody parentInfo =
admin.getParentTopicInfo(parent.brokerAddr, parent.parentTopic);
- if (parentInfo != null) {
- topicCount = Math.max(parentInfo.getLiteTopicCount(), 0);
+ Set<String> countMasters = parent.reportingMasters.isEmpty()
+ ? Set.of(parent.firstBrokerAddr)
+ : parent.reportingMasters;
+ for (String master : countMasters) {
+ try {
+ GetParentTopicInfoResponseBody parentInfo =
admin.getParentTopicInfo(master, parent.parentTopic);
+ if (parentInfo != null) {
+ // A sharded parent exists on every master that reported
it, so the total
+ // lite topic count is the sum across those brokers.
+ topicCount += Math.max(parentInfo.getLiteTopicCount(), 0);
+ }
+ } catch (Exception failure) {
+ log.debug("Failed to read parent topic info for {} on {}: {}",
+ parent.parentTopic, master, failure.getMessage());
}
- } catch (Exception failure) {
- log.debug("Failed to read parent topic info for {}: {}",
parent.parentTopic, failure.getMessage());
}
long totalBacklog = 0;
@@ -230,7 +239,9 @@ public class RocketMQLiteTopicProvider implements
LiteTopicProvider {
int consumerCount = 0;
int sessionBudget = MAX_LITE_SESSION_SCAN;
for (String group : parent.groups) {
- totalBacklog += groupLag(admin, parent.brokerAddr, group);
+ for (String brokerAddr : parent.groupBrokers.getOrDefault(group,
Set.of(parent.firstBrokerAddr))) {
+ totalBacklog += groupLag(admin, brokerAddr, group);
+ }
for (Connection connection : consumerConnections(admin, group)) {
if (sessionBudget-- <= 0) {
log.warn("LiteTopic session scan for {} truncated at {}
sessions",
@@ -714,21 +725,30 @@ public class RocketMQLiteTopicProvider implements
LiteTopicProvider {
/** One parent topic observed across broker masters, with its TTL and
bound consumer groups. */
private static final class ParentTopicAccumulator {
private final String parentTopic;
- private String brokerAddr;
+ private final String firstBrokerAddr;
+ private final Set<String> reportingMasters = new LinkedHashSet<>();
private final Set<String> groups = new LinkedHashSet<>();
+ private final Map<String, Set<String>> groupBrokers = new
LinkedHashMap<>();
private int ttlMinutes = -1;
private ParentTopicAccumulator(String parentTopic, String brokerAddr) {
this.parentTopic = parentTopic;
- this.brokerAddr = brokerAddr;
+ this.firstBrokerAddr = brokerAddr;
}
private void merge(String brokerAddr, Integer ttlMinutes) {
- this.brokerAddr = brokerAddr;
+ reportingMasters.add(brokerAddr);
if (ttlMinutes != null && ttlMinutes > this.ttlMinutes) {
this.ttlMinutes = ttlMinutes;
}
}
+
+ private void recordGroups(String brokerAddr, Set<String> reported) {
+ groups.addAll(reported);
+ for (String group : reported) {
+ groupBrokers.computeIfAbsent(group, key -> new
LinkedHashSet<>()).add(brokerAddr);
+ }
+ }
}
/** The broker master that reported a client's lite subscription, plus
that client's info. */
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProviderTest.java
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProviderTest.java
index 2a5bb8162..71e3861b6 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProviderTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQLiteTopicProviderTest.java
@@ -229,6 +229,34 @@ class RocketMQLiteTopicProviderTest {
});
}
+ @Test
+ void listLiteTopicsSumsShardedParentsAcrossMasters() throws Exception {
+ String brokerB = "broker-b:10911";
+ String otherGroup = "lite-group-2";
+ when(admin.examineBrokerClusterInfo()).thenReturn(cluster(BROKER_A,
brokerB));
+
+ GetBrokerLiteInfoResponseBody infoA = brokerLiteInfo(PARENT, 30, 1,
GROUP);
+ when(admin.getBrokerLiteInfo(BROKER_A)).thenReturn(infoA);
+ GetBrokerLiteInfoResponseBody infoB = brokerLiteInfo(PARENT, 40, 1,
otherGroup);
+ when(admin.getBrokerLiteInfo(brokerB)).thenReturn(infoB);
+ when(admin.getParentTopicInfo(BROKER_A,
PARENT)).thenReturn(parentTopicInfo(PARENT, 30, 1));
+ when(admin.getParentTopicInfo(brokerB,
PARENT)).thenReturn(parentTopicInfo(PARENT, 40, 1));
+ when(admin.getLiteGroupInfo(BROKER_A, GROUP, null,
1)).thenReturn(lag(7));
+ when(admin.getLiteGroupInfo(brokerB, otherGroup, null,
1)).thenReturn(lag(5));
+ when(admin.examineConsumerConnectionInfo(GROUP)).thenReturn(new
ConsumerConnection());
+ when(admin.examineConsumerConnectionInfo(otherGroup)).thenReturn(new
ConsumerConnection());
+
+ List<LiteTopicSummary> summaries = provider.listLiteTopics(null, null);
+
+ assertThat(summaries).singleElement().satisfies(summary -> {
+ // The parent is sharded across both masters, so the lite topic
count and the
+ // backlog must be summed per reporting master rather than read
from one broker.
+ assertThat(summary.getTopicCount()).isEqualTo(2);
+ assertThat(summary.getTotalBacklog()).isEqualTo(12L);
+
assertThat(summary.getAverageTTL()).isEqualTo(TimeUnit.MINUTES.toMillis(40));
+ });
+ }
+
@Test
void listLiteTopicsFiltersByPatternCaseInsensitively() throws Exception {
when(admin.examineBrokerClusterInfo()).thenReturn(cluster(BROKER_A));