You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 04:58:23 UTC
svn commit: r1077270 - in
/hadoop/common/branches/branch-0.20-security-patches/src:
hdfs/org/apache/hadoop/hdfs/server/namenode/
hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/
test/org/apache/hadoop/hdfs/server/namenode/metrics/
Author: omalley
Date: Fri Mar 4 03:58:23 2011
New Revision: 1077270
URL: http://svn.apache.org/viewvc?rev=1077270&view=rev
Log:
commit 4d84015a9442b5f1a51eeab908cac80675ec6aa8
Author: Hairong Kuang <ha...@ucdev21.inktomisearch.com>
Date: Wed Mar 3 00:36:08 2010 +0000
HDFS:204 from http://issues.apache.org/jira/secure/attachment/12437576/getFileNum-yahoo20.patch
+++ b/YAHOO-CHANGES.txt
+ HDFS-204. Revive number of files listed metrics. (hairong)
+
Added:
hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java
Modified:
hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java
Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1077270&r1=1077269&r2=1077270&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java Fri Mar 4 03:58:23 2011
@@ -620,6 +620,9 @@ public class NameNode implements ClientP
throws IOException {
DirectoryListing files = namesystem.getListing(src, startAfter);
myMetrics.numGetListingOps.inc();
+ if (files != null) {
+ myMetrics.numFilesInGetListingOps.inc(files.getPartialListing().length);
+ }
return files;
}
Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java?rev=1077270&r1=1077269&r2=1077270&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/metrics/NameNodeMetrics.java Fri Mar 4 03:58:23 2011
@@ -81,6 +81,8 @@ public class NameNodeMetrics implements
new MetricsIntValue("fsImageLoadTime", registry, "Time loading FS Image at Startup");
public MetricsIntValue numBlocksCorrupted =
new MetricsIntValue("BlocksCorrupted", registry);
+ public MetricsTimeVaryingInt numFilesInGetListingOps =
+ new MetricsTimeVaryingInt("FilesInGetListingOps", registry);
public NameNodeMetrics(Configuration conf, NameNode nameNode) {
Added: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java?rev=1077270&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java (added)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/metrics/TestNNMetricFilesInGetListingOps.java Fri Mar 4 03:58:23 2011
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.namenode.metrics;
+
+import java.io.IOException;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
+import org.apache.hadoop.hdfs.server.namenode.NameNode;
+
+/**
+ * Test case for FilesInGetListingOps metric in Namenode
+ */
+public class TestNNMetricFilesInGetListingOps extends TestCase {
+ private static final Configuration CONF = new Configuration();
+ static {
+ CONF.setLong("dfs.block.size", 100);
+ CONF.setInt("io.bytes.per.checksum", 1);
+ CONF.setLong("dfs.heartbeat.interval", 1L);
+ CONF.setInt("dfs.replication.interval", 1);
+ }
+
+ private MiniDFSCluster cluster;
+ private NameNodeMetrics nnMetrics;
+ private DistributedFileSystem fs;
+ private Random rand = new Random();
+
+ @Override
+ protected void setUp() throws Exception {
+ cluster = new MiniDFSCluster(CONF, 1, true, null);
+ cluster.waitActive();
+ cluster.getNameNode();
+ nnMetrics = NameNode.getNameNodeMetrics();
+ fs = (DistributedFileSystem) cluster.getFileSystem();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ cluster.shutdown();
+ }
+
+ /** create a file with a length of <code>fileLen</code> */
+ private void createFile(String fileName, long fileLen, short replicas) throws IOException {
+ Path filePath = new Path(fileName);
+ DFSTestUtil.createFile(fs, filePath, fileLen, replicas, rand.nextLong());
+ }
+
+
+ public void testFilesInGetListingOps() throws Exception {
+ createFile("/tmp1/t1", 3200, (short)3);
+ createFile("/tmp1/t2", 3200, (short)3);
+ createFile("/tmp2/t1", 3200, (short)3);
+ createFile("/tmp2/t2", 3200, (short)3);
+ cluster.getNameNode().getListing("/tmp1", HdfsFileStatus.EMPTY_NAME) ;
+ assertEquals(2,nnMetrics.numFilesInGetListingOps.getCurrentIntervalValue());
+ cluster.getNameNode().getListing("/tmp2", HdfsFileStatus.EMPTY_NAME) ;
+ assertEquals(4,nnMetrics.numFilesInGetListingOps.getCurrentIntervalValue());
+ // test non-existent path
+ cluster.getNameNode().getListing("/tmp", HdfsFileStatus.EMPTY_NAME) ;
+ assertEquals(4,nnMetrics.numFilesInGetListingOps.getCurrentIntervalValue());
+ // test listing a file
+ cluster.getNameNode().getListing("/tmp1/t1", HdfsFileStatus.EMPTY_NAME) ;
+ assertEquals(5,nnMetrics.numFilesInGetListingOps.getCurrentIntervalValue());
+ }
+}
+