diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/RLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/RLESparseResourceAllocation.java index 63defb5474b..c18a93ed1ba 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/RLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/RLESparseResourceAllocation.java @@ -510,7 +510,11 @@ public class RLESparseResourceAllocation { long previous = a.floorKey(start); a = a.tailMap(previous, true); } - a = a.headMap(end, true); + + if (end < a.lastKey()) { + a = a.headMap(end, true); + } + } RLESparseResourceAllocation ret = new RLESparseResourceAllocation(a, resourceCalculator); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java index b526484f6bf..f8d2a4ad928 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java @@ -282,6 +282,28 @@ public class TestRLESparseResourceAllocation { } + @Test + public void testRangeOverlapping() { + ResourceCalculator resCalc = new DefaultResourceCalculator(); + + RLESparseResourceAllocation r = + new RLESparseResourceAllocation(resCalc); + int[] alloc = {10, 10, 10, 10, 10, 10}; + int start = 100; + Set> inputs = + generateAllocation(start, alloc, false).entrySet(); + for (Entry ip : inputs) { + r.addInterval(ip.getKey(), ip.getValue()); + } + long s = r.getEarliestStartTime(); + long d = r.getLatestNonNullTime(); + + // tries to trigger "out-of-range" bug + r = r.getRangeOverlapping(s, d); + r = r.getRangeOverlapping(s-1, d-1); + r = r.getRangeOverlapping(s+1, d+1); + } + @Test public void testBlocks() { ResourceCalculator resCalc = new DefaultResourceCalculator();