This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch cluster-
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/cluster- by this push:
new 0e9b730 add 800 error code for incorrect configuration. remove some
System.exit(1) in codes
0e9b730 is described below
commit 0e9b730455323d41682ea93bb4da13a70d5939a8
Author: xiangdong huang <[email protected]>
AuthorDate: Mon Sep 27 07:21:03 2021 +0800
add 800 error code for incorrect configuration. remove some System.exit(1)
in codes
---
.../org/apache/iotdb/cluster/ClusterIoTDB.java | 16 ++++----
.../cluster/server/member/MetaGroupMember.java | 1 -
docs/UserGuide/Appendix/Status-Codes.md | 1 +
docs/zh/UserGuide/Appendix/Status-Codes.md | 2 +
.../org/apache/iotdb/db/conf/IoTDBConfigCheck.java | 27 +++++++-------
.../iotdb/db/exception/ConfigurationException.java | 43 ++++++++++++++++++++++
.../java/org/apache/iotdb/db/service/IoTDB.java | 4 +-
.../iotdb/db/integration/IoTDBCheckConfigIT.java | 43 +++++++++-------------
.../java/org/apache/iotdb/rpc/TSStatusCode.java | 5 ++-
9 files changed, 94 insertions(+), 48 deletions(-)
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterIoTDB.java
b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterIoTDB.java
index 851e8a2..e17eb43 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterIoTDB.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterIoTDB.java
@@ -52,6 +52,7 @@ import org.apache.iotdb.db.concurrent.IoTDBThreadPoolFactory;
import org.apache.iotdb.db.conf.IoTDBConfigCheck;
import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.ConfigurationException;
import org.apache.iotdb.db.exception.StartupException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.service.IoTDB;
@@ -213,7 +214,12 @@ public class ClusterIoTDB implements ClusterIoTDBMBean {
ClusterIoTDB cluster = ClusterIoTDBHolder.INSTANCE;
// check config of iotdb,and set some configs in cluster mode
- if (!cluster.serverCheckAndInit()) {
+ try {
+ if (!cluster.serverCheckAndInit()) {
+ return;
+ }
+ } catch (ConfigurationException | IOException e) {
+ logger.error("meet error when doing start checking", e);
return;
}
String mode = args[0];
@@ -238,12 +244,8 @@ public class ClusterIoTDB implements ClusterIoTDBMBean {
}
}
- private boolean serverCheckAndInit() {
- try {
- IoTDBConfigCheck.getInstance().checkConfig();
- } catch (IOException e) {
- logger.error("meet error when doing start checking", e);
- }
+ private boolean serverCheckAndInit() throws ConfigurationException,
IOException {
+ IoTDBConfigCheck.getInstance().checkConfig();
// init server's configuration first, because the cluster configuration
may read settings from
// the server's configuration.
IoTDBDescriptor.getInstance().getConfig().setSyncEnable(false);
diff --git
a/cluster/src/main/java/org/apache/iotdb/cluster/server/member/MetaGroupMember.java
b/cluster/src/main/java/org/apache/iotdb/cluster/server/member/MetaGroupMember.java
index d3d44e1..74fb7da 100644
---
a/cluster/src/main/java/org/apache/iotdb/cluster/server/member/MetaGroupMember.java
+++
b/cluster/src/main/java/org/apache/iotdb/cluster/server/member/MetaGroupMember.java
@@ -80,7 +80,6 @@ import
org.apache.iotdb.cluster.utils.nodetool.function.Status;
import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.engine.StorageEngine;
-import org.apache.iotdb.db.exception.ShutdownException;
import org.apache.iotdb.db.exception.StartupException;
import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.exception.metadata.MetadataException;
diff --git a/docs/UserGuide/Appendix/Status-Codes.md
b/docs/UserGuide/Appendix/Status-Codes.md
index aba90f2..ee11062 100644
--- a/docs/UserGuide/Appendix/Status-Codes.md
+++ b/docs/UserGuide/Appendix/Status-Codes.md
@@ -101,6 +101,7 @@ Here is a list of Status Code and related message:
|705|CONSISTENCY_FAILURE|Consistency check failure|
|706|NO_CONNECTION|Can not get connection error|
|707|NEED_REDIRECTION|Need direction|
+|800|CONFIG_ERROR|Configuration error|
> All exceptions are refactored in latest version by extracting uniform
> message into exception classes. Different error codes are added to all
> exceptions. When an exception is caught and a higher-level exception is
> thrown, the error code will keep and pass so that users will know the
> detailed error reason.
A base exception class "ProcessException" is also added to be extended by all
exceptions.
diff --git a/docs/zh/UserGuide/Appendix/Status-Codes.md
b/docs/zh/UserGuide/Appendix/Status-Codes.md
index d272e1e..ccb4dd3 100644
--- a/docs/zh/UserGuide/Appendix/Status-Codes.md
+++ b/docs/zh/UserGuide/Appendix/Status-Codes.md
@@ -101,5 +101,7 @@ try {
|705|CONSISTENCY_FAILURE|一致性检查失败|
|706|NO_CONNECTION|连接获取失败|
|707|NEED_REDIRECTION|需要重定向|
+|800|CONFIG_ERROR|配置文件有错误项|
+
> 在最新版本中,我们重构了 IoTDB
> 的异常类。通过将错误信息统一提取到异常类中,并为所有异常添加不同的错误代码,从而当捕获到异常并引发更高级别的异常时,错误代码将保留并传递,以便用户了解详细的错误原因。
除此之外,我们添加了一个基础异常类“ProcessException”,由所有异常扩展。
diff --git
a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfigCheck.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfigCheck.java
index 992ef36..d9947a5 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfigCheck.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfigCheck.java
@@ -22,6 +22,7 @@ import org.apache.iotdb.db.conf.directories.DirectoryManager;
import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
import org.apache.iotdb.db.engine.modification.ModificationFile;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.ConfigurationException;
import org.apache.iotdb.db.metadata.logfile.MLogWriter;
import org.apache.iotdb.db.utils.FilePathUtils;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
@@ -164,7 +165,7 @@ public class IoTDBConfigCheck {
* <p>When upgrading the system.properties: (1) create system.properties.tmp
(2) delete
* system.properties (3) rename system.properties.tmp to system.properties
*/
- public void checkConfig() throws IOException {
+ public void checkConfig() throws ConfigurationException, IOException {
propertiesFile =
SystemFileFactory.INSTANCE.getFile(
IoTDBConfigCheck.SCHEMA_DIR + File.separator +
PROPERTIES_FILE_NAME);
@@ -296,7 +297,7 @@ public class IoTDBConfigCheck {
}
/** Check all immutable properties */
- private void checkProperties() throws IOException {
+ private void checkProperties() throws ConfigurationException, IOException {
for (Entry<String, String> entry : systemProperties.entrySet()) {
if (!properties.containsKey(entry.getKey())) {
upgradePropertiesFileFromBrokenFile();
@@ -305,41 +306,41 @@ public class IoTDBConfigCheck {
}
if
(!properties.getProperty(TIMESTAMP_PRECISION_STRING).equals(timestampPrecision))
{
- printErrorLogAndExit(TIMESTAMP_PRECISION_STRING);
+ throwException(TIMESTAMP_PRECISION_STRING, timestampPrecision);
}
if (Boolean.parseBoolean(properties.getProperty(ENABLE_PARTITION_STRING))
!= enablePartition) {
- printErrorLogAndExit(ENABLE_PARTITION_STRING);
+ throwException(ENABLE_PARTITION_STRING, enablePartition);
}
if (Long.parseLong(properties.getProperty(PARTITION_INTERVAL_STRING)) !=
partitionInterval) {
- printErrorLogAndExit(PARTITION_INTERVAL_STRING);
+ throwException(PARTITION_INTERVAL_STRING, partitionInterval);
}
if
(!(properties.getProperty(TSFILE_FILE_SYSTEM_STRING).equals(tsfileFileSystem)))
{
- printErrorLogAndExit(TSFILE_FILE_SYSTEM_STRING);
+ throwException(TSFILE_FILE_SYSTEM_STRING, tsfileFileSystem);
}
if
(!(properties.getProperty(TAG_ATTRIBUTE_SIZE_STRING).equals(tagAttributeTotalSize)))
{
- printErrorLogAndExit(TAG_ATTRIBUTE_SIZE_STRING);
+ throwException(TAG_ATTRIBUTE_SIZE_STRING, tagAttributeTotalSize);
}
if
(!(properties.getProperty(MAX_DEGREE_OF_INDEX_STRING).equals(maxDegreeOfIndexNode)))
{
- printErrorLogAndExit(MAX_DEGREE_OF_INDEX_STRING);
+ throwException(MAX_DEGREE_OF_INDEX_STRING, maxDegreeOfIndexNode);
}
if
(!(properties.getProperty(VIRTUAL_STORAGE_GROUP_NUM).equals(virtualStorageGroupNum)))
{
- printErrorLogAndExit(VIRTUAL_STORAGE_GROUP_NUM);
+ throwException(VIRTUAL_STORAGE_GROUP_NUM, virtualStorageGroupNum);
}
if (!(properties.getProperty(TIME_ENCODER_KEY).equals(timeEncoderValue))) {
- printErrorLogAndExit(TIME_ENCODER_KEY);
+ throwException(TIME_ENCODER_KEY, timeEncoderValue);
}
}
- private void printErrorLogAndExit(String property) {
- logger.error("Wrong {}, please set as: {} !", property,
properties.getProperty(property));
- System.exit(-1);
+ private void throwException(String parameter, Object badValue) throws
ConfigurationException {
+ throw new ConfigurationException(
+ parameter, String.valueOf(badValue),
properties.getProperty(parameter));
}
/** ensure all TsFiles are closed when starting 0.12 */
diff --git
a/server/src/main/java/org/apache/iotdb/db/exception/ConfigurationException.java
b/server/src/main/java/org/apache/iotdb/db/exception/ConfigurationException.java
new file mode 100644
index 0000000..ad50558
--- /dev/null
+++
b/server/src/main/java/org/apache/iotdb/db/exception/ConfigurationException.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.exception;
+
+import org.apache.iotdb.rpc.TSStatusCode;
+
+public class ConfigurationException extends IoTDBException {
+ String parameter;
+ String correctValue;
+
+ public ConfigurationException(String parameter, String badValue, String
correctValue) {
+ super(
+ String.format(
+ "Parameter %s can not be %s, please set to: %s", parameter,
badValue, correctValue),
+ TSStatusCode.CONFIG_ERROR.getStatusCode());
+ this.parameter = parameter;
+ this.correctValue = correctValue;
+ }
+
+ public String getParameter() {
+ return parameter;
+ }
+
+ public String getCorrectValue() {
+ return correctValue;
+ }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
index dd383ea..0b7b46c 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
@@ -30,6 +30,7 @@ import
org.apache.iotdb.db.engine.compaction.CompactionMergeTaskPoolManager;
import org.apache.iotdb.db.engine.flush.FlushManager;
import org.apache.iotdb.db.engine.merge.manage.MergeManager;
import org.apache.iotdb.db.engine.trigger.service.TriggerRegistrationService;
+import org.apache.iotdb.db.exception.ConfigurationException;
import org.apache.iotdb.db.exception.StartupException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.monitor.StatMonitor;
@@ -64,8 +65,9 @@ public class IoTDB implements IoTDBMBean {
public static void main(String[] args) {
try {
IoTDBConfigCheck.getInstance().checkConfig();
- } catch (IOException e) {
+ } catch (ConfigurationException | IOException e) {
logger.error("meet error when doing start checking", e);
+ System.exit(1);
}
IoTDB daemon = IoTDB.getInstance();
daemon.active();
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBCheckConfigIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBCheckConfigIT.java
index d9f56a6..91e72c2 100644
---
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBCheckConfigIT.java
+++
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBCheckConfigIT.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.integration;
import org.apache.iotdb.db.conf.IoTDBConfigCheck;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
+import org.apache.iotdb.db.exception.ConfigurationException;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
@@ -37,14 +38,13 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
-import java.security.AccessControlException;
-import java.security.Permission;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class IoTDBCheckConfigIT {
private File propertiesFile =
@@ -67,15 +67,15 @@ public class IoTDBCheckConfigIT {
EnvironmentUtils.closeStatMonitor();
EnvironmentUtils.envSetUp();
- final SecurityManager securityManager =
- new SecurityManager() {
- public void checkPermission(Permission permission) {
- if (permission.getName().startsWith("exitVM")) {
- throw new AccessControlException("Wrong system config");
- }
- }
- };
- System.setSecurityManager(securityManager);
+ // final SecurityManager securityManager =
+ // new SecurityManager() {
+ // public void checkPermission(Permission permission) {
+ // if (permission.getName().startsWith("exitVM")) {
+ // throw new AccessControlException("Wrong system config");
+ // }
+ // }
+ // };
+ // System.setSecurityManager(securityManager);
bytes = new ByteArrayOutputStream();
console = System.out;
System.setOut(new PrintStream(bytes));
@@ -100,12 +100,7 @@ public class IoTDBCheckConfigIT {
@Test
public void testSaveTimeEncoderToSystemProperties() throws Exception {
- try {
- IoTDBConfigCheck.getInstance().checkConfig();
- } finally {
- System.setSecurityManager(null);
- }
-
+ IoTDBConfigCheck.getInstance().checkConfig();
// read properties from system.properties
try (FileInputStream inputStream = new FileInputStream(propertiesFile);
InputStreamReader inputStreamReader =
@@ -126,12 +121,12 @@ public class IoTDBCheckConfigIT {
EnvironmentUtils.reactiveDaemon();
try {
IoTDBConfigCheck.getInstance().checkConfig();
- } catch (Throwable t) {
- assertEquals("Wrong system config", t.getMessage());
- } finally {
- System.setSecurityManager(null);
+ } catch (ConfigurationException t) {
+ assertEquals(t.getParameter(), "time_encoder");
+ assertEquals(t.getCorrectValue(), "REGULAR");
+ return;
}
- assertTrue(bytes.toString().contains("Wrong time_encoder, please set as:
REGULAR"));
+ fail("should detect configration errors");
}
@Test
@@ -145,9 +140,7 @@ public class IoTDBCheckConfigIT {
try {
IoTDBConfigCheck.getInstance().checkConfig();
} catch (Throwable t) {
- assertTrue(false);
- } finally {
- System.setSecurityManager(null);
+ fail("should have no configration errors");
}
}
diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
index 5bf62fb..8bc0917 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
@@ -93,7 +93,10 @@ public enum TSStatusCode {
CONSISTENCY_FAILURE(705),
NO_CONNECTION(706),
NEED_REDIRECTION(707),
- PARSE_LOG_ERROR(708);
+ PARSE_LOG_ERROR(708),
+
+ // configuration
+ CONFIG_ERROR(800);
private int statusCode;