aswinshakil commented on code in PR #7474:
URL: https://github.com/apache/ozone/pull/7474#discussion_r2033823937


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java:
##########
@@ -499,10 +578,121 @@ public void 
testReconcileContainer(ContainerLayoutVersion layoutVersion) throws
 
     Assertions.assertEquals(0, icrCount.get());
     // This should trigger container report validation in the ICR handler 
above.
-    keyValueHandler.reconcileContainer(mock(DNContainerOperationClient.class), 
container, Collections.emptySet());
+    DNContainerOperationClient mockDnClient = 
mock(DNContainerOperationClient.class);
+    DatanodeDetails peer1 = MockDatanodeDetails.randomDatanodeDetails();
+    DatanodeDetails peer2 = MockDatanodeDetails.randomDatanodeDetails();
+    DatanodeDetails peer3 = MockDatanodeDetails.randomDatanodeDetails();
+    when(mockDnClient.getContainerChecksumInfo(anyLong(), 
any())).thenReturn(null);
+    keyValueHandler.reconcileContainer(mockDnClient, container, 
Sets.newHashSet(peer1, peer2, peer3));
+    // Make sure all the replicas are used for reconciliation.
+    Mockito.verify(mockDnClient, times(3)).getContainerChecksumInfo(anyLong(), 
any());
     Assertions.assertEquals(1, icrCount.get());
   }
 
+  @ParameterizedTest
+  @MethodSource("corruptionValues")
+  public void testFullContainerReconciliation(int numBlocks, int numChunks) 
throws Exception {
+    KeyValueHandler kvHandler = createKeyValueHandler(testRoot);
+    ContainerChecksumTreeManager checksumManager = 
kvHandler.getChecksumManager();
+    DNContainerOperationClient dnClient = 
mock(DNContainerOperationClient.class);
+    XceiverClientManager xceiverClientManager = 
mock(XceiverClientManager.class);
+    TokenHelper tokenHelper = new TokenHelper(new SecurityConfig(conf), null);
+    when(dnClient.getTokenHelper()).thenReturn(tokenHelper);
+    when(dnClient.getXceiverClientManager()).thenReturn(xceiverClientManager);
+    final long containerID = 100L;
+    // Create 3 containers with 10 blocks each and 3 replicas.
+    List<KeyValueContainer> containers = createContainerWithBlocks(kvHandler, 
containerID, 15, 3);
+    assertEquals(3, containers.size());
+
+    // Introduce corruption in each container on different replicas.
+    introduceCorruption(kvHandler, containers.get(1), numBlocks, numChunks, 
false);
+    introduceCorruption(kvHandler, containers.get(2), numBlocks, numChunks, 
true);
+
+    // Without reconciliation, checksums should be different because of the 
corruption.
+    Set<Long> checksumsBeforeReconciliation = new HashSet<>();
+    for (KeyValueContainer kvContainer : containers) {
+      kvHandler.createContainerMerkleTree(kvContainer);
+      Optional<ContainerProtos.ContainerChecksumInfo> containerChecksumInfo =
+          checksumManager.read(kvContainer.getContainerData());
+      assertTrue(containerChecksumInfo.isPresent());
+      
checksumsBeforeReconciliation.add(containerChecksumInfo.get().getContainerMerkleTree().getDataChecksum());
+    }
+    // There should be more than 1 checksum because of the corruption.
+    assertTrue(checksumsBeforeReconciliation.size() > 1);

Review Comment:
   I'm using the same `chunkInfo` for all the chunks to make the test simple 
and debuggable, For case with just missing blocks, It would give the same 
checksum regardless if we delete it from the back or from the front of the 
block data. 



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