Skip to content
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

[remove datanode] Add Remove DataNode SQL #14678

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -256,8 +256,7 @@ public void testIllegalFilePath() {

String errorMsg1 =
TSStatusCode.SQL_PARSE_ERROR.getStatusCode()
+ ": Error occurred while parsing SQL to physical plan: "
+ "line 1:7 mismatched input 'path' expecting STRING_LITERAL";
+ ": Error occurred while parsing SQL to physical plan: line 1:7 no viable alternative at input 'REMOVE path'";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("REMOVE path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ keyWords
| DATA_REGION_GROUP_NUM
| DATABASE
| DATABASES
| DATANODE
| DATANODEID
| DATANODES
| DATASET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ddlStatement
| createContinuousQuery | dropContinuousQuery | showContinuousQueries
// Cluster
| showVariables | showCluster | showRegions | showDataNodes | showConfigNodes | showClusterId
| getRegionId | getTimeSlotList | countTimeSlotList | getSeriesSlotList | migrateRegion | verifyConnection
| getRegionId | getTimeSlotList | countTimeSlotList | getSeriesSlotList | migrateRegion | verifyConnection | removeDataNode
// AINode
| showAINodes | createModel | dropModel | showModels | callInference
// Quota
Expand Down Expand Up @@ -536,6 +536,11 @@ verifyConnection
: VERIFY CONNECTION (DETAILS)?
;

// ---- Remove DataNode
removeDataNode
: REMOVE DATANODE dataNodeId=INTEGER_LITERAL (COMMA dataNodeId=INTEGER_LITERAL)*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove datanodes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both "datanode" and "datanodes" make sense in this context, so I’d prefer to leave it as is for now.

;

// Pipe Task =========================================================================================
createPipe
: CREATE PIPE (IF NOT EXISTS)? pipeName=identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ DATABASES
: D A T A B A S E S
;

DATANODE
: D A T A N O D E
;

DATANODEADDRESS
: D A T A N O D E A D D R E S S
;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


DATANODEID
: D A T A N O D E I D
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetSeriesSlotListTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.GetTimeSlotListTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.MigrateRegionTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.RemoveDataNodeTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.SetTTLTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowAINodesTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.metadata.ShowClusterDetailsTask;
Expand Down Expand Up @@ -115,6 +116,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetSeriesSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetTimeSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterIdStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterStatement;
Expand Down Expand Up @@ -628,6 +630,12 @@ public IConfigTask visitMigrateRegion(
return new MigrateRegionTask(migrateRegionStatement);
}

@Override
public IConfigTask visitRemoveDataNode(
RemoveDataNodeStatement removeDataNodeStatement, MPPQueryContext context) {
return new RemoveDataNodeTask(removeDataNodeStatement);
}

@Override
public IConfigTask visitCreateContinuousQuery(
CreateContinuousQueryStatement createContinuousQueryStatement, MPPQueryContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.apache.iotdb.common.rpc.thrift.FunctionType;
import org.apache.iotdb.common.rpc.thrift.Model;
import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
import org.apache.iotdb.common.rpc.thrift.TFlushReq;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.common.rpc.thrift.TSetConfigurationReq;
Expand Down Expand Up @@ -80,6 +82,8 @@
import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
import org.apache.iotdb.confignode.rpc.thrift.TCreateTopicReq;
import org.apache.iotdb.confignode.rpc.thrift.TCreateTriggerReq;
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRemoveReq;
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRemoveResp;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
import org.apache.iotdb.confignode.rpc.thrift.TDeactivateSchemaTemplateReq;
import org.apache.iotdb.confignode.rpc.thrift.TDeleteDatabasesReq;
Expand Down Expand Up @@ -218,6 +222,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetSeriesSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetTimeSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement;
Expand Down Expand Up @@ -308,6 +313,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -2773,6 +2779,62 @@ public SettableFuture<ConfigTaskResult> migrateRegion(
return future;
}

@Override
public SettableFuture<ConfigTaskResult> removeDataNode(
final RemoveDataNodeStatement removeDataNodeStatement) {
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
try (ConfigNodeClient configNodeClient =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
Set<Integer> nodeIds = removeDataNodeStatement.getNodeIds();

Set<Integer> validNodeIds =
configNodeClient.getDataNodeConfiguration(-1).getDataNodeConfigurationMap().keySet();

Set<Integer> invalidNodeIds = new HashSet<>(nodeIds);
invalidNodeIds.removeAll(validNodeIds);

if (!invalidNodeIds.isEmpty()) {
LOGGER.info("Cannot remove invalid nodeIds:{}", invalidNodeIds);
nodeIds.removeAll(invalidNodeIds);
}

LOGGER.info("Starting to remove DataNode with nodeIds: {}", nodeIds);

final Set<Integer> finalNodeIds = nodeIds;
List<TDataNodeLocation> removeDataNodeLocations =
configNodeClient
.getDataNodeConfiguration(-1)
.getDataNodeConfigurationMap()
.values()
.stream()
.map(TDataNodeConfiguration::getLocation)
.filter(location -> finalNodeIds.contains(location.getDataNodeId()))
.collect(Collectors.toList());
LOGGER.info(
"Start to remove datanode, removed DataNodes endpoint: {}", removeDataNodeLocations);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not recommended to print TDataNodeLocation directly, because it's too long.

Please consider RegionMaintainHandler.simplifiedLocation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

TDataNodeRemoveReq removeReq = new TDataNodeRemoveReq(removeDataNodeLocations);
TDataNodeRemoveResp removeResp = configNodeClient.removeDataNode(removeReq);
LOGGER.info("Submit Remove DataNodes result {} ", removeResp);
if (removeResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
future.setException(
new IoTDBException(
removeResp.getStatus().toString(), removeResp.getStatus().getCode()));
return future;
} else {
LOGGER.info(
"Submit remove-datanode request successfully, but the process may fail. "
+ "more details are shown in the logs of confignode-leader and removed-datanode, "
+ "and after the process of removing datanode ends successfully, "
+ "you are supposed to delete directory and data of the removed-datanode manually");
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
}
} catch (Exception e) {
future.setException(e);
}

return future;
}

@Override
public SettableFuture<ConfigTaskResult> createContinuousQuery(
final CreateContinuousQueryStatement createContinuousQueryStatement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetSeriesSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetTimeSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowClusterStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowDatabaseStatement;
Expand Down Expand Up @@ -249,6 +250,8 @@ SettableFuture<ConfigTaskResult> countTimeSlotList(

SettableFuture<ConfigTaskResult> migrateRegion(MigrateRegionStatement migrateRegionStatement);

SettableFuture<ConfigTaskResult> removeDataNode(RemoveDataNodeStatement removeDataNodeStatement);

SettableFuture<ConfigTaskResult> createContinuousQuery(
CreateContinuousQueryStatement createContinuousQueryStatement, MPPQueryContext context);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.db.queryengine.plan.execution.config.metadata;

import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult;
import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask;
import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;

import com.google.common.util.concurrent.ListenableFuture;

public class RemoveDataNodeTask implements IConfigTask {

protected final RemoveDataNodeStatement statement;

public RemoveDataNodeTask(RemoveDataNodeStatement removeDataNodeStatement) {
this.statement = removeDataNodeStatement;
}

@Override
public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor configTaskExecutor) {
// If the action is executed successfully, return the Future.
// If your operation is async, you can return the corresponding future directly.
return configTaskExecutor.removeDataNode(statement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetSeriesSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetTimeSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowChildNodesStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowChildPathsStatement;
Expand Down Expand Up @@ -229,6 +230,7 @@

import com.google.common.collect.ImmutableSet;
import com.google.common.io.BaseEncoding;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.tsfile.common.conf.TSFileDescriptor;
Expand Down Expand Up @@ -4184,6 +4186,16 @@ public Statement visitMigrateRegion(IoTDBSqlParser.MigrateRegionContext ctx) {
Integer.parseInt(ctx.toId.getText()));
}

@Override
public Statement visitRemoveDataNode(IoTDBSqlParser.RemoveDataNodeContext ctx) {
List<Integer> dataNodeIDs =
ctx.INTEGER_LITERAL().stream()
.map(ParseTree::getText)
.map(Integer::parseInt)
.collect(Collectors.toList());
return new RemoveDataNodeStatement(dataNodeIDs);
}

@Override
public Statement visitVerifyConnection(IoTDBSqlParser.VerifyConnectionContext ctx) {
return new TestConnectionStatement(ctx.DETAILS() != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetSeriesSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.GetTimeSlotListStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.MigrateRegionStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.SetTTLStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowChildNodesStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowChildPathsStatement;
Expand Down Expand Up @@ -577,6 +578,10 @@ public R visitMigrateRegion(MigrateRegionStatement migrateRegionStatement, C con
return visitStatement(migrateRegionStatement, context);
}

public R visitRemoveDataNode(RemoveDataNodeStatement removeDataNodeStatement, C context) {
return visitStatement(removeDataNodeStatement, context);
}

public R visitDeactivateTemplate(
DeactivateTemplateStatement deactivateTemplateStatement, C context) {
return visitStatement(deactivateTemplateStatement, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.db.queryengine.plan.statement.metadata;

import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
import org.apache.iotdb.db.queryengine.plan.statement.IConfigStatement;
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
import org.apache.iotdb.db.queryengine.plan.statement.StatementVisitor;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RemoveDataNodeStatement extends Statement implements IConfigStatement {

final Set<Integer> nodeIds;

public RemoveDataNodeStatement(List<Integer> dataNodeIDs) {
super();
this.nodeIds = new HashSet<>(dataNodeIDs);
}

public Set<Integer> getNodeIds() {
return nodeIds;
}

@Override
public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
return visitor.visitRemoveDataNode(this, context);
}

@Override
public QueryType getQueryType() {
return QueryType.WRITE;
}

@Override
public List<PartialPath> getPaths() {
return Collections.emptyList();
}
}
Loading