You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/07/05 14:33:58 UTC
[shardingsphere] branch master updated: Add synchronized for public and update method in ContextManager (#18872)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 4968590ce95 Add synchronized for public and update method in ContextManager (#18872)
4968590ce95 is described below
commit 4968590ce959532ab092453ef802826dc9ae3b93
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Jul 5 22:33:53 2022 +0800
Add synchronized for public and update method in ContextManager (#18872)
---
.../mode/manager/ContextManager.java | 36 +++++++++++-----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index 42b1b99a4a2..321394ab868 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -122,7 +122,7 @@ public final class ContextManager implements AutoCloseable {
*
* @param databaseName database name
*/
- public void dropDatabase(final String databaseName) {
+ public synchronized void dropDatabase(final String databaseName) {
if (!metaDataContexts.getMetaData().getDatabases().containsKey(databaseName)) {
return;
}
@@ -137,7 +137,7 @@ public final class ContextManager implements AutoCloseable {
* @param databaseName database name
* @param schemaName schema name
*/
- public void addSchema(final String databaseName, final String schemaName) {
+ public synchronized void addSchema(final String databaseName, final String schemaName) {
if (metaDataContexts.getMetaData().getDatabases().get(databaseName).getSchemas().containsKey(schemaName)) {
return;
}
@@ -153,19 +153,19 @@ public final class ContextManager implements AutoCloseable {
* @param toBeChangedTable to be changed table
* @param toBeDeletedTableName to be deleted table name
*/
- public void alterSchema(final String databaseName, final String schemaName, final ShardingSphereTable toBeChangedTable, final String toBeDeletedTableName) {
+ public synchronized void alterSchema(final String databaseName, final String schemaName, final ShardingSphereTable toBeChangedTable, final String toBeDeletedTableName) {
if (metaDataContexts.getMetaData().getDatabases().containsKey(databaseName)) {
Optional.ofNullable(toBeChangedTable).ifPresent(optional -> alterTable(databaseName, schemaName, optional));
Optional.ofNullable(toBeDeletedTableName).ifPresent(optional -> dropTable(databaseName, schemaName, optional));
}
}
- private void alterTable(final String databaseName, final String schemaName, final ShardingSphereTable beBoChangedTable) {
+ private synchronized void alterTable(final String databaseName, final String schemaName, final ShardingSphereTable beBoChangedTable) {
alterTable(metaDataContexts.getMetaData().getDatabases().get(databaseName), schemaName, beBoChangedTable);
metaDataContexts.getOptimizerContext().alterTable(databaseName, schemaName, beBoChangedTable);
}
- private void alterTable(final ShardingSphereDatabase database, final String schemaName, final ShardingSphereTable beBoChangedTable) {
+ private synchronized void alterTable(final ShardingSphereDatabase database, final String schemaName, final ShardingSphereTable beBoChangedTable) {
if (containsMutableDataNodeRule(database, schemaName, beBoChangedTable.getName())) {
database.reloadRules(instanceContext);
}
@@ -189,7 +189,7 @@ public final class ContextManager implements AutoCloseable {
* @param databaseName database name
* @param schemaName schema name
*/
- public void dropSchema(final String databaseName, final String schemaName) {
+ public synchronized void dropSchema(final String databaseName, final String schemaName) {
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabases().get(databaseName);
if (null == database || !database.getSchemas().containsKey(schemaName)) {
return;
@@ -205,7 +205,7 @@ public final class ContextManager implements AutoCloseable {
* @param toBeAddedDataSourcePropsMap data source properties map
* @throws SQLException SQL exception
*/
- public void addResource(final String databaseName, final Map<String, DataSourceProperties> toBeAddedDataSourcePropsMap) throws SQLException {
+ public synchronized void addResource(final String databaseName, final Map<String, DataSourceProperties> toBeAddedDataSourcePropsMap) throws SQLException {
refreshMetaDataContextForAddResource(databaseName, toBeAddedDataSourcePropsMap);
metaDataContexts.getPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, toBeAddedDataSourcePropsMap));
}
@@ -217,7 +217,7 @@ public final class ContextManager implements AutoCloseable {
* @param toBeAlteredDataSourcePropsMap data source properties map
* @throws SQLException SQL exception
*/
- public void alterResource(final String databaseName, final Map<String, DataSourceProperties> toBeAlteredDataSourcePropsMap) throws SQLException {
+ public synchronized void alterResource(final String databaseName, final Map<String, DataSourceProperties> toBeAlteredDataSourcePropsMap) throws SQLException {
refreshMetaDataContextForAlterResource(databaseName, toBeAlteredDataSourcePropsMap);
metaDataContexts.getPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, toBeAlteredDataSourcePropsMap));
}
@@ -228,7 +228,7 @@ public final class ContextManager implements AutoCloseable {
* @param databaseName database name
* @param toBeDroppedResourceNames to be dropped resource names
*/
- public void dropResource(final String databaseName, final Collection<String> toBeDroppedResourceNames) {
+ public synchronized void dropResource(final String databaseName, final Collection<String> toBeDroppedResourceNames) {
Map<String, DataSource> dataSourceMap = metaDataContexts.getMetaData().getDatabases().get(databaseName).getResource().getDataSources();
// TODO should check to be dropped resources are unused here. ContextManager is atomic domain to maintain metadata, not Dist SQL handler
for (String each : toBeDroppedResourceNames) {
@@ -244,7 +244,7 @@ public final class ContextManager implements AutoCloseable {
* @param ruleConfigs rule configurations
*/
@SuppressWarnings("rawtypes")
- public void alterRuleConfiguration(final String databaseName, final Collection<RuleConfiguration> ruleConfigs) {
+ public synchronized void alterRuleConfiguration(final String databaseName, final Collection<RuleConfiguration> ruleConfigs) {
try {
Collection<ResourceHeldRule> staleResourceHeldRules = getStaleResourceHeldRules(databaseName);
metaDataContexts = createMetaDataContexts(databaseName, null, ruleConfigs);
@@ -262,7 +262,7 @@ public final class ContextManager implements AutoCloseable {
* @param dataSourcePropsMap altered data source properties map
*/
@SuppressWarnings("rawtypes")
- public void alterDataSourceConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
+ public synchronized void alterDataSourceConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
try {
Collection<ResourceHeldRule> staleResourceHeldRules = getStaleResourceHeldRules(databaseName);
SwitchingResource switchingResource = new ResourceSwitchManager().create(metaDataContexts.getMetaData().getDatabases().get(databaseName).getResource(), dataSourcePropsMap);
@@ -283,7 +283,7 @@ public final class ContextManager implements AutoCloseable {
* @param ruleConfigs rule configurations
*/
@SuppressWarnings("rawtypes")
- public void alterDataSourceAndRuleConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<RuleConfiguration> ruleConfigs) {
+ public synchronized void alterDataSourceAndRuleConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<RuleConfiguration> ruleConfigs) {
try {
Collection<ResourceHeldRule> staleResourceHeldRules = getStaleResourceHeldRules(databaseName);
SwitchingResource switchingResource = new ResourceSwitchManager().create(metaDataContexts.getMetaData().getDatabases().get(databaseName).getResource(), dataSourcePropsMap);
@@ -333,7 +333,7 @@ public final class ContextManager implements AutoCloseable {
*
* @param ruleConfigs global rule configuration
*/
- public void alterGlobalRuleConfiguration(final Collection<RuleConfiguration> ruleConfigs) {
+ public synchronized void alterGlobalRuleConfiguration(final Collection<RuleConfiguration> ruleConfigs) {
if (ruleConfigs.isEmpty()) {
return;
}
@@ -348,7 +348,7 @@ public final class ContextManager implements AutoCloseable {
*
* @param props properties to be altered
*/
- public void alterProperties(final Properties props) {
+ public synchronized void alterProperties(final Properties props) {
renewMetaDataContexts(rebuildMetaDataContexts(new ConfigurationProperties(props)));
}
@@ -357,7 +357,7 @@ public final class ContextManager implements AutoCloseable {
*
* @param databaseName database name to be reloaded
*/
- public void reloadMetaData(final String databaseName) {
+ public synchronized void reloadMetaData(final String databaseName) {
try {
Map<String, ShardingSphereSchema> schemas = loadActualSchema(databaseName);
deleteSchemas(databaseName, schemas);
@@ -375,7 +375,7 @@ public final class ContextManager implements AutoCloseable {
* @param schemaName schema name
* @param tableName logic table name
*/
- public void reloadMetaData(final String databaseName, final String schemaName, final String tableName) {
+ public synchronized void reloadMetaData(final String databaseName, final String schemaName, final String tableName) {
try {
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabases().get(databaseName);
GenericSchemaBuilderMaterials materials = new GenericSchemaBuilderMaterials(database.getProtocolType(),
@@ -394,7 +394,7 @@ public final class ContextManager implements AutoCloseable {
* @param dataSourceName data source name
* @param tableName logic table name
*/
- public void reloadMetaData(final String databaseName, final String schemaName, final String dataSourceName, final String tableName) {
+ public synchronized void reloadMetaData(final String databaseName, final String schemaName, final String dataSourceName, final String tableName) {
try {
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabases().get(databaseName);
GenericSchemaBuilderMaterials materials = new GenericSchemaBuilderMaterials(database.getProtocolType(), database.getResource().getDatabaseType(),
@@ -413,7 +413,7 @@ public final class ContextManager implements AutoCloseable {
* @param schemaName schema name
* @param dataSourceName data source name
*/
- public void reloadSchemaMetaData(final String databaseName, final String schemaName, final String dataSourceName) {
+ public synchronized void reloadSchemaMetaData(final String databaseName, final String schemaName, final String dataSourceName) {
try {
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabases().get(databaseName);
database.reloadRules(instanceContext);