yandrey321 commented on code in PR #9258: URL: https://github.com/apache/ozone/pull/9258#discussion_r2852834260
########## hadoop-ozone/integration-test-recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconTasksV2MultiNode.java: ########## @@ -0,0 +1,178 @@ +/* + * 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.recon; + +import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_REPORT_INTERVAL; +import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_PIPELINE_REPORT_INTERVAL; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.Duration; +import java.util.List; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.pipeline.PipelineManager; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManagerV2.UnhealthyContainerRecordV2; +import org.apache.hadoop.ozone.recon.scm.ReconContainerManager; +import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade; +import org.apache.hadoop.ozone.recon.tasks.ReconTaskConfig; +import org.apache.ozone.recon.schema.ContainerSchemaDefinitionV2; +import org.apache.ozone.test.LambdaTestUtils; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Integration tests for ContainerHealthTaskV2 with multi-node clusters. + * + * These tests are separate from TestReconTasks because they require + * different cluster configurations (3 datanodes) and would conflict + * with the @BeforeEach/@AfterEach setup in that class. + */ +public class TestReconTasksV2MultiNode { + + private static MiniOzoneCluster cluster; + private static ReconContainerManager reconContainerManager; + private static PipelineManager reconPipelineManager; + + @BeforeAll + public static void setupCluster() throws Exception { + OzoneConfiguration testConf = new OzoneConfiguration(); + testConf.set(HDDS_CONTAINER_REPORT_INTERVAL, "5s"); + testConf.set(HDDS_PIPELINE_REPORT_INTERVAL, "5s"); + + ReconTaskConfig taskConfig = testConf.getObject(ReconTaskConfig.class); + taskConfig.setMissingContainerTaskInterval(Duration.ofSeconds(10)); + testConf.setFromObject(taskConfig); + + testConf.set("ozone.scm.stale.node.interval", "6s"); + testConf.set("ozone.scm.dead.node.interval", "8s"); + + ReconService reconService = new ReconService(testConf); + cluster = MiniOzoneCluster.newBuilder(testConf) + .setNumDatanodes(3) + .addService(reconService) + .build(); + + cluster.waitForClusterToBeReady(); + + ReconStorageContainerManagerFacade reconScm = (ReconStorageContainerManagerFacade) + reconService.getReconServer().getReconStorageContainerManager(); + reconPipelineManager = reconScm.getPipelineManager(); + reconContainerManager = (ReconContainerManager) reconScm.getContainerManager(); + } + + @BeforeEach + public void cleanupBeforeEach() throws Exception { + // Ensure each test starts from a clean unhealthy-container table. + reconContainerManager.getContainerSchemaManagerV2().clearAllUnhealthyContainerRecords(); + // Ensure Recon has initialized pipeline state before assertions. + LambdaTestUtils.await(60000, 5000, + () -> (!reconPipelineManager.getPipelines().isEmpty())); + } + + @AfterAll + public static void shutdownCluster() { + if (cluster != null) { + cluster.shutdown(); + } + } + + /** + * Test that ContainerHealthTaskV2 can query UNDER_REPLICATED containers. + * Steps: + * 1. Create a cluster with 3 datanodes + * 2. Verify the query mechanism for UNDER_REPLICATED state works + * + * Note: Creating actual under-replication scenarios in integration tests + * requires containers to have data written to them before physical replicas + * are created on datanodes. This is complex to set up properly. + * + * In production, under-replication occurs when: + * 1. A datanode goes down or becomes unreachable + * 2. A datanode's disk fails + * 3. Network partitions occur + * 4. Datanodes are decommissioned + * + * The detection logic is tested end-to-end in: + * - TestReconTasks.testContainerHealthTaskV2WithSCMSync() - which proves + * Recon's RM logic works for MISSING containers (similar detection logic) + * + * Full end-to-end test for UNDER_REPLICATED would require: + * 1. Allocate container with RF=3 + * 2. Write actual data to container (creates physical replicas) + * 3. Shut down 1 datanode + * 4. Wait for SCM to mark datanode as dead (stale/dead intervals) + * 5. Wait for ContainerHealthTaskV2 to run (task interval) + * 6. Verify UNDER_REPLICATED state in V2 table with correct replica counts + * 7. Restart datanode and verify container becomes healthy + */ + @Test + public void testContainerHealthTaskV2UnderReplicated() throws Exception { + cluster.waitForPipelineTobeReady(HddsProtos.ReplicationFactor.THREE, 60000); + + // Verify the query mechanism for UNDER_REPLICATED state works + List<UnhealthyContainerRecordV2> underReplicatedContainers = + reconContainerManager.getContainerSchemaManagerV2() + .getUnhealthyContainers( + ContainerSchemaDefinitionV2.UnHealthyContainerStates.UNDER_REPLICATED, + 0L, 0L, 1000); + + // Should be empty in normal operation (all replicas healthy) + assertEquals(0, underReplicatedContainers.size()); Review Comment: is there a test that reproduces a situation with different types of unhealthy containers? Here both tests expects 0 unhealthy containers. -- 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]
