Skip to content

HDDS-10374. Make container scanner generate merkle trees during the scan #7490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 63 commits into
base: HDDS-10239-container-reconciliation
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a8b8dbc
Merge branch 'HDDS-10239-container-reconciliation' into HDDS-10374-sc…
errose28 Nov 22, 2024
999a913
Add code to build and write the tree from the data scanners
errose28 Nov 22, 2024
b0d1ba9
Update todo in acceptance test
errose28 Nov 25, 2024
382bce2
Add unit tests for tree generation by scanners based on container state
errose28 Nov 25, 2024
28b1889
Add initial (failing) unit test for KeyValueContaienrCheck
errose28 Nov 26, 2024
dc182e8
Update container data checksum when building the tree
errose28 Nov 26, 2024
a3401a9
Fix handling of fully truncated block of 0 size
errose28 Jan 7, 2025
a25d44d
Add unit tests for new addBlock method in tree
errose28 Jan 7, 2025
7550a3c
Test that SCM gets a checksum with the container report
errose28 Jan 7, 2025
847f8d8
Add (failing) tests that SCM sees updated checksums
errose28 Jan 7, 2025
452c294
Update acceptance test
errose28 Jan 8, 2025
dc45eca
Add javadoc for tree generation from metadata
errose28 Jan 8, 2025
1cb291f
Data integration tests passing
errose28 Jan 8, 2025
d6b21d2
Don't generate tree from metadata for unhealthy container
errose28 Jan 9, 2025
2a2dbbd
Checkstyle
errose28 Jan 9, 2025
c9a077c
Marking container unhealthy should not write a merkle tree (test fix)
errose28 Jan 9, 2025
0bbbdc5
Checkstyle
errose28 Jan 9, 2025
7b971a9
Address review comments
errose28 Jan 13, 2025
15d6848
Merge branch 'HDDS-10239-container-reconciliation' into HDDS-10374-sc…
errose28 Apr 11, 2025
0989881
Initial use of on demand scan in TestKeyValueHandler
errose28 Apr 11, 2025
834be96
Make on-demand scanner a normal instance
errose28 Apr 15, 2025
e73757e
Register on-demand scan callback in ContainerSet
errose28 Apr 15, 2025
f0d8efe
Migrate scanContainer usage in prod code
errose28 Apr 15, 2025
4cb054c
Switch terminology from error to scan. Add existence checks
errose28 Apr 15, 2025
8abedb6
Update tests
errose28 Apr 15, 2025
577a075
Add unit test for ContainerSet
errose28 Apr 16, 2025
4c8d843
Checkstyle
errose28 Apr 16, 2025
0bd4127
Improve comments and test
errose28 Apr 16, 2025
61fae12
Merge branch 'non-static-on-demand-scan' into HDDS-10374-scanner-buil…
errose28 Apr 16, 2025
61f30f3
WIP migrate reconciliation unit tests
errose28 Apr 17, 2025
192eb7b
Most tests passing
errose28 Apr 23, 2025
0cf79f6
Improve logging in test and prod code
errose28 Apr 28, 2025
8b30f54
Fix tree tracking during reconcile process
errose28 Apr 28, 2025
9c74f4b
Use mixin to standardize scanner operations, log checksum changes in …
errose28 Apr 29, 2025
d550669
Logging improvements
errose28 Apr 29, 2025
97e02ea
Add checksum validation, generate readable data
errose28 Apr 30, 2025
22b41b8
Use tree writer between peer updates. All tests pass
errose28 May 5, 2025
f49a9dd
Wait for on-demand scans to complete in test
errose28 May 5, 2025
f5d4dbf
Improve char data generation, reset scan metrics
errose28 May 5, 2025
1140c90
Update test name
errose28 May 5, 2025
e0aa7cb
Checkstyle
errose28 May 5, 2025
62d7794
Merge branch 'HDDS-10239-container-reconciliation' into HDDS-10374-sc…
errose28 May 6, 2025
9c3b87c
Merge branch 'reconcile-unit-test-framework' into HDDS-10374-scanner-…
errose28 May 6, 2025
9322b4a
Fix TODOs dependent on this patch
errose28 May 13, 2025
9b75957
Rename container scan helper
errose28 May 13, 2025
f615275
Add comment on failure type
errose28 May 13, 2025
dadc829
Fix checkstyle unique to this PR
errose28 May 13, 2025
076a82e
Merge branch 'HDDS-10239-container-reconciliation' into HDDS-10374-sc…
errose28 May 14, 2025
cc55527
Fix sending ICR when only checksum changes (pending test)
errose28 May 14, 2025
35879b4
Updates after reviewing diff
errose28 May 14, 2025
1ab8c14
Add unit test for KeyValueHandler#updateContainerChecksum
errose28 May 14, 2025
6c8be07
Improve and update scanner integration tests
errose28 May 14, 2025
60a1a6e
Add unit tests that checksum update failure does not stop container s…
errose28 May 14, 2025
d035c17
Checkstyle
errose28 May 14, 2025
53336ae
Fix scan gap for unit test
errose28 May 15, 2025
56e7ed4
Merge branch 'HDDS-10239-container-reconciliation' into HDDS-10374-sc…
errose28 May 16, 2025
2504638
Fix metadata scan test
errose28 May 16, 2025
4be9992
Update based on review
errose28 May 19, 2025
c0b89dd
pmd
errose28 May 19, 2025
e24a24e
Update ContainerData checksum info after reconcile with each peer
errose28 May 22, 2025
dc27f74
Support bypassing scan gap (tests are failing)
errose28 May 22, 2025
e2974b4
Checkstyle
errose28 May 27, 2025
34b4b9a
Fix scan gap bug. All tests expected to pass
errose28 May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve char data generation, reset scan metrics
  • Loading branch information
errose28 committed May 5, 2025
commit f5d4dbf3e796ebe35c108b0889ae541b1f76f4be
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.apache.hadoop.ozone.container.keyvalue;

import org.apache.commons.io.IOUtils;
import org.apache.commons.text.RandomStringGenerator;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand Down Expand Up @@ -28,6 +29,7 @@
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -111,7 +113,7 @@ public static Stream<Arguments> corruptionValues() {
public static final Logger LOG = LoggerFactory.getLogger(TestKeyValueHandlerContainerReconciliation.class);

// All container replicas will be placed in this directory, and the same replicas will be re-used for each test run.
// @TempDir
@TempDir
private static Path containerDir;
private static DNContainerOperationClient dnClient;
private static MockedStatic<ContainerProtocolCalls> containerProtocolMock;
Expand All @@ -130,7 +132,6 @@ public static Stream<Arguments> corruptionValues() {
*/
@BeforeAll
public static void setup() throws Exception {
containerDir = Files.createTempDirectory("reconcile");
LOG.info("Data written to {}", containerDir);
dnClient = new DNContainerOperationClient(new OzoneConfiguration(), null, null);
datanodes = new ArrayList<>();
Expand All @@ -147,11 +148,19 @@ public static void setup() throws Exception {

datanodes.forEach(d -> d.scanContainer(CONTAINER_ID));
healthyDataChecksum = assertUniqueChecksumCount(CONTAINER_ID, datanodes, 1);
// Do not count the initial synchronous scan to build the merkle tree towards the scan count in the tests.
// This lets each test run start counting the number of scans from zero.
datanodes.forEach(MockDatanode::resetOnDemandScanCount);

containerProtocolMock = Mockito.mockStatic(ContainerProtocolCalls.class);
mockContainerProtocolCalls();
}

@AfterEach
public void reset() {
datanodes.forEach(MockDatanode::resetOnDemandScanCount);
}

@AfterAll
public static void teardown() {
if (containerProtocolMock != null) {
Expand All @@ -176,8 +185,7 @@ public void testContainerReconciliation(int numBlocksToDelete, int numChunksToCo

// Each datanode should have had one on-demand scan during test setup, and a second one after corruption was
// introduced.
final int originalScanCount = 2;
waitForExpectedScanCount(originalScanCount);
waitForExpectedScanCount(1);

// Reconcile each datanode with its peers.
// In a real cluster, SCM will not send a command to reconcile a datanode with itself.
Expand All @@ -190,21 +198,20 @@ public void testContainerReconciliation(int numBlocksToDelete, int numChunksToCo
}
// Reconciliation should have triggered a second on-demand scan for each replica. Wait for them to finish before
// checking the results.
waitForExpectedScanCount(originalScanCount + 1);
waitForExpectedScanCount(2);
// After reconciliation, checksums should be the same for all containers.
long repairedDataChecksum = assertUniqueChecksumCount(CONTAINER_ID, datanodes, 1);
assertEquals(healthyDataChecksum, repairedDataChecksum);
}

/**
* Uses the on-demand container scanner metrics to wait for the expected number of on demand scans to complete.
* Since the metrics are static and shared across all datanodes in this test, this count should be the total number
* of scans across all nodes.
* Uses the on-demand container scanner metrics to wait for the expected number of on-demand scans to complete on
* every datanode.
*/
private void waitForExpectedScanCount(int expectedCount) throws Exception {
for (MockDatanode datanode: datanodes) {
try {
GenericTestUtils.waitFor(() -> datanode.getOnDemandScanCount() == expectedCount, 100, 5_000);
GenericTestUtils.waitFor(() -> datanode.getOnDemandScanCount() == expectedCount, 100, 10_000);
} catch (TimeoutException ex) {
LOG.error("Timed out waiting for on-demand scan count {} to reach expected count {} on datanode {}",
datanode.getOnDemandScanCount(), expectedCount, datanode);
Expand Down Expand Up @@ -410,6 +417,10 @@ public int getOnDemandScanCount() {
return onDemandScanner.getMetrics().getNumContainersScanned();
}

public void resetOnDemandScanCount() {
onDemandScanner.getMetrics().resetNumContainersScanned();
}

public void reconcileContainer(DNContainerOperationClient dnClient, Collection<DatanodeDetails> peers,
long containerID) {
log.info("Beginning reconciliation on this mock datanode");
Expand All @@ -421,9 +432,8 @@ public void reconcileContainer(DNContainerOperationClient dnClient, Collection<D
}

/**
* Creates a container with normal and deleted blocks.
* First it will insert normal blocks, and then it will insert
* deleted blocks.
* Create a container with the specified number of blocks. Block data is human-readable so the block files can be
* inspected when debugging the test.
*/
public void addContainerWithBlocks(long containerId, int blocks) throws Exception {
ContainerProtos.CreateContainerRequestProto createRequest =
Expand All @@ -447,7 +457,11 @@ public void addContainerWithBlocks(long containerId, int blocks) throws Exceptio

// Create data to put in the container.
// Seed using the container ID so that all replicas are identical.
Random byteGenerator = new Random(containerId);
RandomStringGenerator generator = new RandomStringGenerator.Builder()
.withinRange('a', 'z')
.usingRandom(new Random(containerId)::nextInt)
.get();

// This array will keep getting populated with new bytes for each chunk.
byte[] chunkData = new byte[CHUNK_LEN];
int bytesPerChecksum = 2 * (int) OzoneConsts.KB;
Expand All @@ -465,9 +479,10 @@ public void addContainerWithBlocks(long containerId, int blocks) throws Exceptio
ChunkInfo info = new ChunkInfo(chunkName, offset, chunkData.length);

// Generate data for the chunk and compute its checksum.
// byteGenerator.nextBytes(chunkData);
// Data is generated as one ascii character per line, so block files are human-readable if further
// debugging is needed.
for (int c = 0; c < chunkData.length; c += 2) {
chunkData[c] = (byte) (byteGenerator.nextInt(95) + 32);
chunkData[c] = (byte)generator.generate(1).charAt(0);
chunkData[c+1] = (byte)'\n';
}

Expand Down