hemantk-12 commented on code in PR #4015:
URL: https://github.com/apache/ozone/pull/4015#discussion_r1041600158


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -426,6 +428,30 @@ public void testNonExistentBucket()
             () -> createSnapshot(volume, bucket));
   }
 
+
+  @Test
+  public void testBucketDeleteIfSnapshotExists() throws Exception {
+    String volume1 = "vol-" + RandomStringUtils.randomNumeric(5);
+    String bucket1 = "buc-" + RandomStringUtils.randomNumeric(5);
+    String bucket2 = "buc-" + RandomStringUtils.randomNumeric(5);
+    store.createVolume(volume1);
+    OzoneVolume volume = store.getVolume(volume1);
+    volume.createBucket(bucket1);
+    volume.createBucket(bucket2);
+    OzoneBucket bucketWithSnapshot = volume.getBucket(bucket1);
+    OzoneBucket bucketWithoutSnapshot = volume.getBucket(bucket2);
+    String key = "key-";
+    createFileKey(bucketWithSnapshot, key);
+    createFileKey(bucketWithoutSnapshot, key);
+    createSnapshot(volume1, bucket1);
+    deleteKeys(bucketWithSnapshot);
+    deleteKeys(bucketWithoutSnapshot);
+    OzoneTestUtils.expectOmException(BUCKET_SNAPSHOT_EXISTS,

Review Comment:
   nit: Junit5 asserts Throwable .
   ```suggestion
       OMException omException = Assertions.assertThrows(OMException.class,
           () -> volume.deleteBucket(bucket1));
       Assertions.assertEquals(expectedResultCode, omException.getResult());
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/bucket/OMBucketDeleteRequest.java:
##########
@@ -198,6 +215,35 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
     }
   }
 
+  private boolean bucketContainSnapshot(OMMetadataManager omMetadataManager,

Review Comment:
   nit: I feel that readability of code will improve if you create small 
function like this.
   
   ```suggestion
   
     private boolean bucketContainSnapshot(OMMetadataManager omMetadataManager,
                                           String snapshotBucketKey)
         throws IOException {
   
       return bucketContainSnapshotInCache(omMetadataManager, 
snapshotBucketKey) ||
           bucketContainSnapshotInTable(omMetadataManager, snapshotBucketKey);
     }
   
     private boolean bucketContainSnapshotInCache(
         OMMetadataManager omMetadataManager,
         String snapshotBucketKey
     ) {
       Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> 
cacheIter =
           omMetadataManager.getSnapshotInfoTable().cacheIterator();
   
       while (cacheIter.hasNext()) {
         Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> cacheKeyValue =
             cacheIter.next();
         String key = cacheKeyValue.getKey().getCacheKey();
         if (key.startsWith(snapshotBucketKey)) {
           return true;
         }
       }
       return false;
     }
   
     private boolean bucketContainSnapshotInTable(
         OMMetadataManager omMetadataManager,
         String snapshotBucketKey
     ) throws IOException {
   
       try (TableIterator<String, ? extends Table.KeyValue<String, 
SnapshotInfo>>
                snapshotIterator = omMetadataManager
           .getSnapshotInfoTable().iterator()) {
         snapshotIterator.seek(snapshotBucketKey);
   
         if (snapshotIterator.hasNext()) {
           return snapshotIterator.next()
               .getKey()
               .startsWith(snapshotBucketKey);
         }
       }
   
       return false;
     }
   ```



-- 
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]

Reply via email to