hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bor...@apache.org
Subject svn commit: r1076831 - in /hadoop/hdfs/branches/HDFS-1052: ./ src/java/org/apache/hadoop/hdfs/server/datanode/ src/test/hdfs/org/apache/hadoop/hdfs/ src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/ src/test/hdfs/org/apache/hadoop/test/
Date Thu, 03 Mar 2011 22:11:30 GMT
Author: boryas
Date: Thu Mar  3 22:11:29 2011
New Revision: 1076831

URL: http://svn.apache.org/viewvc?rev=1076831&view=rev
Log:
HDFS-1715. HDFS Federation: warning/error not generated when datanode sees inconsistent/different
Cluster ID between namenodes

Modified:
    hadoop/hdfs/branches/HDFS-1052/CHANGES.txt
    hadoop/hdfs/branches/HDFS-1052/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
    hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/MiniDFSCluster.java
    hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMultipleRegistrations.java
    hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/test/GenericTestUtils.java

Modified: hadoop/hdfs/branches/HDFS-1052/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/HDFS-1052/CHANGES.txt?rev=1076831&r1=1076830&r2=1076831&view=diff
==============================================================================
--- hadoop/hdfs/branches/HDFS-1052/CHANGES.txt (original)
+++ hadoop/hdfs/branches/HDFS-1052/CHANGES.txt Thu Mar  3 22:11:29 2011
@@ -175,6 +175,9 @@ Trunk (unreleased changes)
 
     HDFS-1714. HDFS Federation: refactor upgrade object in DataNode (boryas) 
 
+    HDFS-1715. HDFS Federation: warning/error not generated when datanode sees 
+    inconsistent/different Cluster ID between namenodes (boryas)
+
   IMPROVEMENTS
 
     HDFS-1510. Added test-patch.properties required by test-patch.sh (nigel)

Modified: hadoop/hdfs/branches/HDFS-1052/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/HDFS-1052/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java?rev=1076831&r1=1076830&r2=1076831&view=diff
==============================================================================
--- hadoop/hdfs/branches/HDFS-1052/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
(original)
+++ hadoop/hdfs/branches/HDFS-1052/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
Thu Mar  3 22:11:29 2011
@@ -389,10 +389,13 @@ public class DataNode extends Configured
     }
   }
 
-  private synchronized void setClusterId(String cid) {
-    if(clusterId==null) {
-      clusterId = cid;
+  private synchronized void setClusterId(String cid) throws IOException {
+    if(clusterId != null && !clusterId.equals(cid)) {
+      throw new IOException ("cluster id doesn't match. old cid=" + clusterId 
+          + " new cid="+ cid);
     }
+    // else
+    clusterId = cid;    
   }
 
   private void initConfig(Configuration conf) throws UnknownHostException {
@@ -732,9 +735,20 @@ public class DataNode extends Configured
       // handshake with NN
       NamespaceInfo nsInfo = handshake();
       setNamespaceInfo(nsInfo);
-      setClusterId(nsInfo.clusterID);
-      
-      setupBPStorage();
+      synchronized(DataNode.this) {
+        // we do not allow namenode from different cluster to register
+        if(clusterId != null && !clusterId.equals(nsInfo.clusterID)) {
+          throw new IOException(
+              "cannot register with the namenode because clusterid do not match:"
+              + " nn=" + nsInfo.getBlockPoolID() + "; nn cid=" + nsInfo.clusterID + 
+              ";dn cid=" + clusterId);
+        }
+
+        setupBPStorage();
+
+        setClusterId(nsInfo.clusterID);
+      }
+    
       initPeriodicScanners(conf);
     }
     
@@ -948,7 +962,7 @@ public class DataNode extends Configured
     }
     
     //Cleanup method to be called by current thread before exiting.
-    private void cleanUp() {
+    private synchronized void cleanUp() {
       
       if(upgradeManager != null)
         upgradeManager.shutdownUpgrade();
@@ -2533,7 +2547,7 @@ public class DataNode extends Configured
   }
   
   @Override // DataNodeMXBean
-  public String getClusterId() {
+  public synchronized String getClusterId() {
     return clusterId;
   }
   

Modified: hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/MiniDFSCluster.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/MiniDFSCluster.java?rev=1076831&r1=1076830&r2=1076831&view=diff
==============================================================================
--- hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/MiniDFSCluster.java
(original)
+++ hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/MiniDFSCluster.java
Thu Mar  3 22:11:29 2011
@@ -1337,12 +1337,13 @@ public class MiniDFSCluster {
     if (nameNodes.length == 0 || nameNodes[nnIndex] == null) {
       return;
     }
+    String bpid = nameNodes[nnIndex].nameNode.getFSImage().getBlockPoolID();
     InetSocketAddress addr = new InetSocketAddress("localhost",
         getNameNodePort(nnIndex));
     DFSClient client = new DFSClient(addr, conf);
 
     // ensure all datanodes have registered and sent heartbeat to the namenode
-    while (shouldWait(client.datanodeReport(DatanodeReportType.LIVE))) {
+    while (shouldWait(client.datanodeReport(DatanodeReportType.LIVE), bpid)) {
       try {
         Thread.sleep(100);
       } catch (InterruptedException e) {
@@ -1361,7 +1362,7 @@ public class MiniDFSCluster {
     }
   }
   
-  private synchronized boolean shouldWait(DatanodeInfo[] dnInfo) {
+  private synchronized boolean shouldWait(DatanodeInfo[] dnInfo, String bpid) {
     for (DataNodeProperties dn : dataNodes) {
       // If any one of the datanode is down, then do not continue to wait
       // since the subsequent checks to stop waiting in this method are never
@@ -1369,6 +1370,11 @@ public class MiniDFSCluster {
       if (!dn.datanode.isDatanodeUp()) {
         return false;
       }
+
+      // if registration of this datanode with the namenode failed -  don't wait
+      if(!dn.datanode.isBPServiceAlive(bpid)) {
+        return false;
+      }
     }
     
     if (dnInfo.length != numDataNodes) {

Modified: hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMultipleRegistrations.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMultipleRegistrations.java?rev=1076831&r1=1076830&r2=1076831&view=diff
==============================================================================
--- hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMultipleRegistrations.java
(original)
+++ hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMultipleRegistrations.java
Thu Mar  3 22:11:29 2011
@@ -18,6 +18,11 @@
 
 package org.apache.hadoop.hdfs.server.datanode;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 import java.util.Collection;
 
@@ -26,11 +31,12 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.server.common.HdfsConstants.StartupOption;
 import org.apache.hadoop.hdfs.server.datanode.DataNode.BPOfferService;
 import org.apache.hadoop.hdfs.server.datanode.FSDataset.VolumeInfo;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
-import static org.junit.Assert.*;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -175,4 +181,38 @@ public class TestDataNodeMultipleRegistr
       }
     }
   }
+  
+  @Test
+  public void testClusterIdMismatch() throws IOException {
+    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numNameNodes(2).
+    nameNodePort(9928).build();
+    try {
+      cluster.waitActive();
+
+      DataNode dn = cluster.getDataNodes().get(0);
+      BPOfferService [] bposs = dn.getAllBpOs(); 
+      LOG.info("dn bpos len (should be 2):" + bposs.length);
+      Assert.assertEquals("should've registered with two namenodes", bposs.length,2);
+      
+      // add another namenode
+      cluster.addNameNode(conf, 9938);
+      bposs = dn.getAllBpOs(); 
+      LOG.info("dn bpos len (should be 3):" + bposs.length);
+      Assert.assertEquals("should've registered with three namenodes", bposs.length,3);
+      
+      // change cluster id and another Namenode
+      StartupOption.FORMAT.setClusterId("DifferentCID");
+      cluster.addNameNode(conf, 9948);
+      NameNode nn4 = cluster.getNameNode(3);
+      assertNotNull("cannot create nn4", nn4);
+      
+      bposs = dn.getAllBpOs(); 
+      LOG.info("dn bpos len (still should be 3):" + bposs.length);
+      Assert.assertEquals("should've registered with three namenodes", 3, bposs.length);
+    } finally {
+      if(cluster != null) 
+        cluster.shutdown();
+    }
+  }
+
 }

Modified: hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/test/GenericTestUtils.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/test/GenericTestUtils.java?rev=1076831&r1=1076830&r2=1076831&view=diff
==============================================================================
--- hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/test/GenericTestUtils.java
(original)
+++ hadoop/hdfs/branches/HDFS-1052/src/test/hdfs/org/apache/hadoop/test/GenericTestUtils.java
Thu Mar  3 22:11:29 2011
@@ -41,7 +41,10 @@ public abstract class GenericTestUtils {
    * @throws IOException
    */
   public static void formatNamenode(Configuration conf) throws IOException {
-    StartupOption.FORMAT.setClusterId("testClusterID");
+    String clusterId = StartupOption.FORMAT.getClusterId();
+    if(clusterId == null || clusterId.isEmpty())
+      StartupOption.FORMAT.setClusterId("testClusterID");
+
     NameNode.format(conf);
   }
 }



Mime
View raw message