diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java index 69fe716c96e..9155ae33dcf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/DominantResourceCalculator.java @@ -210,27 +210,19 @@ public class DominantResourceCalculator extends ResourceCalculator { public Resource multiplyAndNormalizeUp(Resource r, double by, Resource stepFactor) { return Resources.createResource( - roundUp( - (int)Math.ceil(r.getMemorySize() * by), stepFactor.getMemorySize()), - roundUp( - (int)Math.ceil(r.getVirtualCores() * by), - stepFactor.getVirtualCores()) - ); + roundUp((long) Math.ceil((float) (r.getMemorySize() * by)), + stepFactor.getMemorySize()), + roundUp((int) Math.ceil((float) (r.getVirtualCores() * by)), + stepFactor.getVirtualCores())); } @Override public Resource multiplyAndNormalizeDown(Resource r, double by, Resource stepFactor) { return Resources.createResource( - roundDown( - (int)(r.getMemorySize() * by), - stepFactor.getMemorySize() - ), - roundDown( - (int)(r.getVirtualCores() * by), - stepFactor.getVirtualCores() - ) - ); + roundDown((long) (r.getMemorySize() * by), stepFactor.getMemorySize()), + roundDown((int) (r.getVirtualCores() * by), + stepFactor.getVirtualCores())); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java index c60f1e87e4b..c8fa132c11f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java @@ -4416,4 +4416,44 @@ public class TestCapacityScheduler { Assert.assertEquals(b1.getState(), QueueState.RUNNING); Assert.assertTrue(!b1.getChildQueues().isEmpty()); } + + @Test(timeout = 30000) + public void testAMLimitDouble() throws Exception { + CapacitySchedulerConfiguration config = + new CapacitySchedulerConfiguration(); + config.set(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS, + DominantResourceCalculator.class.getName()); + CapacitySchedulerConfiguration conf = + new CapacitySchedulerConfiguration(config); + conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, + ResourceScheduler.class); + conf.setInt("yarn.scheduler.minimum-allocation-mb", 512); + conf.setInt("yarn.scheduler.minimum-allocation-vcores", 1); + MockRM rm = new MockRM(conf); + rm.start(); + rm.registerNode("127.0.0.1:1234", 10 * GB); + rm.registerNode("127.0.0.1:1235", 10 * GB); + rm.registerNode("127.0.0.1:1236", 10 * GB); + rm.registerNode("127.0.0.1:1237", 10 * GB); + ResourceScheduler scheduler = rm.getRMContext().getScheduler(); + waitforNMRegistered(scheduler, 4, 5); + LeafQueue queueA = + (LeafQueue) ((CapacityScheduler) scheduler).getQueue("default"); + Resource amResourceLimit = queueA.getAMResourceLimit(); + Assert.assertEquals(4096, amResourceLimit.getMemorySize()); + Assert.assertEquals(4, amResourceLimit.getVirtualCores()); + rm.stop(); + } + + private void waitforNMRegistered(ResourceScheduler scheduler, int nodecount, + int timesec) throws InterruptedException { + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < timesec * 1000) { + if (scheduler.getNumClusterNodes() < nodecount) { + Thread.sleep(100); + } else { + break; + } + } + } }