From c6914b1cb6e4cab8263cd3ae5cc00bc7a8de25de Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Thu, 25 Nov 2021 07:53:04 +0530 Subject: [PATCH] HDFS-16350. Datanode start time should be set after RPC server starts successfully (#3711) (cherry picked from commit cdc13e91b619159dc4bf185ad53b950bdf5de52a) --- .../java/org/apache/hadoop/hdfs/server/datanode/DataNode.java | 3 ++- .../apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index bd57f402966..f35534cc703 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -416,7 +416,7 @@ public class DataNode extends ReconfigurableBase private ScheduledThreadPoolExecutor metricsLoggerTimer; - private final long startTime = now(); + private long startTime = 0; /** * Creates a dummy DataNode for testing purpose. @@ -2681,6 +2681,7 @@ public class DataNode extends ReconfigurableBase } ipcServer.setTracer(tracer); ipcServer.start(); + startTime = now(); startPlugins(getConf()); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java index f72f1bce130..ea43cccbb18 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java @@ -77,6 +77,7 @@ public class TestDataNodeMXBean extends SaslDataTransferTestCase { Assert.assertEquals(datanode.getVersion(),version); // get attribute "DNStartedTimeInMillis" long startTime = (long) mbs.getAttribute(mxbeanName, "DNStartedTimeInMillis"); + Assert.assertTrue("Datanode start time should not be 0", startTime > 0); Assert.assertEquals(datanode.getDNStartedTimeInMillis(), startTime); // get attribute "SotfwareVersion" String softwareVersion =