sadanand48 commented on a change in pull request #3227:
URL: https://github.com/apache/ozone/pull/3227#discussion_r833561516
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreWithFSO.java
##########
@@ -213,6 +213,79 @@ public void testCreateKey() throws Exception {
dirPathC.getObjectID(), true);
}
+ /**
+ * Tests bucket deletion behaviour. Buckets should not be allowed to be
+ * deleted if they contain files or directories under them.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBucketWithKeyDelete() throws Exception {
+ // Create temporary volume and bucket for this test.
+ OzoneBucket testBucket = TestDataUtil
+ .createVolumeAndBucket(cluster, BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ String testVolumeName = testBucket.getVolumeName();
+ String testBucketName = testBucket.getName();
+
+ String parent = "a/b/c/";
+ String file = "key" + RandomStringUtils.randomNumeric(5);
+ String key = parent + file;
+
+ OzoneClient client = cluster.getClient();
+
+ ObjectStore objectStore = client.getObjectStore();
+ OzoneVolume ozoneVolume = objectStore.getVolume(testVolumeName);
+ assertEquals(ozoneVolume.getName(), testVolumeName);
+ OzoneBucket ozoneBucket = ozoneVolume.getBucket(testBucketName);
+ assertEquals(ozoneBucket.getName(), testBucketName);
+
+ Table<String, OmKeyInfo> openFileTable =
+ cluster.getOzoneManager().getMetadataManager()
+ .getOpenKeyTable(getBucketLayout());
+
+ // before file creation
+ verifyKeyInFileTable(openFileTable, file, 0, true);
+
+ // Create a key.
+ ozoneBucket.createKey(key, 10).close();
+
+ try {
+ // Try to delete the bucket while a key is present under it.
+ ozoneVolume.deleteBucket(testBucketName);
+ fail("Bucket Deletion should fail, since bucket is not empty.");
+ } catch (IOException ioe) {
+ // Do nothing
+ }
+
+ // Delete the key (this only deletes the file)
+ ozoneBucket.deleteKey(key);
+ try {
+ // Try to delete the bucket while intermediate dirs are present under it.
+ ozoneVolume.deleteBucket(testBucketName);
+ fail("Bucket Deletion should fail, since bucket still contains " +
+ "intermediate directories");
+ } catch (IOException ioe) {
+ // Do nothing
+ }
+
+ // Delete last level of directories.
+ ozoneBucket.deleteDirectory(parent, true);
+ try {
+ // Try to delete the bucket while dirs are present under it.
+ ozoneVolume.deleteBucket(testBucketName);
+ fail("Bucket Deletion should fail, since bucket still contains " +
+ "intermediate directories");
+ } catch (IOException ioe) {
+ // Do nothing
+ }
+
+ // Delete all the intermediate directories
+ ozoneBucket.deleteDirectory("a/", true);
Review comment:
maybe also add an assertion for isBucketEmpty when bucket is both empty
and non empty
```suggestion
ozoneBucket.deleteDirectory("a/", true);
Assert.assertTrue(cluster.getOzoneManager().getMetadataManager()
.isBucketEmpty(testVolumeName, testBucketName));
```
##########
File path:
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
##########
@@ -1455,6 +1458,9 @@ public void testRenameFile() throws Exception {
assertTrue("Renamed failed: /dir/file1", getFs().exists(file1Destin));
FileStatus[] fStatus = getFs().listStatus(dirPath);
assertEquals("Renamed failed", 1, fStatus.length);
+
+ // We cannot delete a non-empty bucket.
+ getFs().delete(dirPath, true);
Review comment:
We can delete a non-empty bucket if recursive is set to true via
Filesystem, there is already a check on this [line
](https://github.com/apache/ozone/blob/4ff630082b39ca0ebbb9080913f52f9a7b9d7d18/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java#L1089)for
non recursive bucket deletion, I guess we can remove this and other
occurrences of this in testRenameFileToDir & testRenameToParentDir, The test
added in TestObjectStoreWithFSO should be good. For recursive bucket deletion I
can add separate test in HDDS-6414
--
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]