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_r339086559
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/PartitionTrackerImpl.java
##########
@@ -122,6 +122,27 @@ public void
stopTrackingAndReleasePartitionsFor(ResourceID producingTaskExecutor
stopTrackingAndReleasePartitions(resultPartitionIds);
}
+ @Override
+ public void stopTrackingAndReleaseOrPromotePartitionsFor(ResourceID
producingTaskExecutorId) {
+ Preconditions.checkNotNull(producingTaskExecutorId);
+
+ // this is a bit icky since we make 2 calls to
pT#stopTrackingPartitions
+ Collection<ResultPartitionID> resultPartitionIds =
partitionTable.stopTrackingPartitions(producingTaskExecutorId);
+
+ // stop tracking partitions to be released and group them by
task executor ID
+ Map<ResourceID, List<ResultPartitionDeploymentDescriptor>>
partitionsToReleaseOrPromoteByResourceId = resultPartitionIds.stream()
+ .map(this::internalStopTrackingPartition)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
Review comment:
I see this pattern recurring multiple times in this class. What we actually
would like to have is something like `.flatMap(Optional::stream)`. Maybe we
should add a simple utility method for this which we add to `OptionalUtils`:
```
static <T> Stream<T> toStream(Optional<T> opt) {
if (opt.isPresent())
return Stream.of(opt.get());
else
return Stream.empty();
}
```
Then it would be `.flatMap(OptionalUtils::toStream)`.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services