You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/09/19 08:33:24 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #9697: [FLINK-14094] [runtime] [metric] Fix OperatorIOMetricGroup repeat register problem

tillrohrmann commented on a change in pull request #9697: [FLINK-14094] [runtime] [metric] Fix OperatorIOMetricGroup repeat register problem
URL: https://github.com/apache/flink/pull/9697#discussion_r326051179
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/metrics/groups/TaskMetricGroup.java
 ##########
 @@ -143,20 +143,17 @@ public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name)
 			LOG.warn("The operator name {} exceeded the {} characters length limit and was truncated.", name, METRICS_OPERATOR_NAME_MAX_LENGTH);
 			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;
+		if (operators.containsKey(key)) {
+			return operators.get(key);
+		}
 
+		OperatorMetricGroup operator = new OperatorMetricGroup(this.registry, this, operatorID, name);
 		synchronized (this) {
-			OperatorMetricGroup previous = operators.put(key, operator);
-			if (previous == null) {
-				// no operator group so far
-				return operator;
-			} else {
-				// already had an operator group. restore that one.
-				operators.put(key, previous);
-				return previous;
-			}
+			operators.put(key, operator);
+			return operator;
 
 Review comment:
   I'd suggest to do it the following way:
   
   ```
   public OperatorMetricGroup getOrAddOperator(OperatorID operatorID, String name) {
   		final String metricName;
   		if (name != null && name.length() > METRICS_OPERATOR_NAME_MAX_LENGTH) {
   			LOG.warn("The operator name {} exceeded the {} characters length limit and was truncated.", name, METRICS_OPERATOR_NAME_MAX_LENGTH);
   			metricName = name.substring(0, METRICS_OPERATOR_NAME_MAX_LENGTH);
   		} else {
   			metricName = name;
   		}
   		// unique OperatorIDs only exist in streaming, so we have to rely on the name for batch operators
   		final String key = operatorID + metricName;
   
   		synchronized (this) {
   			return operators.computeIfAbsent(key, ignored -> new OperatorMetricGroup(this.registry, this, operatorID, metricName));
   		}
   	}
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services