liyuheng55555 commented on code in PR #14634: URL: https://github.com/apache/iotdb/pull/14634#discussion_r1914614670
########## integration-test/src/test/java/org/apache/iotdb/confignode/it/regionmigration/pass/commit/IoTDB_RegionReconstruct_IoTV1_IT.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.iotdb.confignode.it.regionmigration.pass.commit; + +import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; +import org.apache.iotdb.commons.cluster.NodeStatus; +import org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework; +import org.apache.iotdb.consensus.ConsensusFactory; +import org.apache.iotdb.isession.SessionDataSet; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.rpc.StatementExecutionException; +import org.apache.iotdb.session.Session; + +import org.apache.commons.io.FileUtils; +import org.apache.tsfile.read.common.RowRecord; +import org.awaitility.Awaitility; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.sql.Connection; +import java.sql.Statement; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static org.apache.iotdb.util.MagicUtils.makeItCloseQuietly; + +@Category({ClusterIT.class}) +@RunWith(IoTDBTestRunner.class) +public class IoTDB_RegionReconstruct_IoTV1_IT extends IoTDBRegionOperationReliabilityITFramework { + private static final String RECONSTRUCT_FORMAT = "reconstruct region %d on %d"; + private static Logger LOGGER = LoggerFactory.getLogger(IoTDB_RegionReconstruct_IoTV1_IT.class); + + @Test + public void normal1C3DTest() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS) + .setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) + .setDataReplicationFactor(2) + .setSchemaReplicationFactor(3); + + EnvFactory.getEnv().initClusterEnvironment(1, 3); + + try (Connection connection = makeItCloseQuietly(EnvFactory.getEnv().getConnection()); + Statement statement = makeItCloseQuietly(connection.createStatement()); + SyncConfigNodeIServiceClient client = + (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { + // prepare data + statement.execute(INSERTION1); + statement.execute(FLUSH_COMMAND); + + // collect necessary information + Map<Integer, Set<Integer>> dataRegionMap = getDataRegionMap(statement); + Set<Integer> allDataNodeId = getAllDataNodes(statement); + + // select datanode + final int selectedRegion = 1; + Assert.assertTrue(dataRegionMap.containsKey(selectedRegion)); + Assert.assertEquals(2, dataRegionMap.get(selectedRegion).size()); + Iterator<Integer> iterator = dataRegionMap.get(selectedRegion).iterator(); + final int dataNodeToBeClosed = iterator.next(); + final int dataNodeToBeReconstructed = iterator.next(); + final int dataNodeAlwaysGood = + allDataNodeId.stream() + .filter(x -> x != dataNodeToBeReconstructed && x != dataNodeToBeClosed) + .findAny() + .get(); + final DataNodeWrapper dataNodeWrapper = + EnvFactory.getEnv().dataNodeIdToWrapper(dataNodeAlwaysGood).get(); + Session session = + new Session.Builder() + .host(dataNodeWrapper.getIp()) + .port(dataNodeWrapper.getPort()) + .build(); + session.open(); + + // delete one DataNode's data dir, stop another DataNode + FileUtils.deleteDirectory( + new File( + EnvFactory.getEnv() + .dataNodeIdToWrapper(dataNodeToBeReconstructed) + .get() + .getDataPath())); + EnvFactory.getEnv().dataNodeIdToWrapper(dataNodeToBeClosed).get().stopForcibly(); + + // now, the query should throw exception + Assert.assertThrows( + StatementExecutionException.class, + () -> session.executeQueryStatement("select * from root.**")); + + // start DataNode, reconstruct the delete one + EnvFactory.getEnv().dataNodeIdToWrapper(dataNodeToBeClosed).get().start(); + EnvFactory.getAbstractEnv().checkNodeInStatus(dataNodeToBeClosed, NodeStatus.Running); + session.executeNonQueryStatement( + String.format(RECONSTRUCT_FORMAT, selectedRegion, dataNodeToBeReconstructed)); + Thread.sleep(5000); Review Comment: actually we need it, because in some cases the result of `show regions` won't change so quickly -- 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]
