From 94e71e109716bddf9ef4ee393f8e08b377ec20df Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Thu, 5 Dec 2024 18:02:07 +0800 Subject: [PATCH 01/11] HDFS-17683. Add metrics for acquiring dataset read/write lock. --- .../hadoop/hdfs/server/datanode/DataNode.java | 4 ++-- .../server/datanode/DataSetLockManager.java | 21 ++++++++++++++----- .../datanode/metrics/DataNodeMetrics.java | 12 +++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) 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 87e8eee681d1d..ef778791cfd9c 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 @@ -512,7 +512,7 @@ private static Tracer createTracer(Configuration conf) { this.pipelineSupportSlownode = false; this.socketFactory = NetUtils.getDefaultSocketFactory(conf); this.dnConf = new DNConf(this); - this.dataSetLockManager = new DataSetLockManager(conf); + this.dataSetLockManager = new DataSetLockManager(conf, this); initOOBTimeout(); storageLocationChecker = null; volumeChecker = new DatasetVolumeChecker(conf, new Timer()); @@ -535,7 +535,7 @@ private static Tracer createTracer(Configuration conf) { super(conf); this.tracer = createTracer(conf); this.fileIoProvider = new FileIoProvider(conf, this); - this.dataSetLockManager = new DataSetLockManager(conf); + this.dataSetLockManager = new DataSetLockManager(conf, this); this.blockScanner = new BlockScanner(this); this.lastDiskErrorCheck = 0; this.maxNumberOfBlocksToLog = conf.getLong(DFS_MAX_NUM_BLOCKS_TO_LOG_KEY, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataSetLockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataSetLockManager.java index 5579541eb72d8..3abcf12fc8b12 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataSetLockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataSetLockManager.java @@ -27,6 +27,7 @@ import java.util.Stack; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.hadoop.util.Time; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +41,7 @@ public class DataSetLockManager implements DataNodeLockManager Date: Thu, 5 Dec 2024 18:06:06 +0800 Subject: [PATCH 02/11] trigger yetus. From 9d06760f255ebb5f8c4d8bf8e1ca4d855a50a6d9 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Thu, 5 Dec 2024 18:46:15 +0800 Subject: [PATCH 03/11] trigger yetus. From 4bfade3c70372d6fceebccca4fc6e362376869b1 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Mon, 9 Dec 2024 14:46:38 +0800 Subject: [PATCH 04/11] add UT --- .../server/datanode/TestDataNodeMetrics.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java index 3a0b5238360a2..adf8c6d060d2f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java @@ -19,6 +19,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY; import static org.apache.hadoop.test.MetricsAsserts.assertCounter; +import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt; import static org.apache.hadoop.test.MetricsAsserts.assertInverseQuantileGauges; import static org.apache.hadoop.test.MetricsAsserts.assertQuantileGauges; import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; @@ -816,4 +817,26 @@ public Boolean get() { }, 100, 10000); } } + + @Test + public void testDataNodeDatasetLockMetrics() throws IOException { + Configuration conf = new HdfsConfiguration(); + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); + try { + FileSystem fs = cluster.getFileSystem(); + // Create and read a 1 byte file + Path tmpfile = new Path("/tmp.txt"); + DFSTestUtil.createFile(fs, tmpfile, + (long)1, (short)1, 1L); + DFSTestUtil.readFile(fs, tmpfile); + List datanodes = cluster.getDataNodes(); + assertEquals(datanodes.size(), 1); + DataNode datanode = datanodes.get(0); + MetricsRecordBuilder rb = getMetrics(datanode.getMetrics().name()); + assertCounterGt("AcquireDatasetWriteLockNumOps", (long)1, rb); + assertCounterGt("AcquireDatasetReadLockNumOps", (long)1, rb); + } finally { + if (cluster != null) {cluster.shutdown();} + } + } } From 217ea1438a9218411597e46414760db5aaa0277f Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Mon, 9 Dec 2024 14:48:25 +0800 Subject: [PATCH 05/11] fix checkstyle --- .../hadoop/hdfs/server/datanode/TestDataNodeMetrics.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java index adf8c6d060d2f..2c4a386de591c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java @@ -836,7 +836,9 @@ public void testDataNodeDatasetLockMetrics() throws IOException { assertCounterGt("AcquireDatasetWriteLockNumOps", (long)1, rb); assertCounterGt("AcquireDatasetReadLockNumOps", (long)1, rb); } finally { - if (cluster != null) {cluster.shutdown();} + if (cluster != null) { + cluster.shutdown(); + } } } } From bf4b991a3821ed56ee8e3af728566ce4d5732b29 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Mon, 9 Dec 2024 20:33:02 +0800 Subject: [PATCH 06/11] trigger yetus. From 655d8289f670c95278c514fb86a50f41731f0d33 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Tue, 10 Dec 2024 23:00:33 +0800 Subject: [PATCH 07/11] trigger yetus. From 4d3b3ca95d74f54ad36bfb6e73a8a73fd0711393 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Wed, 11 Dec 2024 09:36:29 +0800 Subject: [PATCH 08/11] trigger yetus. From 0bdb7fa8bc74f7f7f049513e9fb89ab6800b2f04 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Mon, 16 Dec 2024 10:07:07 +0800 Subject: [PATCH 09/11] add metrics in Metrics.md --- .../hadoop-common/src/site/markdown/Metrics.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md b/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md index 4850d247db423..eba84a726bd6b 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md @@ -534,6 +534,10 @@ Each metrics record contains tags such as SessionId and Hostname as additional i | `ProcessedCommandsOpNumOps` | Total number of processed commands operations | | `ProcessedCommandsOpAvgTime` | Average time of processed commands operations in milliseconds | | `NullStorageBlockReports` | Number of blocks in IBRs that failed due to null storage | +| `AcquireDatasetReadLockNumOps` | Total number of acquiring dataset read lock operations | +| `AcquireDatasetReadLockAvgTime` | Average time of acquiring dataset read lock operations in nanoseconds | +| `AcquireDatasetWriteLockNumOps` | Total number of acquiring dataset write lock operations | +| `AcquireDatasetWriteLockAvgTime` | Average time of acquiring dataset write lock operations in nanoseconds | FsVolume -------- From 0d97be036476f4c51a1c4ab16e65c2d96ca557fc Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Thu, 19 Dec 2024 11:11:00 +0800 Subject: [PATCH 10/11] use try-with-resources in testDataNodeDatasetLockMetrics --- .../hadoop/hdfs/server/datanode/TestDataNodeMetrics.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java index 2c4a386de591c..3a74f835f4ad8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java @@ -821,13 +821,12 @@ public Boolean get() { @Test public void testDataNodeDatasetLockMetrics() throws IOException { Configuration conf = new HdfsConfiguration(); - MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); - try { + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build()) { FileSystem fs = cluster.getFileSystem(); // Create and read a 1 byte file Path tmpfile = new Path("/tmp.txt"); DFSTestUtil.createFile(fs, tmpfile, - (long)1, (short)1, 1L); + (long)1, (short)1, 1L); DFSTestUtil.readFile(fs, tmpfile); List datanodes = cluster.getDataNodes(); assertEquals(datanodes.size(), 1); @@ -835,10 +834,6 @@ public void testDataNodeDatasetLockMetrics() throws IOException { MetricsRecordBuilder rb = getMetrics(datanode.getMetrics().name()); assertCounterGt("AcquireDatasetWriteLockNumOps", (long)1, rb); assertCounterGt("AcquireDatasetReadLockNumOps", (long)1, rb); - } finally { - if (cluster != null) { - cluster.shutdown(); - } } } } From 04cabfb540edb2128ffe130313226d7c0d812372 Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Sat, 21 Dec 2024 18:20:28 +0800 Subject: [PATCH 11/11] trigger yetus.