This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 f6d5ec1c45c Add AlterStorageUnitConnectionInfoException (#30709)
f6d5ec1c45c is described below
commit f6d5ec1c45cb53d9b6cf9b30d4a498a7595e2560
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 13:21:46 2024 +0800
Add AlterStorageUnitConnectionInfoException (#30709)
* Adjust error message of ResourceDefinitionException and
RuleDefinitionException
* Add AlterStorageUnitConnectionInfoException
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
...va => AlterStorageUnitConnectionInfoException.java} | 18 +++++-------------
.../storageunit/InvalidStorageUnitsException.java | 4 ----
.../rdl/resource/AlterStorageUnitExecutor.java | 4 ++--
.../rdl/resource/RegisterStorageUnitExecutor.java | 3 +--
.../rdl/resource/AlterStorageUnitExecutorTest.java | 9 +++++----
.../rdl/resource/RegisterStorageUnitExecutorTest.java | 5 ++---
8 files changed, 17 insertions(+), 28 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 1dee32a4407..ab655a94c6c 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
@@ -34,6 +34,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 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'. |
| 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 313314aad31..80d5c32fe9f 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,6 +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.
|
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/AlterStorageUnitConnectionInfoException.java
similarity index 57%
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/AlterStorageUnitConnectionInfoException.java
index 37b8c48165f..d12ea46710f 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/AlterStorageUnitConnectionInfoException.java
@@ -23,21 +23,13 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.c
import java.util.Collection;
/**
- * Invalid storage units exception.
+ * Alter storage unit connection info exception.
*/
-public final class InvalidStorageUnitsException extends
ResourceDefinitionException {
+public final class AlterStorageUnitConnectionInfoException extends
ResourceDefinitionException {
- private static final long serialVersionUID = 7029641448948791509L;
+ private static final long serialVersionUID = 525999625052706626L;
- 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 String errorMessage) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages is: %s", errorMessage);
- }
-
- public InvalidStorageUnitsException(final Collection<String>
errorMessages) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages are: %s", errorMessages);
+ public AlterStorageUnitConnectionInfoException(final Collection<String>
storageUnitNames) {
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 8, "Can not alter
connection info in storage units: '%s'.", String.join(", ", storageUnitNames));
}
}
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 37b8c48165f..5a6339be5de 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
@@ -33,10 +33,6 @@ public final class InvalidStorageUnitsException extends
ResourceDefinitionExcept
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages is: %s", cause.getMessage());
}
- public InvalidStorageUnitsException(final String errorMessage) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "Can not process
invalid storage units, error messages is: %s", errorMessage);
- }
-
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/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
index d2350dd1b84..4d588e062d5 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java
@@ -33,6 +33,7 @@ import
org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcU
import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException;
+import
org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException;
import
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
@@ -91,8 +92,7 @@ public final class AlterStorageUnitExecutor implements
DistSQLUpdateExecutor<Alt
private void checkDatabase(final AlterStorageUnitStatement sqlStatement) {
Collection<String> invalidStorageUnitNames =
sqlStatement.getStorageUnits().stream().collect(Collectors.toMap(DataSourceSegment::getName,
each -> each)).entrySet().stream()
.filter(each -> !isSameDatabase(each.getValue(),
database.getResourceMetaData().getStorageUnits().get(each.getKey()))).map(Entry::getKey).collect(Collectors.toSet());
-
ShardingSpherePreconditions.checkState(invalidStorageUnitNames.isEmpty(),
- () -> new InvalidStorageUnitsException(String.format("Can not
alter the database of %s", invalidStorageUnitNames)));
+
ShardingSpherePreconditions.checkState(invalidStorageUnitNames.isEmpty(), () ->
new AlterStorageUnitConnectionInfoException(invalidStorageUnitNames));
}
private boolean isSameDatabase(final DataSourceSegment segment, final
StorageUnit storageUnit) {
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
index 015fd2826bb..371a2a5228c 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java
@@ -99,8 +99,7 @@ public final class RegisterStorageUnitExecutor implements
DistSQLUpdateExecutor<
return;
}
Collection<String> duplicatedDataSourceNames =
requiredDataSourceNames.stream().filter(logicalDataSourceNames::contains).collect(Collectors.toSet());
-
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(),
- () -> new InvalidStorageUnitsException(String.format("%s
already existed in rule", duplicatedDataSourceNames)));
+
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), ()
-> new DuplicateStorageUnitExceptionDefinition(duplicatedDataSourceNames));
}
private Collection<String> getCurrentStorageUnitNames(final ContextManager
contextManager) {
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
index 09c240d5450..9064965753d 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.distsql.handler.executor.rdl.resource;
-import
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
-import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
-import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
import
org.apache.shardingsphere.distsql.segment.HostnameAndPortBasedDataSourceSegment;
import org.apache.shardingsphere.distsql.segment.URLBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.AlterStorageUnitStatement;
import
org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
+import
org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException;
+import
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
+import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -92,7 +92,8 @@ class AlterStorageUnitExecutorTest {
when(storageUnit.getConnectionProperties()).thenReturn(connectionProps);
when(resourceMetaData.getStorageUnits()).thenReturn(Collections.singletonMap("ds_0",
storageUnit));
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
- assertThrows(InvalidStorageUnitsException.class, () ->
executor.executeUpdate(createAlterStorageUnitStatement("ds_0"),
mockContextManager(mock(MetaDataContexts.class, RETURNS_DEEP_STUBS))));
+ assertThrows(AlterStorageUnitConnectionInfoException.class,
+ () ->
executor.executeUpdate(createAlterStorageUnitStatement("ds_0"),
mockContextManager(mock(MetaDataContexts.class, RETURNS_DEEP_STUBS))));
}
private ContextManager mockContextManager(final MetaDataContexts
metaDataContexts) {
diff --git
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
index de633ba262d..666f8e2f92a 100644
---
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
+++
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java
@@ -17,12 +17,11 @@
package org.apache.shardingsphere.distsql.handler.executor.rdl.resource;
-import
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
-import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
import
org.apache.shardingsphere.distsql.segment.HostnameAndPortBasedDataSourceSegment;
import org.apache.shardingsphere.distsql.segment.URLBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.RegisterStorageUnitStatement;
+import
org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
@@ -88,7 +87,7 @@ class RegisterStorageUnitExecutorTest {
DataSourceMapperRuleAttribute ruleAttribute =
mock(DataSourceMapperRuleAttribute.class);
when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0",
Collections.emptyList()));
when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
- assertThrows(InvalidStorageUnitsException.class, () ->
executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
+ assertThrows(DuplicateStorageUnitExceptionDefinition.class, () ->
executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager));
}
private RegisterStorageUnitStatement createRegisterStorageUnitStatement() {