Skip to content

Commit 2dca4d8

Browse files
author
yakunw2
committed
Fixed the race condition in testViewFsMultipleExportPoint
1 parent 1272a01 commit 2dca4d8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/DFSClientCache.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,19 @@ private void prepareAddressMap() throws IOException {
170170
// if a unique nnid, add it to the map
171171
if (value == null) {
172172
LOG.info("Added export: {} FileSystem URI: {} with namenodeId: {}",
173-
exportPath, exportPath, namenodeId);
173+
exportPath, exportURI, namenodeId);
174174
namenodeUriMap.put(namenodeId, exportURI);
175-
} else {
176-
// if the nnid already exists, it better be the for the same namenode
175+
} else if (!value.equals(exportURI)) {
176+
// Only throw exception if different URIs have the same namenode ID
177177
String msg = String.format("FS:%s, Namenode ID collision for path:%s "
178178
+ "nnid:%s uri being added:%s existing uri:%s", fs.getScheme(),
179179
exportPath, namenodeId, exportURI, value);
180180
LOG.error(msg);
181181
throw new FileSystemException(msg);
182+
} else {
183+
// Same URI with same namenode ID - this is expected and safe to ignore
184+
LOG.debug("Export path {} resolves to same URI {} as existing entry, skipping",
185+
exportPath, exportURI);
182186
}
183187
}
184188
}

hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/Nfs3Utils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.InetSocketAddress;
2222
import java.net.URI;
2323
import java.nio.file.FileSystemException;
24+
import java.util.Objects;
2425

2526
import io.netty.buffer.ByteBuf;
2627
import io.netty.channel.Channel;
@@ -242,7 +243,7 @@ public static int getNamenodeId(Configuration conf) {
242243
public static int getNamenodeId(Configuration conf, URI namenodeURI) {
243244
InetSocketAddress address =
244245
DFSUtilClient.getNNAddressCheckLogical(conf, namenodeURI);
245-
return address.hashCode();
246+
return Objects.hash(namenodeURI.toString(), address.toString());
246247
}
247248

248249
public static URI getResolvedURI(FileSystem fs, String exportPath)

0 commit comments

Comments
 (0)