hevinhsu commented on code in PR #10598: URL: https://github.com/apache/ozone/pull/10598#discussion_r3643138718
########## 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: In my understanding, `TestFailureHandlingByClient` does not use a user-defined host, so this shouldn't be an issue. I'm curious though — `TestFailureHandlingByClient` doesn't seem to verify racks. I tried removing `conf.setClass(NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, StaticMapping.class, DNSToSwitchMapping.class);` and all tests still passed. So I'm wondering why we need to configure `StaticMapping` here at all. -- 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]
