HDFS-17031. Reduce some repeated codes in RouterRpcServer. (#5701). Contributed by Chengwei Wang.

Reviewed-by: Inigo Goiri <inigoiri@apache.org>
Reviewed-by: Simbarashe Dzinamarira <sdzinamarira@linkedin.com>
Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
smarthan 2023-06-01 11:02:38 +08:00 committed by GitHub
parent f8b7ddf69c
commit 9f1e23cc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1830,18 +1830,8 @@ protected List<RemoteLocation> getLocationsForPath(String path,
* @return If the path is in a read only mount point. * @return If the path is in a read only mount point.
*/ */
private boolean isPathReadOnly(final String path) { private boolean isPathReadOnly(final String path) {
if (subclusterResolver instanceof MountTableResolver) { MountTable entry = getMountTable(path);
try { return entry != null && entry.isReadOnly();
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;
} }
/** /**
@ -1940,18 +1930,8 @@ public FederationRPCMetrics getRPCMetrics() {
* @return If a path should be in all subclusters. * @return If a path should be in all subclusters.
*/ */
boolean isPathAll(final String path) { boolean isPathAll(final String path) {
if (subclusterResolver instanceof MountTableResolver) { MountTable entry = getMountTable(path);
try { return entry != null && entry.isAll();
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;
} }
/** /**
@ -1961,18 +1941,20 @@ boolean isPathAll(final String path) {
* @return If a path should support failed subclusters. * @return If a path should support failed subclusters.
*/ */
boolean isPathFaultTolerant(final String path) { boolean isPathFaultTolerant(final String path) {
MountTable entry = getMountTable(path);
return entry != null && entry.isFaultTolerant();
}
private MountTable getMountTable(final String path){
if (subclusterResolver instanceof MountTableResolver) { if (subclusterResolver instanceof MountTableResolver) {
try { try {
MountTableResolver mountTable = (MountTableResolver) subclusterResolver; MountTableResolver mountTable = (MountTableResolver) subclusterResolver;
MountTable entry = mountTable.getMountPoint(path); return mountTable.getMountPoint(path);
if (entry != null) {
return entry.isFaultTolerant();
}
} catch (IOException e) { } catch (IOException e) {
LOG.error("Cannot get mount point", e); LOG.error("Cannot get mount point", e);
} }
} }
return false; return null;
} }
/** /**