Skip to content

Commit e966edd

Browse files
committed
YARN-9644. First RMContext object is always leaked during switch over. Contributed by Bibin A Chundatt.
1 parent 0c8813f commit e966edd

File tree

2 files changed

+16
-6
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager

2 files changed

+16
-6
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMNMInfo.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626

2727
import javax.management.NotCompliantMBeanException;
28+
import javax.management.ObjectName;
2829
import javax.management.StandardMBean;
2930

3031
import org.slf4j.Logger;
@@ -43,6 +44,7 @@ public class RMNMInfo implements RMNMInfoBeans {
4344
LoggerFactory.getLogger(RMNMInfo.class);
4445
private RMContext rmContext;
4546
private ResourceScheduler scheduler;
47+
private ObjectName mbeanObjectName;
4648

4749
/**
4850
* Constructor for RMNMInfo registers the bean with JMX.
@@ -56,14 +58,17 @@ public RMNMInfo(RMContext rmc, ResourceScheduler sched) {
5658

5759
StandardMBean bean;
5860
try {
59-
bean = new StandardMBean(this,RMNMInfoBeans.class);
60-
MBeans.register("ResourceManager", "RMNMInfo", bean);
61+
bean = new StandardMBean(this, RMNMInfoBeans.class);
62+
mbeanObjectName = MBeans.register("ResourceManager", "RMNMInfo", bean);
6163
} catch (NotCompliantMBeanException e) {
62-
LOG.warn("Error registering RMNMInfo MBean", e);
64+
LOG.warn("Error registering RMNMInfo MBean", e);
6365
}
6466
LOG.info("Registered RMNMInfo MBean");
6567
}
6668

69+
public void unregister() {
70+
MBeans.unregister(mbeanObjectName);
71+
}
6772

6873
static class InfoMap extends LinkedHashMap<String, Object> {
6974
private static final long serialVersionUID = 1L;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ public class RMActiveServices extends CompositeService {
641641
private ResourceManager rm;
642642
private boolean fromActive = false;
643643
private StandByTransitionRunnable standByTransitionRunnable;
644+
private RMNMInfo rmnmInfo;
644645

645646
RMActiveServices(ResourceManager rm) {
646647
super("RMActiveServices");
@@ -845,7 +846,7 @@ protected void serviceInit(Configuration configuration) throws Exception {
845846
addService(proxyCAManager);
846847
rmContext.setProxyCAManager(proxyCAManager);
847848

848-
new RMNMInfo(rmContext, scheduler);
849+
rmnmInfo = new RMNMInfo(rmContext, scheduler);
849850

850851
if (conf.getBoolean(YarnConfiguration.YARN_API_SERVICES_ENABLE,
851852
false)) {
@@ -924,6 +925,10 @@ protected void serviceStop() throws Exception {
924925
super.serviceStop();
925926

926927
DefaultMetricsSystem.shutdown();
928+
// unregister rmnmInfo bean
929+
if (rmnmInfo != null) {
930+
rmnmInfo.unregister();
931+
}
927932
if (rmContext != null) {
928933
RMStateStore store = rmContext.getStateStore();
929934
try {
@@ -1182,9 +1187,9 @@ protected void startWepApp() {
11821187
params.put("com.sun.jersey.config.property.packages", apiPackages);
11831188
}
11841189

1185-
Builder<ApplicationMasterService> builder =
1190+
Builder<ResourceManager> builder =
11861191
WebApps
1187-
.$for("cluster", ApplicationMasterService.class, masterService,
1192+
.$for("cluster", ResourceManager.class, this,
11881193
"ws")
11891194
.with(conf)
11901195
.withServlet("API-Service", "/app/*",

0 commit comments

Comments
 (0)