From e2f6299f6f580d7a03f2377d19ac85f55fd4e73b Mon Sep 17 00:00:00 2001 From: Jian He Date: Mon, 14 Aug 2017 10:51:04 -0700 Subject: [PATCH] YARN-6959. RM may allocate wrong AM Container for new attempt. Contributed by Yuqi Wang --- .../scheduler/AbstractYarnScheduler.java | 1 + .../scheduler/capacity/CapacityScheduler.java | 13 ++++++ .../scheduler/fair/FairScheduler.java | 15 +++++- .../scheduler/fifo/FifoScheduler.java | 15 +++++- .../scheduler/fair/TestFairScheduler.java | 46 +++++++++---------- 5 files changed, 63 insertions(+), 27 deletions(-) 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/AbstractYarnScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java index d506f4d2cce..79caab0633a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java @@ -323,6 +323,7 @@ protected void containerIncreasedOnNode(ContainerId containerId, } + // TODO: Rename it to getCurrentApplicationAttempt public T getApplicationAttempt(ApplicationAttemptId applicationAttemptId) { SchedulerApplication app = applications.get( applicationAttemptId.getApplicationId()); 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 328698207dc..e4ca0031b83 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 @@ -903,6 +903,19 @@ public Allocation allocate(ApplicationAttemptId applicationAttemptId, ContainerUpdates updateRequests) { FiCaSchedulerApp application = getApplicationAttempt(applicationAttemptId); if (application == null) { + LOG.error("Calling allocate on removed or non existent application " + + applicationAttemptId.getApplicationId()); + return EMPTY_ALLOCATION; + } + + // The allocate may be the leftover from previous attempt, and it will + // impact current attempt, such as confuse the request and allocation for + // current attempt's AM container. + // Note outside precondition check for the attempt id may be + // outdated here, so double check it here is necessary. + if (!application.getApplicationAttemptId().equals(applicationAttemptId)) { + LOG.error("Calling allocate on previous or removed " + + "or non existent application attempt " + applicationAttemptId); return EMPTY_ALLOCATION; } 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/fair/FairScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java index db02bab3a37..0f417c39519 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FairScheduler.java @@ -835,8 +835,19 @@ public Allocation allocate(ApplicationAttemptId appAttemptId, // Make sure this application exists FSAppAttempt application = getSchedulerApp(appAttemptId); if (application == null) { - LOG.info("Calling allocate on removed " + - "or non existent application " + appAttemptId); + LOG.error("Calling allocate on removed or non existent application " + + appAttemptId.getApplicationId()); + return EMPTY_ALLOCATION; + } + + // The allocate may be the leftover from previous attempt, and it will + // impact current attempt, such as confuse the request and allocation for + // current attempt's AM container. + // Note outside precondition check for the attempt id may be + // outdated here, so double check it here is necessary. + if (!application.getApplicationAttemptId().equals(appAttemptId)) { + LOG.error("Calling allocate on previous or removed " + + "or non existent application attempt " + appAttemptId); return EMPTY_ALLOCATION; } 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/fifo/FifoScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java index a8d4f48591f..92a88b925d9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java @@ -329,8 +329,19 @@ public Allocation allocate(ApplicationAttemptId applicationAttemptId, ContainerUpdates updateRequests) { FifoAppAttempt application = getApplicationAttempt(applicationAttemptId); if (application == null) { - LOG.error("Calling allocate on removed " + - "or non-existent application " + applicationAttemptId); + LOG.error("Calling allocate on removed or non existent application " + + applicationAttemptId.getApplicationId()); + return EMPTY_ALLOCATION; + } + + // The allocate may be the leftover from previous attempt, and it will + // impact current attempt, such as confuse the request and allocation for + // current attempt's AM container. + // Note outside precondition check for the attempt id may be + // outdated here, so double check it here is necessary. + if (!application.getApplicationAttemptId().equals(applicationAttemptId)) { + LOG.error("Calling allocate on previous or removed " + + "or non existent application attempt " + applicationAttemptId); return EMPTY_ALLOCATION; } 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/fair/TestFairScheduler.java b/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 0d54c3322c8..941c215df4c 100644 --- a/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 +++ b/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 @@ -2107,49 +2107,49 @@ public void testQueueDemandCalculation() throws Exception { scheduler.init(conf); scheduler.start(); scheduler.reinitialize(conf, resourceManager.getRMContext()); + int minReqSize = + FairSchedulerConfiguration.DEFAULT_RM_SCHEDULER_INCREMENT_ALLOCATION_MB; + // First ask, queue1 requests 1 large (minReqSize * 2). ApplicationAttemptId id11 = createAppAttemptId(1, 1); createMockRMApp(id11); - scheduler.addApplication(id11.getApplicationId(), "root.queue1", "user1", false); + scheduler.addApplication(id11.getApplicationId(), + "root.queue1", "user1", false); scheduler.addApplicationAttempt(id11, false, false); - ApplicationAttemptId id21 = createAppAttemptId(2, 1); - createMockRMApp(id21); - scheduler.addApplication(id21.getApplicationId(), "root.queue2", "user1", false); - scheduler.addApplicationAttempt(id21, false, false); - ApplicationAttemptId id22 = createAppAttemptId(2, 2); - createMockRMApp(id22); - - scheduler.addApplication(id22.getApplicationId(), "root.queue2", "user1", false); - scheduler.addApplicationAttempt(id22, false, false); - - int minReqSize = - FairSchedulerConfiguration.DEFAULT_RM_SCHEDULER_INCREMENT_ALLOCATION_MB; - - // First ask, queue1 requests 1 large (minReqSize * 2). List ask1 = new ArrayList(); - ResourceRequest request1 = - createResourceRequest(minReqSize * 2, ResourceRequest.ANY, 1, 1, true); + ResourceRequest request1 = createResourceRequest(minReqSize * 2, + ResourceRequest.ANY, 1, 1, true); ask1.add(request1); scheduler.allocate(id11, ask1, new ArrayList(), null, null, NULL_UPDATE_REQUESTS); // Second ask, queue2 requests 1 large. + ApplicationAttemptId id21 = createAppAttemptId(2, 1); + createMockRMApp(id21); + scheduler.addApplication(id21.getApplicationId(), + "root.queue2", "user1", false); + scheduler.addApplicationAttempt(id21, false, false); List ask2 = new ArrayList(); - ResourceRequest request2 = createResourceRequest(2 * minReqSize, "foo", 1, 1, - false); + ResourceRequest request2 = createResourceRequest(2 * minReqSize, + "foo", 1, 1, false); ResourceRequest request3 = createResourceRequest(2 * minReqSize, - ResourceRequest.ANY, 1, 1, false); + ResourceRequest.ANY, 1, 1, false); ask2.add(request2); ask2.add(request3); scheduler.allocate(id21, ask2, new ArrayList(), null, null, NULL_UPDATE_REQUESTS); // Third ask, queue2 requests 2 small (minReqSize). + ApplicationAttemptId id22 = createAppAttemptId(2, 2); + createMockRMApp(id22); + scheduler.addApplication(id22.getApplicationId(), + "root.queue2", "user1", false); + scheduler.addApplicationAttempt(id22, false, false); List ask3 = new ArrayList(); - ResourceRequest request4 = createResourceRequest(minReqSize, "bar", 2, 2, - true); + ResourceRequest request4 = createResourceRequest(minReqSize, + "bar", 2, 2, true); ResourceRequest request5 = createResourceRequest(minReqSize, - ResourceRequest.ANY, 2, 2, true); + ResourceRequest.ANY, 2, 2, true); ask3.add(request4); ask3.add(request5); scheduler.allocate(id22, ask3, new ArrayList(),