From 5b44b0c9edb16e79c581a121806547f8346e2128 Mon Sep 17 00:00:00 2001 From: Naganarasimha Date: Tue, 6 Dec 2016 06:53:38 +0530 Subject: [PATCH] YARN-5921. Incorrect synchronization in RMContextImpl#setHAServiceState/getHAServiceState. Contributed by Varun Saxena (cherry picked from commit f3b8ff54ab08545d7093bf8861b44ec9912e8dc3) --- .../yarn/server/resourcemanager/RMContextImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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/RMContextImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java index ed9942bce2f..a549930e2bb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java @@ -73,6 +73,8 @@ public class RMContextImpl implements RMContext { private RMApplicationHistoryWriter rmApplicationHistoryWriter; private SystemMetricsPublisher systemMetricsPublisher; + private final Object haServiceStateLock = new Object(); + /** * Default constructor. To be used in conjunction with setter methods for * individual fields. @@ -237,9 +239,9 @@ public class RMContextImpl implements RMContext { this.isHAEnabled = isHAEnabled; } - void setHAServiceState(HAServiceState haServiceState) { - synchronized (haServiceState) { - this.haServiceState = haServiceState; + void setHAServiceState(HAServiceState serviceState) { + synchronized (haServiceStateLock) { + this.haServiceState = serviceState; } } @@ -335,7 +337,7 @@ public class RMContextImpl implements RMContext { @Override public HAServiceState getHAServiceState() { - synchronized (haServiceState) { + synchronized (haServiceStateLock) { return haServiceState; } }