hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1125028 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
Date Thu, 19 May 2011 18:06:04 GMT
Author: suresh
Date: Thu May 19 18:06:03 2011
New Revision: 1125028

URL: http://svn.apache.org/viewvc?rev=1125028&view=rev
Log:
HDFS-1905. Improve namenode -format command by not making -clusterId parameter mandatory.
Contributed by Bharath Mundlapudi.


Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
    hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1125028&r1=1125027&r2=1125028&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Thu May 19 18:06:03 2011
@@ -439,6 +439,9 @@ Trunk (unreleased changes)
     HDFS-1958. Confirmation should be more lenient of user input when
     formatting the NameNode. (todd)
 
+    HDFS-1905. Improve namenode -format command by not making -clusterId
+    parameter mandatory. (Bharath Mundlapudi via suresh)
+
   OPTIMIZATIONS
 
     HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1125028&r1=1125027&r2=1125028&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Thu May
19 18:06:03 2011
@@ -1494,23 +1494,16 @@ public class NameNode implements Namenod
       }
     }
 
-    FSImage fsImage = new FSImage(dirsToFormat, editDirsToFormat);
-    FSNamesystem nsys = new FSNamesystem(fsImage, conf);
-    
     // if clusterID is not provided - see if you can find the current one
     String clusterId = StartupOption.FORMAT.getClusterId();
     if(clusterId == null || clusterId.equals("")) {
-      // try to get one from the existing storage
-      clusterId = fsImage.getStorage().determineClusterId();
-      if (clusterId == null || clusterId.equals("")) {
-        throw new IllegalArgumentException("Format must be provided with clusterid");
-      }
-      if(isConfirmationNeeded) {
-        if (!confirmPrompt("Use existing cluster id=" + clusterId + "?")) {
-          throw new IllegalArgumentException("Format must be provided with clusterid");
-        }
-      }
+      //Generate a new cluster id
+      clusterId = NNStorage.newClusterID();
     }
+    System.out.println("Formatting using clusterid: " + clusterId);
+    
+    FSImage fsImage = new FSImage(dirsToFormat, editDirsToFormat);
+    FSNamesystem nsys = new FSNamesystem(fsImage, conf);
     nsys.dir.fsImage.getStorage().format(clusterId);
     return false;
   }

Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java?rev=1125028&r1=1125027&r2=1125028&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
(original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestClusterId.java
Thu May 19 18:06:03 2011
@@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.na
 
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -44,13 +45,29 @@ public class TestClusterId {
   private static final Log LOG = LogFactory.getLog(TestClusterId.class);
   File hdfsDir;
   
+  private String getClusterId(Configuration config) throws IOException {
+    // see if cluster id not empty.
+    Collection<URI> dirsToFormat = FSNamesystem.getNamespaceDirs(config);
+    Collection<URI> editsToFormat = new ArrayList<URI>(0);
+    FSImage fsImage = new FSImage(dirsToFormat, editsToFormat);
+    
+    Iterator<StorageDirectory> sdit = 
+      fsImage.getStorage().dirIterator(NNStorage.NameNodeDirType.IMAGE);
+    StorageDirectory sd = sdit.next();
+    Properties props = sd.readFrom(sd.getVersionFile());
+    String cid = props.getProperty("clusterID");
+    LOG.info("successfully formated : sd="+sd.getCurrentDir() + ";cid="+cid);
+    return cid;
+  }
+  
   @Before
   public void setUp() throws IOException {
     String baseDir = System.getProperty("test.build.data", "build/test/data");
 
     hdfsDir = new File(baseDir, "dfs");
     if ( hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir) ) {
-      throw new IOException("Could not delete test directory '" + hdfsDir + "'");
+      throw new IOException("Could not delete test directory '" + 
+          hdfsDir + "'");
     }
     LOG.info("hdfsdir is " + hdfsDir.getAbsolutePath());
   }
@@ -58,7 +75,8 @@ public class TestClusterId {
   @After
   public void tearDown() throws IOException {
     if ( hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir) ) {
-      throw new IOException("Could not tearDown test directory '" + hdfsDir + "'");
+      throw new IOException("Could not tearDown test directory '" +
+          hdfsDir + "'");
     }
   }
   
@@ -68,53 +86,25 @@ public class TestClusterId {
     
     config.set(DFS_NAMENODE_NAME_DIR_KEY, new File(hdfsDir, "name").getPath());
 
-    // 1. should fail to format without cluster id
-    StartupOption.FORMAT.setClusterId("");
-    try {
-      NameNode.format(config);
-      fail("should fail to format without cluster id");
-    } catch (IllegalArgumentException e) {
-      LOG.info("correctly thrown IllegalArgumentException ");
-    } catch (Exception e) {
-      fail("failed with a wrong exception:" + e.getLocalizedMessage());
-    }
+    // 1. should format without cluster id
+    //StartupOption.FORMAT.setClusterId("");
+    NameNode.format(config);
+    // see if cluster id not empty.
+    String cid = getClusterId(config);
+    assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals("")) );
 
-    // 2. successful format
+    // 2. successful format with given clusterid
     StartupOption.FORMAT.setClusterId("mycluster");
-    try {
-      NameNode.format(config);
-    } catch (Exception e) {
-      fail("failed to format namenode:"+e.getLocalizedMessage());
-    }
-    // see if cluster id not empty.
-    Collection<URI> dirsToFormat = FSNamesystem.getNamespaceDirs(config);
-    Collection<URI> editsToFormat = new ArrayList<URI>(0);
-    FSImage fsImage = new FSImage(dirsToFormat, editsToFormat);
-    
-    Iterator<StorageDirectory> sdit = 
-      fsImage.getStorage().dirIterator(NNStorage.NameNodeDirType.IMAGE);
-    StorageDirectory sd = sdit.next();
-    Properties props = sd.readFrom(sd.getVersionFile());
-    String cid = props.getProperty("clusterID");
-    LOG.info("successfully formated : sd="+sd.getCurrentDir() + ";cid="+cid);
-    if(cid == null || cid.equals("")) {
-      fail("didn't get new ClusterId");
-    }
-    
+    NameNode.format(config);
+    // see if cluster id matches with given clusterid.
+    cid = getClusterId(config);
+    assertTrue("ClusterId didn't match", cid.equals("mycluster"));
 
-    // 3. format with existing cluster id
+    // 3. format without any clusterid again. It should generate new
+    //clusterid.
     StartupOption.FORMAT.setClusterId("");
-    try {
-      NameNode.format(config);
-    } catch (Exception e) {
-      fail("failed to format namenode:"+e.getLocalizedMessage());
-    }
-    props = sd.readFrom(sd.getVersionFile());
-    String newCid = props.getProperty("clusterID");
-    LOG.info("successfully formated with new cid: sd="+sd.getCurrentDir() + ";cid="+newCid);
-    if(newCid == null || newCid.equals("")) {
-      fail("didn't get new ClusterId");
-    }
-    assertTrue("should be the same", newCid.equals(cid));
+    NameNode.format(config);
+    String newCid = getClusterId(config);
+    assertFalse("ClusterId should not be the same", newCid.equals(cid));
   }
 }



Mime
View raw message