Skip to content

Commit 8b85f3e

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 8b85f3e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.apache.hadoop.conf.Configuration;
3131
import org.apache.hadoop.hdfs.server.federation.resolver.PathLocation;
32+
import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
3233
import org.apache.hadoop.hdfs.server.federation.resolver.order.AvailableSpaceResolver.SubclusterAvailableSpace;
3334
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
3435
import org.apache.hadoop.hdfs.server.federation.router.Router;
@@ -116,8 +117,10 @@ protected Map<String, SubclusterAvailableSpace> getSubclusterInfo(
116117
protected String chooseFirstNamespace(String path, PathLocation loc) {
117118
Map<String, SubclusterAvailableSpace> subclusterInfo =
118119
getSubclusterMapping();
119-
List<SubclusterAvailableSpace> subclusterList = new LinkedList<>(
120-
subclusterInfo.values());
120+
List<SubclusterAvailableSpace> subclusterList = new LinkedList<>();
121+
for (RemoteLocation dest : loc.getDestinations()) {
122+
subclusterList.add(subclusterInfo.get(dest.getNameserviceId()));
123+
}
121124
Collections.sort(subclusterList, comparator);
122125

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

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/order/TestAvailableSpaceResolver.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,12 @@ private void verifyRank(float balancerPreference, boolean shouldOrdered,
229229
}
230230
subclusters.clear();
231231
}
232+
233+
@Test
234+
public void testChooseFirstNamespace() throws Exception {
235+
MultipleDestinationMountTableResolver mountTableResolver =
236+
mockAvailableSpaceResolver(1.0f);
237+
PathLocation loc = mountTableResolver.getDestinationForPath("/space");
238+
assertEquals("subcluster9", loc.getDefaultLocation().getNameserviceId());
239+
}
232240
}

0 commit comments

Comments
 (0)