kerneltime commented on code in PR #7943:
URL: https://github.com/apache/ozone/pull/7943#discussion_r1970708958


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/impl/TestBlockManagerImpl.java:
##########
@@ -196,6 +200,65 @@ public void testPutAndGetBlock(ContainerTestVersionInfo 
versionInfo)
 
   }
 
+  @ContainerTestVersionInfo.ContainerTest
+  public void testPutBlockForClosed(ContainerTestVersionInfo versionInfo)
+      throws Exception {
+    initTest(versionInfo);
+    KeyValueContainerData containerData = keyValueContainer.getContainerData();
+    assertEquals(0, containerData.getBlockCount());
+    keyValueContainer.close();
+    assertEquals(CLOSED, keyValueContainer.getContainerState());
+    // 1. Put Block with bcsId = 2, Overwrite = true
+    blockManager.putBlockForClosedContainer(keyValueContainer, blockData1, 
true);
+
+    try (DBHandle db = BlockUtils.getDB(containerData, config)) {
+      BlockData fromGetBlockData;
+      //Check Container's bcsId
+      fromGetBlockData = blockManager.getBlock(keyValueContainer, 
blockData1.getBlockID());
+      assertEquals(1, containerData.getBlockCount());
+      assertEquals(1, containerData.getBlockCommitSequenceId());
+      assertEquals(1, fromGetBlockData.getBlockCommitSequenceId());
+      assertEquals(1, 
db.getStore().getMetadataTable().get(containerData.getBcsIdKey()));
+      assertEquals(1, 
db.getStore().getMetadataTable().get(containerData.getBlockCountKey()));
+
+      // 2. Put Block with bcsId = 2, Overwrite = false
+      BlockData blockData2 = createBlockData(1L, 3L, 1, 0, 2048, 2);
+      blockManager.putBlockForClosedContainer(keyValueContainer, blockData2, 
false);
+
+      // The block should be written, but we won't be able to read it, As 
BcsId < container's BcsId
+      // fails during block read.
+      Assertions.assertThrows(StorageContainerException.class, () -> 
blockManager
+          .getBlock(keyValueContainer, blockData2.getBlockID()));
+      assertEquals(2, containerData.getBlockCount());
+      // BcsId should still be 1, as the BcsId is not overwritten
+      assertEquals(1, containerData.getBlockCommitSequenceId());
+      assertEquals(2, 
db.getStore().getMetadataTable().get(containerData.getBlockCountKey()));
+      assertEquals(1, 
db.getStore().getMetadataTable().get(containerData.getBcsIdKey()));
+
+      // 3. Put Block with bcsId = 2, Overwrite = true
+      // This should succeed as we are overwriting the BcsId, The container 
BcsId should be updated to 3
+      // The block count should not change.
+      blockManager.putBlockForClosedContainer(keyValueContainer, blockData2, 
true);
+      fromGetBlockData = blockManager.getBlock(keyValueContainer, 
blockData2.getBlockID());
+      assertEquals(2, containerData.getBlockCount());
+      assertEquals(2, containerData.getBlockCommitSequenceId());
+      assertEquals(2, fromGetBlockData.getBlockCommitSequenceId());
+      assertEquals(2, 
db.getStore().getMetadataTable().get(containerData.getBlockCountKey()));
+      assertEquals(2, 
db.getStore().getMetadataTable().get(containerData.getBcsIdKey()));

Review Comment:
   Should this be 2 or 3?



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