From 10a0ddbac3c3e578bc317d846875a6f76b121004 Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Wed, 19 Aug 2015 09:42:35 -0700 Subject: [PATCH] HDFS-8911. NameNode Metric : Add Editlog counters as a JMX metric. (Contributed by Anu Engineer) --- .../src/site/markdown/Metrics.md | 2 ++ hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hdfs/server/namenode/FSEditLog.java | 7 ++++ .../hdfs/server/namenode/FSNamesystem.java | 19 +++++++++++ .../namenode/metrics/FSNamesystemMBean.java | 10 ++++++ .../namenode/TestFSNamesystemMBean.java | 34 ++++++++++++++++++- 6 files changed, 74 insertions(+), 1 deletion(-) 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 788c829f203..2e9a4f7cc82 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md @@ -236,6 +236,8 @@ Each metrics record contains tags such as HAState and Hostname as additional inf | `HAState` | (HA-only) Current state of the NameNode: initializing or active or standby or stopping state | | `FSState` | Current state of the file system: Safemode or Operational | | `LockQueueLength` | Number of threads waiting to acquire FSNameSystem lock | +| `TotalSyncCount` | Total number of sync operations performed by edit log | +| `TotalSyncTimes` | Total number of milliseconds spent by various edit logs in sync operation| JournalNode ----------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index b7192eeb237..0a8bb98e71a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -466,6 +466,9 @@ Release 2.8.0 - UNRELEASED HDFS-8826. In Balancer, add an option to specify the source node list so that balancer only selects blocks to move from those nodes. (szetszwo) + HDFS-8911. NameNode Metric : Add Editlog counters as a JMX metric. + (Anu Engineer via Arpit Agarwal) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java index f6d95bc5aa0..81a0954139b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java @@ -1647,4 +1647,11 @@ private JournalManager createJournal(URI uri) { } } + /** + + * Return total number of syncs happened on this edit log. + + * @return long - count + + */ + public long getTotalSyncCount() { + return editLogStream.getNumSync(); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 4b496213112..7c5a89c9317 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -7273,5 +7273,24 @@ private static void enableAsyncAuditLog() { } } + /** + * Return total number of Sync Operations on FSEditLog. + */ + @Override + @Metric({"TotalSyncCount", + "Total number of sync operations performed on edit logs"}) + public long getTotalSyncCount() { + return fsImage.editLog.getTotalSyncCount(); + } + + /** + * Return total time spent doing sync operations on FSEditLog. + */ + @Override + @Metric({"TotalSyncTimes", + "Total time spend in sync operation on various edit logs"}) + public String getTotalSyncTimes() { + return fsImage.editLog.getJournalSet().getSyncTimes(); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/FSNamesystemMBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/FSNamesystemMBean.java index 0fa48419ab2..b314f7f8f86 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/FSNamesystemMBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/metrics/FSNamesystemMBean.java @@ -198,4 +198,14 @@ public interface FSNamesystemMBean { * @return int - Number of Threads waiting to acquire FSNameSystemLock */ int getFsLockQueueLength(); + + /** + * Return total number of Sync Operations on FSEditLog. + */ + long getTotalSyncCount(); + + /** + * Return total time spent doing sync operations on FSEditLog. + */ + String getTotalSyncTimes(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java index fb3179a9e99..3c0d54acb5e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemMBean.java @@ -30,6 +30,8 @@ import javax.management.MBeanServer; import javax.management.ObjectName; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.junit.Test; @@ -159,4 +161,34 @@ public void testWithFSNamesystemWriteLock() throws Exception { } } } -} \ No newline at end of file + + @Test(timeout = 120000) + public void testFsEditLogMetrics() throws Exception { + final Configuration conf = new Configuration(); + MiniDFSCluster cluster = null; + try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); + cluster.waitActive(); + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + ObjectName mxbeanNameFs = + new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState"); + + FileSystem fs = cluster.getFileSystem(); + final int NUM_OPS = 10; + for (int i = 0; i < NUM_OPS; i++) { + final Path path = new Path(String.format("/user%d", i)); + fs.mkdirs(path); + } + + long syncCount = (long) mbs.getAttribute(mxbeanNameFs, "TotalSyncCount"); + String syncTimes = + (String) mbs.getAttribute(mxbeanNameFs, "TotalSyncTimes"); + assertTrue(syncCount > 0); + assertNotNull(syncTimes); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } +}