ivandika3 commented on code in PR #10598:
URL: https://github.com/apache/ozone/pull/10598#discussion_r3614842456
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java:
##########
@@ -698,14 +771,32 @@ protected List<HddsDatanodeService> createHddsDatanodes()
for (int i = 0; i < numOfDatanodes; i++) {
OzoneConfiguration dnConf = dnFactory.apply(conf);
+ if (hosts != null) {
+ dnConf.set(HddsConfigKeys.HDDS_DATANODE_HOST_NAME_KEY, hosts[i]);
+ }
+ // Bypass InetAddress.getName() resolution for custom hostnames by
starting DN via YAML.
+ confDatanodeViaYaml(dnConf);
Review Comment:
Could you help explain this? This seems quite to be another workaround.
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneCluster.java:
##########
@@ -369,6 +382,36 @@ public Builder setDatanodeFactory(DatanodeFactory factory)
{
return this;
}
+ /**
+ * Sets the rack location for each datanode. The length of the array
+ * determines the number of datanodes to start. Each entry is a rack
+ * path such as {@code "/rack0"}.
+ *
+ * @param racks rack path per datanode
+ * @return this Builder
+ */
+ public Builder setRacks(String[] racks) {
+ this.racks = Arrays.copyOf(racks, racks.length);
+ this.numOfDatanodes = racks.length;
+ return this;
+ }
+
+ /**
+ * Sets the hostname for each datanode. When used together with
+ * {@link #setRacks}, the hostnames are used as keys in the
+ * {@code StaticMapping} instead of the default synthetic names
+ * ({@code "dn-0"}, {@code "dn-1"}, …). The length of the array must
+ * match the number of datanodes.
+ *
+ * @param hosts hostname per datanode
+ * @return this Builder
+ */
+ public Builder setHosts(String[] hosts) {
+ this.hosts = Arrays.copyOf(hosts, hosts.length);
+ this.numOfDatanodes = hosts.length;
+ return this;
+ }
Review Comment:
Nit: It might be better to instead validate that the number of hosts and
racks is equal to `numOfDatanodes` in the `build()` method instead of updating
the `numOfDatanodes` in implicitly.
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/FixedHostMapping.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.ozone;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+import org.apache.hadoop.net.CachedDNSToSwitchMapping;
+import org.apache.hadoop.net.DNSToSwitchMapping;
+import org.apache.hadoop.net.NetworkTopology;
+
+/**
+ * A {@link CachedDNSToSwitchMapping} implementation that resolves hostnames
+ * to rack locations using a statically configured map, bypassing DNS lookups.
+ *
+ * <p>This is intended for use in test environments (e.g. {@code
MiniOzoneCluster})
+ * where DataNode hostnames may be synthetic or unresolvable via DNS. The
standard
+ * {@link CachedDNSToSwitchMapping} performs DNS normalization before rack
resolution,
+ * which can cause synthetic hostnames to be incorrectly resolved to a real IP
address,
+ * leading to rack mapping failures. This class avoids that by resolving
directly
+ * against the registered hostname.
+ *
+ * <p>The mapping is stored in a JVM-wide static map. Callers must invoke
+ * {@link #addNode(String, String)} before cluster startup to register
hostname-to-rack
+ * entries, and should call {@link #clear()} after each test to avoid
cross-test pollution.
+ *
+ * <p>Usage:
+ * <pre>{@code
+ * FixedHostMapping.addNode("dn-0.test", "/rack1");
+ * FixedHostMapping.addNode("dn-1.test", "/rack1");
+ * FixedHostMapping.addNode("dn-2.test", "/rack2");
+ *
+ * conf.setClass(
+ * CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
+ * FixedHostMapping.class,
+ * DNSToSwitchMapping.class);
+ * }</pre>
+ */
+public class FixedHostMapping extends CachedDNSToSwitchMapping {
Review Comment:
Thanks for the info. Yes, unlike HDFS seems Ozone will try to wrap it in
`CachedDNSToSwitchMapping` which was introduced in HDDS-1663. Personally, I
don't think we need to always wrap to to `CachedDNSToSwitchMapping` due to the
issue you mentioned, that way we can simply use `StaticMapping`. However, let's
leave it be for now.
Although I saw some `StaticMapping` usage in integration tests like in
`TestFailureHandlingByClient`, not sure if this has similar issues.
```
conf.setClass(NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
StaticMapping.class, DNSToSwitchMapping.class);
StaticMapping.addNodeToRack(NetUtils.normalizeHostNames(
Collections.singleton(HddsUtils.getHostName(conf))).get(0),
"/rack1");
```
cc: @ChenSammi
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]