diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java index 6836758..fcc4571 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java @@ -48,16 +48,7 @@ public static void computeShares( Collection schedulables, Resource totalResources, ResourceType type) { - Collection activeSchedulables = new ArrayList(); - for (Schedulable sched : schedulables) { - if ((sched instanceof FSQueue) && !((FSQueue) sched).isActive()) { - setResourceValue(0, sched.getFairShare(), type); - } else { - activeSchedulables.add(sched); - } - } - - computeSharesInternal(activeSchedulables, totalResources, type, false); + computeSharesInternal(schedulables, totalResources, type, false); } /** @@ -117,8 +108,20 @@ public static void computeSteadyShares( * iterations of binary search is a constant (dependent on desired precision). */ private static void computeSharesInternal( - Collection schedulables, Resource totalResources, - ResourceType type, boolean isSteadyShare) { + Collection schedulablesOrig, + Resource totalResources, ResourceType type, boolean isSteadyShare) { + Collection schedulables = new ArrayList(); + for (Schedulable sched : schedulablesOrig) { + if (isZeroShareSchedulable(sched, isSteadyShare, type)) { + if (isSteadyShare) { + setResourceValue(0, ((FSQueue) sched).getSteadyFairShare(), type); + } else { + setResourceValue(0, sched.getFairShare(), type); + } + } else { + schedulables.add(sched); + } + } if (schedulables.isEmpty()) { return; } @@ -196,7 +199,16 @@ private static int computeShare(Schedulable sched, double w2rRatio, share = Math.min(share, getResourceValue(sched.getMaxShare(), type)); return (int) share; } - + + private static boolean isZeroShareSchedulable(Schedulable sched, + boolean isSteadyShare, ResourceType type) { + return (getResourceValue(sched.getMaxShare(), type) <= 0) || + ((sched.getWeights().getWeight(type) <= 0) && + (getResourceValue(sched.getMinShare(), type) <= 0)) || + (!isSteadyShare && (sched instanceof FSQueue) && + !((FSQueue) sched).isActive()); + } + private static int getResourceValue(Resource resource, ResourceType type) { switch (type) { case MEMORY: diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java index 79e3184..3e63c27 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/TestFairScheduler.java @@ -307,7 +307,51 @@ public void testSimpleFairShareCalculation() throws IOException { assertEquals(3414, p.getMetrics().getSteadyFairShareMB()); } } - + + @Test + public void testFairShareWithZeroWeight() throws IOException { + conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, ALLOC_FILE); + // set queueA and queueB weight zero. + PrintWriter out = new PrintWriter(new FileWriter(ALLOC_FILE)); + out.println(""); + out.println(""); + out.println(""); + out.println("0.0"); + out.println(""); + out.println(""); + out.println("0.0"); + out.println(""); + out.println(""); + out.close(); + + scheduler.init(conf); + scheduler.start(); + scheduler.reinitialize(conf, resourceManager.getRMContext()); + + // Add one big node (only care about aggregate capacity) + RMNode node1 = + MockNodes.newNodeInfo(1, Resources.createResource(8 * 1024, 8), 1, + "127.0.0.1"); + NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); + scheduler.handle(nodeEvent1); + + // Queue A wants 2 * 1024. + createSchedulingRequest(2 * 1024, "queueA", "user1"); + // Queue B wants 6 * 1024 + createSchedulingRequest(6 * 1024, "queueB", "user1"); + + scheduler.update(); + + FSLeafQueue queue = scheduler.getQueueManager().getLeafQueue( + "queueA", false); + // queueA's weight is 0.0, so its fair share should be 0. + assertEquals(0, queue.getFairShare().getMemory()); + // queueB's weight is 0.0, so its fair share should be 0. + queue = scheduler.getQueueManager().getLeafQueue( + "queueB", false); + assertEquals(0, queue.getFairShare().getMemory()); + } + @Test public void testSimpleHierarchicalFairShareCalculation() throws IOException { scheduler.init(conf);