linyiqun commented on a change in pull request #1557:
URL: https://github.com/apache/ozone/pull/1557#discussion_r519096971
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemV1.java
##########
@@ -260,6 +260,44 @@ private void testListFilesRecursive() throws Exception {
expectedFilesCount, actualCount);
}
+
+ protected void testRenameDir() throws Exception {
+ final String root = "/root_dir";
+ final String dir = root + "/dir1";
+ final Path source = new Path(fs.getUri().toString() + dir);
+ final Path dest = new Path(source.toString() + ".renamed");
+ // Add a sub-dir to the directory to be moved.
+ final Path subdir = new Path(source, "sub_dir1");
+ fs.mkdirs(subdir);
+ LOG.info("Created dir {}", subdir);
+
+ // case-1) source is a sub-dir to destin
Review comment:
Comment is not right, here source is parent dir,
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemV1.java
##########
@@ -260,6 +260,44 @@ private void testListFilesRecursive() throws Exception {
expectedFilesCount, actualCount);
}
+
+ protected void testRenameDir() throws Exception {
+ final String root = "/root_dir";
+ final String dir = root + "/dir1";
+ final Path source = new Path(fs.getUri().toString() + dir);
+ final Path dest = new Path(source.toString() + ".renamed");
+ // Add a sub-dir to the directory to be moved.
+ final Path subdir = new Path(source, "sub_dir1");
+ fs.mkdirs(subdir);
+ LOG.info("Created dir {}", subdir);
+
+ // case-1) source is a sub-dir to destin
+ final Path sourceRoot = new Path(fs.getUri().toString() + root);
+ LOG.info("Rename op-> source:/root_dir to destin:/root_dir/dir1/sub_dir1");
+ try {
+ fs.rename(sourceRoot, subdir);
+ Assert.fail("Should throw exception : Cannot rename a directory to" +
+ " its own subdirectory");
+ } catch (OMException e) {
+ // expected
+ }
+
+ LOG.info("Will move {} to {}", source, dest);
+ fs.rename(source, dest);
+
+ assertTrue("Directory rename failed", fs.exists(dest));
+ // Verify that the subdir is also renamed i.e. keys corresponding to the
+ // sub-directories of the renamed directory have also been renamed.
+ assertTrue("Keys under the renamed directory not renamed",
+ fs.exists(new Path(dest, "sub_dir1")));
+
+ // Test if one path belongs to other FileSystem.
+ Path fakeDir = new Path(fs.getUri().toString() + "fake" + dir);
+ LambdaTestUtils.intercept(IllegalArgumentException.class, "Wrong FS",
+ () -> fs.rename(fakeDir, dest));
Review comment:
Can we add additional test cases that can fully cover current rename
logic:
* Rename to a existed file, failed.
* Rename to a existed folder:
Rename from /a, to /b, final key will be /b/a
* Rename to a parent folder:
case1: parent folder does't exist, and then failed
case2: parent folder existed, then succeed
##########
File path:
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
##########
@@ -407,6 +414,29 @@ public boolean rename(Path src, Path dst) throws
IOException {
return result;
}
+ private boolean renameV1(Path src, Path dst) throws IOException {
+ incrementCounter(Statistic.INVOCATION_RENAME);
+ statistics.incrementWriteOps(1);
+ super.checkPath(src);
+ super.checkPath(dst);
+
+ String srcPath = src.toUri().getPath();
+ String dstPath = dst.toUri().getPath();
+ if (srcPath.equals(dstPath)) {
+ return true;
+ }
+
+ LOG.trace("rename() from:{} to:{}", src, dst);
+ if (src.isRoot()) {
+ // Cannot rename root of file system
+ LOG.trace("Cannot rename the root of a filesystem");
+ return false;
+ }
+
+ adapter.renameKey(srcPath, dstPath);
+ return true;
+ }
Review comment:
As we also do the refactor for the OzoneFileSystem rename change, can we
try to add corresponding unit test for this? Or we will add this later? I
didn't see this part of test.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]