[IOTDB-6193] Reject Node startup when loading configuration file failed (#11331)
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java index b52f7f7..f0ec2a9 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java
@@ -106,11 +106,14 @@ commonProperties.load(inputStream); } catch (FileNotFoundException e) { - LOGGER.warn("Fail to find config file {}", url, e); + LOGGER.error("Fail to find config file {}, reject ConfigNode startup.", url, e); + System.exit(-1); } catch (IOException e) { - LOGGER.warn("Cannot load config file, use default configuration", e); + LOGGER.error("Cannot load config file, reject ConfigNode startup.", e); + System.exit(-1); } catch (Exception e) { - LOGGER.warn("Incorrect format in config file, use default configuration", e); + LOGGER.error("Incorrect format in config file, reject ConfigNode startup.", e); + System.exit(-1); } } else { LOGGER.warn( @@ -127,7 +130,8 @@ commonProperties.putAll(properties); loadProperties(commonProperties); } catch (IOException | BadNodeUrlException e) { - LOGGER.warn("Couldn't load ConfigNode conf file, use default config", e); + LOGGER.error("Couldn't load ConfigNode conf file, reject ConfigNode startup.", e); + System.exit(-1); } finally { conf.updatePath(); commonDescriptor @@ -268,8 +272,7 @@ "region_group_allocate_policy", conf.getRegionGroupAllocatePolicy().name()) .trim())); } catch (IllegalArgumentException e) { - LOGGER.warn( - "The configured region allocate strategy does not exist, use the default: GREEDY!"); + throw new IOException(e); } conf.setCnRpcAdvancedCompressionEnable(
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/SystemPropertiesUtils.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/SystemPropertiesUtils.java index 0f7b9e4..9faebf5 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/SystemPropertiesUtils.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/SystemPropertiesUtils.java
@@ -57,6 +57,7 @@ private static final String CN_INTERNAL_ADDRESS = "cn_internal_address"; private static final String CN_INTERNAL_PORT = "cn_internal_port"; private static final String CN_CONSENSUS_PORT = "cn_consensus_port"; + private static final String TIMESTAMP_PRECISION = "timestamp_precision"; private static final String CN_CONSENSUS_PROTOCOL = "config_node_consensus_protocol_class"; private static final String DATA_CONSENSUS_PROTOCOL = "data_region_consensus_protocol_class"; private static final String SCHEMA_CONSENSUS_PROTOCOL = "schema_region_consensus_protocol_class"; @@ -127,6 +128,17 @@ } } + if (systemProperties.getProperty(TIMESTAMP_PRECISION, null) == null) { + needReWrite = true; + } else { + String timestampPrecision = systemProperties.getProperty(TIMESTAMP_PRECISION); + if (!timestampPrecision.equals(COMMON_CONFIG.getTimestampPrecision())) { + LOGGER.warn( + format, TIMESTAMP_PRECISION, COMMON_CONFIG.getTimestampPrecision(), timestampPrecision); + COMMON_CONFIG.setTimestampPrecision(timestampPrecision); + } + } + // Consensus protocol configuration String configNodeConsensusProtocolClass = systemProperties.getProperty(CN_CONSENSUS_PROTOCOL, null); @@ -280,7 +292,7 @@ SERIES_PARTITION_EXECUTOR_CLASS, conf.getSeriesPartitionExecutorClass()); systemProperties.setProperty( TIME_PARTITION_INTERVAL, String.valueOf(COMMON_CONFIG.getTimePartitionInterval())); - systemProperties.setProperty("timestamp_precision", COMMON_CONFIG.getTimestampPrecision()); + systemProperties.setProperty(TIMESTAMP_PRECISION, COMMON_CONFIG.getTimestampPrecision()); // DataNode Functions systemProperties.setProperty("schema_engine_mode", COMMON_CONFIG.getSchemaEngineMode());
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java index 4e082a7..483c874 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -89,7 +89,15 @@ for (IPropertiesLoader loader : propertiesLoaderServiceLoader) { logger.info("Will reload properties from {} ", loader.getClass().getName()); Properties properties = loader.loadProperties(); - loadProperties(properties); + try { + loadProperties(properties); + } catch (Exception e) { + logger.error( + "Failed to reload properties from {}, reject DataNode startup.", + loader.getClass().getName(), + e); + System.exit(-1); + } conf.setCustomizedProperties(loader.getCustomizedProperties()); TSFileDescriptor.getInstance().overwriteConfigByCustomSettings(properties); TSFileDescriptor.getInstance() @@ -162,11 +170,14 @@ logger.info("Start to read config file {}", url); commonProperties.load(inputStream); } catch (FileNotFoundException e) { - logger.warn("Fail to find config file {}", url, e); + logger.error("Fail to find config file {}, reject DataNode startup.", url, e); + System.exit(-1); } catch (IOException e) { - logger.warn("Cannot load config file, use default configuration", e); + logger.error("Cannot load config file, reject DataNode startup.", e); + System.exit(-1); } catch (Exception e) { - logger.warn("Incorrect format in config file, use default configuration", e); + logger.error("Incorrect format in config file, reject DataNode startup.", e); + System.exit(-1); } } else { logger.warn( @@ -182,11 +193,14 @@ commonProperties.putAll(properties); loadProperties(commonProperties); } catch (FileNotFoundException e) { - logger.warn("Fail to find config file {}", url, e); + logger.error("Fail to find config file {}, reject DataNode startup.", url, e); + System.exit(-1); } catch (IOException e) { - logger.warn("Cannot load config file, use default configuration", e); + logger.error("Cannot load config file, reject DataNode startup.", e); + System.exit(-1); } catch (Exception e) { - logger.warn("Incorrect format in config file, use default configuration", e); + logger.error("Incorrect format in config file, reject DataNode startup.", e); + System.exit(-1); } finally { // update all data seriesPath conf.updatePath(); @@ -204,7 +218,7 @@ } } - public void loadProperties(Properties properties) { + public void loadProperties(Properties properties) throws BadNodeUrlException { conf.setClusterSchemaLimitLevel( properties .getProperty("cluster_schema_limit_level", conf.getClusterSchemaLimitLevel())
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java index 01a2571..82e6e9b 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
@@ -25,16 +25,11 @@ import org.apache.iotdb.commons.utils.NodeUrlUtils; import org.apache.iotdb.confignode.rpc.thrift.TGlobalConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.util.Properties; public class CommonDescriptor { - private static final Logger LOGGER = LoggerFactory.getLogger(CommonDescriptor.class); - private final CommonConfig config = new CommonConfig(); private CommonDescriptor() {} @@ -62,7 +57,7 @@ config.setProcedureWalFolder(systemDir + File.separator + "procedure"); } - public void loadCommonProps(Properties properties) { + public void loadCommonProps(Properties properties) throws BadNodeUrlException { config.setAuthorizerProvider( properties.getProperty("authorizer_provider_class", config.getAuthorizerProvider()).trim()); // if using org.apache.iotdb.db.auth.authorizer.OpenIdAuthorizer, openID_url is needed. @@ -212,13 +207,8 @@ NodeUrlUtils.convertTEndPointUrl(config.getTargetMLNodeEndPoint())); loadPipeProps(properties); - try { - config.setTargetMLNodeEndPoint(NodeUrlUtils.parseTEndPointUrl(endPointUrl)); - } catch (BadNodeUrlException e) { - LOGGER.warn( - "Illegal target MLNode endpoint url format in config file: {}, use default configuration.", - endPointUrl); - } + + config.setTargetMLNodeEndPoint(NodeUrlUtils.parseTEndPointUrl(endPointUrl)); config.setSchemaEngineMode( properties.getProperty("schema_engine_mode", String.valueOf(config.getSchemaEngineMode())));