You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/04/27 04:02:15 UTC

[GitHub] [flink] KarmaGYZ commented on a change in pull request #11916: [FLINK-17390][yarn] Fix Hadoop 2.10+ compatibility for WorkerSpecContainerResourceAdapter.

KarmaGYZ commented on a change in pull request #11916:
URL: https://github.com/apache/flink/pull/11916#discussion_r415494145



##########
File path: flink-yarn/src/main/java/org/apache/flink/yarn/WorkerSpecContainerResourceAdapter.java
##########
@@ -128,12 +142,61 @@ private int normalize(final int value, final int unitValue) {
 		return MathUtils.divideRoundUp(value, unitValue) * unitValue;
 	}
 
-	boolean resourceWithinMaxAllocation(final Resource resource) {
-		return resource.getMemory() <= maxMemMB && resource.getVirtualCores() <= maxVcore;
+	boolean resourceWithinMaxAllocation(final InternalContainerResource resource) {
+		return resource.memory <= maxMemMB && resource.vcores <= maxVcore;
 	}
 
 	enum MatchingStrategy {
 		MATCH_VCORE,
 		IGNORE_VCORE
 	}
+
+	/**
+	 * An {@link InternalContainerResource} corresponds to a {@link Resource}.
+	 * This class is for {@link WorkerSpecContainerResourceAdapter} internal usages only, to overcome the problem that
+	 * hash codes are calculated inconsistently across different {@link Resource} implementations.
+	 */
+	private class InternalContainerResource {
+		private final int memory;
+		private final int vcores;
+
+		private InternalContainerResource(final int memory, final int vcores) {
+			this.memory = memory;
+			this.vcores = vcores;
+		}
+
+		private InternalContainerResource(final Resource resource) {
+			this(
+				Preconditions.checkNotNull(resource).getMemory(),
+				Preconditions.checkNotNull(resource).getVirtualCores());
+		}
+
+		private Resource toResource() {
+			return Resource.newInstance(memory, vcores);
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			if (obj == this) {
+				return true;
+			} else if (obj != null && obj.getClass() == InternalContainerResource.class) {

Review comment:
       It might be better to replace "InternalContainerResource.class" with "getClass()".




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