فهرست منبع

HDFS-14096. [SPS] : Add Support for Storage Policy Satisfier in ViewFs. Contributed by Ayush Saxena.

Surendra Singh Lilhore 6 سال پیش
والد
کامیت
788e7473a4

+ 10 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java

@@ -1254,6 +1254,16 @@ public abstract class AbstractFileSystem {
         + " doesn't support deleteSnapshot");
   }
 
+  /**
+   * Set the source path to satisfy storage policy.
+   * @param path The source path referring to either a directory or a file.
+   * @throws IOException
+   */
+  public void satisfyStoragePolicy(final Path path) throws IOException {
+    throw new UnsupportedOperationException(
+        getClass().getSimpleName() + " doesn't support satisfyStoragePolicy");
+  }
+
   /**
    * Set the storage policy for a given file or directory.
    *

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

@@ -2780,6 +2780,24 @@ public class FileContext {
     }.resolve(this, absF);
   }
 
+  /**
+   * Set the source path to satisfy storage policy.
+   * @param path The source path referring to either a directory or a file.
+   * @throws IOException
+   */
+  public void satisfyStoragePolicy(final Path path)
+      throws IOException {
+    final Path absF = fixRelativePart(path);
+    new FSLinkResolver<Void>() {
+      @Override
+      public Void next(final AbstractFileSystem fs, final Path p)
+          throws IOException {
+        fs.satisfyStoragePolicy(path);
+        return null;
+      }
+    }.resolve(this, absF);
+  }
+
   /**
    * Set the storage policy for a given file or directory.
    *

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

@@ -3085,6 +3085,16 @@ public abstract class FileSystem extends Configured
         + " doesn't support removeXAttr");
   }
 
+  /**
+   * Set the source path to satisfy storage policy.
+   * @param path The source path referring to either a directory or a file.
+   * @throws IOException
+   */
+  public void satisfyStoragePolicy(final Path path) throws IOException {
+    throw new UnsupportedOperationException(
+        getClass().getSimpleName() + " doesn't support setStoragePolicy");
+  }
+
   /**
    * Set the storage policy for a given file or directory.
    *

+ 5 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java

@@ -645,6 +645,11 @@ public class FilterFileSystem extends FileSystem {
     fs.removeXAttr(path, name);
   }
 
+  @Override
+  public void satisfyStoragePolicy(Path src) throws IOException {
+    fs.satisfyStoragePolicy(src);
+  }
+
   @Override
   public void setStoragePolicy(Path src, String policyName)
       throws IOException {

+ 5 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFs.java

@@ -405,6 +405,11 @@ public abstract class FilterFs extends AbstractFileSystem {
     myFs.deleteSnapshot(path, snapshotName);
   }
 
+  @Override
+  public void satisfyStoragePolicy(final Path path) throws IOException {
+    myFs.satisfyStoragePolicy(path);
+  }
+
   @Override
   public void setStoragePolicy(Path path, String policyName)
       throws IOException {

+ 5 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java

@@ -449,6 +449,11 @@ class ChRootedFileSystem extends FilterFileSystem {
     return super.getStoragePolicy(fullPath(src));
   }
 
+  @Override
+  public void satisfyStoragePolicy(Path src) throws IOException {
+    super.satisfyStoragePolicy(fullPath(src));
+  }
+
   @Override
   public void setStoragePolicy(Path src, String policyName) throws IOException {
     super.setStoragePolicy(fullPath(src), policyName);

+ 5 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFs.java

@@ -398,6 +398,11 @@ class ChRootedFs extends AbstractFileSystem {
     myFs.deleteSnapshot(fullPath(snapshotDir), snapshotName);
   }
 
+  @Override
+  public void satisfyStoragePolicy(final Path path) throws IOException {
+    myFs.satisfyStoragePolicy(path);
+  }
+
   @Override
   public void setStoragePolicy(Path path, String policyName)
     throws IOException {

+ 13 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

@@ -810,6 +810,13 @@ public class ViewFileSystem extends FileSystem {
     res.targetFileSystem.deleteSnapshot(res.remainingPath, snapshotName);
   }
 
+  @Override
+  public void satisfyStoragePolicy(Path src) throws IOException {
+    InodeTree.ResolveResult<FileSystem> res =
+        fsState.resolve(getUriPath(src), true);
+    res.targetFileSystem.satisfyStoragePolicy(res.remainingPath);
+  }
+
   @Override
   public void setStoragePolicy(Path src, String policyName) throws IOException {
     InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(src),
@@ -1245,6 +1252,12 @@ public class ViewFileSystem extends FileSystem {
       throw new NotInMountpointException(f, "getQuotaUsage");
     }
 
+    @Override
+    public void satisfyStoragePolicy(Path src) throws IOException {
+      checkPathIsSlash(src);
+      throw readOnlyMountTable("satisfyStoragePolicy", src);
+    }
+
     @Override
     public void setStoragePolicy(Path src, String policyName)
         throws IOException {

+ 12 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java

@@ -751,6 +751,13 @@ public class ViewFs extends AbstractFileSystem {
     res.targetFileSystem.deleteSnapshot(res.remainingPath, snapshotName);
   }
 
+  @Override
+  public void satisfyStoragePolicy(final Path path) throws IOException {
+    InodeTree.ResolveResult<AbstractFileSystem> res =
+        fsState.resolve(getUriPath(path), true);
+    res.targetFileSystem.satisfyStoragePolicy(res.remainingPath);
+  }
+
   @Override
   public void setStoragePolicy(final Path path, final String policyName)
       throws IOException {
@@ -1154,6 +1161,11 @@ public class ViewFs extends AbstractFileSystem {
       throw readOnlyMountTable("deleteSnapshot", path);
     }
 
+    @Override
+    public void satisfyStoragePolicy(final Path path) throws IOException {
+      throw readOnlyMountTable("satisfyStoragePolicy", path);
+    }
+
     @Override
     public void setStoragePolicy(Path path, String policyName)
         throws IOException {

+ 2 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystem.java

@@ -213,6 +213,8 @@ public class TestHarFileSystem {
 
     public void access(Path path, FsAction mode) throws IOException;
 
+    void satisfyStoragePolicy(Path src) throws IOException;
+
     public void setStoragePolicy(Path src, String policyName)
         throws IOException;
 

+ 5 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java

@@ -968,6 +968,11 @@ abstract public class ViewFileSystemBaseTest {
     fsView.unsetStoragePolicy(new Path("/internalDir"));
   }
 
+  @Test(expected = AccessControlException.class)
+  public void testInternalSatisfyStoragePolicy() throws IOException {
+    fsView.satisfyStoragePolicy(new Path("/internalDir"));
+  }
+
   @Test(expected = NotInMountpointException.class)
   public void testInternalgetStoragePolicy() throws IOException {
     fsView.getStoragePolicy(new Path("/internalDir"));

+ 5 - 0
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java

@@ -489,6 +489,11 @@ public class Hdfs extends AbstractFileSystem {
     dfs.checkAccess(getUriPath(path), mode);
   }
 
+  @Override
+  public void satisfyStoragePolicy(Path path) throws IOException {
+    dfs.satisfyStoragePolicy(getUriPath(path));
+  }
+
   @Override
   public void setStoragePolicy(Path path, String policyName) throws IOException {
     dfs.setStoragePolicy(getUriPath(path), policyName);

+ 1 - 5
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

@@ -2870,11 +2870,7 @@ public class DistributedFileSystem extends FileSystem
   }
 
   /**
-   * Set the source path to satisfy storage policy. This API is non-recursive
-   * in nature, i.e., if the source path is a directory then all the files
-   * immediately under the directory would be considered for satisfying the
-   * policy and the sub-directories if any under this path will be skipped.
-   *
+   * Set the source path to satisfy storage policy.
    * @param path The source path referring to either a directory or a file.
    * @throws IOException
    */