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 1fce04c5741..d1e7a1b7383 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 abstract class AbstractFileSystem { + " 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 5866c4960c8..568bf04ce16 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 @@ -2705,6 +2705,23 @@ public class FileContext { }.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 74f3adaa409..a2e626cc86f 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 @@ -2666,7 +2666,7 @@ public abstract class FileSystem extends Configured implements Closeable { * @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 248377c9727..d7e313ffe8c 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 abstract class FilterFs extends AbstractFileSystem { 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 568b9a0f861..f07e07f199d 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 @@ class ChRootedFs extends AbstractFileSystem { 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 6f05e77dd01..2f932969502 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 class ViewFs extends AbstractFileSystem { 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 6dd88844b0c..82ee41a1221 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 class Hdfs extends AbstractFileSystem { 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));