22
22
import org .apache .iotdb .common .rpc .thrift .TConfigNodeLocation ;
23
23
import org .apache .iotdb .common .rpc .thrift .TEndPoint ;
24
24
import org .apache .iotdb .common .rpc .thrift .TSStatus ;
25
+ import org .apache .iotdb .commons .ServerCommandLine ;
25
26
import org .apache .iotdb .commons .client .ClientManagerMetrics ;
26
27
import org .apache .iotdb .commons .concurrent .ThreadModule ;
27
28
import org .apache .iotdb .commons .concurrent .ThreadName ;
28
29
import org .apache .iotdb .commons .concurrent .ThreadPoolMetrics ;
29
30
import org .apache .iotdb .commons .conf .CommonConfig ;
30
31
import org .apache .iotdb .commons .conf .CommonDescriptor ;
31
32
import org .apache .iotdb .commons .conf .IoTDBConstant ;
33
+ import org .apache .iotdb .commons .exception .BadNodeUrlException ;
34
+ import org .apache .iotdb .commons .exception .ConfigurationException ;
32
35
import org .apache .iotdb .commons .exception .IllegalPathException ;
36
+ import org .apache .iotdb .commons .exception .IoTDBException ;
33
37
import org .apache .iotdb .commons .exception .StartupException ;
34
38
import org .apache .iotdb .commons .service .JMXService ;
35
39
import org .apache .iotdb .commons .service .RegisterManager ;
43
47
import org .apache .iotdb .confignode .conf .ConfigNodeConfig ;
44
48
import org .apache .iotdb .confignode .conf .ConfigNodeConstant ;
45
49
import org .apache .iotdb .confignode .conf .ConfigNodeDescriptor ;
50
+ import org .apache .iotdb .confignode .conf .ConfigNodeRemoveCheck ;
51
+ import org .apache .iotdb .confignode .conf .ConfigNodeStartupCheck ;
46
52
import org .apache .iotdb .confignode .conf .SystemPropertiesUtils ;
47
53
import org .apache .iotdb .confignode .manager .ConfigManager ;
48
54
import org .apache .iotdb .confignode .manager .consensus .ConsensusManager ;
74
80
import java .util .List ;
75
81
import java .util .concurrent .TimeUnit ;
76
82
77
- public class ConfigNode implements ConfigNodeMBean {
83
+ public class ConfigNode extends ServerCommandLine implements ConfigNodeMBean {
78
84
79
85
private static final Logger LOGGER = LoggerFactory .getLogger (ConfigNode .class );
80
86
@@ -101,11 +107,13 @@ public class ConfigNode implements ConfigNodeMBean {
101
107
102
108
protected ConfigManager configManager ;
103
109
104
- protected ConfigNode () {
110
+ public ConfigNode () {
111
+ super ("ConfigNode" );
105
112
// We do not init anything here, so that we can re-initialize the instance in IT.
113
+ ConfigNodeHolder .instance = this ;
106
114
}
107
115
108
- public static void main (String [] args ) {
116
+ public static void main (String [] args ) throws Exception {
109
117
LOGGER .info (
110
118
"{} environment variables: {}" ,
111
119
ConfigNodeConstant .GLOBAL_NAME ,
@@ -114,7 +122,60 @@ public static void main(String[] args) {
114
122
"{} default charset is: {}" ,
115
123
ConfigNodeConstant .GLOBAL_NAME ,
116
124
Charset .defaultCharset ().displayName ());
117
- new ConfigNodeCommandLine ().doMain (args );
125
+ ConfigNode configNode = new ConfigNode ();
126
+ int returnCode = configNode .run (args );
127
+ if (returnCode != 0 ) {
128
+ System .exit (returnCode );
129
+ }
130
+ }
131
+
132
+ @ Override
133
+ protected void start () throws IoTDBException {
134
+ try {
135
+ // Do ConfigNode startup checks
136
+ LOGGER .info ("Starting IoTDB {}" , IoTDBConstant .VERSION_WITH_BUILD );
137
+ ConfigNodeStartupCheck checks = new ConfigNodeStartupCheck (IoTDBConstant .CN_ROLE );
138
+ checks .startUpCheck ();
139
+ } catch (StartupException | ConfigurationException | IOException e ) {
140
+ LOGGER .error ("Meet error when doing start checking" , e );
141
+ throw new IoTDBException ("Error starting" , -1 );
142
+ }
143
+ active ();
144
+ }
145
+
146
+ @ Override
147
+ protected void remove (Long nodeId ) throws IoTDBException {
148
+ // If the nodeId was null, this is a shorthand for removing the current dataNode.
149
+ // In this case we need to find our nodeId.
150
+ if (nodeId == null ) {
151
+ nodeId = (long ) CONF .getConfigNodeId ();
152
+ }
153
+
154
+ try {
155
+ LOGGER .info ("Starting to remove ConfigNode with node-id {}" , nodeId );
156
+
157
+ try {
158
+ TConfigNodeLocation removeConfigNodeLocation =
159
+ ConfigNodeRemoveCheck .getInstance ().removeCheck (Long .toString (nodeId ));
160
+ if (removeConfigNodeLocation == null ) {
161
+ LOGGER .error (
162
+ "The ConfigNode to be removed is not in the cluster, or the input format is incorrect." );
163
+ return ;
164
+ }
165
+
166
+ ConfigNodeRemoveCheck .getInstance ().removeConfigNode (removeConfigNodeLocation );
167
+ } catch (BadNodeUrlException e ) {
168
+ LOGGER .warn ("No ConfigNodes need to be removed." , e );
169
+ return ;
170
+ }
171
+
172
+ LOGGER .info (
173
+ "ConfigNode: {} is removed. If the confignode data directory is no longer needed, you can delete it manually." ,
174
+ nodeId );
175
+ } catch (IOException e ) {
176
+ LOGGER .error ("Meet error when doing remove ConfigNode" , e );
177
+ throw new IoTDBException ("Error removing" , -1 );
178
+ }
118
179
}
119
180
120
181
public void active () {
@@ -465,7 +526,7 @@ public void setConfigManager(ConfigManager configManager) {
465
526
466
527
private static class ConfigNodeHolder {
467
528
468
- private static ConfigNode instance = new ConfigNode () ;
529
+ private static ConfigNode instance ;
469
530
470
531
private ConfigNodeHolder () {
471
532
// Empty constructor
0 commit comments