sadanand48 commented on code in PR #4675:
URL: https://github.com/apache/ozone/pull/4675#discussion_r1187319544
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/keys/DeleteKeyHandler.java:
##########
@@ -45,6 +64,81 @@ protected void execute(OzoneClient client, OzoneAddress
address)
OzoneVolume vol = client.getObjectStore().getVolume(volumeName);
OzoneBucket bucket = vol.getBucket(bucketName);
- bucket.deleteKey(keyName);
+
+ float hadoopTrashInterval = getConf().getFloat(
+ FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);
+
+ long trashInterval =
+ (long) (getConf().getFloat(
+ OMConfigKeys.OZONE_FS_TRASH_INTERVAL_KEY,
+ hadoopTrashInterval) * 10000);
+
+ // If Bucket layout is FSO and Trash is enabled
+ // In this case during delete operation move key to trash
+ if (bucket.getBucketLayout().isFileSystemOptimized() && trashInterval > 0
+ && !skipTrash && !keyName.contains(".Trash")) {
+
+ keyName = OzoneFSUtils.removeTrailingSlashIfNeeded(keyName);
+ try {
+ // Check if key exists in Ozone
+ OzoneKeyDetails key = bucket.getKey(keyName);
+ if (key == null) {
+ out().printf("Key not found %s", keyName);
+ return;
+ }
+ // Check whether directory is empty or not
+ Iterator<? extends OzoneKey> ozoneKeyIterator =
+ bucket.listKeys(keyName, keyName);
Review Comment:
bucket.listKeys() by default will return 1000 entries in each RPC. This
might be a little unnecessary as we only want to check if the directory is
empty or not here, Even if there is a single key with given prefix, it should
conclude that directory is non-empty.
1. I couldn't find an API for listKeys with maxEntries param but instead
you could use
``` java
public List<OzoneFileStatus> listStatus(String keyName, boolean recursive,
String startKey, long numEntries) throws IOException
```
and pass numEntries as 1.
3. To check if it is directory you could use `
bucket.getFileStatus(key).isDirectory();`
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/keys/DeleteKeyHandler.java:
##########
@@ -45,6 +64,81 @@ protected void execute(OzoneClient client, OzoneAddress
address)
OzoneVolume vol = client.getObjectStore().getVolume(volumeName);
OzoneBucket bucket = vol.getBucket(bucketName);
- bucket.deleteKey(keyName);
+
+ float hadoopTrashInterval = getConf().getFloat(
+ FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);
+
+ long trashInterval =
+ (long) (getConf().getFloat(
+ OMConfigKeys.OZONE_FS_TRASH_INTERVAL_KEY,
+ hadoopTrashInterval) * 10000);
+
+ // If Bucket layout is FSO and Trash is enabled
+ // In this case during delete operation move key to trash
+ if (bucket.getBucketLayout().isFileSystemOptimized() && trashInterval > 0
+ && !skipTrash && !keyName.contains(".Trash")) {
+
+ keyName = OzoneFSUtils.removeTrailingSlashIfNeeded(keyName);
+ try {
+ // Check if key exists in Ozone
+ OzoneKeyDetails key = bucket.getKey(keyName);
+ if (key == null) {
+ out().printf("Key not found %s", keyName);
+ return;
+ }
+ // Check whether directory is empty or not
+ Iterator<? extends OzoneKey> ozoneKeyIterator =
+ bucket.listKeys(keyName, keyName);
Review Comment:
bucket.listKeys() by default will return 1000 entries in each RPC. This
might be a little unnecessary as we only want to check if the directory is
empty or not here, Even if there is a single key with given prefix, it should
conclude that directory is non-empty.
1. I couldn't find an API for listKeys with maxEntries param but instead
you could use
``` java
public List<OzoneFileStatus> listStatus(String keyName, boolean recursive,
String startKey, long numEntries) throws IOException
```
and pass numEntries as 1.
2. To check if it is directory you could use `
bucket.getFileStatus(key).isDirectory();`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]