From 2d06d885c84b2e4a3acb6d3e0c50d4870e37ca82 Mon Sep 17 00:00:00 2001 From: Miklos Szegedi Date: Tue, 3 Apr 2018 10:01:00 -0700 Subject: [PATCH] YARN-8035. Uncaught exception in ContainersMonitorImpl during relaunch due to the process ID changing. Contributed by Shane Kumpf. --- .../monitor/ContainerMetrics.java | 2 +- .../monitor/TestContainerMetrics.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java index a6aa337239..2a958494e8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java @@ -274,7 +274,7 @@ public void recordCpuUsage( } public void recordProcessId(String processId) { - registry.tag(PROCESSID_INFO, processId); + registry.tag(PROCESSID_INFO, processId, true); } public void recordResourceLimit(int vmemLimit, int pmemLimit, int cpuVcores) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/TestContainerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/TestContainerMetrics.java index 1840d62f12..8b2bff1c28 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/TestContainerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/TestContainerMetrics.java @@ -206,4 +206,21 @@ public void testContainerMetricsHistogram() throws Exception { } Assert.assertEquals(expectedValues.keySet(), testResults); } + + @Test + public void testContainerMetricsUpdateContainerPid() { + ContainerId containerId = mock(ContainerId.class); + ContainerMetrics metrics = ContainerMetrics.forContainer(containerId, + 100, 1); + + String origPid = "1234"; + metrics.recordProcessId(origPid); + assertEquals(origPid, metrics.registry.getTag( + ContainerMetrics.PROCESSID_INFO.name()).value()); + + String newPid = "4321"; + metrics.recordProcessId(newPid); + assertEquals(newPid, metrics.registry.getTag( + ContainerMetrics.PROCESSID_INFO.name()).value()); + } }