sreejasahithi commented on code in PR #10105:
URL: https://github.com/apache/ozone/pull/10105#discussion_r3121883523
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/block/TestDeletedBlockLog.java:
##########
@@ -996,4 +997,81 @@ private void
mockInadequateReplicaUnhealthyContainerInfo(long containerID,
ContainerID.valueOf(containerID)))
.thenReturn(replicaSet);
}
+
+ /**
+ * Verifies that for EC containers, totalBlockSize in the delete transaction
+ * is set to replicatedSize / (k+m), not the full logical stripe size.
+ */
+ @Test
+ public void testECContainerTotalBlockSizeIsPerReplicaSize() throws Exception
{
+ // EC(6,3) container: 9 required nodes.
+ final int dataBlocks = 6;
+ final int parityBlocks = 3;
+ final int chunkSize = 1024 * 1024; // 1 MB
+ ECReplicationConfig ecConfig = new ECReplicationConfig(dataBlocks,
parityBlocks,
+ ECReplicationConfig.EcCodec.RS, chunkSize);
+
+ final long containerID = 9999L;
+ ContainerInfo ecContainerInfo = new ContainerInfo.Builder()
+ .setContainerID(containerID)
+ .setReplicationConfig(ecConfig)
+ .setState(HddsProtos.LifeCycleState.CLOSED)
+ .setOwner("TestDeletedBlockLog")
+ .setPipelineID(PipelineID.randomId())
+ .build();
+ // Register the container in both the in-memory map (used by the
+ // updateDeleteTransactionId mock) and the DB table (used by getContainer).
+ ContainerID ecContainerCID = ecContainerInfo.containerID();
+ containers.put(ecContainerCID, ecContainerInfo);
+ containerTable.put(ecContainerCID, ecContainerInfo);
+ final Set<ContainerReplica> ecReplicas = dnList.stream()
+ .map(dd -> ContainerReplica.newBuilder()
+ .setContainerID(ecContainerCID)
+ .setContainerState(ContainerReplicaProto.State.CLOSED)
+ .setDatanodeDetails(dd)
+ .build())
+ .collect(Collectors.toSet());
+ replicas.put(ecContainerCID, ecReplicas);
+
+ // Simulate deletion of a single logical EC block of 64 MB.
+ // logicalSize = 64 MB; replicatedSize includes parity overhead.
+ long logicalSize = 64L * 1024 * 1024;
+ // Compute expected replicatedSize using the same formula as QuotaUtil.
+ long dataStripeSize = (long) dataBlocks * chunkSize;
+ long fullStripes = logicalSize / dataStripeSize;
+ long partialFirstChunk = Math.min(chunkSize, logicalSize % dataStripeSize);
+ long parityOverhead = fullStripes * parityBlocks * chunkSize
+ + partialFirstChunk * parityBlocks;
+ long expectedReplicatedSize = logicalSize + parityOverhead;
+ int requiredNodes = ecConfig.getRequiredNodes(); // = 9
+
+ List<DeletedBlock> blocks = Collections.singletonList(
+ new DeletedBlock(new BlockID(containerID, 1L), logicalSize,
expectedReplicatedSize));
+
+ Map<Long, List<DeletedBlock>> blockMap = new HashMap<>();
+ blockMap.put(containerID, blocks);
+
+
SCMDeletedBlockTransactionStatusManager.setDisableDataDistributionForTest(false);
+ deletedBlockLog.addTransactions(blockMap);
+ scmHADBTransactionBuffer.flush();
+
+ // Read back the stored transaction and verify totalBlockSize.
+ try (Table.KeyValueIterator<Long, DeletedBlocksTransaction> iter =
+
deletedBlockLog.getDeletedBlockLogStateManager().getReadOnlyIterator()) {
+ boolean found = false;
+ while (iter.hasNext()) {
+ DeletedBlocksTransaction tx = iter.next().getValue();
+ if (tx.getContainerID() == containerID) {
+ found = true;
+ assertEquals(expectedReplicatedSize,
tx.getTotalBlockReplicatedSize());
+ long expectedPerReplica = expectedReplicatedSize / requiredNodes;
+ assertEquals(expectedPerReplica, tx.getTotalBlockSize());
+ // Sanity check: per-replica * requiredNodes == replicatedSize
(within integer division).
+ assertEquals(expectedReplicatedSize / requiredNodes * requiredNodes,
+ tx.getTotalBlockSize() * requiredNodes);
+ }
Review Comment:
The third assertEquals can never fail.
after the second assertion passes, tx.getTotalBlockSize() is guaranteed to
equal expectedReplicatedSize / requiredNodes. Substituting that into the third
assertion gives (expectedReplicatedSize / requiredNodes) * requiredNodes ==
(expectedReplicatedSize / requiredNodes) * requiredNodes both sides are
identical, so it always passes regardless of the actual values.
--
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]