xiaoyuyao commented on a change in pull request #1089:
URL: https://github.com/apache/hadoop-ozone/pull/1089#discussion_r451112711



##########
File path: 
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
##########
@@ -516,6 +520,62 @@ public FileStatusAdapter getFileStatus(String path, URI 
uri,
     }
   }
 
+  /**
+   * Get trash roots for current user or all users.
+   *
+   * Note:
+   * 1. When allUsers flag is false, this only returns the trash roots for
+   * those that the current user has access to.
+   * 2. Also it is not particularly efficient to use this API when there are
+   * a lot of volumes and buckets as the client has to iterate through all
+   * buckets in all volumes.
+   *
+   * @param allUsers return trashRoots of all users if true, used by emptier
+   * @param fs Pointer to the current OFS FileSystem
+   * @return
+   */
+  public Collection<FileStatus> getTrashRoots(boolean allUsers,
+      BasicRootedOzoneFileSystem fs) {
+    List<FileStatus> ret = new ArrayList<>();
+    try {
+      Iterator<? extends OzoneVolume> iterVol;
+      String username = UserGroupInformation.getCurrentUser().getUserName();
+      if (allUsers) {
+        iterVol = objectStore.listVolumes("");
+      } else {
+        iterVol = objectStore.listVolumesByUser(username, "", "");
+      }
+      while (iterVol.hasNext()) {
+        OzoneVolume volume = iterVol.next();
+        Path volumePath = new Path(OZONE_URI_DELIMITER, volume.getName());
+        Iterator<? extends OzoneBucket> bucketIter = volume.listBuckets("");
+        while (bucketIter.hasNext()) {
+          OzoneBucket bucket = bucketIter.next();
+          Path bucketPath = new Path(volumePath, bucket.getName());
+          Path trashRoot = new Path(bucketPath, FileSystem.TRASH_PREFIX);
+          if (allUsers) {
+            if (fs.exists(trashRoot)) {
+              for (FileStatus candidate : fs.listStatus(trashRoot)) {
+                if (fs.exists(candidate.getPath()) && candidate.isDirectory()) 
{
+                  ret.add(candidate);
+                }
+              }
+            }
+          } else {
+            Path userTrash = new Path(trashRoot, username);
+            if (fs.exists(userTrash) &&
+                fs.getFileStatus(userTrash).isDirectory()) {
+              ret.add(fs.getFileStatus(userTrash));
+            }
+          }
+        }
+      }
+    } catch (IOException ex) {
+      throw new RuntimeException(ex);

Review comment:
       I don't think we should throw RuntimeException here. We can log a 
warning and return an empty collection instead. 




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to