From 51a16b1ff0087249ea2fc3bab439c637850ace39 Mon Sep 17 00:00:00 2001 From: Arun Suresh Date: Mon, 6 Jun 2016 21:18:32 -0700 Subject: [PATCH] YARN-4525. Fix bug in RLESparseResourceAllocation.getRangeOverlapping(). (Ishai Menache and Carlo Curino via asuresh) (cherry picked from commit 3a154f75ed85d864b3ffd35818992418f2b6aa59) (cherry picked from commit d3655f41230fd5a5f3bdb0124d5754459e593e82) --- .../RLESparseResourceAllocation.java | 6 ++++- .../TestRLESparseResourceAllocation.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 85fafa7ecec..a1163683442 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();