From e60f5b6c40cbed867dc838d2e3a5a291e49b7047 Mon Sep 17 00:00:00 2001 From: Sanford Ryza Date: Tue, 18 Feb 2014 17:51:40 +0000 Subject: [PATCH] YARN-1721. When moving app between queues in Fair Scheduler, grab lock on FSSchedulerApp (Sandy Ryza) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1569443 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../scheduler/fair/FairScheduler.java | 40 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 5954faac6b..77171b5e64 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -289,6 +289,9 @@ Release 2.4.0 - UNRELEASED instead rely on the http policy framework. And also fix some bugs related to https handling in YARN web-apps. (Haohui Mai via vinodkv) + YARN-1721. When moving app between queues in Fair Scheduler, grab lock on + FSSchedulerApp (Sandy Ryza) + Release 2.3.1 - UNRELEASED INCOMPATIBLE CHANGES 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 e057e740fb..939d82fefb 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 @@ -1366,24 +1366,26 @@ public synchronized String moveApplication(ApplicationId appId, throw new YarnException("App to be moved " + appId + " not found."); } FSSchedulerApp attempt = (FSSchedulerApp) app.getCurrentAppAttempt(); - - FSLeafQueue oldQueue = (FSLeafQueue) app.getQueue(); - FSLeafQueue targetQueue = queueMgr.getLeafQueue(queueName, false); - if (targetQueue == null) { - throw new YarnException("Target queue " + queueName - + " not found or is not a leaf queue."); + // To serialize with FairScheduler#allocate, synchronize on app attempt + synchronized (attempt) { + FSLeafQueue oldQueue = (FSLeafQueue) app.getQueue(); + FSLeafQueue targetQueue = queueMgr.getLeafQueue(queueName, false); + if (targetQueue == null) { + throw new YarnException("Target queue " + queueName + + " not found or is not a leaf queue."); + } + if (targetQueue == oldQueue) { + return oldQueue.getQueueName(); + } + + if (oldQueue.getRunnableAppSchedulables().contains( + attempt.getAppSchedulable())) { + verifyMoveDoesNotViolateConstraints(attempt, oldQueue, targetQueue); + } + + executeMove(app, attempt, oldQueue, targetQueue); + return targetQueue.getQueueName(); } - if (targetQueue == oldQueue) { - return oldQueue.getQueueName(); - } - - if (oldQueue.getRunnableAppSchedulables().contains( - attempt.getAppSchedulable())) { - verifyMoveDoesNotViolateConstraints(attempt, oldQueue, targetQueue); - } - - executeMove(app, attempt, oldQueue, targetQueue); - return targetQueue.getQueueName(); } private void verifyMoveDoesNotViolateConstraints(FSSchedulerApp app, @@ -1420,8 +1422,8 @@ private void verifyMoveDoesNotViolateConstraints(FSSchedulerApp app, } /** - * Helper for moveApplication, which is synchronized, so all operations will - * be atomic. + * Helper for moveApplication, which has appropriate synchronization, so all + * operations will be atomic. */ private void executeMove(SchedulerApplication app, FSSchedulerApp attempt, FSLeafQueue oldQueue, FSLeafQueue newQueue) {