Forráskód Böngészése

HDFS-894. DatanodeID.ipcPort is not updated when existing node re-registers. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@910760 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 15 éve
szülő
commit
c00241c308

+ 3 - 0
CHANGES.txt

@@ -134,6 +134,9 @@ Trunk (unreleased changes)
     HDFS-938. Replace calls to UGI.getUserName() with UGI.getShortUserName()
     (jghoman)
 
+    HDFS-894. DatanodeID.ipcPort is not updated when existing node re-registers.
+    (Todd Lipcon via tomwhite)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 1 - 0
src/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java

@@ -153,6 +153,7 @@ public class DatanodeID implements WritableComparable<DatanodeID> {
   public void updateRegInfo(DatanodeID nodeReg) {
     name = nodeReg.getName();
     infoPort = nodeReg.getInfoPort();
+    ipcPort = nodeReg.getIpcPort();
     // update any more fields added in future.
   }
     

+ 84 - 0
src/test/hdfs/org/apache/hadoop/hdfs/TestDatanodeRegistration.java

@@ -0,0 +1,84 @@
+/**
+ * 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;
+
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.hdfs.protocol.FSConstants.DatanodeReportType;
+import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
+import org.apache.hadoop.hdfs.DFSClient;
+import org.apache.hadoop.fs.Path;
+import junit.framework.TestCase;
+
+/**
+ * This class tests that a file need not be closed before its
+ * data can be read by another client.
+ */
+public class TestDatanodeRegistration extends TestCase {
+
+  /**
+   * Regression test for HDFS-894 ensures that, when datanodes
+   * are restarted, the new IPC port is registered with the
+   * namenode.
+   */
+  public void testChangeIpcPort() throws Exception {
+    HdfsConfiguration conf = new HdfsConfiguration();
+    MiniDFSCluster cluster = null;
+    FileSystem fs = null;
+    try {
+      cluster = new MiniDFSCluster(conf, 1, true, null);
+      fs = cluster.getFileSystem();
+
+      InetSocketAddress addr = new InetSocketAddress(
+        "localhost",
+        cluster.getNameNodePort());
+      DFSClient client = new DFSClient(addr, conf);
+
+      // Restart datanodes
+      cluster.restartDataNodes();
+
+      // Wait until we get a heartbeat from the new datanode
+      DatanodeInfo[] report = client.datanodeReport(DatanodeReportType.ALL);
+      long firstUpdateAfterRestart = report[0].getLastUpdate();
+
+      boolean gotHeartbeat = false;
+      for (int i = 0; i < 10 && !gotHeartbeat; i++) {
+        try {
+          Thread.sleep(i*1000);
+        } catch (InterruptedException ie) {}
+
+        report = client.datanodeReport(DatanodeReportType.ALL);
+        gotHeartbeat = (report[0].getLastUpdate() > firstUpdateAfterRestart);
+      }
+      if (!gotHeartbeat) {
+        fail("Never got a heartbeat from restarted datanode.");
+      }
+
+      int realIpcPort = cluster.getDataNodes().get(0)
+        .dnRegistration.getIpcPort();
+      // Now make sure the reported IPC port is the correct one.
+      assertEquals(realIpcPort, report[0].getIpcPort());
+    } finally {
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
+}