Skip to content

Commit e6fb8e4

Browse files
committed
HDFS-17602. RBF mount point with SPACE order can not find the most available namespace, it will choose an irrelevant namespace
1 parent 321a6cc commit e6fb8e4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/order/AvailableSpaceResolver.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import java.util.Collections;
2323
import java.util.Comparator;
2424
import java.util.HashMap;
25+
import java.util.HashSet;
2526
import java.util.LinkedList;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Random;
30+
import java.util.Set;
2931

3032
import org.apache.hadoop.conf.Configuration;
3133
import org.apache.hadoop.hdfs.server.federation.resolver.PathLocation;
@@ -118,6 +120,19 @@ protected String chooseFirstNamespace(String path, PathLocation loc) {
118120
getSubclusterMapping();
119121
List<SubclusterAvailableSpace> subclusterList = new LinkedList<>(
120122
subclusterInfo.values());
123+
if (loc != null && loc.getDestinations() != null) {
124+
Set<String> locSet = new HashSet<String>();
125+
for (RemoteLocation dest : loc.getDestinations()) {
126+
locSet.add(dest.getNameserviceId());
127+
}
128+
List<SubclusterAvailableSpace> filteredSubclusterList = new LinkedList<>();
129+
for (SubclusterAvailableSpace cluster : subclusterList) {
130+
if (locSet.contains(cluster.getNameserviceId())) {
131+
filteredSubclusterList.add(cluster);
132+
}
133+
}
134+
subclusterList = filteredSubclusterList;
135+
}
121136
Collections.sort(subclusterList, comparator);
122137

123138
return subclusterList.size() > 0 ? subclusterList.get(0).getNameserviceId()

0 commit comments

Comments
 (0)