Skip to content

Commit

Permalink
Revert "Get reloaded metadata asynchronously after rule configuration…
Browse files Browse the repository at this point in the history
… altered (apache#34236)"

This reverts commit 2849b62
  • Loading branch information
menghaoranss committed Jan 4, 2025
1 parent 52a599d commit 7fee89e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 132 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,13 @@ public class MetaDataContextManager {

private final RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine;

private final MetaDataContextHolder metaDataContextHolder;

public MetaDataContextManager(final AtomicReference<MetaDataContexts> metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext, final PersistRepository repository) {
this.metaDataContexts = metaDataContexts;
this.computeNodeInstanceContext = computeNodeInstanceContext;
metaDataContextHolder = new MetaDataContextHolder(metaDataContexts);
resourceSwitchManager = new ResourceSwitchManager();
databaseManager = new ShardingSphereDatabaseDataManager(metaDataContexts);
storageUnitManager = new StorageUnitManager(metaDataContexts, computeNodeInstanceContext, repository, resourceSwitchManager);
databaseRuleConfigurationManager = new DatabaseRuleConfigurationManager(metaDataContextHolder, computeNodeInstanceContext, repository);
databaseRuleConfigurationManager = new DatabaseRuleConfigurationManager(metaDataContexts, computeNodeInstanceContext, repository);
schemaMetaDataManager = new SchemaMetaDataManager(metaDataContexts, repository);
ruleItemManager = new RuleItemManager(metaDataContexts, repository, databaseRuleConfigurationManager);
globalConfigurationManager = new GlobalConfigurationManager(metaDataContexts, repository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.metadata.MetaDataContextHolder;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory;
import org.apache.shardingsphere.mode.spi.PersistRepository;
Expand All @@ -36,22 +35,23 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
* Database rule configuration manager.
*/
public final class DatabaseRuleConfigurationManager {

private final MetaDataContextHolder metaDataContextHolder;
private final AtomicReference<MetaDataContexts> metaDataContexts;

private final ComputeNodeInstanceContext computeNodeInstanceContext;

private final MetaDataPersistService metaDataPersistService;

public DatabaseRuleConfigurationManager(final MetaDataContextHolder metaDataContextHolder, final ComputeNodeInstanceContext computeNodeInstanceContext,
public DatabaseRuleConfigurationManager(final AtomicReference<MetaDataContexts> metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext,
final PersistRepository repository) {
this.metaDataContextHolder = metaDataContextHolder;
this.metaDataContexts = metaDataContexts;
this.computeNodeInstanceContext = computeNodeInstanceContext;
metaDataPersistService = new MetaDataPersistService(repository);
}
Expand All @@ -65,7 +65,7 @@ public DatabaseRuleConfigurationManager(final MetaDataContextHolder metaDataCont
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public synchronized void alterRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) throws SQLException {
ShardingSphereDatabase database = metaDataContextHolder.getMetaDataContexts().get().getMetaData().getDatabase(databaseName);
ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName);
Collection<ShardingSphereRule> rules = new LinkedList<>(database.getRuleMetaData().getRules());
Optional<ShardingSphereRule> toBeChangedRule = rules.stream().filter(each -> each.getConfiguration().getClass().equals(ruleConfig.getClass())).findFirst();
if (toBeChangedRule.isPresent() && toBeChangedRule.get() instanceof PartialRuleUpdateSupported && ((PartialRuleUpdateSupported) toBeChangedRule.get()).partialUpdate(ruleConfig)) {
Expand All @@ -87,7 +87,7 @@ public synchronized void alterRuleConfiguration(final String databaseName, final
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public synchronized void dropRuleConfiguration(final String databaseName, final RuleConfiguration ruleConfig) throws SQLException {
ShardingSphereDatabase database = metaDataContextHolder.getMetaDataContexts().get().getMetaData().getDatabase(databaseName);
ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName);
Collection<ShardingSphereRule> rules = new LinkedList<>(database.getRuleMetaData().getRules());
Optional<ShardingSphereRule> toBeChangedRule = rules.stream().filter(each -> each.getConfiguration().getClass().equals(ruleConfig.getClass())).findFirst();
if (toBeChangedRule.isPresent() && toBeChangedRule.get() instanceof PartialRuleUpdateSupported && ((PartialRuleUpdateSupported) toBeChangedRule.get()).partialUpdate(ruleConfig)) {
Expand All @@ -104,8 +104,8 @@ public synchronized void dropRuleConfiguration(final String databaseName, final

private void refreshMetadata(final String databaseName, final Collection<RuleConfiguration> ruleConfigurations) throws SQLException {
MetaDataContexts reloadMetaDataContexts = MetaDataContextsFactory.createByAlterRule(databaseName, false,
ruleConfigurations, metaDataContextHolder.getMetaDataContexts().get(), metaDataPersistService, computeNodeInstanceContext);
metaDataContextHolder.updateMetaDataContextsAsync(reloadMetaDataContexts);
ruleConfigurations, metaDataContexts.get(), metaDataPersistService, computeNodeInstanceContext);
metaDataContexts.set(reloadMetaDataContexts);
}

private Collection<RuleConfiguration> getRuleConfigurations(final Collection<ShardingSphereRule> rules) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur
}

private void afterRuleConfigurationAltered(final String databaseName, final MetaDataContexts originalMetaDataContexts) {
MetaDataContexts reloadMetaDataContexts = metaDataContextManager.getMetaDataContextHolder().getMetaDataContextsAsync();
if (!reloadMetaDataContexts.equals(originalMetaDataContexts)) {
metaDataPersistService.persistReloadDatabaseByAlter(
databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName));
}
MetaDataContexts reloadMetaDataContexts = metaDataContextManager.getMetaDataContexts().get();
metaDataPersistService.persistReloadDatabaseByAlter(
databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName));
}

@Override
Expand All @@ -237,11 +235,9 @@ public void removeRuleConfiguration(final String databaseName, final String rule
}

private void afterRuleConfigurationDropped(final String databaseName, final MetaDataContexts originalMetaDataContexts) {
MetaDataContexts reloadMetaDataContexts = metaDataContextManager.getMetaDataContextHolder().getMetaDataContextsAsync();
if (!reloadMetaDataContexts.equals(originalMetaDataContexts)) {
metaDataPersistService.persistReloadDatabaseByDrop(
databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName));
}
MetaDataContexts reloadMetaDataContexts = metaDataContextManager.getMetaDataContexts().get();
metaDataPersistService.persistReloadDatabaseByDrop(
databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), originalMetaDataContexts.getMetaData().getDatabase(databaseName));
}

@Override
Expand Down

0 comments on commit 7fee89e

Please sign in to comment.