-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-8553. Improve scanner integration tests. #4936
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
Merged
adoroszlai
merged 13 commits into
apache:master
from
errose28:HDDS-8553-scanner-intg-tests
Jun 23, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5280f02
Initial split of container integration tests
errose28 1618e2f
Add integration tests for all scanners independently
errose28 48fc7e3
Delete old duplicate integration test classes
errose28 6ea2667
On demand and background tests apss with the exception of contaienr file
errose28 f8e6a23
Fix flaky metadata tests and other minor improvements
errose28 18ffb9f
Throw IOException on yaml parse error
errose28 a5f4c15
Move test corruption types to enum
errose28 ae2b869
Use exclude list for corruption types and tweak timeouts
errose28 971105c
Checkstyle
errose28 1c99459
Add license headers
errose28 cccd88f
Revert log4j config change
errose28 c840215
Add tests and fixes for file truncation
errose28 5c7baa3
Fix checkstyle and findbugs
errose28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ava/org/apache/hadoop/ozone/dn/scanner/TestBackgroundContainerDataScannerIntegration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| */ | ||
| package org.apache.hadoop.ozone.dn.scanner; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.BackgroundContainerDataScanner; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.ContainerScannerConfiguration; | ||
| import org.apache.ozone.test.GenericTestUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Integration tests for the background container data scanner. This scanner | ||
| * checks all data and metadata in the container. | ||
| */ | ||
| @RunWith(Parameterized.class) | ||
| public class TestBackgroundContainerDataScannerIntegration | ||
| extends TestContainerScannerIntegrationAbstract { | ||
|
|
||
| private final ContainerCorruptions corruption; | ||
|
|
||
| @Parameterized.Parameters(name = "{0}") | ||
| public static Collection<Object[]> supportedCorruptionTypes() { | ||
| // Background container data scanner should be able to detect all errors. | ||
| return ContainerCorruptions.getAllParamsExcept(); | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws Exception { | ||
| OzoneConfiguration ozoneConfig = new OzoneConfiguration(); | ||
| ozoneConfig.setBoolean( | ||
| ContainerScannerConfiguration.HDDS_CONTAINER_SCRUB_ENABLED, true); | ||
| // Make sure the background metadata scanner does not detect failures | ||
| // before the data scanner under test does. | ||
| ozoneConfig.setBoolean( | ||
| ContainerScannerConfiguration.HDDS_CONTAINER_SCRUB_DEV_METADATA_ENABLED, | ||
| false); | ||
| // Make the background data scanner run frequently to reduce test time. | ||
| ozoneConfig.setTimeDuration( | ||
| ContainerScannerConfiguration.DATA_SCAN_INTERVAL_KEY, | ||
| SCAN_INTERVAL.getSeconds(), TimeUnit.SECONDS); | ||
| buildCluster(ozoneConfig); | ||
| } | ||
|
|
||
| public TestBackgroundContainerDataScannerIntegration( | ||
| ContainerCorruptions corruption) { | ||
| this.corruption = corruption; | ||
| } | ||
|
|
||
| /** | ||
| * {@link BackgroundContainerDataScanner} should detect corrupted blocks | ||
| * in a closed container without client interaction. | ||
| */ | ||
| @Test | ||
| public void testCorruptionDetected() throws Exception { | ||
| long containerID = writeDataThenCloseContainer(); | ||
| // Container corruption has not yet been introduced. | ||
| Assert.assertEquals(ContainerProtos.ContainerDataProto.State.CLOSED, | ||
| getDnContainer(containerID).getContainerState()); | ||
|
|
||
| corruption.applyTo(getDnContainer(containerID)); | ||
| // Wait for the scanner to detect corruption. | ||
| GenericTestUtils.waitFor(() -> | ||
| getDnContainer(containerID).getContainerState() == | ||
| ContainerProtos.ContainerDataProto.State.UNHEALTHY, | ||
| 500, 5000); | ||
|
|
||
| // Wait for SCM to get a report of the unhealthy replica. | ||
| waitForScmToSeeUnhealthyReplica(containerID); | ||
| } | ||
| } | ||
120 changes: 120 additions & 0 deletions
120
...org/apache/hadoop/ozone/dn/scanner/TestBackgroundContainerMetadataScannerIntegration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| */ | ||
| package org.apache.hadoop.ozone.dn.scanner; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.BackgroundContainerMetadataScanner; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.ContainerScannerConfiguration; | ||
| import org.apache.ozone.test.GenericTestUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Collection; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Integration tests for the background container metadata scanner. This | ||
| * scanner does a quick check of container metadata to find obvious failures | ||
| * faster than a full data scan. | ||
| */ | ||
| @RunWith(Parameterized.class) | ||
| public class TestBackgroundContainerMetadataScannerIntegration | ||
| extends TestContainerScannerIntegrationAbstract { | ||
|
|
||
| private final ContainerCorruptions corruption; | ||
|
|
||
| @Parameterized.Parameters(name = "{0}") | ||
| public static Collection<Object[]> supportedCorruptionTypes() { | ||
| return ContainerCorruptions.getAllParamsExcept( | ||
| ContainerCorruptions.MISSING_BLOCK, | ||
| ContainerCorruptions.CORRUPT_BLOCK, | ||
| ContainerCorruptions.TRUNCATED_BLOCK); | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws Exception { | ||
| OzoneConfiguration ozoneConfig = new OzoneConfiguration(); | ||
| // Speed up SCM closing of open container when an unhealthy replica is | ||
| // reported. | ||
| ReplicationManager.ReplicationManagerConfiguration rmConf = ozoneConfig | ||
| .getObject(ReplicationManager.ReplicationManagerConfiguration.class); | ||
| rmConf.setInterval(Duration.ofSeconds(1)); | ||
| ozoneConfig.setFromObject(rmConf); | ||
|
|
||
| ozoneConfig.setBoolean( | ||
| ContainerScannerConfiguration.HDDS_CONTAINER_SCRUB_ENABLED, true); | ||
| // Make sure the background data scanner does not detect failures | ||
| // before the metadata scanner under test does. | ||
| ozoneConfig.setBoolean( | ||
| ContainerScannerConfiguration.HDDS_CONTAINER_SCRUB_DEV_DATA_ENABLED, | ||
| false); | ||
| // Make the background metadata scanner run frequently to reduce test time. | ||
| ozoneConfig.setTimeDuration( | ||
| ContainerScannerConfiguration.METADATA_SCAN_INTERVAL_KEY, | ||
| SCAN_INTERVAL.getSeconds(), TimeUnit.SECONDS); | ||
| buildCluster(ozoneConfig); | ||
| } | ||
|
|
||
| public TestBackgroundContainerMetadataScannerIntegration( | ||
| ContainerCorruptions corruption) { | ||
| this.corruption = corruption; | ||
| } | ||
|
|
||
| /** | ||
| * {@link BackgroundContainerMetadataScanner} should detect corrupted metadata | ||
| * in open or closed containers without client interaction. | ||
| */ | ||
| @Test | ||
| public void testCorruptionDetected() throws Exception { | ||
| // Write data to an open and closed container. | ||
| long closedContainerID = writeDataThenCloseContainer(); | ||
| Assert.assertEquals(ContainerProtos.ContainerDataProto.State.CLOSED, | ||
| getDnContainer(closedContainerID).getContainerState()); | ||
| long openContainerID = writeDataToOpenContainer(); | ||
| Assert.assertEquals(ContainerProtos.ContainerDataProto.State.OPEN, | ||
| getDnContainer(openContainerID).getContainerState()); | ||
|
|
||
| // Corrupt both containers. | ||
| corruption.applyTo(getDnContainer(closedContainerID)); | ||
| corruption.applyTo(getDnContainer(openContainerID)); | ||
| // Wait for the scanner to detect corruption. | ||
| GenericTestUtils.waitFor(() -> | ||
| getDnContainer(closedContainerID).getContainerState() == | ||
| ContainerProtos.ContainerDataProto.State.UNHEALTHY, | ||
| 500, 5000); | ||
| GenericTestUtils.waitFor(() -> | ||
| getDnContainer(openContainerID).getContainerState() == | ||
| ContainerProtos.ContainerDataProto.State.UNHEALTHY, | ||
| 500, 5000); | ||
|
|
||
| // Wait for SCM to get reports of the unhealthy replicas. | ||
| waitForScmToSeeUnhealthyReplica(closedContainerID); | ||
| waitForScmToSeeUnhealthyReplica(openContainerID); | ||
| // Once the unhealthy replica is reported, the open container's lifecycle | ||
| // state in SCM should move to closed. | ||
| waitForScmToCloseContainer(openContainerID); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since it is new code, it would be great if you use JUnit-5 and its parameterized tests.