szetszwo commented on code in PR #1346:
URL: https://github.com/apache/ratis/pull/1346#discussion_r2794657577


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/MessageMetrics.java:
##########
@@ -58,17 +58,9 @@ private static RatisMetricRegistry createRegistry(String 
endpointId, String endp
   }
 
   private void inc(String metricNamePrefix, Type t) {
-    types.get(t)
-        .computeIfAbsent(metricNamePrefix, prefix -> 
getRegistry().counter(prefix + t.getSuffix()))
-        .inc();
-    final Map<String, LongCounter> counters = types.get(t);
-    LongCounter c = counters.get(metricNamePrefix);
-    if (c == null) {
-      synchronized (counters) {
-        c = counters.computeIfAbsent(metricNamePrefix, prefix -> 
getRegistry().counter(prefix + t.getSuffix()));
-      }
-    }
-    c.inc();
+    final LongCounter counter = types.get(t)
+        .computeIfAbsent(metricNamePrefix, prefix -> 
getRegistry().counter(prefix + t.getSuffix()));
+    counter.inc();

Review Comment:
   @slfan1989 , thanks a lot for working on this!
   
   You are right that the second computeIfAbsent is useless.  The change looks 
good.  Could you keep the first three lines unchanged as below?  
   
   ```java
     private void inc(String metricNamePrefix, Type t) {
       types.get(t)
           .computeIfAbsent(metricNamePrefix, prefix -> 
getRegistry().counter(prefix + t.getSuffix()))
           .inc();
     }
   ```



-- 
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