From 918ba9e82fb0bc6f96301c7ca74a32018b60c49e Mon Sep 17 00:00:00 2001 From: Ahmed Hussein <50450311+amahussein@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:02:53 -0600 Subject: [PATCH] HDFS-15694. Avoid calling UpdateHeartBeatState inside DataNodeDescriptor. (#2487) Contributed by Kuhu Shukla and Ahmed Hussein --- .../hdfs/server/blockmanagement/DatanodeDescriptor.java | 6 ++++-- .../server/blockmanagement/TestDatanodeDescriptor.java | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java index 2dbcc21775..e0e5c354cb 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java @@ -237,7 +237,8 @@ public Type getType() { */ public DatanodeDescriptor(DatanodeID nodeID) { super(nodeID); - updateHeartbeatState(StorageReport.EMPTY_ARRAY, 0L, 0L, 0, 0, null); + setLastUpdate(Time.now()); + setLastUpdateMonotonic(Time.monotonicNow()); } /** @@ -248,7 +249,8 @@ public DatanodeDescriptor(DatanodeID nodeID) { public DatanodeDescriptor(DatanodeID nodeID, String networkLocation) { super(nodeID, networkLocation); - updateHeartbeatState(StorageReport.EMPTY_ARRAY, 0L, 0L, 0, 0, null); + setLastUpdate(Time.now()); + setLastUpdateMonotonic(Time.monotonicNow()); } public CachedBlocksList getPendingCached() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeDescriptor.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeDescriptor.java index 9580bae3ba..eefc1d5034 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeDescriptor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestDatanodeDescriptor.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -63,16 +64,16 @@ public void testBlocksCounter() throws Exception { DatanodeStorageInfo[] storages = dd.getStorageInfos(); assertTrue(storages.length > 0); // add first block - assertTrue(storages[0].addBlock(blk) == AddBlockResult.ADDED); + assertEquals(AddBlockResult.ADDED, storages[0].addBlock(blk)); assertEquals(1, dd.numBlocks()); // remove a non-existent block assertFalse(BlocksMap.removeBlock(dd, blk1)); assertEquals(1, dd.numBlocks()); // add an existent block - assertFalse(storages[0].addBlock(blk) == AddBlockResult.ADDED); + assertNotEquals(AddBlockResult.ADDED, storages[0].addBlock(blk)); assertEquals(1, dd.numBlocks()); // add second block - assertTrue(storages[0].addBlock(blk1) == AddBlockResult.ADDED); + assertEquals(AddBlockResult.ADDED, storages[0].addBlock(blk1)); assertEquals(2, dd.numBlocks()); // remove first block assertTrue(BlocksMap.removeBlock(dd, blk));