SaketaChalamchala commented on code in PR #10217:
URL: https://github.com/apache/ozone/pull/10217#discussion_r3336815381


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestQuotaRepairTask.java:
##########
@@ -187,6 +198,64 @@ public void testQuotaRepairForOldVersionVolumeBucket() 
throws Exception {
     assertEquals(-1, volArgsVerify.getQuotaInNamespace());
   }
 
+  @Test
+  public void testQuotaRepairDeletedTableSnapshotQuota() throws Exception {
+    OzoneManagerProtocolProtos.OMResponse respMock = 
mock(OzoneManagerProtocolProtos.OMResponse.class);
+    when(respMock.getSuccess()).thenReturn(true);
+    OzoneManagerRatisServer ratisServerMock = 
mock(OzoneManagerRatisServer.class);
+    AtomicReference<OzoneManagerProtocolProtos.OMRequest> ref = new 
AtomicReference<>();
+    doAnswer(invocation -> {
+      ref.set(invocation.getArgument(0, 
OzoneManagerProtocolProtos.OMRequest.class));
+      return respMock;
+    }).when(ratisServerMock).submitRequest(any(), any(), anyLong());
+    when(ozoneManager.getOmRatisServer()).thenReturn(ratisServerMock);
+
+    OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+        omMetadataManager, BucketLayout.OBJECT_STORE);
+
+    String keyName = "/user/snapKey";
+    OMRequestTestUtils.addKeyToTableAndCache(volumeName, bucketName,
+        keyName, -1, RatisReplicationConfig.getInstance(THREE), 1L, 
omMetadataManager);
+
+    String ozoneKey = omMetadataManager.getOzoneKey(volumeName, bucketName, 
keyName);
+    OmBucketInfo bucketInfo = omMetadataManager.getBucketTable().get(
+        omMetadataManager.getBucketKey(volumeName, bucketName));
+    long bucketObjId = bucketInfo.getObjectID();
+
+    OMRequestTestUtils.deleteKey(ozoneKey, bucketObjId, omMetadataManager, 2L);
+
+    RepeatedOmKeyInfo deletedEntry = 
omMetadataManager.getDeletedTable().get(ozoneKey);
+    long expectedSnapNs = deletedEntry.getOmKeyInfoList().size();
+
+    bucketInfo = omMetadataManager.getBucketTable().get(
+        omMetadataManager.getBucketKey(volumeName, bucketName));
+    OmBucketInfo corruptedSnapshot = bucketInfo.toBuilder()
+        .setSnapshotUsedBytes(7L)
+        .setSnapshotUsedNamespace(99L)
+        .build();
+    String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+    omMetadataManager.getBucketTable().put(bucketKey, corruptedSnapshot);
+    omMetadataManager.getBucketTable().addCacheEntry(
+        new CacheKey<>(bucketKey), CacheValue.get(3L, corruptedSnapshot));
+
+    QuotaRepairTask quotaRepairTask = new QuotaRepairTask(ozoneManager);
+    CompletableFuture<Boolean> repair = quotaRepairTask.repair();
+    assertTrue(awaitRepair(repair));
+
+    OMQuotaRepairRequest omQuotaRepairRequest = new 
OMQuotaRepairRequest(ref.get());
+    OMClientResponse omClientResponse = 
omQuotaRepairRequest.validateAndUpdateCache(ozoneManager, 1);
+    BatchOperation batchOperation = 
omMetadataManager.getStore().initBatchOperation();
+    ((OMQuotaRepairResponse) omClientResponse).addToDBBatch(omMetadataManager, 
batchOperation);
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    OmBucketInfo repaired = omMetadataManager.getBucketTable().get(bucketKey);
+    assertEquals(0, repaired.getUsedBytes());
+    assertEquals(0, repaired.getUsedNamespace());
+    assertEquals(expectedSnapNs, repaired.getSnapshotUsedNamespace());
+    assertTrue(repaired.getSnapshotUsedBytes() > 0,
+        "Snapshot pending-delete bytes must be recomputed from deletedTable");

Review Comment:
   Thanks for the patch @jojochuang and @sadanand48. We should add test 
coverage to include recalculating pending-delete bytes from snapshot DB deleted 
tables as well.



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