dawidwys commented on a change in pull request #17946:
URL: https://github.com/apache/flink/pull/17946#discussion_r759946453



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/ExecutionAttemptMappingProvider.java
##########
@@ -56,14 +56,16 @@ protected boolean removeEldestEntry(
     }
 
     public Optional<ExecutionVertex> getVertex(ExecutionAttemptID id) {
-        if (!cachedTasksById.containsKey(id)) {
-            cachedTasksById.putAll(getCurrentAttemptMappings());
+        synchronized (cachedTasksById) {

Review comment:
       I am thinking if the entire caching here is not overly complicated. As 
far as I understand it, we're rebuilding the entire `cachedTasksById` on each 
miss. Wouldn't it make more sense to do so explicitly? What do you think about 
code as follows?
   
   ```
       public Optional<ExecutionVertex> getVertex(ExecutionAttemptID id) {
           ExecutionVertex vertex = cachedTasksById.get(id);
           if (vertex != null) {
               return Optional.of(vertex);
           } else {
               return updateAndGet(id);
           }
       }
   
       private synchronized Optional<ExecutionVertex> 
updateAndGet(ExecutionAttemptID id) {
           ExecutionVertex vertex;
           // might've been updated by another thread
           vertex = cachedTasksById.get(id);
           if (vertex != null) {
               return Optional.of(vertex);
           }
           cachedTasksById = getCurrentAttemptMappings();
           return Optional.ofNullable(cachedTasksById.get(id));
       }
   ```




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