tillrohrmann commented on a change in pull request #11353: [FLINK-16438][yarn] 
Make YarnResourceManager starts workers using WorkerResourceSpec requested by 
SlotManager
URL: https://github.com/apache/flink/pull/11353#discussion_r404124170
 
 

 ##########
 File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
 ##########
 @@ -615,4 +632,85 @@ protected double getCpuCores(final Configuration 
configuration) {
                //noinspection NumericCastThatLosesPrecision
                return cpuCoresLong;
        }
+
+       /**
+        * Utility class for converting between Flink {@link 
WorkerResourceSpec} and Yarn {@link Resource}.
+        */
+       @VisibleForTesting
+       static class WorkerSpecContainerResourceAdapter {
+               private final Configuration flinkConfig;
+               private final int minMemMB;
+               private final int minVcore;
+               private final boolean matchVcores;
+               private final Map<WorkerResourceSpec, Resource> 
workerSpecToContainerResource;
+               private final Map<Resource, Collection<WorkerResourceSpec>> 
containerResourceToWorkerSpecs;
+               private final Map<Integer, Collection<Resource>> 
containerMemoryToContainerResource;
+
+               @VisibleForTesting
+               WorkerSpecContainerResourceAdapter(
+                               final Configuration flinkConfig,
+                               final int minMemMB,
+                               final int minVcore,
+                               final boolean matchVcores) {
+                       this.flinkConfig = 
Preconditions.checkNotNull(flinkConfig);
+                       this.minMemMB = minMemMB;
+                       this.minVcore = minVcore;
+                       this.matchVcores = matchVcores;
+                       workerSpecToContainerResource = new HashMap<>();
+                       containerResourceToWorkerSpecs = new HashMap<>();
+                       containerMemoryToContainerResource = new HashMap<>();
+               }
+
+               @VisibleForTesting
+               Resource getContainerResource(final WorkerResourceSpec 
workerResourceSpec) {
+                       return workerSpecToContainerResource.computeIfAbsent(
+                               Preconditions.checkNotNull(workerResourceSpec),
+                               this::createAndMapContainerResource);
+               }
+
+               @VisibleForTesting
+               Collection<WorkerResourceSpec> getWorkerSpecs(final Resource 
containerResource) {
+                       return 
getEquivalentContainerResource(containerResource).stream()
+                               .flatMap(resource -> 
containerResourceToWorkerSpecs.getOrDefault(resource, 
Collections.emptyList()).stream())
+                               .collect(Collectors.toList());
+               }
+
+               @VisibleForTesting
+               Collection<Resource> getEquivalentContainerResource(final 
Resource containerResource) {
+                       // Yarn might ignore the requested vcores, depending on 
its configurations.
+                       // In such cases, we should also not matching vcores.
+                       return matchVcores ?
+                               Collections.singletonList(containerResource) :
+                               
containerMemoryToContainerResource.getOrDefault(containerResource.getMemory(), 
Collections.emptyList());
+               }
+
+               private Resource createAndMapContainerResource(final 
WorkerResourceSpec workerResourceSpec) {
+                       // TODO: need to unset process/flink memory size from 
configuration if dynamic worker resource is activated
 
 Review comment:
   In general I agree unless it is not yet fully supported by the RM 
implementation. If it is, then I guess we also don't need this comment. If it 
is not supported, then the check state will help us to remember what needs to 
be changed.

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