diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java index 2040d9d9f925a..c3448a5a2de0d 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java @@ -66,7 +66,7 @@ public void executeUpdate() throws SQLException { } @SuppressWarnings("rawtypes") - private void executeRuleDefinitionUpdate() { + private void executeRuleDefinitionUpdate() throws SQLException { Optional databaseExecutor = TypedSPILoader.findService(DatabaseRuleDefinitionExecutor.class, sqlStatement.getClass()); if (databaseExecutor.isPresent()) { new DatabaseRuleDefinitionExecuteEngine((DatabaseRuleDefinitionStatement) sqlStatement, contextManager, diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java index 20d07acebce6b..17beb3bb25a42 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.mode.manager.ContextManager; +import java.sql.SQLException; import java.util.Optional; /** @@ -46,9 +47,10 @@ public final class DatabaseRuleDefinitionExecuteEngine { /** * Execute update. + * @throws SQLException SQL Exception */ @SuppressWarnings("unchecked") - public void executeUpdate() { + public void executeUpdate() throws SQLException { executor.setDatabase(database); Optional rule = database.getRuleMetaData().findSingleRule(executor.getRuleClass()); executor.setRule(rule.orElse(null)); diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleOperator.java index 523ea733e1c22..5af9541b3a5db 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/DatabaseRuleOperator.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion; +import java.sql.SQLException; import java.util.Collection; /** @@ -36,6 +37,7 @@ public interface DatabaseRuleOperator { * @param database database * @param currentRuleConfig current rule configuration * @return meta data versions + * @throws SQLException SQL Exception */ - Collection operate(DatabaseRuleDefinitionStatement sqlStatement, ShardingSphereDatabase database, RuleConfiguration currentRuleConfig); + Collection operate(DatabaseRuleDefinitionStatement sqlStatement, ShardingSphereDatabase database, RuleConfiguration currentRuleConfig) throws SQLException; } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/AlterDatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/AlterDatabaseRuleOperator.java index e76262bcadf42..af775294f7fc4 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/AlterDatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/AlterDatabaseRuleOperator.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; +import java.sql.SQLException; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map.Entry; @@ -48,7 +49,8 @@ public final class AlterDatabaseRuleOperator implements DatabaseRuleOperator { @Override @SuppressWarnings("unchecked") - public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { + public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, + final RuleConfiguration currentRuleConfig) throws SQLException { RuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getMetaDataManagerPersistService(); RuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(toBeAlteredRuleConfig); diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/CreateDatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/CreateDatabaseRuleOperator.java index 4afde93767ca4..a3db248705738 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/CreateDatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/CreateDatabaseRuleOperator.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; +import java.sql.SQLException; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map.Entry; @@ -48,7 +49,8 @@ public final class CreateDatabaseRuleOperator implements DatabaseRuleOperator { @Override @SuppressWarnings("unchecked") - public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { + public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, + final RuleConfiguration currentRuleConfig) throws SQLException { RuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); MetaDataContexts originalMetaDataContexts = contextManager.getMetaDataContexts(); MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getMetaDataManagerPersistService(); diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java index c308b9e09c0c4..d55abf3acb51f 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java @@ -34,6 +34,7 @@ import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine; import org.apache.shardingsphere.mode.manager.ContextManager; +import java.sql.SQLException; import java.util.Collection; import java.util.Collections; import java.util.Objects; @@ -51,7 +52,8 @@ public final class DropDatabaseRuleOperator implements DatabaseRuleOperator { @Override @SuppressWarnings("unchecked") - public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { + public Collection operate(final DatabaseRuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, + final RuleConfiguration currentRuleConfig) throws SQLException { if (!executor.hasAnyOneToBeDropped(sqlStatement)) { return Collections.emptyList(); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java index e19f5f7bc0409..224e8cdedf540 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java @@ -76,9 +76,10 @@ public DatabaseRuleConfigurationManager(final AtomicReference * * @param databaseName database name * @param ruleConfig rule configurations + * @throws SQLException SQL Exception */ @SuppressWarnings({"unchecked", "rawtypes"}) - public synchronized void alterRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) { + public synchronized void alterRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) throws SQLException { ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName); Collection rules = new LinkedList<>(database.getRuleMetaData().getRules()); Optional toBeChangedRule = rules.stream().filter(each -> each.getConfiguration().getClass().equals(ruleConfig.getClass())).findFirst(); @@ -86,14 +87,10 @@ public synchronized void alterRuleConfiguration(final String databaseName, final ((PartialRuleUpdateSupported) toBeChangedRule.get()).updateConfiguration(ruleConfig); return; } - try { - rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); - rules.addAll(DatabaseRulesBuilder.build(databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), - ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); - refreshMetadata(databaseName, database, rules); - } catch (final SQLException ex) { - log.error("Alter database: {} rule configurations failed", databaseName, ex); - } + rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); + rules.addAll(DatabaseRulesBuilder.build(databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), + ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); + refreshMetadata(databaseName, database, rules); } /** @@ -101,9 +98,10 @@ public synchronized void alterRuleConfiguration(final String databaseName, final * * @param databaseName database name * @param ruleConfig rule configurations + * @throws SQLException SQL Exception */ @SuppressWarnings({"unchecked", "rawtypes"}) - public synchronized void dropRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) { + public synchronized void dropRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) throws SQLException { ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName); Collection rules = new LinkedList<>(database.getRuleMetaData().getRules()); Optional toBeChangedRule = rules.stream().filter(each -> each.getConfiguration().getClass().equals(ruleConfig.getClass())).findFirst(); @@ -111,16 +109,12 @@ public synchronized void dropRuleConfiguration(final String databaseName, final ((PartialRuleUpdateSupported) toBeChangedRule.get()).updateConfiguration(ruleConfig); return; } - try { - rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); - if (!((DatabaseRuleConfiguration) ruleConfig).isEmpty()) { - rules.addAll(DatabaseRulesBuilder.build(databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), - ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); - } - refreshMetadata(databaseName, database, rules); - } catch (final SQLException ex) { - log.error("Drop database: {} rule configurations failed", databaseName, ex); + rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); + if (!((DatabaseRuleConfiguration) ruleConfig).isEmpty()) { + rules.addAll(DatabaseRulesBuilder.build(databaseName, database.getProtocolType(), database.getRuleMetaData().getRules(), + ruleConfig, computeNodeInstanceContext, database.getResourceMetaData())); } + refreshMetadata(databaseName, database, rules); } private void refreshMetadata(final String databaseName, final ShardingSphereDatabase database, final Collection rules) throws SQLException { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java index 6e189a811ee4b..0fd4182005478 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/RuleItemManager.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; +import java.sql.SQLException; import java.util.concurrent.atomic.AtomicReference; /** @@ -49,9 +50,10 @@ public RuleItemManager(final AtomicReference metaDataContexts, * Alter with rule item. * * @param event alter rule item event + * @throws SQLException SQL Exception */ @SuppressWarnings({"rawtypes", "unchecked", "unused"}) - public void alterRuleItem(final AlterRuleItemEvent event) { + public void alterRuleItem(final AlterRuleItemEvent event) throws SQLException { if (!event.getActiveVersion().equals(metaDataPersistService.getMetaDataVersionPersistService() .getActiveVersionByFullPath(event.getActiveVersionKey()))) { return; @@ -71,9 +73,10 @@ public void alterRuleItem(final AlterRuleItemEvent event) { * Drop with rule item. * * @param event drop rule item event + * @throws SQLException SQL Exception */ @SuppressWarnings({"rawtypes", "unchecked", "unused"}) - public void dropRuleItem(final DropRuleItemEvent event) { + public void dropRuleItem(final DropRuleItemEvent event) throws SQLException { String databaseName = event.getDatabaseName(); if (!metaDataContexts.get().getMetaData().containsDatabase(databaseName)) { return; diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/DropTableStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/DropTableStatementSchemaRefresher.java index 9cad41834e004..6fdd2b29d7cd2 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/DropTableStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/DropTableStatementSchemaRefresher.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; +import java.sql.SQLException; import java.util.Collection; /** @@ -36,7 +37,7 @@ public final class DropTableStatementSchemaRefresher implements MetaDataRefreshe @Override public void refresh(final MetaDataManagerPersistService metaDataManagerPersistService, final ShardingSphereDatabase database, final Collection logicDataSourceNames, - final String schemaName, final DatabaseType databaseType, final DropTableStatement sqlStatement, final ConfigurationProperties props) { + final String schemaName, final DatabaseType databaseType, final DropTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException { AlterSchemaMetaDataPOJO alterSchemaMetaDataPOJO = new AlterSchemaMetaDataPOJO(database.getName(), schemaName); sqlStatement.getTables().forEach(each -> alterSchemaMetaDataPOJO.getDroppedTables().add(each.getTableName().getIdentifier().getValue())); boolean isRuleRefreshRequired = TableRefreshUtils.isRuleRefreshRequired(database.getRuleMetaData(), schemaName, sqlStatement.getTables()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/MetaDataManagerPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/MetaDataManagerPersistService.java index 19a57b69fe602..7afc2b36c4d97 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/MetaDataManagerPersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/MetaDataManagerPersistService.java @@ -109,8 +109,9 @@ public interface MetaDataManagerPersistService { * * @param databaseName database name * @param ruleConfigs rule configs + * @throws SQLException SQL exception */ - void alterSingleRuleConfiguration(String databaseName, Collection ruleConfigs); + void alterSingleRuleConfiguration(String databaseName, Collection ruleConfigs) throws SQLException; /** * Alter rule configuration. @@ -118,16 +119,18 @@ public interface MetaDataManagerPersistService { * @param databaseName database name * @param toBeAlteredRuleConfig to be altered rule config * @return meta data versions + * @throws SQLException SQL exception */ - Collection alterRuleConfiguration(String databaseName, RuleConfiguration toBeAlteredRuleConfig); + Collection alterRuleConfiguration(String databaseName, RuleConfiguration toBeAlteredRuleConfig) throws SQLException; /** * Remove rule configuration item. * * @param databaseName database name * @param toBeRemovedRuleConfig to be removed rule config + * @throws SQLException SQL exception */ - void removeRuleConfigurationItem(String databaseName, RuleConfiguration toBeRemovedRuleConfig); + void removeRuleConfigurationItem(String databaseName, RuleConfiguration toBeRemovedRuleConfig) throws SQLException; /** * Remove rule configuration. diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java index 39a6c69091223..56ab971745373 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java @@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.mode.manager.ContextManager; +import java.sql.SQLException; + /** * Rule item changed subscriber. */ @@ -36,9 +38,10 @@ public final class RuleItemChangedSubscriber implements EventSubscriber { * Renew with alter rule item. * * @param event alter rule item event + * @throws SQLException SQL Exception */ @Subscribe - public void renew(final AlterRuleItemEvent event) { + public void renew(final AlterRuleItemEvent event) throws SQLException { contextManager.getMetaDataContextManager().getRuleItemManager().alterRuleItem(event); } @@ -46,9 +49,10 @@ public void renew(final AlterRuleItemEvent event) { * Renew with drop rule item. * * @param event drop rule item event + * @throws SQLException SQL Exception */ @Subscribe - public void renew(final DropRuleItemEvent event) { + public void renew(final DropRuleItemEvent event) throws SQLException { contextManager.getMetaDataContextManager().getRuleItemManager().dropRuleItem(event); } } diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java index cd609053dcdab..f63a34fe3c8dd 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java @@ -270,7 +270,7 @@ public void unregisterStorageUnits(final String databaseName, final Collection ruleConfigs) { + public void alterSingleRuleConfiguration(final String databaseName, final Collection ruleConfigs) throws SQLException { ruleConfigs.removeIf(each -> !each.getClass().isAssignableFrom(SingleRuleConfiguration.class)); Collection metaDataVersions = metaDataPersistService.getDatabaseRulePersistService() .persistConfigurations(metaDataContextManager.getMetaDataContexts().get().getMetaData().getDatabase(databaseName).getName(), ruleConfigs); @@ -280,7 +280,7 @@ public void alterSingleRuleConfiguration(final String databaseName, final Collec } @Override - public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) { + public Collection alterRuleConfiguration(final String databaseName, final RuleConfiguration toBeAlteredRuleConfig) throws SQLException { if (null != toBeAlteredRuleConfig) { Collection metaDataVersions = metaDataPersistService.getDatabaseRulePersistService() .persistConfigurations(metaDataContextManager.getMetaDataContexts().get().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig)); @@ -301,7 +301,7 @@ private Optional buildAlterRuleItemEvent(final String databaseNam } @Override - public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) { + public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) throws SQLException { if (null != toBeRemovedRuleConfig) { Collection metaDataVersions = metaDataPersistService.getDatabaseRulePersistService() .deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig));