From 9f1e23cc675ebefc9f6c0bcad14fdf03b311f39b Mon Sep 17 00:00:00 2001 From: smarthan <1139557635@qq.com> Date: Thu, 1 Jun 2023 11:02:38 +0800 Subject: [PATCH] HDFS-17031. Reduce some repeated codes in RouterRpcServer. (#5701). Contributed by Chengwei Wang. Reviewed-by: Inigo Goiri Reviewed-by: Simbarashe Dzinamarira Signed-off-by: Ayush Saxena --- .../federation/router/RouterRpcServer.java | 40 +++++-------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java index 9d4c2caaa1..1c3a28a992 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java @@ -1830,18 +1830,8 @@ protected List getLocationsForPath(String path, * @return If the path is in a read only mount point. */ private boolean isPathReadOnly(final String path) { - if (subclusterResolver instanceof MountTableResolver) { - try { - MountTableResolver mountTable = (MountTableResolver)subclusterResolver; - MountTable entry = mountTable.getMountPoint(path); - if (entry != null && entry.isReadOnly()) { - return true; - } - } catch (IOException e) { - LOG.error("Cannot get mount point", e); - } - } - return false; + MountTable entry = getMountTable(path); + return entry != null && entry.isReadOnly(); } /** @@ -1940,18 +1930,8 @@ public FederationRPCMetrics getRPCMetrics() { * @return If a path should be in all subclusters. */ boolean isPathAll(final String path) { - if (subclusterResolver instanceof MountTableResolver) { - try { - MountTableResolver mountTable = (MountTableResolver) subclusterResolver; - MountTable entry = mountTable.getMountPoint(path); - if (entry != null) { - return entry.isAll(); - } - } catch (IOException e) { - LOG.error("Cannot get mount point", e); - } - } - return false; + MountTable entry = getMountTable(path); + return entry != null && entry.isAll(); } /** @@ -1961,18 +1941,20 @@ boolean isPathAll(final String path) { * @return If a path should support failed subclusters. */ boolean isPathFaultTolerant(final String path) { + MountTable entry = getMountTable(path); + return entry != null && entry.isFaultTolerant(); + } + + private MountTable getMountTable(final String path){ if (subclusterResolver instanceof MountTableResolver) { try { MountTableResolver mountTable = (MountTableResolver) subclusterResolver; - MountTable entry = mountTable.getMountPoint(path); - if (entry != null) { - return entry.isFaultTolerant(); - } + return mountTable.getMountPoint(path); } catch (IOException e) { LOG.error("Cannot get mount point", e); } } - return false; + return null; } /**