XorSum commented on code in PR #8179:
URL: https://github.com/apache/hadoop/pull/8179#discussion_r2689115235
##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java:
##########
@@ -629,14 +629,27 @@ public String getDefaultNamespace() {
private MountTable findDeepest(final String path) {
readLock.lock();
try {
- Entry<String, MountTable> entry = this.tree.floorEntry(path);
- while (entry != null && !isParentEntry(path, entry.getKey())) {
- entry = this.tree.lowerEntry(entry.getKey());
+ Entry<String, MountTable> floorEntry = this.tree.floorEntry(path);
+ if (floorEntry != null && isParentEntry(path, floorEntry.getKey())) {
+ return floorEntry.getValue();
}
Review Comment:
@KeeProMise Thanks for the suggestion to use HashMap! However, I think it's
better to keep using TreeMap for the following two reasons:
1. **Other code depends on TreeMap-specific methods**: There are other
methods (e.g., `getMountPoints`, `getTreeValues`) that use
`TreeMap.subMap(from, to)`, which does not exist in `HashMap`.
2. **Performance trade-offs between TreeMap and HashMap**: The benchmark
results show that HashMap is not always better than TreeMap. Their performance
characteristics differ depending on the use case:
- **TreeMap performs better for the hit case**
- **HashMap performs better for the not hit case**
The benchmark code is available at:
https://gist.github.com/XorSum/c1ed0b37b46eb6f1e6eb103867a9a0f5
Given that mount hits are the common case in production (as you mentioned
"it should hit in most cases"), TreeMap provides better overall performance for
the typical workload.
--
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]