azagrebin commented on a change in pull request #6599: [FLINK-10150][metrics] 
Fix OperatorMetricGroup creation for Batch
URL: https://github.com/apache/flink/pull/6599#discussion_r213666345
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/metrics/groups/TaskMetricGroup.java
 ##########
 @@ -144,15 +144,17 @@ public OperatorMetricGroup addOperator(OperatorID 
operatorID, String name) {
                        name = name.substring(0, 
METRICS_OPERATOR_NAME_MAX_LENGTH);
                }
                OperatorMetricGroup operator = new 
OperatorMetricGroup(this.registry, this, operatorID, name);
+               // unique OperatorIDs only exist in streaming, so we have to 
rely on the name for batch operators
+               final String key = operatorID + name;
 
                synchronized (this) {
-                       OperatorMetricGroup previous = 
operators.put(operatorID, operator);
+                       OperatorMetricGroup previous = operators.put(key, 
operator);
 
 Review comment:
   I suggest to reduce the code under `synchronized` using:
   ```
   return operators.putIfAbsent(key, operator);
   ```
   Also, I would rename `addOperator` function name to `getOrAddOperatorMetric`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to