From 4a043b3fec702f3e91525a20f5f36657e9fbf8df Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Thu, 21 Apr 2016 18:07:35 -0700 Subject: [PATCH] HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou. --- .../apache/hadoop/fs/AbstractFileSystem.java | 11 +++++++++++ .../java/org/apache/hadoop/fs/FileContext.java | 17 +++++++++++++++++ .../java/org/apache/hadoop/fs/FileSystem.java | 2 +- .../java/org/apache/hadoop/fs/FilterFs.java | 6 ++++++ .../org/apache/hadoop/fs/viewfs/ChRootedFs.java | 6 ++++++ .../org/apache/hadoop/fs/viewfs/ViewFs.java | 8 ++++++++ .../main/java/org/apache/hadoop/fs/Hdfs.java | 5 +++++ 7 files changed, 54 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java index 1fce04c574..d1e7a1b738 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java @@ -1236,6 +1236,17 @@ public void setStoragePolicy(final Path path, final String policyName) + " doesn't support setStoragePolicy"); } + + /** + * Unset the storage policy set for a given file or directory. + * @param src file or directory path. + * @throws IOException + */ + public void unsetStoragePolicy(final Path src) throws IOException { + throw new UnsupportedOperationException(getClass().getSimpleName() + + " doesn't support unsetStoragePolicy"); + } + /** * Retrieve the storage policy for a given file or directory. * diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java index d96abad059..d1afd41fe1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java @@ -2695,6 +2695,23 @@ public Void next(final AbstractFileSystem fs, final Path p) }.resolve(this, absF); } + /** + * Unset the storage policy set for a given file or directory. + * @param src file or directory path. + * @throws IOException + */ + public void unsetStoragePolicy(final Path src) throws IOException { + final Path absF = fixRelativePart(src); + new FSLinkResolver() { + @Override + public Void next(final AbstractFileSystem fs, final Path p) + throws IOException { + fs.unsetStoragePolicy(src); + return null; + } + }.resolve(this, absF); + } + /** * Query the effective storage policy ID for the given file or directory. * diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index e0ea7ac736..719c571cc6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -2663,7 +2663,7 @@ public void setStoragePolicy(final Path src, final String policyName) * @param src file or directory path. * @throws IOException */ - public void unsetStoragePolicy(Path src) throws IOException { + public void unsetStoragePolicy(final Path src) throws IOException { throw new UnsupportedOperationException(getClass().getSimpleName() + " doesn't support unsetStoragePolicy"); } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java index 248377c972..d7e313ffe8 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java @@ -405,6 +405,12 @@ public void setStoragePolicy(Path path, String policyName) myFs.setStoragePolicy(path, policyName); } + @Override + public void unsetStoragePolicy(final Path src) + throws IOException { + myFs.unsetStoragePolicy(src); + } + @Override public BlockStoragePolicySpi getStoragePolicy(final Path src) throws IOException { diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java index 568b9a0f86..f07e07f199 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java @@ -385,6 +385,12 @@ public void setStoragePolicy(Path path, String policyName) myFs.setStoragePolicy(fullPath(path), policyName); } + @Override + public void unsetStoragePolicy(final Path src) + throws IOException { + myFs.unsetStoragePolicy(fullPath(src)); + } + @Override public BlockStoragePolicySpi getStoragePolicy(final Path src) throws IOException { diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java index 6f05e77dd0..2f93296950 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java @@ -749,6 +749,14 @@ public void setStoragePolicy(final Path path, final String policyName) res.targetFileSystem.setStoragePolicy(res.remainingPath, policyName); } + @Override + public void unsetStoragePolicy(final Path src) + throws IOException { + InodeTree.ResolveResult res = + fsState.resolve(getUriPath(src), true); + res.targetFileSystem.unsetStoragePolicy(res.remainingPath); + } + /** * Retrieve the storage policy for a given file or directory. * diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java index 6dd88844b0..82ee41a122 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java @@ -473,6 +473,11 @@ public void setStoragePolicy(Path path, String policyName) throws IOException { dfs.setStoragePolicy(getUriPath(path), policyName); } + @Override + public void unsetStoragePolicy(final Path src) throws IOException { + dfs.unsetStoragePolicy(getUriPath(src)); + } + @Override public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException { return dfs.getStoragePolicy(getUriPath(src));