You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2020/04/22 08:26:30 UTC

[GitHub] [hadoop] dhirajh commented on a change in pull request #1964: HDFS-15281: Make sure ZKFC uses dfs.namenode.rpc-address to bind to host address

dhirajh commented on a change in pull request #1964:
URL: https://github.com/apache/hadoop/pull/1964#discussion_r412743403



##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;

Review comment:
       Fixed

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSZKFailoverController.java
##########
@@ -111,21 +111,37 @@ protected HAServiceTarget dataToTarget(byte[] data) {
   @Override
   protected InetSocketAddress getRpcAddressToBindTo() {
     int zkfcPort = getZkfcPort(conf);
-    return new InetSocketAddress(localTarget.getAddress().getAddress(),
-          zkfcPort);
+    String zkfcBindAddr = getZkfcServerBindHost(conf);
+    if (zkfcBindAddr == null || zkfcBindAddr.isEmpty()) {
+      zkfcBindAddr = localTarget.getAddress().getAddress().getHostAddress();
+    }
+    return new InetSocketAddress(zkfcBindAddr, zkfcPort);
   }
-  
 
   @Override
   protected PolicyProvider getPolicyProvider() {
     return new HDFSPolicyProvider();
   }
-  
+
   static int getZkfcPort(Configuration conf) {
     return conf.getInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY,
         DFSConfigKeys.DFS_HA_ZKFC_PORT_DEFAULT);
   }
-  
+
+  /** Given a configuration get the bind host that could be used by ZKFC.
+   * We derive it from NN service rpc bind host or NN rpc bind host.
+   */
+  protected String getZkfcServerBindHost(Configuration conf) {

Review comment:
       Fixed

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.apache.hadoop.net.ServerSocketUtil;
+import org.junit.Test;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+
+
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+
+public class TestDFSZKFCRespectsBindHostKeys {
+    public static final Log LOG = LogFactory.getLog(TestDFSZKFCRespectsBindHostKeys.class);
+    private static final String WILDCARD_ADDRESS = "0.0.0.0";
+    private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1";
+
+    @Test(timeout=300000)
+    public void testRpcBindHostKey() throws IOException {
+        Configuration conf = new HdfsConfiguration();
+        MiniDFSCluster cluster = null;
+        //conf.set(ZKFailoverController.ZK_QUORUM_KEY + ".ns1", hostPort);
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1",
+                ServerSocketUtil.getPort(10023, 100));
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2",
+                ServerSocketUtil.getPort(10024, 100));
+
+        LOG.info("Testing without " + DFS_NAMENODE_RPC_BIND_HOST_KEY);
+
+        // prefer non-ephemeral port to avoid port collision on restartNameNode
+        MiniDFSNNTopology topology = new MiniDFSNNTopology()
+                .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
+                        .addNN(new MiniDFSNNTopology.NNConf("nn1")
+                                .setIpcPort(ServerSocketUtil.getPort(10021, 100)))
+                        .addNN(new MiniDFSNNTopology.NNConf("nn2")
+                                .setIpcPort(ServerSocketUtil.getPort(10022, 100))));
+        // ZKFC should not bind the wildcard address by default.
+        try {

Review comment:
       Went with the first suggestion

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.apache.hadoop.net.ServerSocketUtil;
+import org.junit.Test;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+
+
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+
+public class TestDFSZKFCRespectsBindHostKeys {

Review comment:
       Fixed. I moved tests case to TestDFSZKFailoverController

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.apache.hadoop.net.ServerSocketUtil;
+import org.junit.Test;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+
+
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+
+public class TestDFSZKFCRespectsBindHostKeys {
+    public static final Log LOG = LogFactory.getLog(TestDFSZKFCRespectsBindHostKeys.class);
+    private static final String WILDCARD_ADDRESS = "0.0.0.0";
+    private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1";
+
+    @Test(timeout=300000)
+    public void testRpcBindHostKey() throws IOException {
+        Configuration conf = new HdfsConfiguration();
+        MiniDFSCluster cluster = null;
+        //conf.set(ZKFailoverController.ZK_QUORUM_KEY + ".ns1", hostPort);
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1",
+                ServerSocketUtil.getPort(10023, 100));
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2",
+                ServerSocketUtil.getPort(10024, 100));
+
+        LOG.info("Testing without " + DFS_NAMENODE_RPC_BIND_HOST_KEY);
+
+        // prefer non-ephemeral port to avoid port collision on restartNameNode
+        MiniDFSNNTopology topology = new MiniDFSNNTopology()
+                .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
+                        .addNN(new MiniDFSNNTopology.NNConf("nn1")
+                                .setIpcPort(ServerSocketUtil.getPort(10021, 100)))
+                        .addNN(new MiniDFSNNTopology.NNConf("nn2")
+                                .setIpcPort(ServerSocketUtil.getPort(10022, 100))));
+        // ZKFC should not bind the wildcard address by default.
+        try {
+
+            cluster = new MiniDFSCluster.Builder(conf).nnTopology(topology).numDataNodes(0).build();
+
+            DFSZKFailoverController zkfc = DFSZKFailoverController.create(
+                    conf);
+
+            assertThat("Bind address not expected to be wildcard by default.",

Review comment:
       Fixed.

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.apache.hadoop.net.ServerSocketUtil;
+import org.junit.Test;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+
+
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+
+public class TestDFSZKFCRespectsBindHostKeys {
+    public static final Log LOG = LogFactory.getLog(TestDFSZKFCRespectsBindHostKeys.class);
+    private static final String WILDCARD_ADDRESS = "0.0.0.0";
+    private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1";
+
+    @Test(timeout=300000)
+    public void testRpcBindHostKey() throws IOException {
+        Configuration conf = new HdfsConfiguration();
+        MiniDFSCluster cluster = null;
+        //conf.set(ZKFailoverController.ZK_QUORUM_KEY + ".ns1", hostPort);
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1",
+                ServerSocketUtil.getPort(10023, 100));
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2",
+                ServerSocketUtil.getPort(10024, 100));
+
+        LOG.info("Testing without " + DFS_NAMENODE_RPC_BIND_HOST_KEY);
+
+        // prefer non-ephemeral port to avoid port collision on restartNameNode
+        MiniDFSNNTopology topology = new MiniDFSNNTopology()
+                .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
+                        .addNN(new MiniDFSNNTopology.NNConf("nn1")
+                                .setIpcPort(ServerSocketUtil.getPort(10021, 100)))
+                        .addNN(new MiniDFSNNTopology.NNConf("nn2")
+                                .setIpcPort(ServerSocketUtil.getPort(10022, 100))));
+        // ZKFC should not bind the wildcard address by default.
+        try {
+

Review comment:
       Fixed

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSZKFCRespectsBindHostKeys.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.tools;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.apache.hadoop.net.ServerSocketUtil;
+import org.junit.Test;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+
+
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+
+public class TestDFSZKFCRespectsBindHostKeys {
+    public static final Log LOG = LogFactory.getLog(TestDFSZKFCRespectsBindHostKeys.class);
+    private static final String WILDCARD_ADDRESS = "0.0.0.0";
+    private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1";
+
+    @Test(timeout=300000)
+    public void testRpcBindHostKey() throws IOException {
+        Configuration conf = new HdfsConfiguration();
+        MiniDFSCluster cluster = null;
+        //conf.set(ZKFailoverController.ZK_QUORUM_KEY + ".ns1", hostPort);
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1",
+                ServerSocketUtil.getPort(10023, 100));
+        conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2",
+                ServerSocketUtil.getPort(10024, 100));
+
+        LOG.info("Testing without " + DFS_NAMENODE_RPC_BIND_HOST_KEY);
+
+        // prefer non-ephemeral port to avoid port collision on restartNameNode
+        MiniDFSNNTopology topology = new MiniDFSNNTopology()
+                .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
+                        .addNN(new MiniDFSNNTopology.NNConf("nn1")
+                                .setIpcPort(ServerSocketUtil.getPort(10021, 100)))
+                        .addNN(new MiniDFSNNTopology.NNConf("nn2")
+                                .setIpcPort(ServerSocketUtil.getPort(10022, 100))));
+        // ZKFC should not bind the wildcard address by default.
+        try {
+
+            cluster = new MiniDFSCluster.Builder(conf).nnTopology(topology).numDataNodes(0).build();
+
+            DFSZKFailoverController zkfc = DFSZKFailoverController.create(
+                    conf);
+
+            assertThat("Bind address not expected to be wildcard by default.",
+                    zkfc.getRpcAddressToBindTo().getHostString(), is(LOCALHOST_SERVER_ADDRESS));
+        } finally {
+            if (cluster != null) {
+                cluster.shutdown();
+                cluster = null;
+            }
+        }
+
+        LOG.info("Testing with " + DFS_NAMENODE_RPC_BIND_HOST_KEY);
+
+        // Tell NN to bind the wildcard address.
+        conf.set(DFS_NAMENODE_RPC_BIND_HOST_KEY, WILDCARD_ADDRESS);

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org