Github user pnowojski commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4840#discussion_r146819586
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/legacy/metrics/MetricStore.java
 ---
    @@ -260,50 +293,66 @@ public String getMetric(String name, String 
defaultValue) {
                                ? value
                                : defaultValue;
                }
    -   }
     
    -   /**
    -    * Sub-structure containing metrics of the JobManager.
    -    */
    -   public static class JobManagerMetricStore extends ComponentMetricStore {
    +           public static ComponentMetricStore 
unmodifiable(ComponentMetricStore source) {
    +                   if (source == null) {
    +                           return null;
    +                   }
    +                   return new 
ComponentMetricStore(unmodifiableMap(source.metrics));
    +           }
        }
     
        /**
         * Sub-structure containing metrics of a single TaskManager.
         */
    +   @ThreadSafe
        public static class TaskManagerMetricStore extends ComponentMetricStore 
{
    -           public final Set<String> garbageCollectorNames = new 
HashSet<>();
    +           public final Set<String> garbageCollectorNames;
    +
    +           public TaskManagerMetricStore() {
    +                   this(new ConcurrentHashMap<>(), 
ConcurrentHashMap.newKeySet());
    +           }
    +
    +           public TaskManagerMetricStore(Map<String, String> metrics, 
Set<String> garbageCollectorNames) {
    +                   super(metrics);
    +                   this.garbageCollectorNames = 
checkNotNull(garbageCollectorNames);
    +           }
     
                public void addGarbageCollectorName(String name) {
                        garbageCollectorNames.add(name);
                }
    +
    +           public static TaskManagerMetricStore 
unmodifiable(TaskManagerMetricStore source) {
    --- End diff --
    
    Then you pay costs of copying all of the objects, which is much higher 
compared to the synchronisation. But yes, you can do that. In that case you 
don't need concurrent hash maps. 
    
    If you intend to go in other direction with this and leave the current code 
in the master as it is, please log the work in Jira for this after the release 
(I will close release blocker issue for which I started this PR). However I 
have an impression that any follow up work would be easier on top of this 
change and in the mean time this is still way better then current code on 
master branch with this external synchronisation.  


---

Reply via email to