swamirishi commented on code in PR #4187:
URL: https://github.com/apache/ozone/pull/4187#discussion_r1253418052


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -558,6 +583,584 @@ public void testCreateSnapshotMissingMandatoryParams() 
throws Exception {
             () -> createSnapshot(nullstr, bucket));
   }
 
+  private Set<OmKeyInfo> getDeletedKeysFromRocksDb(
+      OMMetadataManager metadataManager) throws IOException {
+    Set<OmKeyInfo> deletedKeys = Sets.newHashSet();
+    try (TableIterator<String,
+        ? extends Table.KeyValue<String, RepeatedOmKeyInfo>>
+             deletedTableIterator = metadataManager.getDeletedTable()
+            .iterator()) {
+      while (deletedTableIterator.hasNext()) {
+        Table.KeyValue<String, RepeatedOmKeyInfo> val =
+            deletedTableIterator.next();
+        deletedKeys.addAll(val.getValue().getOmKeyInfoList());
+      }
+    }
+
+    try (TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>>
+             deletedDirTableIterator = metadataManager.getDeletedDirTable()
+            .iterator()) {
+      while (deletedDirTableIterator.hasNext()) {
+        deletedKeys.add(deletedDirTableIterator.next().getValue());
+      }
+    }
+    return deletedKeys;
+  }
+
+  private OmKeyInfo getOmKeyInfo(String volume, String bucket,
+                                 String key) throws IOException {
+    return cluster.getOzoneManager().getKeyManager()
+            .getKeyInfo(new OmKeyArgs.Builder().setVolumeName(volume)
+            .setBucketName(bucket).setKeyName(key).build(), null);
+  }
+
+  /**
+   * Testing scenario:
+   * 1) Key k1 is created.
+   * 2) Snapshot snap1 created.
+   * 3) Snapshot snap2 is created
+   * 4) Key k1 is deleted.
+   * 5) Snapshot snap3 is created.
+   * 6) Snapdiff b/w snap3 & snap2 taken to assert difference of 1 key
+   */
+  @Test
+  public void testSnapDiffHandlingReclaimWithLatestUse() throws Exception {
+    String testVolumeName = "vol" + RandomStringUtils.randomNumeric(5);
+    String testBucketName = "bucket1";
+    store.createVolume(testVolumeName);
+    OzoneVolume volume = store.getVolume(testVolumeName);
+    volume.createBucket(testBucketName);
+    OzoneBucket bucket = volume.getBucket(testBucketName);
+    String key1 = "k1";
+    key1 = createFileKeyWithPrefix(bucket, key1);
+    String snap1 = "snap1";
+    createSnapshot(testVolumeName, testBucketName, snap1);
+    String snap2 = "snap2";
+    createSnapshot(testVolumeName, testBucketName, snap2);
+    getOmKeyInfo(testVolumeName, testBucketName, key1);
+    bucket.deleteKey(key1);
+    String snap3 = "snap3";
+    createSnapshot(testVolumeName, testBucketName, snap3);
+    SnapshotDiffReportOzone diff =
+        getSnapDiffReport(testVolumeName, testBucketName, snap1, snap2);
+    Assert.assertEquals(diff.getDiffList().size(), 0);
+    diff = getSnapDiffReport(testVolumeName, testBucketName, snap2, snap3);
+    Assert.assertEquals(diff.getDiffList().size(), 1);
+    Assert.assertEquals(diff.getDiffList(), Arrays.asList(
+        SnapshotDiffReportOzone.getDiffReportEntry(
+            SnapshotDiffReport.DiffType.DELETE, OZONE_URI_DELIMITER + key1)));
+  }
+
+  /**
+   * Testing scenario:
+   * 1) Key k1 is created.
+   * 2) Snapshot snap1 created.
+   * 3) Key k1 is deleted.
+   * 4) Snapshot snap2 is created.
+   * 5) Snapshot snap3 is created.
+   * 6) Snapdiff b/w snap3 & snap1 taken to assert difference of 1 key.
+   * 7) Snapdiff b/w snap3 & snap2 taken to assert difference of 0 key.
+   */
+  @Test
+  public void testSnapDiffHandlingReclaimWithPreviousUse() throws Exception {
+    String testVolumeName = "vol" + RandomStringUtils.randomNumeric(5);
+    String testBucketName = "bucket1";
+    store.createVolume(testVolumeName);
+    OzoneVolume volume = store.getVolume(testVolumeName);
+    volume.createBucket(testBucketName);
+    OzoneBucket bucket = volume.getBucket(testBucketName);
+    String key1 = "k1";
+    key1 = createFileKeyWithPrefix(bucket, key1);
+    getOmKeyInfo(testVolumeName, testBucketName, key1);
+    String snap1 = "snap1";
+    createSnapshot(testVolumeName, testBucketName, snap1);
+    bucket.deleteKey(key1);
+    String snap2 = "snap2";
+    createSnapshot(testVolumeName, testBucketName, snap2);
+    String snap3 = "snap3";
+    createSnapshot(testVolumeName, testBucketName, snap3);
+    SnapshotDiffReportOzone diff = getSnapDiffReport(testVolumeName,
+        testBucketName, snap1, snap3);
+    Assert.assertEquals(diff.getDiffList().size(), 1);
+    Assert.assertEquals(diff.getDiffList(), Arrays.asList(
+        SnapshotDiffReportOzone.getDiffReportEntry(
+            SnapshotDiffReport.DiffType.DELETE, OZONE_URI_DELIMITER + key1)));
+    diff = getSnapDiffReport(testVolumeName, testBucketName,
+            snap2, snap3);
+    Assert.assertEquals(diff.getDiffList().size(), 0);
+  }
+
+  /**
+   * Testing scenario:
+   * 1) Key k1 is created.
+   * 2) Snapshot snap1 created.
+   * 3) Key k1 is deleted.
+   * 4) Key k1 is recreated.
+   * 5) Snapshot snap2 is created.
+   * 6) Snapdiff b/w snapshot of Active FS & snap1 taken to assert difference 
of 2 keys.
+   * 7) Snapdiff b/w snapshot of Active FS & snap2 taken to assert difference 
of 0 key.
+   * 8) Checking rocks db to ensure the object created shouldn't be reclaimed
+   *    as it is used by snapshot.
+   * 9) Key k1 is deleted.
+   * 10) Snapdiff b/w snapshot of Active FS & snap1 taken to assert difference 
of 1 key.
+   * 11) Snapdiff b/w snapshot of Active FS & snap2 taken to assert difference 
of 1 key.
+   */
+  @Test
+  public void testSnapDiffReclaimWithKeyRecreation() throws Exception {
+    String testVolumeName = "vol" + RandomStringUtils.randomNumeric(5);
+    String testBucketName = "bucket1";
+    store.createVolume(testVolumeName);
+    OzoneVolume volume = store.getVolume(testVolumeName);
+    volume.createBucket(testBucketName);
+    OzoneBucket bucket = volume.getBucket(testBucketName);
+    String key1 = "k1";
+    key1 = createFileKeyWithPrefix(bucket, key1);
+    getOmKeyInfo(testVolumeName, testBucketName, key1);
+    String snap1 = "snap1";
+    createSnapshot(testVolumeName, testBucketName, snap1);
+    bucket.deleteKey(key1);
+    key1 = createFileKey(bucket, key1);
+    getOmKeyInfo(testVolumeName, testBucketName, key1);
+    String snap2 = "snap2";
+    createSnapshot(testVolumeName, testBucketName, snap2);
+    String snap3 = "snap3";
+    createSnapshot(testVolumeName, testBucketName, snap3);
+    SnapshotDiffReportOzone diff = getSnapDiffReport(testVolumeName,
+        testBucketName, snap1, snap3);
+    Assert.assertEquals(diff.getDiffList().size(), 2);
+    Assert.assertEquals(diff.getDiffList(), Arrays.asList(
+        SnapshotDiffReportOzone.getDiffReportEntry(
+            SnapshotDiffReport.DiffType.DELETE, OZONE_URI_DELIMITER + key1),
+        SnapshotDiffReportOzone.getDiffReportEntry(
+            SnapshotDiffReport.DiffType.CREATE, OZONE_URI_DELIMITER + key1)));
+    diff = getSnapDiffReport(testVolumeName, testBucketName,
+            snap2, snap3);
+    Assert.assertEquals(diff.getDiffList().size(), 0);
+    bucket.deleteKey(key1);
+    String snap4 = "snap4";
+    createSnapshot(testVolumeName, testBucketName, snap4);
+    diff = getSnapDiffReport(testVolumeName, testBucketName,
+            snap1, snap4);
+    Assert.assertEquals(diff.getDiffList().size(), 1);
+    Assert.assertEquals(diff.getDiffList(), Arrays.asList(
+        SnapshotDiffReportOzone.getDiffReportEntry(
+            SnapshotDiffReport.DiffType.DELETE, OZONE_URI_DELIMITER + key1)));
+    diff = getSnapDiffReport(testVolumeName, testBucketName,
+            snap2, snap4);

Review Comment:
   done



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