You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ay...@apache.org on 2021/10/03 04:33:16 UTC

[hadoop] branch trunk updated: HDFS-16222. Fix ViewDFS with mount points for HDFS only API. (#3422). Contributed by Ayush Saxena.

This is an automated email from the ASF dual-hosted git repository.

ayushsaxena pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 5f04526  HDFS-16222. Fix ViewDFS with mount points for HDFS only API. (#3422). Contributed by Ayush Saxena.
5f04526 is described below

commit 5f0452602fe742a0771dbe8587b8b0f8ed01d76b
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Sun Oct 3 10:02:35 2021 +0530

    HDFS-16222. Fix ViewDFS with mount points for HDFS only API. (#3422). Contributed by Ayush Saxena.
    
    Signed-off-by: Vinayakumar B <vi...@apache.org>
---
 .../fs/viewfs/ViewFileSystemOverloadScheme.java    | 15 +++--
 .../hadoop/hdfs/TestViewDistributedFileSystem.java | 73 ++++++++++++++++++++++
 2 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystemOverloadScheme.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystemOverloadScheme.java
index 7dfd1eb..e91b665 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystemOverloadScheme.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystemOverloadScheme.java
@@ -347,12 +347,15 @@ public class ViewFileSystemOverloadScheme extends ViewFileSystem {
       res = fsState.resolve(getUriPath(path), true);
       FileSystem fs = res.isInternalDir() ?
           (fsState.getRootFallbackLink() != null ?
-              ((ChRootedFileSystem) fsState
-                  .getRootFallbackLink().getTargetFileSystem()).getMyFs() :
+              fsState.getRootFallbackLink().getTargetFileSystem() :
               fsGetter().get(path.toUri(), conf)) :
-          ((ChRootedFileSystem) res.targetFileSystem).getMyFs();
-      return new MountPathInfo<FileSystem>(res.remainingPath, res.resolvedPath,
-          fs);
+          res.targetFileSystem;
+      if (fs instanceof ChRootedFileSystem) {
+        ChRootedFileSystem chFs = (ChRootedFileSystem) fs;
+        return new MountPathInfo<>(chFs.fullPath(res.remainingPath),
+            chFs.getMyFs());
+      }
+      return new MountPathInfo<FileSystem>(res.remainingPath, fs);
     } catch (FileNotFoundException e) {
       // No link configured with passed path.
       throw new NotInMountpointException(path,
@@ -368,7 +371,7 @@ public class ViewFileSystemOverloadScheme extends ViewFileSystem {
     private Path pathOnTarget;
     private T targetFs;
 
-    public MountPathInfo(Path pathOnTarget, String resolvedPath, T targetFs) {
+    public MountPathInfo(Path pathOnTarget, T targetFs) {
       this.pathOnTarget = pathOnTarget;
       this.targetFs = targetFs;
     }
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java
index 6582d47..d7cc241 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java
@@ -32,6 +32,10 @@ import org.junit.Test;
 import java.io.IOException;
 import java.net.URI;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 public class TestViewDistributedFileSystem extends TestDistributedFileSystem{
   @Override
   HdfsConfiguration getTestConfiguration() {
@@ -118,4 +122,73 @@ public class TestViewDistributedFileSystem extends TestDistributedFileSystem{
       }
     }
   }
+
+  @Test
+  public void testRenameWithOptionsWithMountEntries() throws IOException {
+    Configuration conf = getTestConfiguration();
+    MiniDFSCluster cluster = null;
+    try {
+      cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
+      URI defaultUri =
+          URI.create(conf.get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY));
+      conf.set("fs.viewfs.mounttable." + defaultUri.getHost() + ".linkFallback",
+          defaultUri.toString());
+      Path target = new Path(defaultUri.toString(), "/src");
+      ConfigUtil.addLink(conf, defaultUri.getHost(), "/source",
+          target.toUri());
+      FileSystem defaultFs = FileSystem.get(defaultUri, conf);
+      defaultFs.mkdirs(target);
+      try (ViewDistributedFileSystem fileSystem = (ViewDistributedFileSystem) FileSystem
+          .get(conf)) {
+        final Path testDir = new Path("/source");
+        Path filePath = new Path(testDir, "file");
+        Path renamedFilePath = new Path(testDir, "fileRename");
+        // Create a file.
+        fileSystem.create(filePath).close();
+        // Check the file exists before rename is called.
+        assertTrue(fileSystem.exists(filePath));
+        fileSystem.rename(filePath, renamedFilePath, Options.Rename.NONE);
+        // Check the file is not present at source location post a rename.
+        assertFalse(fileSystem.exists(filePath));
+        // Check the file is there at target location post rename.
+        assertTrue(fileSystem.exists(renamedFilePath));
+      }
+    } finally {
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
+
+  @Test
+  public void testQuota() throws IOException {
+    Configuration conf = getTestConfiguration();
+    MiniDFSCluster cluster = null;
+    try {
+      cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
+      URI defaultUri =
+          URI.create(conf.get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY));
+      conf.set("fs.viewfs.mounttable." + defaultUri.getHost() + ".linkFallback",
+          defaultUri.toString());
+      Path target = new Path(defaultUri.toString(), "/src");
+      // /source -> /src
+      ConfigUtil.addLink(conf, defaultUri.getHost(), "/source",
+          target.toUri());
+      FileSystem defaultFs = FileSystem.get(defaultUri, conf);
+      defaultFs.mkdirs(target);
+      try (ViewDistributedFileSystem fileSystem = (ViewDistributedFileSystem) FileSystem
+          .get(conf)) {
+        final Path testDir = new Path("/source");
+        // Set Quota via ViewDFS
+        fileSystem.setQuota(testDir, 10L, 10L);
+        // Check quota through actual DFS
+        assertEquals(10,
+            defaultFs.getQuotaUsage(target).getSpaceQuota());
+      }
+    } finally {
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org