This is an automated email from the ASF dual-hosted git repository.

lizhanhui 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 4ea8d1ff6c refactor(LmqBrokerStatsManager): extract common method to 
eliminate duplicate logic (#9034)
4ea8d1ff6c is described below

commit 4ea8d1ff6c3c306454ec23d4e4bba4db0b9987fc
Author: asapple <65564735+asap...@users.noreply.github.com>
AuthorDate: Sat Dec 7 17:59:46 2024 +0800

    refactor(LmqBrokerStatsManager): extract common method to eliminate 
duplicate logic (#9034)
    
    Extracted the duplicated logic of replacing group and topic with LMQ_PREFIX 
based on configuration into a common method, improving code structure and 
maintainability.
---
 .../store/stats/LmqBrokerStatsManager.java         | 116 +++------------------
 1 file changed, 17 insertions(+), 99 deletions(-)

diff --git 
a/store/src/main/java/org/apache/rocketmq/store/stats/LmqBrokerStatsManager.java
 
b/store/src/main/java/org/apache/rocketmq/store/stats/LmqBrokerStatsManager.java
index 20ed879331..4caea19f56 100644
--- 
a/store/src/main/java/org/apache/rocketmq/store/stats/LmqBrokerStatsManager.java
+++ 
b/store/src/main/java/org/apache/rocketmq/store/stats/LmqBrokerStatsManager.java
@@ -30,139 +30,57 @@ public class LmqBrokerStatsManager extends 
BrokerStatsManager {
 
     @Override
     public void incGroupGetNums(final String group, final String topic, final 
int incValue) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incGroupGetNums(lmqGroup, lmqTopic, incValue);
+        super.incGroupGetNums(getAdjustedGroup(group), 
getAdjustedTopic(topic), incValue);
     }
 
     @Override
     public void incGroupGetSize(final String group, final String topic, final 
int incValue) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incGroupGetSize(lmqGroup, lmqTopic, incValue);
+        super.incGroupGetSize(getAdjustedGroup(group), 
getAdjustedTopic(topic), incValue);
     }
 
     @Override
     public void incGroupAckNums(final String group, final String topic, final 
int incValue) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incGroupAckNums(lmqGroup, lmqTopic, incValue);
+        super.incGroupAckNums(getAdjustedGroup(group), 
getAdjustedTopic(topic), incValue);
     }
 
     @Override
     public void incGroupCkNums(final String group, final String topic, final 
int incValue) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incGroupCkNums(lmqGroup, lmqTopic, incValue);
+        super.incGroupCkNums(getAdjustedGroup(group), getAdjustedTopic(topic), 
incValue);
     }
 
     @Override
     public void incGroupGetLatency(final String group, final String topic, 
final int queueId, final int incValue) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incGroupGetLatency(lmqGroup, lmqTopic, queueId, incValue);
+        super.incGroupGetLatency(getAdjustedGroup(group), 
getAdjustedTopic(topic), queueId, incValue);
     }
 
     @Override
     public void incSendBackNums(final String group, final String topic) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.incSendBackNums(lmqGroup, lmqTopic);
+        super.incSendBackNums(getAdjustedGroup(group), 
getAdjustedTopic(topic));
     }
 
     @Override
     public double tpsGroupGetNums(final String group, final String topic) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        return super.tpsGroupGetNums(lmqGroup, lmqTopic);
+        return super.tpsGroupGetNums(getAdjustedGroup(group), 
getAdjustedTopic(topic));
     }
 
     @Override
     public void recordDiskFallBehindTime(final String group, final String 
topic, final int queueId,
         final long fallBehind) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.recordDiskFallBehindTime(lmqGroup, lmqTopic, queueId, 
fallBehind);
+        super.recordDiskFallBehindTime(getAdjustedGroup(group), 
getAdjustedTopic(topic), queueId, fallBehind);
     }
 
     @Override
     public void recordDiskFallBehindSize(final String group, final String 
topic, final int queueId,
         final long fallBehind) {
-        String lmqGroup = group;
-        String lmqTopic = topic;
-        if (!brokerConfig.isEnableLmqStats()) {
-            if (MixAll.isLmq(group)) {
-                lmqGroup = MixAll.LMQ_PREFIX;
-            }
-            if (MixAll.isLmq(topic)) {
-                lmqTopic = MixAll.LMQ_PREFIX;
-            }
-        }
-        super.recordDiskFallBehindSize(lmqGroup, lmqTopic, queueId, 
fallBehind);
+        super.recordDiskFallBehindSize(getAdjustedGroup(group), 
getAdjustedTopic(topic), queueId, fallBehind);
+    }
+
+    private String getAdjustedGroup(String group) {
+        return !brokerConfig.isEnableLmqStats() && MixAll.isLmq(group) ? 
MixAll.LMQ_PREFIX : group;
+    }
+
+    private String getAdjustedTopic(String topic) {
+        return !brokerConfig.isEnableLmqStats() && MixAll.isLmq(topic) ? 
MixAll.LMQ_PREFIX : topic;
     }
 
 }

Reply via email to