Author: cnauroth Date: Thu Jun 26 23:12:45 2014 New Revision: 1605928 URL: http://svn.apache.org/r1605928 Log: HDFS-6572. Add an option to the NameNode that prints the software and on-disk image versions. Contributed by Charles Lamb.
Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1605928&r1=1605927&r2=1605928&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Thu Jun 26 23:12:45 2014 @@ -479,6 +479,9 @@ Release 2.5.0 - UNRELEASED HDFS-6595. Allow the maximum threads for balancing on datanodes to be configurable. (Benoy Antony via szetszwo) + HDFS-6572. Add an option to the NameNode that prints the software and + on-disk image versions. (Charles Lamb via cnauroth) + OPTIMIZATIONS HDFS-6214. Webhdfs has poor throughput for files >2GB (daryn) Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java?rev=1605928&r1=1605927&r2=1605928&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java Thu Jun 26 23:12:45 2014 @@ -92,7 +92,8 @@ public final class HdfsServerConstants { RECOVER ("-recover"), FORCE("-force"), NONINTERACTIVE("-nonInteractive"), - RENAMERESERVED("-renameReserved"); + RENAMERESERVED("-renameReserved"), + METADATAVERSION("-metadataVersion"); private static final Pattern ENUM_WITH_ROLLING_UPGRADE_OPTION = Pattern.compile( "(\\w+)\\((\\w+)\\)"); Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java?rev=1605928&r1=1605927&r2=1605928&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java Thu Jun 26 23:12:45 2014 @@ -214,6 +214,13 @@ public class FSImage implements Closeabl int layoutVersion = storage.getLayoutVersion(); + if (startOpt == StartupOption.METADATAVERSION) { + System.out.println("HDFS Image Version: " + layoutVersion); + System.out.println("Software format version: " + + HdfsConstants.NAMENODE_LAYOUT_VERSION); + return false; + } + if (layoutVersion < Storage.LAST_PRE_UPGRADE_LAYOUT_VERSION) { NNStorage.checkVersionUpgradable(storage.getLayoutVersion()); } @@ -289,6 +296,12 @@ public class FSImage implements Closeabl storage.dirIterator(); it.hasNext();) { StorageDirectory sd = it.next(); StorageState curState; + if (startOpt == StartupOption.METADATAVERSION) { + /* All we need is the layout version. */ + storage.readProperties(sd); + return true; + } + try { curState = sd.analyzeStorage(startOpt, storage); // sd is locked but not opened Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1605928&r1=1605927&r2=1605928&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Thu Jun 26 23:12:45 2014 @@ -201,25 +201,28 @@ public class NameNode implements NameNod }; private static final String USAGE = "Usage: java NameNode [" - + StartupOption.BACKUP.getName() + "] | [" - + StartupOption.CHECKPOINT.getName() + "] | [" + + StartupOption.BACKUP.getName() + "] | \n\t[" + + StartupOption.CHECKPOINT.getName() + "] | \n\t[" + StartupOption.FORMAT.getName() + " [" + StartupOption.CLUSTERID.getName() + " cid ] [" + StartupOption.FORCE.getName() + "] [" - + StartupOption.NONINTERACTIVE.getName() + "] ] | [" + + StartupOption.NONINTERACTIVE.getName() + "] ] | \n\t[" + StartupOption.UPGRADE.getName() + " [" + StartupOption.CLUSTERID.getName() + " cid]" + - " [" + StartupOption.RENAMERESERVED.getName() + "<k-v pairs>] ] | [" - + StartupOption.ROLLBACK.getName() + "] | [" + " [" + StartupOption.RENAMERESERVED.getName() + "<k-v pairs>] ] | \n\t[" + + StartupOption.ROLLBACK.getName() + "] | \n\t[" + StartupOption.ROLLINGUPGRADE.getName() + " <" + RollingUpgradeStartupOption.DOWNGRADE.name().toLowerCase() + "|" - + RollingUpgradeStartupOption.ROLLBACK.name().toLowerCase() + "> ] | [" - + StartupOption.FINALIZE.getName() + "] | [" - + StartupOption.IMPORT.getName() + "] | [" - + StartupOption.INITIALIZESHAREDEDITS.getName() + "] | [" - + StartupOption.BOOTSTRAPSTANDBY.getName() + "] | [" - + StartupOption.RECOVER.getName() + " [ " + StartupOption.FORCE.getName() - + " ] ]"; + + RollingUpgradeStartupOption.ROLLBACK.name().toLowerCase() + "> ] | \n\t[" + + StartupOption.FINALIZE.getName() + "] | \n\t[" + + StartupOption.IMPORT.getName() + "] | \n\t[" + + StartupOption.INITIALIZESHAREDEDITS.getName() + "] | \n\t[" + + StartupOption.BOOTSTRAPSTANDBY.getName() + "] | \n\t[" + + StartupOption.RECOVER.getName() + " [ " + + StartupOption.FORCE.getName() + "] ] | \n\t[" + + StartupOption.METADATAVERSION.getName() + " ] " + + " ]"; + public long getProtocolVersion(String protocol, long clientVersion) throws IOException { @@ -1266,6 +1269,8 @@ public class NameNode implements NameNod "can't understand option \"" + args[i] + "\""); } } + } else if (StartupOption.METADATAVERSION.getName().equalsIgnoreCase(cmd)) { + startOpt = StartupOption.METADATAVERSION; } else { return null; } @@ -1318,6 +1323,21 @@ public class NameNode implements NameNod } } + /** + * Verify that configured directories exist, then print the metadata versions + * of the software and the image. + * + * @param conf configuration to use + * @throws IOException + */ + private static boolean printMetadataVersion(Configuration conf) + throws IOException { + final FSImage fsImage = new FSImage(conf); + final FSNamesystem fs = new FSNamesystem(conf, fsImage, false); + return fsImage.recoverTransitionRead( + StartupOption.METADATAVERSION, fs, null); + } + public static NameNode createNameNode(String argv[], Configuration conf) throws IOException { LOG.info("createNameNode " + Arrays.asList(argv)); @@ -1382,6 +1402,11 @@ public class NameNode implements NameNod NameNode.doRecovery(startOpt, conf); return null; } + case METADATAVERSION: { + printMetadataVersion(conf); + terminate(0); + return null; // avoid javac warning + } default: { DefaultMetricsSystem.initialize("NameNode"); return new NameNode(conf); Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java?rev=1605928&view=auto ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java (added) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java Thu Jun 26 23:12:45 2014 @@ -0,0 +1,77 @@ +/** + * 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; + +import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; +import static org.junit.Assert.assertTrue; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hadoop.hdfs.protocol.HdfsConstants; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +public class TestMetadataVersionOutput { + + private MiniDFSCluster dfsCluster = null; + private final Configuration conf = new Configuration(); + + @Before + public void setUp() throws Exception { + dfsCluster = new MiniDFSCluster.Builder(conf). + numDataNodes(1). + checkExitOnShutdown(false). + build(); + dfsCluster.waitClusterUp(); + } + + @After + public void tearDown() throws Exception { + if (dfsCluster != null) { + dfsCluster.shutdown(); + } + Thread.sleep(2000); + } + + @Test(timeout = 30000) + public void testMetadataVersionOutput() throws IOException { + + final PrintStream origOut = System.out; + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final PrintStream stdOut = new PrintStream(baos); + System.setOut(stdOut); + try { + NameNode.createNameNode(new String[] { "-metadataVersion" }, conf); + } catch (Exception e) { + assertExceptionContains("ExitException", e); + } + /* Check if meta data version is printed correctly. */ + final String verNumStr = HdfsConstants.NAMENODE_LAYOUT_VERSION + ""; + assertTrue(baos.toString("UTF-8"). + contains("HDFS Image Version: " + verNumStr)); + assertTrue(baos.toString("UTF-8"). + contains("Software format version: " + verNumStr)); + System.setOut(origOut); + } +}