Skip to content
Closed
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 @@ -19,13 +19,16 @@

package org.apache.iotdb.confignode.it.regionmigration.pass.commit;

import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
import org.apache.iotdb.confignode.it.regionmigration.IoTDBRegionOperationReliabilityITFramework;
import org.apache.iotdb.confignode.rpc.thrift.TExtendRegionReq;
import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.rpc.TSStatusCode;

import org.awaitility.Awaitility;
import org.junit.Assert;
Expand All @@ -38,6 +41,7 @@
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -120,6 +124,50 @@ public void singleRegionTest() throws Exception {
}
}

@Test
public void rejectInvalidTargetDataNodeTest() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS)
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setDataReplicationFactor(1)
.setSchemaReplicationFactor(1);

EnvFactory.getEnv().initClusterEnvironment(1, 3);

try (final Connection connection = makeItCloseQuietly(EnvFactory.getEnv().getConnection());
final Statement statement = makeItCloseQuietly(connection.createStatement());
SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
statement.execute(INSERTION1);
statement.execute(FLUSH_COMMAND);

Map<Integer, Set<Integer>> regionMap = getAllRegionMap(statement);
Set<Integer> allDataNodeIds = getAllDataNodes(statement);
Assert.assertFalse(regionMap.isEmpty());

int selectedRegion = regionMap.keySet().iterator().next();
int unknownDataNodeId = Collections.max(allDataNodeIds) + 1000;
int configNodeId = client.showCluster().getConfigNodeList().get(0).getConfigNodeId();
Assert.assertFalse(allDataNodeIds.contains(configNodeId));

assertExtendRegionRejected(client, selectedRegion, unknownDataNodeId);
assertExtendRegionRejected(client, selectedRegion, configNodeId);
Assert.assertEquals(regionMap, getAllRegionMap(statement));
}
}

private void assertExtendRegionRejected(
SyncConfigNodeIServiceClient client, int regionId, int dataNodeId) throws Exception {
TSStatus status =
client.extendRegion(new TExtendRegionReq(Collections.singletonList(regionId), dataNodeId));
Assert.assertEquals(TSStatusCode.EXTEND_REGION_ERROR.getStatusCode(), status.getCode());
Assert.assertEquals(
String.format("Target DataNode %s does not exist in the cluster", dataNodeId),
status.getMessage());
}

private void regionGroupExpand(
Statement statement,
SyncConfigNodeIServiceClient client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@

package org.apache.iotdb.confignode.it.regionmigration.pass.commit;

import org.apache.iotdb.common.rpc.thrift.TSStatus;
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.confignode.rpc.thrift.TReconstructRegionReq;
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.rpc.TSStatusCode;
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;
Expand All @@ -43,6 +47,7 @@
import java.io.File;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -145,4 +150,49 @@ public void normal1C3DTest() throws Exception {
Assert.assertEquals("1.0", rowRecord.getFields().get(1).getStringValue());
}
}

@Test
public void rejectInvalidTargetDataNodeTest() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS)
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setDataReplicationFactor(1)
.setSchemaReplicationFactor(1);

EnvFactory.getEnv().initClusterEnvironment(1, 3);

try (Connection connection = makeItCloseQuietly(EnvFactory.getEnv().getConnection());
Statement statement = makeItCloseQuietly(connection.createStatement());
SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
statement.execute(INSERTION1);
statement.execute(FLUSH_COMMAND);

Map<Integer, Set<Integer>> regionMap = getAllRegionMap(statement);
Set<Integer> allDataNodeIds = getAllDataNodes(statement);
Assert.assertFalse(regionMap.isEmpty());

int selectedRegion = regionMap.keySet().iterator().next();
int unknownDataNodeId = Collections.max(allDataNodeIds) + 1000;
int configNodeId = client.showCluster().getConfigNodeList().get(0).getConfigNodeId();
Assert.assertFalse(allDataNodeIds.contains(configNodeId));

assertReconstructRegionRejected(client, selectedRegion, unknownDataNodeId);
assertReconstructRegionRejected(client, selectedRegion, configNodeId);
Assert.assertEquals(regionMap, getAllRegionMap(statement));
}
}

private void assertReconstructRegionRejected(
SyncConfigNodeIServiceClient client, int regionId, int dataNodeId) throws Exception {
TSStatus status =
client.reconstructRegion(
new TReconstructRegionReq(Collections.singletonList(regionId), dataNodeId));
Assert.assertEquals(TSStatusCode.RECONSTRUCT_REGION_ERROR.getStatusCode(), status.getCode());
Assert.assertEquals(
String.format("Target DataNode %s does not exist in the cluster", dataNodeId),
status.getMessage());
}
}
25 changes: 25 additions & 0 deletions iotdb-core/confignode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<confignode.it.skip>${confignode.test.skip}</confignode.it.skip>
<confignode.test.skip>false</confignode.test.skip>
<confignode.ut.skip>${confignode.test.skip}</confignode.ut.skip>
<i18n.locale>en</i18n.locale>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -238,6 +239,24 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-i18n-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/main/i18n/${i18n.locale}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -267,5 +286,11 @@
<confignode.ut.skip>true</confignode.ut.skip>
</properties>
</profile>
<profile>
<id>with-zh-locale</id>
<properties>
<i18n.locale>zh</i18n.locale>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.i18n;

public final class ManagerMessages {

public static final String
MESSAGE_TARGET_DATANODE_ARG_DOES_NOT_EXIST_IN_THE_CLUSTER_679D59AF =
"Target DataNode %s does not exist in the cluster";

private ManagerMessages() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.i18n;

public final class ManagerMessages {

public static final String
MESSAGE_TARGET_DATANODE_ARG_DOES_NOT_EXIST_IN_THE_CLUSTER_679D59AF =
"目标 DataNode %s 在集群中不存在";

private ManagerMessages() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.iotdb.confignode.consensus.request.write.datanode.RemoveDataNodePlan;
import org.apache.iotdb.confignode.consensus.request.write.procedure.UpdateProcedurePlan;
import org.apache.iotdb.confignode.consensus.request.write.region.CreateRegionGroupsPlan;
import org.apache.iotdb.confignode.i18n.ManagerMessages;
import org.apache.iotdb.confignode.manager.partition.PartitionManager;
import org.apache.iotdb.confignode.persistence.ProcedureInfo;
import org.apache.iotdb.confignode.procedure.PartitionTableAutoCleaner;
Expand Down Expand Up @@ -1011,9 +1012,13 @@ public TSStatus migrateRegion(TMigrateRegionReq migrateRegionReq) {
}

public TSStatus reconstructRegion(TReconstructRegionReq req) {
RegionMaintainHandler handler = env.getRegionMaintainHandler();
final TDataNodeLocation targetDataNode =
configManager.getNodeManager().getRegisteredDataNode(req.getDataNodeId()).getLocation();
getRegisteredDataNodeLocationOrNull(req.getDataNodeId());
if (targetDataNode == null) {
return targetDataNodeNotExistStatus(
req.getDataNodeId(), TSStatusCode.RECONSTRUCT_REGION_ERROR);
}
RegionMaintainHandler handler = env.getRegionMaintainHandler();
try (AutoCloseableLock ignoredLock =
AutoCloseableLock.acquire(env.getSubmitRegionMigrateLock())) {
List<ReconstructRegionProcedure> procedures = new ArrayList<>();
Expand Down Expand Up @@ -1051,8 +1056,16 @@ public TSStatus reconstructRegion(TReconstructRegionReq req) {
}

public TSStatus extendRegions(TExtendRegionReq req) {
final TDataNodeLocation targetDataNode =
getRegisteredDataNodeLocationOrNull(req.getDataNodeId());
if (targetDataNode == null) {
return targetDataNodeNotExistStatus(req.getDataNodeId(), TSStatusCode.EXTEND_REGION_ERROR);
}
return processExtendOrRemoveRegions(
req.getRegionId(), req, this::extendOneRegion, TSStatusCode.EXTEND_REGION_ERROR);
req.getRegionId(),
req,
(regionId, request) -> extendOneRegion(regionId, request, targetDataNode),
TSStatusCode.EXTEND_REGION_ERROR);
}

public TSStatus removeRegions(TRemoveRegionReq req) {
Expand Down Expand Up @@ -1098,7 +1111,8 @@ private <R> TSStatus processExtendOrRemoveRegions(
return resp;
}

private TSStatus extendOneRegion(int theRegionId, TExtendRegionReq req) {
private TSStatus extendOneRegion(
int theRegionId, TExtendRegionReq req, TDataNodeLocation targetDataNode) {
try (AutoCloseableLock ignoredLock =
AutoCloseableLock.acquire(env.getSubmitRegionMigrateLock())) {
TConsensusGroupId regionId;
Expand All @@ -1112,9 +1126,6 @@ private TSStatus extendOneRegion(int theRegionId, TExtendRegionReq req) {
.setMessage("get region group id fail");
}

// find target dn
final TDataNodeLocation targetDataNode =
configManager.getNodeManager().getRegisteredDataNode(req.getDataNodeId()).getLocation();
// select coordinator for adding peer
RegionMaintainHandler handler = env.getRegionMaintainHandler();
final TDataNodeLocation coordinator =
Expand All @@ -1141,6 +1152,20 @@ private TSStatus extendOneRegion(int theRegionId, TExtendRegionReq req) {
}
}

private TDataNodeLocation getRegisteredDataNodeLocationOrNull(int dataNodeId) {
TDataNodeConfiguration dataNodeConfiguration =
configManager.getNodeManager().getRegisteredDataNode(dataNodeId);
return dataNodeConfiguration == null ? null : dataNodeConfiguration.getLocation();
}

private TSStatus targetDataNodeNotExistStatus(int dataNodeId, TSStatusCode statusCode) {
return new TSStatus(statusCode.getStatusCode())
.setMessage(
String.format(
ManagerMessages.MESSAGE_TARGET_DATANODE_ARG_DOES_NOT_EXIST_IN_THE_CLUSTER_679D59AF,
dataNodeId));
}

private TSStatus removeOneRegion(int theRegionId, TRemoveRegionReq req) {
try (AutoCloseableLock ignoredLock =
AutoCloseableLock.acquire(env.getSubmitRegionMigrateLock())) {
Expand Down
Loading
Loading