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/20 06:52:25 UTC

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

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



##########
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.*;
+
+

Review comment:
       nit: this can be one blank line.

##########
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:
       Alternatively, this test can go to `TestDFSZKFailoverController`? We may reuse existing setup and shutdown methods hopefully?

##########
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:
       nit: remove blank lines within `try` clause? Seems related statements. It's fine if you prefer keeping them.
   nit: line length is usually 80 characters. You can check the checkstyle reports from the QA comment, for e.g. https://builds.apache.org/job/hadoop-multibranch/job/PR-1964/2/artifact/out/diff-checkstyle-root.txt

##########
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:
       nit: `assertEquals` is simpler.
   ```
   assertThat("Bind address not expected to be wildcard by default.",
       LOCALHOST_SERVER_ADDRESS, zkfc.getRpcAddressToBindTo().getHostString());
   ```

##########
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:
       nit: not used?

##########
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:
       If you like, you can use try-with on MiniDFSCluster, e.g.
   ```
   try (MiniDFSCluster cluster = new MiniDFSCluster.Builder...) {
       // some stuff using cluster
   }
   ```
   and later
   ```
   try (MiniDFSCluster cluster = new MiniDFSCluster.Builder...) {
       // some stuff using cluster
   }
   ```
   without name conflicts and no necessary to reset cluster to `null` in-between.
   
   But if you move this to `TestDFSZKFailoverController`, we can split this test method into two methods and reuse the mini cluster defined there. I'm fine either way.

##########
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:
       I'm thinking, since we care more about the service RPC binding host, this config should be setting that only.
   ```
   conf.set(DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY, WILDCARD_ADDRESS);
   ```
   Is this agreed?

##########
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:
       This actually can be `private static`. 
   1. First it can be static because it does not refer to this ZKFC object fields
   2. Other methods are `protected` I *guess* because they are overriding parent class `ZKFailoverController` methods. When overriding, we can not change the scope to a smaller one (aka weaker access privilege). So here we keep the `protected` keyword.




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