aswinshakil commented on code in PR #7293:
URL: https://github.com/apache/ozone/pull/7293#discussion_r1846982056
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/checksum/ContainerMerkleTreeTestUtils.java:
##########
@@ -128,24 +138,196 @@ public static ContainerProtos.ContainerChecksumInfo
readChecksumFile(ContainerDa
* structure is preserved throughout serialization, deserialization, and API
calls.
*/
public static ContainerMerkleTree buildTestTree(ConfigurationSource conf) {
- final long blockID1 = 1;
- final long blockID2 = 2;
- final long blockID3 = 3;
- ContainerProtos.ChunkInfo b1c1 = buildChunk(conf, 0, ByteBuffer.wrap(new
byte[]{1, 2, 3}));
- ContainerProtos.ChunkInfo b1c2 = buildChunk(conf, 1, ByteBuffer.wrap(new
byte[]{4, 5, 6}));
- ContainerProtos.ChunkInfo b2c1 = buildChunk(conf, 0, ByteBuffer.wrap(new
byte[]{7, 8, 9}));
- ContainerProtos.ChunkInfo b2c2 = buildChunk(conf, 1, ByteBuffer.wrap(new
byte[]{12, 11, 10}));
- ContainerProtos.ChunkInfo b3c1 = buildChunk(conf, 0, ByteBuffer.wrap(new
byte[]{13, 14, 15}));
- ContainerProtos.ChunkInfo b3c2 = buildChunk(conf, 1, ByteBuffer.wrap(new
byte[]{16, 17, 18}));
-
ContainerMerkleTree tree = new ContainerMerkleTree();
- tree.addChunks(blockID1, Arrays.asList(b1c1, b1c2));
- tree.addChunks(blockID2, Arrays.asList(b2c1, b2c2));
- tree.addChunks(blockID3, Arrays.asList(b3c1, b3c2));
-
+ byte byteValue = 1;
+ for (int blockIndex = 1; blockIndex <= 5; blockIndex++) {
+ List<ContainerProtos.ChunkInfo> chunks = new ArrayList<>();
+ for (int chunkIndex = 0; chunkIndex < 4; chunkIndex++) {
+ chunks.add(buildChunk(conf, chunkIndex, ByteBuffer.wrap(new
byte[]{byteValue++, byteValue++, byteValue++})));
+ }
+ tree.addChunks(blockIndex, chunks);
+ }
return tree;
}
+ /**
+ * Returns a Pair of merkle tree and the expected container diff for that
merkle tree.
+ */
+ public static Pair<ContainerProtos.ContainerMerkleTree,
ContainerChecksumTreeManager.ContainerDiff>
+ buildTestTreeWithMismatches(ContainerMerkleTree originalTree, int
numMissingBlocks, int numMissingChunks,
+ int numCorruptChunks) {
+
+ ContainerProtos.ContainerMerkleTree.Builder treeBuilder =
originalTree.toProto().toBuilder();
+ ContainerChecksumTreeManager.ContainerDiff diff = new
ContainerChecksumTreeManager.ContainerDiff();
+
+ introduceMissingBlocks(treeBuilder, numMissingBlocks, diff);
+ introduceMissingChunks(treeBuilder, numMissingChunks, diff);
+ introduceCorruptChunks(treeBuilder, numCorruptChunks, diff);
+ ContainerProtos.ContainerMerkleTree build = treeBuilder.build();
+ return Pair.of(build, diff);
+ }
+
+ /**
+ * Introduces missing blocks by removing random blocks from the tree.
+ */
+ private static void
introduceMissingBlocks(ContainerProtos.ContainerMerkleTree.Builder treeBuilder,
+ int numMissingBlocks,
+
ContainerChecksumTreeManager.ContainerDiff diff) {
+ // Set to track unique blocks selected for mismatches
+ Set<Integer> selectedBlocks = new HashSet<>();
+ Random random = new Random();
Review Comment:
I would prefer random over fixed placement. If there are some bugs random
has a better chance of catching it rather than fixed placement.
--
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]