Skip to content

Commit

Permalink
Refactor DataSourceStateManager (apache#31006)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Apr 25, 2024
1 parent 0a06b5b commit 71784ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
import org.apache.shardingsphere.infra.state.datasource.exception.UnavailableDataSourceException;

import javax.sql.DataSource;
Expand Down Expand Up @@ -148,12 +149,11 @@ private void checkForceConnection(final Map<String, DataSource> dataSources) {
/**
* Update data source state.
*
* @param databaseName database name
* @param actualDataSourceName actual data source name
* @param qualifiedDataSource qualified data source
* @param dataSourceState data source state
*/
public void updateState(final String databaseName, final String actualDataSourceName, final DataSourceState dataSourceState) {
dataSourceStates.put(getCacheKey(databaseName, actualDataSourceName), dataSourceState);
public void updateState(final QualifiedDataSource qualifiedDataSource, final DataSourceState dataSourceState) {
dataSourceStates.put(getCacheKey(qualifiedDataSource.getDatabaseName(), qualifiedDataSource.getDataSourceName()), dataSourceState);
}

private String getCacheKey(final String databaseName, final String dataSourceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public synchronized void renew(final StorageNodeChangedEvent event) {
if (!contextManager.getMetaDataContexts().getMetaData().containsDatabase(qualifiedDataSource.getDatabaseName())) {
return;
}
DataSourceStateManager.getInstance().updateState(
qualifiedDataSource.getDatabaseName(), qualifiedDataSource.getDataSourceName(), DataSourceState.valueOf(event.getDataSource().getStatus().name()));
DataSourceStateManager.getInstance().updateState(qualifiedDataSource, DataSourceState.valueOf(event.getDataSource().getStatus().name()));
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(qualifiedDataSource.getDatabaseName());
for (StaticDataSourceRuleAttribute each : database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) {
each.updateStatus(qualifiedDataSource, event.getDataSource().getStatus());
Expand Down

0 comments on commit 71784ca

Please sign in to comment.