2424import org .apache .iotdb .commons .ServerCommandLine ;
2525import org .apache .iotdb .commons .exception .BadNodeUrlException ;
2626import org .apache .iotdb .commons .exception .ConfigurationException ;
27+ import org .apache .iotdb .commons .exception .IoTDBException ;
2728import org .apache .iotdb .commons .utils .NodeUrlUtils ;
2829import org .apache .iotdb .confignode .rpc .thrift .TDataNodeConfigurationResp ;
2930import org .apache .iotdb .confignode .rpc .thrift .TDataNodeRemoveReq ;
3233import org .apache .iotdb .db .client .ConfigNodeInfo ;
3334import org .apache .iotdb .db .conf .IoTDBDescriptor ;
3435import org .apache .iotdb .db .conf .IoTDBStopCheck ;
36+ import org .apache .iotdb .rpc .TSStatusCode ;
3537
3638import org .apache .thrift .TException ;
3739import 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