|
| 1 | +diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java |
| 2 | +index e3f4bfcde84..3d65bcad229 100755 |
| 3 | +--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java |
| 4 | ++++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java |
| 5 | +@@ -147,6 +147,13 @@ public class DFSConfigKeys extends CommonConfigurationKeys { |
| 6 | + public static final boolean DFS_DATANODE_DROP_CACHE_BEHIND_READS_DEFAULT = false; |
| 7 | + public static final String DFS_DATANODE_USE_DN_HOSTNAME = "dfs.datanode.use.datanode.hostname"; |
| 8 | + public static final boolean DFS_DATANODE_USE_DN_HOSTNAME_DEFAULT = false; |
| 9 | ++ |
| 10 | ++ public static final String DFS_DATANODE_REGISTERED_HOSTNAME = "dfs.datanode.registered.hostname"; |
| 11 | ++ public static final String DFS_DATANODE_REGISTERED_DATA_PORT = "dfs.datanode.registered.port"; |
| 12 | ++ public static final String DFS_DATANODE_REGISTERED_HTTP_PORT = "dfs.datanode.registered.http.port"; |
| 13 | ++ public static final String DFS_DATANODE_REGISTERED_HTTPS_PORT = "dfs.datanode.registered.https.port"; |
| 14 | ++ public static final String DFS_DATANODE_REGISTERED_IPC_PORT = "dfs.datanode.registered.ipc.port"; |
| 15 | ++ |
| 16 | + public static final String DFS_DATANODE_MAX_LOCKED_MEMORY_KEY = "dfs.datanode.max.locked.memory"; |
| 17 | + public static final long DFS_DATANODE_MAX_LOCKED_MEMORY_DEFAULT = 0; |
| 18 | + public static final String DFS_DATANODE_FSDATASETCACHE_MAX_THREADS_PER_VOLUME_KEY = "dfs.datanode.fsdatasetcache.max.threads.per.volume"; |
| 19 | +@@ -454,6 +461,8 @@ public class DFSConfigKeys extends CommonConfigurationKeys { |
| 20 | + public static final long DFS_DATANODE_PROCESS_COMMANDS_THRESHOLD_DEFAULT = |
| 21 | + TimeUnit.SECONDS.toMillis(2); |
| 22 | + |
| 23 | ++ public static final String DFS_NAMENODE_DATANODE_REGISTRATION_UNSAFE_ALLOW_ADDRESS_OVERRIDE_KEY = "dfs.namenode.datanode.registration.unsafe.allow-address-override"; |
| 24 | ++ public static final boolean DFS_NAMENODE_DATANODE_REGISTRATION_UNSAFE_ALLOW_ADDRESS_OVERRIDE_DEFAULT = false; |
| 25 | + public static final String DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_KEY = "dfs.namenode.datanode.registration.ip-hostname-check"; |
| 26 | + public static final boolean DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_DEFAULT = true; |
| 27 | + |
| 28 | +diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java |
| 29 | +index 07381fc696f..8aeb92cff11 100644 |
| 30 | +--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java |
| 31 | ++++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java |
| 32 | +@@ -180,6 +180,8 @@ public class DatanodeManager { |
| 33 | + private boolean hasClusterEverBeenMultiRack = false; |
| 34 | + |
| 35 | + private final boolean checkIpHostnameInRegistration; |
| 36 | ++ private final boolean allowRegistrationAddressOverride; |
| 37 | ++ |
| 38 | + /** |
| 39 | + * Whether we should tell datanodes what to cache in replies to |
| 40 | + * heartbeat messages. |
| 41 | +@@ -316,6 +318,11 @@ public class DatanodeManager { |
| 42 | + // Block invalidate limit also has some dependency on heartbeat interval. |
| 43 | + // Check setBlockInvalidateLimit(). |
| 44 | + setBlockInvalidateLimit(configuredBlockInvalidateLimit); |
| 45 | ++ this.allowRegistrationAddressOverride = conf.getBoolean( |
| 46 | ++ DFSConfigKeys.DFS_NAMENODE_DATANODE_REGISTRATION_UNSAFE_ALLOW_ADDRESS_OVERRIDE_KEY, |
| 47 | ++ DFSConfigKeys.DFS_NAMENODE_DATANODE_REGISTRATION_UNSAFE_ALLOW_ADDRESS_OVERRIDE_DEFAULT); |
| 48 | ++ LOG.info(DFSConfigKeys.DFS_NAMENODE_DATANODE_REGISTRATION_UNSAFE_ALLOW_ADDRESS_OVERRIDE_KEY |
| 49 | ++ + "=" + allowRegistrationAddressOverride); |
| 50 | + this.checkIpHostnameInRegistration = conf.getBoolean( |
| 51 | + DFSConfigKeys.DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_KEY, |
| 52 | + DFSConfigKeys.DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_DEFAULT); |
| 53 | +@@ -1138,27 +1145,29 @@ void startAdminOperationIfNecessary(DatanodeDescriptor nodeReg) { |
| 54 | + */ |
| 55 | + public void registerDatanode(DatanodeRegistration nodeReg) |
| 56 | + throws DisallowedDatanodeException, UnresolvedTopologyException { |
| 57 | +- InetAddress dnAddress = Server.getRemoteIp(); |
| 58 | +- if (dnAddress != null) { |
| 59 | +- // Mostly called inside an RPC, update ip and peer hostname |
| 60 | +- String hostname = dnAddress.getHostName(); |
| 61 | +- String ip = dnAddress.getHostAddress(); |
| 62 | +- if (checkIpHostnameInRegistration && !isNameResolved(dnAddress)) { |
| 63 | +- // Reject registration of unresolved datanode to prevent performance |
| 64 | +- // impact of repetitive DNS lookups later. |
| 65 | +- final String message = "hostname cannot be resolved (ip=" |
| 66 | +- + ip + ", hostname=" + hostname + ")"; |
| 67 | +- LOG.warn("Unresolved datanode registration: " + message); |
| 68 | +- throw new DisallowedDatanodeException(nodeReg, message); |
| 69 | ++ if (!allowRegistrationAddressOverride) { |
| 70 | ++ InetAddress dnAddress = Server.getRemoteIp(); |
| 71 | ++ if (dnAddress != null) { |
| 72 | ++ // Mostly called inside an RPC, update ip and peer hostname |
| 73 | ++ String hostname = dnAddress.getHostName(); |
| 74 | ++ String ip = dnAddress.getHostAddress(); |
| 75 | ++ if (checkIpHostnameInRegistration && !isNameResolved(dnAddress)) { |
| 76 | ++ // Reject registration of unresolved datanode to prevent performance |
| 77 | ++ // impact of repetitive DNS lookups later. |
| 78 | ++ final String message = "hostname cannot be resolved (ip=" |
| 79 | ++ + ip + ", hostname=" + hostname + ")"; |
| 80 | ++ LOG.warn("Unresolved datanode registration: " + message); |
| 81 | ++ throw new DisallowedDatanodeException(nodeReg, message); |
| 82 | ++ } |
| 83 | ++ // update node registration with the ip and hostname from rpc request |
| 84 | ++ nodeReg.setIpAddr(ip); |
| 85 | ++ nodeReg.setPeerHostName(hostname); |
| 86 | + } |
| 87 | +- // update node registration with the ip and hostname from rpc request |
| 88 | +- nodeReg.setIpAddr(ip); |
| 89 | +- nodeReg.setPeerHostName(hostname); |
| 90 | + } |
| 91 | +- |
| 92 | ++ |
| 93 | + try { |
| 94 | + nodeReg.setExportedKeys(blockManager.getBlockKeys()); |
| 95 | +- |
| 96 | ++ |
| 97 | + // Checks if the node is not on the hosts list. If it is not, then |
| 98 | + // it will be disallowed from registering. |
| 99 | + if (!hostConfigManager.isIncluded(nodeReg)) { |
| 100 | +diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DNConf.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DNConf.java |
| 101 | +index 9b5343321d3..790d508e5ea 100644 |
| 102 | +--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DNConf.java |
| 103 | ++++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DNConf.java |
| 104 | +@@ -100,6 +100,11 @@ public class DNConf { |
| 105 | + final boolean syncOnClose; |
| 106 | + final boolean encryptDataTransfer; |
| 107 | + final boolean connectToDnViaHostname; |
| 108 | ++ private final String registeredHostname; |
| 109 | ++ private final int registeredDataPort; |
| 110 | ++ private final int registeredHttpPort; |
| 111 | ++ private final int registeredHttpsPort; |
| 112 | ++ private final int registeredIpcPort; |
| 113 | + final boolean overwriteDownstreamDerivedQOP; |
| 114 | + private final boolean pmemCacheRecoveryEnabled; |
| 115 | + |
| 116 | +@@ -188,6 +193,11 @@ public DNConf(final Configurable dn) { |
| 117 | + connectToDnViaHostname = getConf().getBoolean( |
| 118 | + DFSConfigKeys.DFS_DATANODE_USE_DN_HOSTNAME, |
| 119 | + DFSConfigKeys.DFS_DATANODE_USE_DN_HOSTNAME_DEFAULT); |
| 120 | ++ registeredHostname = getConf().get(DFSConfigKeys.DFS_DATANODE_REGISTERED_HOSTNAME); |
| 121 | ++ registeredDataPort = getConf().getInt(DFSConfigKeys.DFS_DATANODE_REGISTERED_DATA_PORT, -1); |
| 122 | ++ registeredHttpPort = getConf().getInt(DFSConfigKeys.DFS_DATANODE_REGISTERED_HTTP_PORT, -1); |
| 123 | ++ registeredHttpsPort = getConf().getInt(DFSConfigKeys.DFS_DATANODE_REGISTERED_HTTPS_PORT, -1); |
| 124 | ++ registeredIpcPort = getConf().getInt(DFSConfigKeys.DFS_DATANODE_REGISTERED_IPC_PORT, -1); |
| 125 | + this.blockReportInterval = getConf().getLong( |
| 126 | + DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, |
| 127 | + DFS_BLOCKREPORT_INTERVAL_MSEC_DEFAULT); |
| 128 | +@@ -362,6 +372,66 @@ public boolean getConnectToDnViaHostname() { |
| 129 | + return connectToDnViaHostname; |
| 130 | + } |
| 131 | + |
| 132 | ++ /** |
| 133 | ++ * Returns a hostname to register with the cluster instead of the system |
| 134 | ++ * hostname. |
| 135 | ++ * This is an expert setting and can be used in multihoming scenarios to |
| 136 | ++ * override the detected hostname. |
| 137 | ++ * |
| 138 | ++ * @return null if the system hostname should be used, otherwise a hostname |
| 139 | ++ */ |
| 140 | ++ public String getRegisteredHostname() { |
| 141 | ++ return registeredHostname; |
| 142 | ++ } |
| 143 | ++ |
| 144 | ++ /** |
| 145 | ++ * Returns a port number to register with the cluster instead of the |
| 146 | ++ * data port that the node is listening on. |
| 147 | ++ * This is an expert setting and can be used in multihoming scenarios to |
| 148 | ++ * override the detected port. |
| 149 | ++ * |
| 150 | ++ * @return -1 if the actual port should be used, otherwise a port number |
| 151 | ++ */ |
| 152 | ++ public int getRegisteredDataPort() { |
| 153 | ++ return registeredDataPort; |
| 154 | ++ } |
| 155 | ++ |
| 156 | ++ /** |
| 157 | ++ * Returns a port number to register with the cluster instead of the |
| 158 | ++ * HTTP port that the node is listening on. |
| 159 | ++ * This is an expert setting and can be used in multihoming scenarios to |
| 160 | ++ * override the detected port. |
| 161 | ++ * |
| 162 | ++ * @return -1 if the actual port should be used, otherwise a port number |
| 163 | ++ */ |
| 164 | ++ public int getRegisteredHttpPort() { |
| 165 | ++ return registeredHttpPort; |
| 166 | ++ } |
| 167 | ++ |
| 168 | ++ /** |
| 169 | ++ * Returns a port number to register with the cluster instead of the |
| 170 | ++ * HTTPS port that the node is listening on. |
| 171 | ++ * This is an expert setting and can be used in multihoming scenarios to |
| 172 | ++ * override the detected port. |
| 173 | ++ * |
| 174 | ++ * @return -1 if the actual port should be used, otherwise a port number |
| 175 | ++ */ |
| 176 | ++ public int getRegisteredHttpsPort() { |
| 177 | ++ return registeredHttpsPort; |
| 178 | ++ } |
| 179 | ++ |
| 180 | ++ /** |
| 181 | ++ * Returns a port number to register with the cluster instead of the |
| 182 | ++ * IPC port that the node is listening on. |
| 183 | ++ * This is an expert setting and can be used in multihoming scenarios to |
| 184 | ++ * override the detected port. |
| 185 | ++ * |
| 186 | ++ * @return -1 if the actual port should be used, otherwise a port number |
| 187 | ++ */ |
| 188 | ++ public int getRegisteredIpcPort() { |
| 189 | ++ return registeredIpcPort; |
| 190 | ++ } |
| 191 | ++ |
| 192 | + /** |
| 193 | + * Returns socket timeout |
| 194 | + * |
| 195 | +diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java |
| 196 | +index 96c4ad9ae28..fdb8e631dc8 100644 |
| 197 | +--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java |
| 198 | ++++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java |
| 199 | +@@ -117,6 +117,7 @@ |
| 200 | + import java.util.Iterator; |
| 201 | + import java.util.List; |
| 202 | + import java.util.Map; |
| 203 | ++import java.util.Optional; |
| 204 | + import java.util.Map.Entry; |
| 205 | + import java.util.Set; |
| 206 | + import java.util.UUID; |
| 207 | +@@ -1876,11 +1877,35 @@ DatanodeRegistration createBPRegistration(NamespaceInfo nsInfo) { |
| 208 | + NodeType.DATA_NODE); |
| 209 | + } |
| 210 | + |
| 211 | +- DatanodeID dnId = new DatanodeID( |
| 212 | +- streamingAddr.getAddress().getHostAddress(), hostName, |
| 213 | +- storage.getDatanodeUuid(), getXferPort(), getInfoPort(), |
| 214 | +- infoSecurePort, getIpcPort()); |
| 215 | +- return new DatanodeRegistration(dnId, storageInfo, |
| 216 | ++ String registeredHostname = Optional |
| 217 | ++ .ofNullable(dnConf.getRegisteredHostname()) |
| 218 | ++ .orElseGet(() -> streamingAddr.getAddress().getHostAddress()); |
| 219 | ++ int registeredDataPort = dnConf.getRegisteredDataPort(); |
| 220 | ++ if (registeredDataPort == -1) { |
| 221 | ++ registeredDataPort = getXferPort(); |
| 222 | ++ } |
| 223 | ++ int registeredHttpPort = dnConf.getRegisteredHttpPort(); |
| 224 | ++ if (registeredHttpPort == -1) { |
| 225 | ++ registeredHttpPort = getInfoPort(); |
| 226 | ++ } |
| 227 | ++ int registeredHttpsPort = dnConf.getRegisteredHttpsPort(); |
| 228 | ++ if (registeredHttpsPort == -1) { |
| 229 | ++ registeredHttpsPort = getInfoSecurePort(); |
| 230 | ++ } |
| 231 | ++ int registeredIpcPort = dnConf.getRegisteredIpcPort(); |
| 232 | ++ if (registeredIpcPort == -1) { |
| 233 | ++ registeredIpcPort = getIpcPort(); |
| 234 | ++ } |
| 235 | ++ |
| 236 | ++ DatanodeID dnId = new DatanodeID(registeredHostname, |
| 237 | ++ registeredHostname, |
| 238 | ++ storage.getDatanodeUuid(), |
| 239 | ++ registeredDataPort, |
| 240 | ++ registeredHttpPort, |
| 241 | ++ registeredHttpsPort, |
| 242 | ++ registeredIpcPort); |
| 243 | ++ |
| 244 | ++ return new DatanodeRegistration(dnId, storageInfo, |
| 245 | + new ExportedBlockKeys(), VersionInfo.getVersion()); |
| 246 | + } |
| 247 | + |
0 commit comments