Browse Source

HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou.

Jing Zhao 9 năm trước cách đây
mục cha
commit
4a043b3fec

+ 11 - 0
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.
    *

+ 17 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java

@@ -2695,6 +2695,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<Void>() {
+      @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.
    *

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java

@@ -2663,7 +2663,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");
   }

+ 6 - 0
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 {

+ 6 - 0
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 {

+ 8 - 0
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<AbstractFileSystem> res =
+        fsState.resolve(getUriPath(src), true);
+    res.targetFileSystem.unsetStoragePolicy(res.remainingPath);
+  }
+
   /**
    * Retrieve the storage policy for a given file or directory.
    *

+ 5 - 0
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));