You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ms...@apache.org on 2020/04/16 06:23:51 UTC

[hadoop-ozone] branch master updated: HDDS-2682: OM File create request does not check for existing directory with the same name (#824)

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

msingh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new e9a466d  HDDS-2682: OM File create request does not check for existing directory with the same name (#824)
e9a466d is described below

commit e9a466d9b5f59369528952e6c1e006340aee5751
Author: Rakesh Radhakrishnan <ra...@apache.org>
AuthorDate: Thu Apr 16 11:53:14 2020 +0530

    HDDS-2682: OM File create request does not check for existing directory with the same name (#824)
---
 .../hadoop/fs/ozone/TestOzoneFileSystem.java       | 112 ++++++++++++++++++---
 1 file changed, 97 insertions(+), 15 deletions(-)

diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java
index bc0e752..e9324e6 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystem.java
@@ -21,9 +21,12 @@ package org.apache.hadoop.fs.ozone;
 import java.io.IOException;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileAlreadyExistsException;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -42,6 +45,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.hadoop.test.LambdaTestUtils;
 import org.junit.After;
@@ -65,24 +69,81 @@ public class TestOzoneFileSystem {
   private int rootItemCount;
 
   @Test(timeout = 300_000)
-  public void testFileSystem() throws Exception {
-    OzoneConfiguration conf = new OzoneConfiguration();
-    cluster = MiniOzoneCluster.newBuilder(conf)
-        .setNumDatanodes(3)
-        .build();
-    cluster.waitForClusterToBeReady();
+  public void testCreateFileShouldCheckExistenceOfDirWithSameName()
+          throws Exception {
+    /*
+     * Op 1. create file -> /d1/d2/d3/d4/key2
+     * Op 2. create dir -> /d1/d2/d3/d4/key2
+     *
+     * Reverse of the above steps
+     * Op 2. create dir -> /d1/d2/d3/d4/key3
+     * Op 1. create file -> /d1/d2/d3/d4/key3
+     *
+     * Op 3. create file -> /d1/d2/d3 (d3 as a file inside /d1/d2)
+     */
+    setupOzoneFileSystem();
+
+    Path parent = new Path("/d1/d2/d3/d4/");
+    Path file1 = new Path(parent, "key1");
+    try (FSDataOutputStream outputStream = fs.create(file1, false)) {
+      assertNotNull("Should be able to create file", outputStream);
+    }
 
-    // create a volume and a bucket to be used by OzoneFileSystem
-    OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(cluster);
-    volumeName = bucket.getVolumeName();
-    bucketName = bucket.getName();
+    Path dir1 = new Path("/d1/d2/d3/d4/key2");
+    fs.mkdirs(dir1);
+    try (FSDataOutputStream outputStream1 = fs.create(dir1, false)) {
+      fail("Should throw FileAlreadyExistsException");
+    } catch (FileAlreadyExistsException fae){
+      // ignore as its expected
+    }
 
-    String rootPath = String.format("%s://%s.%s/",
-        OzoneConsts.OZONE_URI_SCHEME, bucket.getName(), bucket.getVolumeName());
+    Path file2 = new Path("/d1/d2/d3/d4/key3");
+    try (FSDataOutputStream outputStream2 = fs.create(file2, false)) {
+      assertNotNull("Should be able to create file", outputStream2);
+    }
+    try {
+      fs.mkdirs(file2);
+      fail("Should throw FileAlreadyExistsException");
+    } catch (FileAlreadyExistsException fae) {
+      // ignore as its expected
+    }
 
-    // Set the fs.defaultFS and start the filesystem
-    conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
-    fs = FileSystem.get(conf);
+    // Op 3. create file -> /d1/d2/d3 (d3 as a file inside /d1/d2)
+    Path file3 = new Path("/d1/d2/d3");
+    try (FSDataOutputStream outputStream2 = fs.create(file3, false)) {
+      fail("Should throw FileAlreadyExistsException");
+    } catch (FileAlreadyExistsException fae) {
+      // ignore as its expected
+    }
+  }
+
+  /**
+   * Make the given file and all non-existent parents into
+   * directories. Has roughly the semantics of Unix @{code mkdir -p}.
+   * {@link FileSystem#mkdirs(Path)}
+   */
+  @Test(timeout = 300_000)
+  public void testMakeDirsWithAnExistingDirectoryPath() throws Exception {
+    /*
+     * Op 1. create file -> /d1/d2/d3/d4/k1 (d3 is a sub-dir inside /d1/d2)
+     * Op 2. create dir -> /d1/d2
+     */
+    setupOzoneFileSystem();
+
+    Path parent = new Path("/d1/d2/d3/d4/");
+    Path file1 = new Path(parent, "key1");
+    try (FSDataOutputStream outputStream = fs.create(file1, false)) {
+      assertNotNull("Should be able to create file", outputStream);
+    }
+
+    Path subdir = new Path("/d1/d2/");
+    boolean status = fs.mkdirs(subdir);
+    assertTrue("Shouldn't send error if dir exists", status);
+  }
+
+  @Test(timeout = 300_000)
+  public void testFileSystem() throws Exception {
+    setupOzoneFileSystem();
 
     testOzoneFsServiceLoader();
     o3fs = (OzoneFileSystem) fs;
@@ -111,6 +172,27 @@ public class TestOzoneFileSystem {
     }
   }
 
+  private void setupOzoneFileSystem()
+          throws IOException, TimeoutException, InterruptedException {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    cluster = MiniOzoneCluster.newBuilder(conf)
+            .setNumDatanodes(3)
+            .build();
+    cluster.waitForClusterToBeReady();
+    // create a volume and a bucket to be used by OzoneFileSystem
+    OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(cluster);
+    volumeName = bucket.getVolumeName();
+    bucketName = bucket.getName();
+
+    String rootPath = String.format("%s://%s.%s/",
+            OzoneConsts.OZONE_URI_SCHEME, bucket.getName(),
+            bucket.getVolumeName());
+
+    // Set the fs.defaultFS and start the filesystem
+    conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+    fs = FileSystem.get(conf);
+  }
+
   private void testOzoneFsServiceLoader() throws IOException {
     assertEquals(
         FileSystem.getFileSystemClass(OzoneConsts.OZONE_URI_SCHEME, null),


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