This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new efbe06b021e Add StorageUnitsConnectException (#30710)
efbe06b021e is described below
commit efbe06b021e7bccb0d50ac90c5ac63ed897480e9
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 14:32:48 2024 +0800
Add StorageUnitsConnectException (#30710)
* Refactor InvalidStorageUnitsException
* Add StorageUnitsConnectException
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 7 ++-----
.../storageunit/InvalidStorageUnitsException.java | 6 ------
...xception.java => StorageUnitsConnectException.java} | 18 ++++++++----------
.../validator/DataSourcePoolPropertiesValidator.java | 11 +++++------
.../DistSQLDataSourcePoolPropertiesValidator.java | 8 +++-----
6 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index ab655a94c6c..c037cca8a0d 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -35,6 +35,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 10106 | Read storage unit '%s' does not exist in rule
'%s'. |
| 42000 | 10107 | There is no storage unit in database '%s'.
|
| 0A000 | 10108 | Can not alter connection info in storage units:
'%s'. |
+| 0A000 | 10109 | Storage units can not connect, error messages are:
%s. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
| 44000 | 10201 | %s rules '%s' do not exist in database '%s'.
|
| 44000 | 10202 | %s rules '%s' in database '%s' are still in used.
|
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 80d5c32fe9f..8352ea8869b 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -20,12 +20,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 10005 | Column '%s' in %s is ambiguous.
|
| 42S02 | 10006 | Unknown column '%s' in '%s'.
|
| 42S02 | 10007 | Table or view \`%s\` does not exist.
|
-| 0A000 | 10108 | Can not alter connection info in storage units:
'%s'. |
| 42000 | 10010 | Rule does not exist.
|
-| 44000 | 10011 | Algorithm '%s.'%s' initialization failed, reason
is: %s. |
-| 44000 | 10012 | '%s' algorithm on %s is required.
|
-| 42S02 | 10013 | '%s' algorithm '%s' on %s is unregistered.
|
-| HY000 | 10015 | Algorithm '%s.%s' execute failed, reason is: %s.
|
| 42S02 | 10020 | Schema \`%s\` does not exist.
|
| 42S02 | 10021 | Single table \`%s\` does not exist.
|
| HY000 | 10022 | Can not load table with database name \`%s\` and
data source name \`%s\`. |
@@ -39,6 +34,8 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 44000 | 10105 | Invalid storage unit status, error message is: %s.
|
| 44000 | 10106 | Read storage unit '%s' does not exist in rule
'%s'. |
| 42000 | 10107 | There is no storage unit in database '%s'.
|
+| 0A000 | 10108 | Can not alter connection info in storage units:
'%s'. |
+| 0A000 | 10109 | Storage units can not connect, error messages are:
%s. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s
|
| 44000 | 10201 | %s rules '%s' do not exist in database '%s'.
|
| 44000 | 10202 | %s rules '%s' in database '%s' are still in used.
|
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
index 5a6339be5de..5429da2a8fd 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.infra.exception.storageunit;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ResourceDefinitionException;
-import java.util.Collection;
-
/**
* Invalid storage units exception.
*/
@@ -32,8 +30,4 @@ public final class InvalidStorageUnitsException extends
ResourceDefinitionExcept
public InvalidStorageUnitsException(final Exception cause) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages is: %s", cause.getMessage());
}
-
- public InvalidStorageUnitsException(final Collection<String>
errorMessages) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages are: %s", errorMessages);
- }
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
similarity index 63%
copy from
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
index 5a6339be5de..a4743f9a925 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/InvalidStorageUnitsException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java
@@ -20,20 +20,18 @@ package
org.apache.shardingsphere.infra.exception.storageunit;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ResourceDefinitionException;
-import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
- * Invalid storage units exception.
+ * Storage units connect exception.
*/
-public final class InvalidStorageUnitsException extends
ResourceDefinitionException {
+public final class StorageUnitsConnectException extends
ResourceDefinitionException {
- private static final long serialVersionUID = 7029641448948791509L;
+ private static final long serialVersionUID = 1824912697040264268L;
- public InvalidStorageUnitsException(final Exception cause) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages is: %s", cause.getMessage());
- }
-
- public InvalidStorageUnitsException(final Collection<String>
errorMessages) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages are: %s", errorMessages);
+ public StorageUnitsConnectException(final Map<String, Exception> causes) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 9, "Storage units can not
connect, error messages are: %s.", causes.entrySet().stream().map(entry ->
String.format(
+ "Storage unit name: '%s', error message is: %s",
entry.getKey(),
entry.getValue().getMessage())).collect(Collectors.joining(System.lineSeparator())));
}
}
diff --git
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidator.java
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidator.java
index 90a69a39c43..d936cb0fc10 100644
---
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidator.java
+++
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidator.java
@@ -27,8 +27,7 @@ import
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Collection;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -42,16 +41,16 @@ public final class DataSourcePoolPropertiesValidator {
* Validate data source pool properties map.
*
* @param propsMap data source pool properties map
- * @return error messages
+ * @return data source name and exception map
*/
- public static Collection<String> validate(final Map<String,
DataSourcePoolProperties> propsMap) {
- Collection<String> result = new LinkedList<>();
+ public static Map<String, Exception> validate(final Map<String,
DataSourcePoolProperties> propsMap) {
+ Map<String, Exception> result = new LinkedHashMap<>();
for (Entry<String, DataSourcePoolProperties> entry :
propsMap.entrySet()) {
try {
validateProperties(entry.getKey(), entry.getValue());
validateConnection(entry.getKey(), entry.getValue());
} catch (final InvalidDataSourcePoolPropertiesException ex) {
- result.add(ex.getMessage());
+ result.put(entry.getKey(), ex);
}
}
return result;
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/validate/DistSQLDataSourcePoolPropertiesValidator.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/validate/DistSQLDataSourcePoolPropertiesValidator.java
index cf3fd37891c..187f3238aa7 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/validate/DistSQLDataSourcePoolPropertiesValidator.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/validate/DistSQLDataSourcePoolPropertiesValidator.java
@@ -20,9 +20,8 @@ package org.apache.shardingsphere.distsql.handler.validate;
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.datasource.pool.props.validator.DataSourcePoolPropertiesValidator;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import
org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsConnectException;
-import java.util.Collection;
import java.util.Map;
/**
@@ -34,10 +33,9 @@ public final class DistSQLDataSourcePoolPropertiesValidator {
* Validate data source properties map.
*
* @param propsMap data source pool properties map
- * @throws InvalidStorageUnitsException invalid storage units exception
*/
public void validate(final Map<String, DataSourcePoolProperties> propsMap)
{
- Collection<String> errorMessages =
DataSourcePoolPropertiesValidator.validate(propsMap);
- ShardingSpherePreconditions.checkState(errorMessages.isEmpty(), () ->
new InvalidStorageUnitsException(errorMessages));
+ Map<String, Exception> exceptions =
DataSourcePoolPropertiesValidator.validate(propsMap);
+ ShardingSpherePreconditions.checkState(exceptions.isEmpty(), () -> new
StorageUnitsConnectException(exceptions));
}
}