jojochuang commented on code in PR #10545:
URL: https://github.com/apache/ozone/pull/10545#discussion_r3462109525


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyDeleteRequestWithFSO.java:
##########
@@ -333,4 +334,72 @@ public void testDeleteParentAfterChildDeleted() throws 
Exception {
     assertEquals(OzoneManagerProtocolProtos.Status.OK, 
response.getOMResponse().getStatus(),
         "Parent delete should succeed after children deleted");
   }
+
+  @Test
+  public void testSnapshotUsedNamespaceAfterDirectoryDeleteAndPurge() throws 
Exception {
+    OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, 
omMetadataManager, getBucketLayout());
+
+    String dirName = "dir1";
+    String dirKeyPath = addKeyToDirTable(volumeName, bucketName, dirName);
+
+    long parentObjectID = 0L;
+    long dirObjectID = 12345L;
+    OmDirectoryInfo omDirectoryInfo = 
OMRequestTestUtils.createOmDirectoryInfo(dirName, dirObjectID, parentObjectID);
+    omMetadataManager.getDirectoryTable().put(dirKeyPath, omDirectoryInfo);
+
+    String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+    OmBucketInfo omBucketInfo = 
omMetadataManager.getBucketTable().get(bucketKey);
+    assertNotNull(omBucketInfo);
+    // Initialize used namespace and snapshot used namespace for test 
predictability
+    omBucketInfo.incrUsedNamespace(1);
+    omMetadataManager.getBucketTable().put(bucketKey, omBucketInfo);
+
+    // Delete the directory
+    long txnId = 100L;
+    OMRequest deleteRequest = doPreExecute(createDeleteKeyRequest(dirName, 
false));
+    OMKeyDeleteRequest omKeyDeleteRequest = 
getOmKeyDeleteRequest(deleteRequest);
+    OMClientResponse deleteResponse = 
omKeyDeleteRequest.validateAndUpdateCache(ozoneManager, txnId++);
+    assertEquals(OzoneManagerProtocolProtos.Status.OK, 
deleteResponse.getOMResponse().getStatus());
+
+    OmBucketInfo bucketInfoAfterDelete = 
omMetadataManager.getBucketTable().get(bucketKey);
+
+    // Perform purge
+    OzoneManagerProtocolProtos.PurgeDirectoriesRequest.Builder purgeDirRequest 
=
+        OzoneManagerProtocolProtos.PurgeDirectoriesRequest.newBuilder();
+
+    long volumeId = omMetadataManager.getVolumeId(volumeName);
+    long bucketId = bucketInfoAfterDelete.getObjectID();
+
+    OzoneManagerProtocolProtos.PurgePathRequest purgePathRequest =
+        OzoneManagerProtocolProtos.PurgePathRequest.newBuilder()
+            .setVolumeId(volumeId)
+            .setBucketId(bucketId)
+            .setDeletedDir(dirKeyPath)
+            .build();
+
+    purgeDirRequest.addDeletedPath(purgePathRequest);
+    purgeDirRequest.addBucketNameInfos(
+        OzoneManagerProtocolProtos.BucketNameInfo.newBuilder()
+            .setVolumeName(volumeName)
+            .setBucketName(bucketName)
+            .setBucketId(bucketId)
+            .setVolumeId(volumeId)
+            .build());
+
+    OMRequest purgeRequest = OMRequest.newBuilder()
+        .setCmdType(OzoneManagerProtocolProtos.Type.PurgeDirectories)
+        .setPurgeDirectoriesRequest(purgeDirRequest)
+        .setClientId(UUID.randomUUID().toString())
+        .build();
+
+    OMDirectoriesPurgeRequestWithFSO omPurgeRequest = new 
OMDirectoriesPurgeRequestWithFSO(purgeRequest);
+    OMClientResponse purgeResponse = 
omPurgeRequest.validateAndUpdateCache(ozoneManager, txnId);
+    assertEquals(OzoneManagerProtocolProtos.Status.OK, 
purgeResponse.getOMResponse().getStatus());
+
+    OmBucketInfo bucketInfoAfterPurge = 
omMetadataManager.getBucketTable().get(bucketKey);
+
+    // We expect snapshotUsedNamespace to not go negative
+    assertTrue(bucketInfoAfterPurge.getSnapshotUsedNamespace() >= 0,
+        "SnapshotUsedNamespace went negative (" + 
bucketInfoAfterPurge.getSnapshotUsedNamespace() + ") due to bug.");

Review Comment:
   ah good point.



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