-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
25b1d19
57e63f1
34de1a2
7c3032d
0832fe6
bf1f49a
a1501a4
f821b12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
|
||
DATANODEID | ||
: D A T A N O D E I D | ||
; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove datanodes?
There was a problem hiding this comment.
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.