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 20:48:59 UTC

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

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



##########
File path: hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java
##########
@@ -321,6 +321,7 @@ private void initHM() {
   
   protected void initRPC() throws IOException {
     InetSocketAddress bindAddr = getRpcAddressToBindTo();
+    LOG.info("ZKFC RpcServer binding to " + bindAddr);

Review comment:
       Use the logger format with {}

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSZKFailoverController.java
##########
@@ -125,7 +128,21 @@ 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.

Review comment:
       Use standard javadoc with a break line and add the param and the return.

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSZKFailoverController.java
##########
@@ -125,7 +128,21 @@ 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.

Review comment:
       It kind of comes from HAUtil but let's make it right here.

##########
File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSZKFailoverController.java
##########
@@ -111,8 +111,11 @@ 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()) {

Review comment:
       As this is already checking for ==null or isEmpty() this is redundant with getZkfcServerBindHost() we could just return the value instead of doing line 139.

##########
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";

Review comment:
       The checkstyle with the spaces will fail here.

##########
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);

Review comment:
       Use logger

##########
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);

Review comment:
       Use logger and logger {} format.

##########
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);

Review comment:
       Let's split this into different test methods and we can potentially do the cluster cleanup in the After method.

##########
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);

Review comment:
       Not needed.




----------------------------------------------------------------
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