wang-jiahua commented on code in PR #10485:
URL: https://github.com/apache/rocketmq/pull/10485#discussion_r3400419460


##########
broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java:
##########
@@ -195,12 +203,32 @@ public AttributesBuilder newAttributesBuilder() {
         return attributesBuilder;
     }
 
+    public Attributes getOrBuildTopicAttributes(String topic, String 
messageType, boolean isSystem) {
+        Attributes lastAttrs = this.lastTopicAttributes;
+        if (lastAttrs != null && isSystem == this.lastTopicIsSystem && 
topic.equals(this.lastTopicName) && messageType.equals(this.lastTopicMsgType)) {
+            return lastAttrs;
+        }

Review Comment:
   Same rationale as above — this is an idempotent query cache. A torn-read 
across the 4 volatile fields can only produce a stale cache miss (falling 
through to the CHM which always returns the correct result). Metrics precision 
impact is negligible.



##########
broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java:
##########
@@ -195,12 +203,32 @@ public AttributesBuilder newAttributesBuilder() {
         return attributesBuilder;
     }
 
+    public Attributes getOrBuildTopicAttributes(String topic, String 
messageType, boolean isSystem) {
+        Attributes lastAttrs = this.lastTopicAttributes;
+        if (lastAttrs != null && isSystem == this.lastTopicIsSystem && 
topic.equals(this.lastTopicName) && messageType.equals(this.lastTopicMsgType)) {
+            return lastAttrs;
+        }
+        String cacheKey = topic + '|' + messageType + '|' + isSystem;
+        Attributes attrs = topicAttributesCache.computeIfAbsent(cacheKey, k ->
+            newAttributesBuilder()
+                .put(LABEL_TOPIC_KEY, topic)
+                .put(LABEL_MESSAGE_TYPE_KEY, messageType)
+                .put(LABEL_IS_SYSTEM_KEY, isSystem)
+                .build()
+        );
+        this.lastTopicName = topic;
+        this.lastTopicMsgType = messageType;
+        this.lastTopicIsSystem = isSystem;
+        this.lastTopicAttributes = attrs;
+        return attrs;
+    }

Review Comment:
   Duplicate of the above comment — same answer applies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to