From 4eda58c13641c14c4b248843a2589781cbcd343f Mon Sep 17 00:00:00 2001 From: Arun Suresh Date: Wed, 10 Jan 2018 09:04:30 -0800 Subject: [PATCH] YARN-7681. Double-check placement constraints in scheduling phase before actual allocation is made. (Weiwei Yang via asuresh) --- .../scheduler/capacity/CapacityScheduler.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java index e682d0fc84..d2713c8fbe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacityScheduler.java @@ -124,6 +124,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.SchedulerContainer; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.constraint.InvalidAllocationTagsQueryException; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.constraint.PlacementConstraintsUtil; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAddedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptAddedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptRemovedSchedulerEvent; @@ -2574,6 +2576,27 @@ public boolean attemptAllocationOnNode(SchedulerApplicationAttempt appAttempt, ResourceCommitRequest resourceCommitRequest = createResourceCommitRequest( appAttempt, schedulingRequest, schedulerNode); + + // Validate placement constraint is satisfied before + // committing the request. + try { + if (!PlacementConstraintsUtil.canSatisfyConstraints( + appAttempt.getApplicationId(), + schedulingRequest.getAllocationTags(), + schedulerNode, + rmContext.getPlacementConstraintManager(), + rmContext.getAllocationTagsManager())) { + LOG.debug("Failed to allocate container for application " + + appAttempt.getApplicationId() + " on node " + + schedulerNode.getNodeName() + + " because this allocation violates the" + + " placement constraint."); + return false; + } + } catch (InvalidAllocationTagsQueryException e) { + LOG.warn("Unable to allocate container", e); + return false; + } return tryCommit(getClusterResource(), resourceCommitRequest, false); } }