diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/DFSClientCache.java b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/DFSClientCache.java index dc1eb8746964e..7ad575331d9bb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/DFSClientCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/DFSClientCache.java @@ -170,15 +170,19 @@ private void prepareAddressMap() throws IOException { // if a unique nnid, add it to the map if (value == null) { LOG.info("Added export: {} FileSystem URI: {} with namenodeId: {}", - exportPath, exportPath, namenodeId); + exportPath, exportURI, namenodeId); namenodeUriMap.put(namenodeId, exportURI); - } else { - // if the nnid already exists, it better be the for the same namenode + } else if (!value.equals(exportURI)) { + // Only throw exception if different URIs have the same namenode ID String msg = String.format("FS:%s, Namenode ID collision for path:%s " + "nnid:%s uri being added:%s existing uri:%s", fs.getScheme(), exportPath, namenodeId, exportURI, value); LOG.error(msg); throw new FileSystemException(msg); + } else { + // Same URI with same namenode ID - this is expected and safe to ignore + LOG.debug("Export path {} resolves to same URI {} as existing entry, skipping", + exportPath, exportURI); } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/Nfs3Utils.java b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/Nfs3Utils.java index c58dc5976b37d..0d3ef5f923abc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/Nfs3Utils.java +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/Nfs3Utils.java @@ -21,6 +21,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.nio.file.FileSystemException; +import java.util.Objects; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; @@ -242,7 +243,7 @@ public static int getNamenodeId(Configuration conf) { public static int getNamenodeId(Configuration conf, URI namenodeURI) { InetSocketAddress address = DFSUtilClient.getNNAddressCheckLogical(conf, namenodeURI); - return address.hashCode(); + return Objects.hash(namenodeURI.toString(), address.toString()); } public static URI getResolvedURI(FileSystem fs, String exportPath)