Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,27 @@ public CommonConfig setDataRatisTriggerSnapshotThreshold(long threshold) {
return this;
}

@Override
public CommonConfig setConfigNodeRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
setProperty(
"config_node_ratis_reconfiguration_max_retry_attempts", String.valueOf(maxRetryAttempts));
return this;
}

@Override
public CommonConfig setSchemaRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
setProperty(
"schema_region_ratis_reconfiguration_max_retry_attempts", String.valueOf(maxRetryAttempts));
return this;
}

@Override
public CommonConfig setDataRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
setProperty(
"data_region_ratis_reconfiguration_max_retry_attempts", String.valueOf(maxRetryAttempts));
return this;
}

@Override
public CommonConfig setSeriesSlotNum(int seriesSlotNum) {
setProperty("series_slot_num", String.valueOf(seriesSlotNum));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ public CommonConfig setDataRatisTriggerSnapshotThreshold(long threshold) {
return this;
}

@Override
public CommonConfig setConfigNodeRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
cnConfig.setConfigNodeRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
dnConfig.setConfigNodeRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
return this;
}

@Override
public CommonConfig setSchemaRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
cnConfig.setSchemaRegionRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
dnConfig.setSchemaRegionRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
return this;
}

@Override
public CommonConfig setDataRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
cnConfig.setDataRegionRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
dnConfig.setDataRegionRatisReconfigurationMaxRetryAttempts(maxRetryAttempts);
return this;
}

@Override
public CommonConfig setSeriesSlotNum(int seriesSlotNum) {
cnConfig.setSeriesSlotNum(seriesSlotNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ public CommonConfig setDataRatisTriggerSnapshotThreshold(long threshold) {
return this;
}

@Override
public CommonConfig setConfigNodeRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
return this;
}

@Override
public CommonConfig setSchemaRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
return this;
}

@Override
public CommonConfig setDataRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts) {
return this;
}

@Override
public CommonConfig setSeriesSlotNum(int seriesSlotNum) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ CommonConfig setEnableAutoLeaderBalanceForIoTConsensus(

CommonConfig setDataRatisTriggerSnapshotThreshold(long threshold);

CommonConfig setConfigNodeRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts);

CommonConfig setSchemaRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts);

CommonConfig setDataRegionRatisReconfigurationMaxRetryAttempts(int maxRetryAttempts);

CommonConfig setSeriesSlotNum(int seriesSlotNum);

CommonConfig setDataPartitionAllocationStrategy(String dataPartitionAllocationStrategy);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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;

import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.it.env.EnvFactory;

import org.junit.Before;

public class IoTDBRegionMigrateITFrameworkForRatis
extends IoTDBRegionOperationReliabilityITFramework {

@Override
@Before
public void setUp() throws Exception {
super.setUp();
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setDataRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setConfigNodeRatisReconfigurationMaxRetryAttempts(10)
.setDataRegionRatisReconfigurationMaxRetryAttempts(10)
.setSchemaRegionRatisReconfigurationMaxRetryAttempts(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ public void failTest(
killNode);
}

public void failAndRollbackTest(
final int dataReplicateFactor,
final int schemaReplicationFactor,
final int configNodeNum,
final int dataNodeNum,
KeySetView<String, Boolean> killConfigNodeKeywords,
KeySetView<String, Boolean> killDataNodeKeywords,
KillNode killNode)
throws Exception {
generalTestWithAllOptions(
dataReplicateFactor,
schemaReplicationFactor,
configNodeNum,
dataNodeNum,
killConfigNodeKeywords,
killDataNodeKeywords,
actionOfKillNode,
false,
killNode,
true);
}

public void killClusterTest(
KeySetView<String, Boolean> configNodeKeywords, boolean expectMigrateSuccess)
throws Exception {
Expand Down Expand Up @@ -204,6 +226,31 @@ public void generalTestWithAllOptions(
final boolean expectMigrateSuccess,
KillNode killNode)
throws Exception {
generalTestWithAllOptions(
dataReplicateFactor,
schemaReplicationFactor,
configNodeNum,
dataNodeNum,
configNodeKeywords,
dataNodeKeywords,
actionWhenDetectKeyWords,
expectMigrateSuccess,
killNode,
false);
}

private void generalTestWithAllOptions(
final int dataReplicateFactor,
final int schemaReplicationFactor,
final int configNodeNum,
final int dataNodeNum,
KeySetView<String, Boolean> configNodeKeywords,
KeySetView<String, Boolean> dataNodeKeywords,
Consumer<KillPointContext> actionWhenDetectKeyWords,
final boolean expectMigrateSuccess,
KillNode killNode,
boolean expectRollbackWhenFail)
throws Exception {
// prepare env
EnvFactory.getEnv()
.getConfig()
Expand Down Expand Up @@ -266,26 +313,42 @@ public void generalTestWithAllOptions(
statement.execute(buildRegionMigrateCommand(selectedRegion, originalDataNode, destDataNode));

boolean success = false;
Predicate<TShowRegionResp> migrateRegionPredicate =
tShowRegionResp -> {
Map<Integer, Set<Integer>> newRegionMap =
getRegionMap(tShowRegionResp.getRegionInfoList());
Set<Integer> dataNodes = newRegionMap.get(selectedRegion);
return !dataNodes.contains(originalDataNode) && dataNodes.contains(destDataNode);
};
try {
awaitUntilSuccess(
client,
selectedRegion,
migrateRegionPredicate,
Optional.of(destDataNode),
Optional.of(originalDataNode));
success = true;
} catch (ConditionTimeoutException e) {
if (expectMigrateSuccess) {
LOGGER.error("Region migrate failed", e);
if (expectRollbackWhenFail) {
awaitKillPointsTriggered(configNodeKeywords);
awaitKillPointsTriggered(dataNodeKeywords);
try {
awaitUntilSuccess(
client,
selectedRegion,
rollbackPredicate(selectedRegion, regionMap.get(selectedRegion), destDataNode),
Optional.empty(),
Optional.of(destDataNode));
} catch (ConditionTimeoutException e) {
LOGGER.error("Region migrate did not roll back", e);
Assert.fail();
}
} else {
Predicate<TShowRegionResp> migrateRegionPredicate =
tShowRegionResp -> {
Map<Integer, Set<Integer>> newRegionMap =
getRegionMap(tShowRegionResp.getRegionInfoList());
Set<Integer> dataNodes = newRegionMap.get(selectedRegion);
return !dataNodes.contains(originalDataNode) && dataNodes.contains(destDataNode);
};
try {
awaitUntilSuccess(
client,
selectedRegion,
migrateRegionPredicate,
Optional.of(destDataNode),
Optional.of(originalDataNode));
success = true;
} catch (ConditionTimeoutException e) {
if (expectMigrateSuccess) {
LOGGER.error("Region migrate failed", e);
Assert.fail();
}
}
}
if (!expectMigrateSuccess && success) {
LOGGER.error("Region migrate succeeded unexpectedly");
Expand All @@ -311,6 +374,28 @@ public void generalTestWithAllOptions(
}
}

private static Predicate<TShowRegionResp> rollbackPredicate(
int selectedRegion, Set<Integer> originalDataNodes, int destDataNode) {
return tShowRegionResp -> {
List<TRegionInfo> selectedDataRegionInfos =
tShowRegionResp.getRegionInfoList().stream()
.filter(
regionInfo ->
regionInfo.getConsensusGroupId().getType() == TConsensusGroupType.DataRegion
&& regionInfo.getConsensusGroupId().getId() == selectedRegion)
.collect(Collectors.toList());
Set<Integer> dataNodes =
selectedDataRegionInfos.stream()
.map(TRegionInfo::getDataNodeId)
.collect(Collectors.toSet());
return dataNodes.equals(originalDataNodes)
&& !dataNodes.contains(destDataNode)
&& selectedDataRegionInfos.stream()
.allMatch(
regionInfo -> RegionStatus.Running.getStatus().equals(regionInfo.getStatus()));
};
}

public static Set<Integer> getAllDataNodes(Statement statement) throws Exception {
ResultSet result = statement.executeQuery(SHOW_DATANODES);
Set<Integer> allDataNodeId = new HashSet<>();
Expand Down Expand Up @@ -428,6 +513,13 @@ void checkKillPointsAllTriggered(KeySetView<String, Boolean> killPoints) {
}
}

private static void awaitKillPointsTriggered(KeySetView<String, Boolean> killPoints) {
if (killPoints.isEmpty()) {
return;
}
Awaitility.await().atMost(2, TimeUnit.MINUTES).until(killPoints::isEmpty);
}

private static String buildRegionMigrateCommand(int who, int from, int to) {
String result = String.format(REGION_MIGRATE_COMMAND_FORMAT, who, from, to);
LOGGER.info(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.daily.datanodecrash.ratis;

import org.apache.iotdb.commons.utils.KillPoint.DataNodeKillPoints;
import org.apache.iotdb.commons.utils.KillPoint.KillNode;
import org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionMigrateITFrameworkForRatis;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.DailyIT;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

@Category({DailyIT.class})
@RunWith(IoTDBTestRunner.class)
public class IoTDBRegionMigrateAddingPeerCrashForRatisIT
extends IoTDBRegionMigrateITFrameworkForRatis {

@Test
public void addingPeerCrashShouldFailAndRollback() throws Exception {
failAndRollbackTest(
2,
2,
1,
3,
noKillPoints(),
buildSet(DataNodeKillPoints.DESTINATION_CREATE_LOCAL_PEER),
KillNode.DESTINATION_DATANODE);
}
}
Loading
Loading