[ 
https://issues.apache.org/jira/browse/HDFS-17449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17834189#comment-17834189
 ] 

ASF GitHub Bot commented on HDFS-17449:
---------------------------------------

teamconfx commented on code in PR #6691:
URL: https://github.com/apache/hadoop/pull/6691#discussion_r1553156626


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java:
##########
@@ -106,9 +106,14 @@ public void initOutOfServiceHosts(List<String> 
decommissionHostNameAndPorts,
         for (String hostNameAndPort : decommissionHostNameAndPorts) {
           DatanodeAdminProperties dn = new DatanodeAdminProperties();
           String[] hostAndPort = hostNameAndPort.split(":");
-          dn.setHostName(hostAndPort[0]);
-          dn.setPort(Integer.parseInt(hostAndPort[1]));
-          dn.setAdminState(AdminStates.DECOMMISSIONED);
+          try {
+            dn.setHostName(hostAndPort[0]);
+            dn.setPort(Integer.parseInt(hostAndPort[1]));
+            dn.setAdminState(AdminStates.DECOMMISSIONED);
+          } catch (Exception e) {
+            throw new IllegalArgumentException("The decommision host name and 
port format is "
+                + "invalid. The format should be in <host>:<port>, not " + 
hostNameAndPort, e);
+          }

Review Comment:
   I've made the change accordingly. Thanks for the advice!





> Ill-formed decommission host name and port pair would trigger IndexOutOfBound 
> error
> -----------------------------------------------------------------------------------
>
>                 Key: HDFS-17449
>                 URL: https://issues.apache.org/jira/browse/HDFS-17449
>             Project: Hadoop HDFS
>          Issue Type: Bug
>            Reporter: ConfX
>            Priority: Major
>              Labels: pull-request-available
>
> h2. What happened:
> Got IndexOutOfBound when trying to run 
> org.apache.hadoop.hdfs.server.namenode.TestDecommissioningStatusWithBackoffMonitor#testDecommissionStatusAfterDNRestart
>  with namenode host provider set to 
> org.apache.hadoop.hdfs.server.blockmanagement.CombinedHostFileManager.
> h2. Buggy code:
> In HostsFileWriter.java:
> {code:java}
> String[] hostAndPort = hostNameAndPort.split(":"); // hostNameAndPort might 
> be invalid
> dn.setHostName(hostAndPort[0]);
> dn.setPort(Integer.parseInt(hostAndPort[1])); // here IndexOutOfBound might 
> be thrown
> dn.setAdminState(AdminStates.DECOMMISSIONED);{code}
> h2. StackTrace:
> {code:java}
> java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
>     at 
> org.apache.hadoop.hdfs.util.HostsFileWriter.initOutOfServiceHosts(HostsFileWriter.java:110){code}
> h2. How to reproduce:
> (1) Set {{dfs.namenode.hosts.provider.classname}} to 
> {{org.apache.hadoop.hdfs.server.blockmanagement.CombinedHostFileManager}}
> (2) Run test: 
> {{org.apache.hadoop.hdfs.server.namenode.TestDecommissioningStatusWithBackoffMonitor#testDecommissionStatusAfterDNRestart}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to