This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 4f1f9b1672d Refactor InvalidStorageUnitsException (#30707)
4f1f9b1672d is described below
commit 4f1f9b1672d5dfb088b5154ef528f5996d42e1b0
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 31 11:39:29 2024 +0800
Refactor InvalidStorageUnitsException (#30707)
---
.../core/exception/type/AlgorithmExecuteException.java | 1 +
.../type/InvalidAlgorithmConfigurationException.java | 1 +
.../exception/storageunit/InvalidStorageUnitsException.java | 8 ++++++++
.../executor/rdl/resource/AlterStorageUnitExecutor.java | 11 +++++------
.../executor/rdl/resource/RegisterStorageUnitExecutor.java | 9 ++++-----
.../executor/rdl/resource/UnregisterStorageUnitExecutor.java | 9 ++++-----
.../backend/util/YamlDatabaseConfigurationImportExecutor.java | 2 +-
7 files changed, 24 insertions(+), 17 deletions(-)
diff --git
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/AlgorithmExecuteException.java
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/AlgorithmExecuteException.java
index f331e27a380..f3f56cf60f1 100644
---
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/AlgorithmExecuteException.java
+++
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/AlgorithmExecuteException.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
/**
* Algorithm execute exception.
*/
+// TODO It is runnable exception, consider about move out from
AlgorithmDefinitionException
public final class AlgorithmExecuteException extends
AlgorithmDefinitionException {
private static final long serialVersionUID = -9099514178650043282L;
diff --git
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/InvalidAlgorithmConfigurationException.java
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/InvalidAlgorithmConfigurationException.java
index a2b62582b43..a60c4c7902e 100644
---
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/InvalidAlgorithmConfigurationException.java
+++
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/type/InvalidAlgorithmConfigurationException.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
/**
* Invalid algorithm configuration exception.
*/
+// TODO consider about merge with AlgorithmInitializationException
public final class InvalidAlgorithmConfigurationException extends
AlgorithmDefinitionException {
private static final long serialVersionUID = 1352014079406440573L;
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 a2022631207..37b8c48165f 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
@@ -29,6 +29,14 @@ public final class InvalidStorageUnitsException extends
ResourceDefinitionExcept
private static final long serialVersionUID = 7029641448948791509L;
+ 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);
}
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 69176855659..d2350dd1b84 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
@@ -20,9 +20,6 @@ package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
-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.engine.update.DistSQLUpdateExecutor;
import
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
import org.apache.shardingsphere.distsql.segment.DataSourceSegment;
@@ -36,13 +33,15 @@ 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.DuplicateStorageUnitExceptionDefinition;
+import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.mode.manager.ContextManager;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
@@ -68,7 +67,7 @@ public final class AlterStorageUnitExecutor implements
DistSQLUpdateExecutor<Alt
contextManager.getInstanceContext().getModeContextManager().alterStorageUnits(database.getName(),
propsMap);
} catch (final SQLException | ShardingSphereExternalException ex) {
log.error("Alter storage unit failed", ex);
- throw new
InvalidStorageUnitsException(Collections.singleton(ex.getMessage()));
+ throw new InvalidStorageUnitsException(ex);
}
}
@@ -93,7 +92,7 @@ public final class AlterStorageUnitExecutor implements
DistSQLUpdateExecutor<Alt
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(Collections.singleton(String.format("Can not alter
the database of %s", invalidStorageUnitNames))));
+ () -> new InvalidStorageUnitsException(String.format("Can not
alter the database of %s", 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 b0369d2e4c6..015fd2826bb 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
@@ -21,8 +21,6 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor;
-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.DataSourceSegment;
import
org.apache.shardingsphere.distsql.segment.converter.DataSourceSegmentsConverter;
@@ -30,6 +28,8 @@ import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.Regist
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.DuplicateStorageUnitExceptionDefinition;
+import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -37,7 +37,6 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
@@ -71,7 +70,7 @@ public final class RegisterStorageUnitExecutor implements
DistSQLUpdateExecutor<
contextManager.getInstanceContext().getModeContextManager().registerStorageUnits(database.getName(),
propsMap);
} catch (final SQLException | ShardingSphereExternalException ex) {
log.error("Register storage unit failed", ex);
- throw new
InvalidStorageUnitsException(Collections.singleton(ex.getMessage()));
+ throw new InvalidStorageUnitsException(ex);
}
}
@@ -101,7 +100,7 @@ public final class RegisterStorageUnitExecutor implements
DistSQLUpdateExecutor<
}
Collection<String> duplicatedDataSourceNames =
requiredDataSourceNames.stream().filter(logicalDataSourceNames::contains).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(),
- () -> new
InvalidStorageUnitsException(Collections.singleton(String.format("%s already
existed in rule", duplicatedDataSourceNames))));
+ () -> new InvalidStorageUnitsException(String.format("%s
already existed in rule", duplicatedDataSourceNames)));
}
private Collection<String> getCurrentStorageUnitNames(final ContextManager
contextManager) {
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
index bfd5867c68e..d3d7d5263bf 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java
@@ -20,14 +20,14 @@ package
org.apache.shardingsphere.distsql.handler.executor.rdl.resource;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
-import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
-import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
-import
org.apache.shardingsphere.infra.exception.storageunit.InUsedStorageUnitException;
import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecutor;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.resource.StorageUnitDefinitionProcessor;
import
org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.UnregisterStorageUnitStatement;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.core.external.server.ShardingSphereServerException;
+import
org.apache.shardingsphere.infra.exception.storageunit.InUsedStorageUnitException;
+import
org.apache.shardingsphere.infra.exception.storageunit.InvalidStorageUnitsException;
+import
org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -36,7 +36,6 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
@@ -61,7 +60,7 @@ public final class UnregisterStorageUnitExecutor implements
DistSQLUpdateExecuto
contextManager.getInstanceContext().getModeContextManager().unregisterStorageUnits(database.getName(),
sqlStatement.getStorageUnitNames());
} catch (final SQLException | ShardingSphereServerException ex) {
log.error("Unregister storage unit failed", ex);
- throw new
InvalidStorageUnitsException(Collections.singleton(ex.getMessage()));
+ throw new InvalidStorageUnitsException(ex);
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 58b32e02583..f28e6847de9 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -118,7 +118,7 @@ public final class YamlDatabaseConfigurationImportExecutor {
try {
ProxyContext.getInstance().getContextManager().getInstanceContext().getModeContextManager().registerStorageUnits(databaseName,
propsMap);
} catch (final SQLException ex) {
- throw new
InvalidStorageUnitsException(Collections.singleton(ex.getMessage()));
+ throw new InvalidStorageUnitsException(ex);
}
Map<String, StorageUnit> storageUnits =
ProxyContext.getInstance().getContextManager()
.getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnits();