You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by wa...@apache.org on 2022/08/17 09:18:56 UTC
[iotdb] branch master updated: [IOTDB-4084] remove DataNode with exit code (#7031)
This is an automated email from the ASF dual-hosted git repository.
wangchao316 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 8d0062050a [IOTDB-4084] remove DataNode with exit code (#7031)
8d0062050a is described below
commit 8d0062050a9e9efd80fb503500f3665b270f988e
Author: QiangShaowei <ba...@163.com>
AuthorDate: Wed Aug 17 17:18:50 2022 +0800
[IOTDB-4084] remove DataNode with exit code (#7031)
[IOTDB-4084] remove DataNode with exit code
---
.../apache/iotdb/commons/ServerCommandLine.java | 2 +-
.../db/service/DataNodeServerCommandLine.java | 39 +++++++++++-----------
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/ServerCommandLine.java b/node-commons/src/main/java/org/apache/iotdb/commons/ServerCommandLine.java
index 32286a548c..9bd4a4d309 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/ServerCommandLine.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/ServerCommandLine.java
@@ -37,7 +37,7 @@ public abstract class ServerCommandLine {
* @param args system args
* @return return 0 if exec success
*/
- protected abstract int run(String[] args);
+ protected abstract int run(String[] args) throws Exception;
protected void usage(String message) {
if (message != null) {
diff --git a/server/src/main/java/org/apache/iotdb/db/service/DataNodeServerCommandLine.java b/server/src/main/java/org/apache/iotdb/db/service/DataNodeServerCommandLine.java
index debe51b5ee..038f0e2612 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/DataNodeServerCommandLine.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/DataNodeServerCommandLine.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.common.rpc.thrift.TEndPoint;
import org.apache.iotdb.commons.ServerCommandLine;
import org.apache.iotdb.commons.exception.BadNodeUrlException;
import org.apache.iotdb.commons.exception.ConfigurationException;
+import org.apache.iotdb.commons.exception.IoTDBException;
import org.apache.iotdb.commons.utils.NodeUrlUtils;
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeConfigurationResp;
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRemoveReq;
@@ -32,6 +33,7 @@ import org.apache.iotdb.db.client.ConfigNodeClient;
import org.apache.iotdb.db.client.ConfigNodeInfo;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.conf.IoTDBStopCheck;
+import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.thrift.TException;
import org.slf4j.Logger;
@@ -65,7 +67,7 @@ public class DataNodeServerCommandLine extends ServerCommandLine {
}
@Override
- protected int run(String[] args) {
+ protected int run(String[] args) throws Exception {
if (args.length < 1) {
usage(null);
return -1;
@@ -104,17 +106,14 @@ public class DataNodeServerCommandLine extends ServerCommandLine {
*
* @param args IPs for removed datanodes, split with ','
*/
- private void doRemoveNode(String[] args) {
- try {
- removePrepare(args);
- removeNodesFromCluster(args);
- removeTail();
- } catch (Exception e) {
- logger.error("remove Data Nodes error", e);
- }
+ private void doRemoveNode(String[] args) throws Exception {
+ // throw all exception to ServerCommandLine, it used System.exit
+ removePrepare(args);
+ removeNodesFromCluster(args);
+ removeTail();
}
- private void removePrepare(String[] args) throws BadNodeUrlException {
+ private void removePrepare(String[] args) throws BadNodeUrlException, TException {
ConfigNodeInfo.getInstance()
.updateConfigNodeList(IoTDBDescriptor.getInstance().getConfig().getTargetConfigNodeList());
try (ConfigNodeClient configNodeClient = new ConfigNodeClient()) {
@@ -137,18 +136,15 @@ public class DataNodeServerCommandLine extends ServerCommandLine {
.map(TEndPoint::getIp)
.collect(Collectors.toList());
IoTDBStopCheck.getInstance().checkIpInCluster(removedDataNodeIps, onlineDataNodeIps);
- } catch (TException e) {
- logger.error("remove Data Nodes check failed", e);
}
}
- private void removeNodesFromCluster(String[] args) throws BadNodeUrlException {
+ private void removeNodesFromCluster(String[] args)
+ throws BadNodeUrlException, TException, IoTDBException {
logger.info("start to remove DataNode from cluster");
List<TDataNodeLocation> dataNodeLocations = buildDataNodeLocations(args[1]);
if (dataNodeLocations.isEmpty()) {
- logger.error("data nodes location is empty");
- // throw Exception OR return?
- return;
+ throw new BadNodeUrlException("build DataNode location is empty");
}
logger.info(
"there has data nodes location will be removed. size is: {}, detail: {}",
@@ -158,8 +154,10 @@ public class DataNodeServerCommandLine extends ServerCommandLine {
try (ConfigNodeClient configNodeClient = new ConfigNodeClient()) {
TDataNodeRemoveResp removeResp = configNodeClient.removeDataNode(removeReq);
logger.info("Remove result {} ", removeResp.toString());
- } catch (TException e) {
- logger.error("send remove Data Node request failed!", e);
+ if (removeResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ throw new IoTDBException(
+ removeResp.getStatus().toString(), removeResp.getStatus().getCode());
+ }
}
}
@@ -191,7 +189,10 @@ public class DataNodeServerCommandLine extends ServerCommandLine {
if (endPoints.size() != dataNodeLocations.size()) {
logger.error(
"build DataNode locations error, "
- + "because number of input ip NOT EQUALS the number of fetched DataNodeLocations, will return empty locations");
+ + "because number of input DataNode({}) NOT EQUALS the number of fetched DataNodeLocations({}), will return empty locations",
+ endPoints.size(),
+ dataNodeLocations.size());
+ dataNodeLocations.clear();
return dataNodeLocations;
}