You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by si...@apache.org on 2020/06/30 05:08:39 UTC
[hadoop-ozone] branch master updated: HDDS-3868. Implement
getTrashRoot and getTrashRoots in o3fs (#1134)
This is an automated email from the ASF dual-hosted git repository.
siyao 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 bf23dcb HDDS-3868. Implement getTrashRoot and getTrashRoots in o3fs (#1134)
bf23dcb is described below
commit bf23dcb95194fc844485de860846edb45b7aeb63
Author: Siyao Meng <50...@users.noreply.github.com>
AuthorDate: Mon Jun 29 22:08:28 2020 -0700
HDDS-3868. Implement getTrashRoot and getTrashRoots in o3fs (#1134)
---
.../hadoop/fs/ozone/TestOzoneFileSystem.java | 56 ++++++++++++++++++++++
.../hadoop/fs/ozone/BasicOzoneFileSystem.java | 47 ++++++++++++++++++
2 files changed, 103 insertions(+)
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 ba3d643..75107d0 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
@@ -20,6 +20,7 @@ package org.apache.hadoop.fs.ozone;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
@@ -41,11 +42,14 @@ import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneKeyDetails;
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
+import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.commons.io.IOUtils;
+import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
+import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -163,6 +167,8 @@ public class TestOzoneFileSystem {
testOzoneFsServiceLoader();
o3fs = (OzoneFileSystem) fs;
+ testGetTrashRoots();
+ testGetTrashRoot();
testGetDirectoryModificationTime();
testListStatusOnRoot();
@@ -561,4 +567,54 @@ public class TestOzoneFileSystem {
assertTrue(modificationTime <= fileStatuses[0].getModificationTime());
}
}
+
+ public void testGetTrashRoot() throws IOException {
+ String username = UserGroupInformation.getCurrentUser().getShortUserName();
+ Path trashRoot = new Path(OZONE_URI_DELIMITER, TRASH_PREFIX);
+ // Input path doesn't matter, o3fs.getTrashRoot() only cares about username
+ Path inPath1 = new Path("o3fs://bucket2.volume1/path/to/key");
+ // Test with current user
+ Path outPath1 = o3fs.getTrashRoot(inPath1);
+ Path expectedOutPath1 = new Path(trashRoot, username);
+ Assert.assertEquals(expectedOutPath1, outPath1);
+ }
+
+ public void testGetTrashRoots() throws IOException {
+ String username = UserGroupInformation.getCurrentUser().getShortUserName();
+ Path trashRoot = new Path(OZONE_URI_DELIMITER, TRASH_PREFIX);
+ Path userTrash = new Path(trashRoot, username);
+
+ Collection<FileStatus> res = o3fs.getTrashRoots(false);
+ Assert.assertEquals(0, res.size());
+
+ fs.mkdirs(userTrash);
+ res = o3fs.getTrashRoots(false);
+ Assert.assertEquals(1, res.size());
+ res.forEach(e -> Assert.assertEquals(
+ userTrash.toString(), e.getPath().toUri().getPath()));
+ // Only have one user trash for now
+ res = o3fs.getTrashRoots(true);
+ Assert.assertEquals(1, res.size());
+
+ // Create a few more random user trash dir
+ for (int i = 1; i <= 5; i++) {
+ Path moreUserTrash = new Path(trashRoot, "trashuser" + i);
+ fs.mkdirs(moreUserTrash);
+ }
+
+ // And create a file, which should be ignored
+ fs.create(new Path(trashRoot, "trashuser99"));
+
+ // allUsers = false should still return current user trash
+ res = o3fs.getTrashRoots(false);
+ Assert.assertEquals(1, res.size());
+ res.forEach(e -> Assert.assertEquals(
+ userTrash.toString(), e.getPath().toUri().getPath()));
+ // allUsers = true should return all user trash
+ res = o3fs.getTrashRoots(true);
+ Assert.assertEquals(6, res.size());
+
+ // Clean up
+ o3fs.delete(trashRoot, true);
+ }
}
diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
index f0df9b2..e723df7 100644
--- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
+++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
@@ -51,6 +51,7 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -607,6 +608,52 @@ public class BasicOzoneFileSystem extends FileSystem {
}
/**
+ * Get the root directory of Trash for a path.
+ * Returns /.Trash/<username>
+ * Caller appends either Current or checkpoint timestamp for trash destination
+ * @param path the trash root of the path to be determined.
+ * @return trash root
+ */
+ @Override
+ public Path getTrashRoot(Path path) {
+ final Path pathToTrash = new Path(OZONE_URI_DELIMITER, TRASH_PREFIX);
+ return new Path(pathToTrash, getUsername());
+ }
+
+ /**
+ * Get all the trash roots for current user or all users.
+ *
+ * @param allUsers return trash roots for all users if true.
+ * @return all the trash root directories.
+ * Returns .Trash of users if {@code /.Trash/$USER} exists.
+ */
+ @Override
+ public Collection<FileStatus> getTrashRoots(boolean allUsers) {
+ Path trashRoot = new Path(OZONE_URI_DELIMITER, TRASH_PREFIX);
+ List<FileStatus> ret = new ArrayList<>();
+ try {
+ if (!allUsers) {
+ Path userTrash = new Path(trashRoot, userName);
+ if (exists(userTrash) && getFileStatus(userTrash).isDirectory()) {
+ ret.add(getFileStatus(userTrash));
+ }
+ } else {
+ if (exists(trashRoot)) {
+ FileStatus[] candidates = listStatus(trashRoot);
+ for (FileStatus candidate : candidates) {
+ if (candidate.isDirectory()) {
+ ret.add(candidate);
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ LOG.warn("Can't get all trash roots", ex);
+ }
+ return ret;
+ }
+
+ /**
* Creates a directory. Directory is represented using a key with no value.
*
* @param path directory path to be created
---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-commits-help@hadoop.apache.org