diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java index f162348244021..cd95373e7467b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/DatanodeID.java @@ -302,6 +302,7 @@ public void updateRegInfo(DatanodeID nodeReg) { setIpAndXferPort(nodeReg.getIpAddr(), nodeReg.getIpAddrBytes(), nodeReg.getXferPort()); hostName = nodeReg.getHostName(); + hostNameBytes = nodeReg.getHostNameBytes(); peerHostName = nodeReg.getPeerHostName(); infoPort = nodeReg.getInfoPort(); infoSecurePort = nodeReg.getInfoSecurePort(); diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestDatanodeID.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestDatanodeID.java new file mode 100644 index 0000000000000..f4022339878f7 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/protocol/TestDatanodeID.java @@ -0,0 +1,39 @@ +/** + * 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.protocol; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class TestDatanodeID { + + @Test + public void testUpdateRegInfoUpdatesHostNameBytes() { + DatanodeID original = new DatanodeID("1.2.3.4", "host1-dc2", + "uuid-1", 9866, 9864, 9865, 9867); + + DatanodeID updated = new DatanodeID("1.2.3.4", "host1-dc2.example.com", + "uuid-1", 9866, 9864, 9865, 9867); + + original.updateRegInfo(updated); + assertEquals("host1-dc2.example.com", original.getHostName()); + assertEquals("host1-dc2.example.com", + original.getHostNameBytes().toStringUtf8()); + } +} \ No newline at end of file