tillrohrmann commented on a change in pull request #9960: [FLINK-14476] Extend 
PartitionTracker to support promotions
URL: https://github.com/apache/flink/pull/9960#discussion_r340536894
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/PartitionTrackerImpl.java
 ##########
 @@ -173,12 +199,69 @@ private void internalReleasePartitionsOnTaskExecutor(
                }
        }
 
-       private void 
internalReleasePartitionsOnShuffleMaster(Collection<ResultPartitionDeploymentDescriptor>
 partitionDeploymentDescriptors) {
-               partitionDeploymentDescriptors.stream()
+       private void internalReleaseOrPromotePartitionsOnTaskExecutor(
+               ResourceID potentialPartitionLocation,
+               Collection<ResultPartitionDeploymentDescriptor> 
partitionDeploymentDescriptors) {
+
+               final Set<ResultPartitionID> partitionsRequiringRpcReleaseCalls 
=
+                       getPartitionsToReleaseOrPromote(
+                               partitionDeploymentDescriptors,
+                               filterByPersistence(false));
+
+               final Set<ResultPartitionID> partitionsRequiringRpcPromoteCalls 
=
+                       getPartitionsToReleaseOrPromote(
+                               partitionDeploymentDescriptors,
+                               filterByPersistence(true));
+
+               if (!partitionsRequiringRpcReleaseCalls.isEmpty() || 
!partitionsRequiringRpcPromoteCalls.isEmpty()) {
+                       taskExecutorGatewayLookup
+                               .lookup(potentialPartitionLocation)
+                               .ifPresent(taskExecutorGateway ->
+                                       
taskExecutorGateway.releaseOrPromotePartitions(jobId, 
partitionsRequiringRpcReleaseCalls, partitionsRequiringRpcPromoteCalls));
+               }
+       }
+
+       private static Set<ResultPartitionID> getPartitionsToReleaseOrPromote(
+                       Collection<ResultPartitionDeploymentDescriptor> 
partitionDeploymentDescriptors,
+                       Predicate<ResultPartitionDeploymentDescriptor> 
persistenceFilter) {
+
+               return partitionDeploymentDescriptors.stream()
+                       
.filter(PartitionTrackerImpl::excludePartitionsWithoutLocalResources)
+                       .filter(persistenceFilter)
+                       .map(PartitionTrackerImpl::getResultPartitionId)
+                       .collect(Collectors.toSet());
+       }
+
+       private void 
internalReleasePartitionsOnShuffleMaster(Stream<ResultPartitionDeploymentDescriptor>
 partitionDeploymentDescriptors) {
+               partitionDeploymentDescriptors
                        
.map(ResultPartitionDeploymentDescriptor::getShuffleDescriptor)
                        .forEach(shuffleMaster::releasePartitionExternally);
        }
 
+       private static <X> Stream<X> asStream(Optional<X> optional) {
+               if (optional.isPresent()) {
+                       return Stream.of(optional.get());
+               } else {
+                       return Stream.empty();
+               }
+       }
 
 Review comment:
   Shall we make this an utility for other components as well? We could add 
`OptionalUtils` to `flink-core`.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to