Skip to content

Commit 8d00620

Browse files
authored
[IOTDB-4084] remove DataNode with exit code (apache#7031)
[IOTDB-4084] remove DataNode with exit code
1 parent 42b00d6 commit 8d00620

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

node-commons/src/main/java/org/apache/iotdb/commons/ServerCommandLine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public abstract class ServerCommandLine {
3737
* @param args system args
3838
* @return return 0 if exec success
3939
*/
40-
protected abstract int run(String[] args);
40+
protected abstract int run(String[] args) throws Exception;
4141

4242
protected void usage(String message) {
4343
if (message != null) {

server/src/main/java/org/apache/iotdb/db/service/DataNodeServerCommandLine.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.iotdb.commons.ServerCommandLine;
2525
import org.apache.iotdb.commons.exception.BadNodeUrlException;
2626
import org.apache.iotdb.commons.exception.ConfigurationException;
27+
import org.apache.iotdb.commons.exception.IoTDBException;
2728
import org.apache.iotdb.commons.utils.NodeUrlUtils;
2829
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeConfigurationResp;
2930
import org.apache.iotdb.confignode.rpc.thrift.TDataNodeRemoveReq;
@@ -32,6 +33,7 @@
3233
import org.apache.iotdb.db.client.ConfigNodeInfo;
3334
import org.apache.iotdb.db.conf.IoTDBDescriptor;
3435
import org.apache.iotdb.db.conf.IoTDBStopCheck;
36+
import org.apache.iotdb.rpc.TSStatusCode;
3537

3638
import org.apache.thrift.TException;
3739
import org.slf4j.Logger;
@@ -65,7 +67,7 @@ protected String getUsage() {
6567
}
6668

6769
@Override
68-
protected int run(String[] args) {
70+
protected int run(String[] args) throws Exception {
6971
if (args.length < 1) {
7072
usage(null);
7173
return -1;
@@ -104,17 +106,14 @@ protected int run(String[] args) {
104106
*
105107
* @param args IPs for removed datanodes, split with ','
106108
*/
107-
private void doRemoveNode(String[] args) {
108-
try {
109-
removePrepare(args);
110-
removeNodesFromCluster(args);
111-
removeTail();
112-
} catch (Exception e) {
113-
logger.error("remove Data Nodes error", e);
114-
}
109+
private void doRemoveNode(String[] args) throws Exception {
110+
// throw all exception to ServerCommandLine, it used System.exit
111+
removePrepare(args);
112+
removeNodesFromCluster(args);
113+
removeTail();
115114
}
116115

117-
private void removePrepare(String[] args) throws BadNodeUrlException {
116+
private void removePrepare(String[] args) throws BadNodeUrlException, TException {
118117
ConfigNodeInfo.getInstance()
119118
.updateConfigNodeList(IoTDBDescriptor.getInstance().getConfig().getTargetConfigNodeList());
120119
try (ConfigNodeClient configNodeClient = new ConfigNodeClient()) {
@@ -137,18 +136,15 @@ private void removePrepare(String[] args) throws BadNodeUrlException {
137136
.map(TEndPoint::getIp)
138137
.collect(Collectors.toList());
139138
IoTDBStopCheck.getInstance().checkIpInCluster(removedDataNodeIps, onlineDataNodeIps);
140-
} catch (TException e) {
141-
logger.error("remove Data Nodes check failed", e);
142139
}
143140
}
144141

145-
private void removeNodesFromCluster(String[] args) throws BadNodeUrlException {
142+
private void removeNodesFromCluster(String[] args)
143+
throws BadNodeUrlException, TException, IoTDBException {
146144
logger.info("start to remove DataNode from cluster");
147145
List<TDataNodeLocation> dataNodeLocations = buildDataNodeLocations(args[1]);
148146
if (dataNodeLocations.isEmpty()) {
149-
logger.error("data nodes location is empty");
150-
// throw Exception OR return?
151-
return;
147+
throw new BadNodeUrlException("build DataNode location is empty");
152148
}
153149
logger.info(
154150
"there has data nodes location will be removed. size is: {}, detail: {}",
@@ -158,8 +154,10 @@ private void removeNodesFromCluster(String[] args) throws BadNodeUrlException {
158154
try (ConfigNodeClient configNodeClient = new ConfigNodeClient()) {
159155
TDataNodeRemoveResp removeResp = configNodeClient.removeDataNode(removeReq);
160156
logger.info("Remove result {} ", removeResp.toString());
161-
} catch (TException e) {
162-
logger.error("send remove Data Node request failed!", e);
157+
if (removeResp.getStatus().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
158+
throw new IoTDBException(
159+
removeResp.getStatus().toString(), removeResp.getStatus().getCode());
160+
}
163161
}
164162
}
165163

@@ -191,7 +189,10 @@ private List<TDataNodeLocation> buildDataNodeLocations(String endPorts)
191189
if (endPoints.size() != dataNodeLocations.size()) {
192190
logger.error(
193191
"build DataNode locations error, "
194-
+ "because number of input ip NOT EQUALS the number of fetched DataNodeLocations, will return empty locations");
192+
+ "because number of input DataNode({}) NOT EQUALS the number of fetched DataNodeLocations({}), will return empty locations",
193+
endPoints.size(),
194+
dataNodeLocations.size());
195+
dataNodeLocations.clear();
195196
return dataNodeLocations;
196197
}
197198

0 commit comments

Comments
 (0)