From 42a2bddcb709bf9159ddacc7c885cb20595c85d5 Mon Sep 17 00:00:00 2001 From: Jian He Date: Wed, 2 Dec 2015 11:07:18 -0800 Subject: [PATCH] YARN-4398. Remove unnecessary synchronization in RMStateStore. Contributed by Ning Ding (cherry picked from commit 6b9a5beb2b2f9589ef86670f2d763e8488ee5e90) --- hadoop-yarn-project/CHANGES.txt | 2 ++ .../org/apache/hadoop/yarn/event/AsyncDispatcher.java | 5 +---- .../server/resourcemanager/recovery/RMStateStore.java | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 84037d24177..9ade6b32fea 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -37,6 +37,8 @@ Release 2.7.3 - UNRELEASED YARN-4380. TestResourceLocalizationService.testDownloadingResourcesOnContainerKill fails intermittently. (Varun Saxena via ozawa) + YARN-4398. Remove unnecessary synchronization in RMStateStore. (Ning Ding via jianhe) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/AsyncDispatcher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/AsyncDispatcher.java index 6cdfaad839b..403381ba8b5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/AsyncDispatcher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/AsyncDispatcher.java @@ -64,7 +64,7 @@ public class AsyncDispatcher extends AbstractService implements Dispatcher { // For drainEventsOnStop enabled only, block newly coming events into the // queue while stopping. private volatile boolean blockNewEvents = false; - private EventHandler handlerInstance = null; + private final EventHandler handlerInstance = new GenericEventHandler(); private Thread eventHandlingThread; protected final Map, EventHandler> eventDispatchers; @@ -224,9 +224,6 @@ public class AsyncDispatcher extends AbstractService implements Dispatcher { @Override public EventHandler getEventHandler() { - if (handlerInstance == null) { - handlerInstance = new GenericEventHandler(); - } return handlerInstance; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java index 109853bc568..aca350594d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStore.java @@ -655,7 +655,7 @@ public abstract class RMStateStore extends AbstractService { * RMAppStoredEvent will be sent on completion to notify the RMApp */ @SuppressWarnings("unchecked") - public synchronized void storeNewApplication(RMApp app) { + public void storeNewApplication(RMApp app) { ApplicationSubmissionContext context = app .getApplicationSubmissionContext(); assert context instanceof ApplicationSubmissionContextPBImpl; @@ -666,7 +666,7 @@ public abstract class RMStateStore extends AbstractService { } @SuppressWarnings("unchecked") - public synchronized void updateApplicationState( + public void updateApplicationState( ApplicationStateData appState) { dispatcher.getEventHandler().handle(new RMStateUpdateAppEvent(appState)); } @@ -693,7 +693,7 @@ public abstract class RMStateStore extends AbstractService { * This does not block the dispatcher threads * RMAppAttemptStoredEvent will be sent on completion to notify the RMAppAttempt */ - public synchronized void storeNewApplicationAttempt(RMAppAttempt appAttempt) { + public void storeNewApplicationAttempt(RMAppAttempt appAttempt) { Credentials credentials = getCredentialsFromAppAttempt(appAttempt); AggregateAppResourceUsage resUsage = @@ -711,7 +711,7 @@ public abstract class RMStateStore extends AbstractService { } @SuppressWarnings("unchecked") - public synchronized void updateApplicationAttemptState( + public void updateApplicationAttemptState( ApplicationAttemptStateData attemptState) { dispatcher.getEventHandler().handle( new RMStateUpdateAppAttemptEvent(attemptState)); @@ -842,7 +842,7 @@ public abstract class RMStateStore extends AbstractService { * There is no notification of completion for this operation. */ @SuppressWarnings("unchecked") - public synchronized void removeApplication(RMApp app) { + public void removeApplication(RMApp app) { ApplicationStateData appState = ApplicationStateData.newInstance( app.getSubmitTime(), app.getStartTime(),