Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename StorageResource's variable names #28615

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static ShardingSphereDatabase create(final String name, final DatabaseTyp
}

private static ResourceMetaData createResourceMetaData(final String databaseName, final StorageResource storageResource, final Map<String, DataSourcePoolProperties> propsMap) {
return new ResourceMetaData(databaseName, storageResource.getDataSourceMap(), storageResource.getStorageUnitNodeMap(), propsMap);
return new ResourceMetaData(databaseName, storageResource.getDataSources(), storageResource.getStorageUnitNodeMap(), propsMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
@Getter
public final class ResourceMetaData {

private final Map<StorageNodeName, DataSource> dataSourceMap;
private final Map<StorageNodeName, DataSource> dataSources;

private final StorageUnitMetaData storageUnitMetaData;

public ResourceMetaData(final Map<String, DataSource> dataSources) {
dataSourceMap = StorageNodeUtils.getStorageNodeDataSources(dataSources);
storageUnitMetaData = new StorageUnitMetaData(null, dataSourceMap, dataSources.entrySet().stream()
this.dataSources = StorageNodeUtils.getStorageNodeDataSources(dataSources);
storageUnitMetaData = new StorageUnitMetaData(null, this.dataSources, dataSources.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)),
StorageUnitNodeMapUtils.fromDataSources(dataSources));
}

public ResourceMetaData(final String databaseName, final Map<StorageNodeName, DataSource> dataSourceMap,
public ResourceMetaData(final String databaseName, final Map<StorageNodeName, DataSource> dataSources,
final Map<String, StorageNode> storageUnitNodeMap, final Map<String, DataSourcePoolProperties> propsMap) {
this.dataSourceMap = dataSourceMap;
storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, propsMap, storageUnitNodeMap);
this.dataSources = dataSources;
storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSources, propsMap, storageUnitNodeMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
@Getter
public final class StorageResource {

private final Map<StorageNodeName, DataSource> dataSourceMap;
private final Map<StorageNodeName, DataSource> dataSources;

private final Map<String, StorageNode> storageUnitNodeMap;

private final Map<String, DataSource> wrappedDataSources;

public StorageResource(final Map<StorageNodeName, DataSource> dataSourceMap, final Map<String, StorageNode> storageUnitNodeMap) {
this.dataSourceMap = dataSourceMap;
public StorageResource(final Map<StorageNodeName, DataSource> dataSources, final Map<String, StorageNode> storageUnitNodeMap) {
this.dataSources = dataSources;
this.storageUnitNodeMap = storageUnitNodeMap;
wrappedDataSources = createWrappedDataSources();
}
Expand All @@ -49,7 +49,7 @@ private Map<String, DataSource> createWrappedDataSources() {
Map<String, DataSource> result = new LinkedHashMap<>(storageUnitNodeMap.size(), 1F);
for (Entry<String, StorageNode> entry : storageUnitNodeMap.entrySet()) {
StorageNode storageNode = entry.getValue();
DataSource dataSource = dataSourceMap.get(storageNode.getName());
DataSource dataSource = dataSources.get(storageNode.getName());
if (null != dataSource) {
result.put(entry.getKey(), new CatalogSwitchableDataSource(dataSource, storageNode.getCatalog(), storageNode.getUrl()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void assertGetDataSources() {
@Test
void assertGetStorageNodes() {
DataSourceGeneratedDatabaseConfiguration databaseConfig = createDataSourceGeneratedDatabaseConfiguration();
HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeName("normal_db"));
HikariDataSource hikariDataSource = (HikariDataSource) databaseConfig.getStorageResource().getDataSources().get(new StorageNodeName("normal_db"));
assertThat(hikariDataSource.getJdbcUrl(), is("jdbc:mock://127.0.0.1/normal_db"));
assertThat(hikariDataSource.getUsername(), is("root"));
assertThat(hikariDataSource.getPassword(), is(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void assertGetDataSources() {
@Test
void assertGetStorageNodes() {
DataSourceProvidedDatabaseConfiguration databaseConfig = createDataSourceProvidedDatabaseConfiguration();
MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSourceMap().get(new StorageNodeName("foo_ds"));
MockedDataSource dataSource = (MockedDataSource) databaseConfig.getStorageResource().getDataSources().get(new StorageNodeName("foo_ds"));
assertThat(dataSource.getUrl(), is("jdbc:mock://127.0.0.1/foo_ds"));
assertThat(dataSource.getUsername(), is("root"));
assertThat(dataSource.getPassword(), is("root"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void assertClose() throws Exception {
ShardingSphereDataSource actual = createShardingSphereDataSource(dataSource);
actual.close();
Map<StorageNodeName, DataSource> dataSourceMap = getContextManager(actual).getMetaDataContexts().getMetaData()
.getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSourceMap();
.getDatabase(DefaultDatabase.LOGIC_NAME).getResourceMetaData().getDataSources();
assertTrue(((HikariDataSource) dataSourceMap.get(new StorageNodeName("ds"))).isClosed());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private Collection<RuleConfiguration> decorateRuleConfigs(final String databaseN

private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) {
if (!databaseConfigs.getDataSources().isEmpty() && databaseConfigs.getDataSourcePoolPropertiesMap().isEmpty()) {
return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap());
return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSources());
}
return databaseConfigs.getDataSourcePoolPropertiesMap();
}
Expand All @@ -132,7 +132,7 @@ private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(fin
public Map<String, DataSourceConfiguration> getEffectiveDataSources(final String databaseName, final Map<String, ? extends DatabaseConfiguration> databaseConfigs) {
Map<String, DataSourcePoolProperties> propsMap = dataSourceUnitService.load(databaseName);
if (databaseConfigs.containsKey(databaseName) && !databaseConfigs.get(databaseName).getDataSources().isEmpty()) {
databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy());
databaseConfigs.get(databaseName).getStorageResource().getDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy());
}
return propsMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> DataSourcePoolPropertiesCreator.createConfiguration(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private Collection<RuleConfiguration> decorateRuleConfigs(final String databaseN

private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(final DatabaseConfiguration databaseConfigs) {
if (!databaseConfigs.getDataSources().isEmpty() && databaseConfigs.getDataSourcePoolPropertiesMap().isEmpty()) {
return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSourceMap());
return getDataSourcePoolPropertiesMap(databaseConfigs.getStorageResource().getDataSources());
}
return databaseConfigs.getDataSourcePoolPropertiesMap();
}
Expand All @@ -145,7 +145,7 @@ private Map<String, DataSourcePoolProperties> getDataSourcePoolPropertiesMap(fin
public Map<String, DataSourceConfiguration> getEffectiveDataSources(final String databaseName, final Map<String, ? extends DatabaseConfiguration> databaseConfigs) {
Map<String, DataSourcePoolProperties> propsMap = dataSourceUnitService.load(databaseName);
if (databaseConfigs.containsKey(databaseName) && !databaseConfigs.get(databaseName).getDataSources().isEmpty()) {
databaseConfigs.get(databaseName).getStorageResource().getDataSourceMap().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy());
databaseConfigs.get(databaseName).getStorageResource().getDataSources().values().forEach(each -> new DataSourcePoolDestroyer(each).asyncDestroy());
}
return propsMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> DataSourcePoolPropertiesCreator.createConfiguration(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void alterSchemaMetaData(final String databaseName, final ShardingSphereD
* @return ShardingSphere databases
*/
public Map<String, ShardingSphereDatabase> renewDatabase(final ShardingSphereDatabase database, final SwitchingResource resource) {
Map<StorageNodeName, DataSource> newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSourceMap(), resource);
Map<StorageNodeName, DataSource> newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSources(), resource);
Map<String, StorageNode> newStorageUnitNodeMap = getNewStorageUnitNodeMap(database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits(), resource);
Map<String, DataSourcePoolProperties> propsMap = database.getResourceMetaData().getStorageUnitMetaData().getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> currentValue, LinkedHashMap::new));
Expand All @@ -285,7 +285,7 @@ public Map<String, ShardingSphereDatabase> renewDatabase(final ShardingSphereDat
private Map<StorageNodeName, DataSource> getNewStorageNodes(final Map<StorageNodeName, DataSource> currentStorageNodes, final SwitchingResource resource) {
Map<StorageNodeName, DataSource> result = new LinkedHashMap<>();
for (Entry<StorageNodeName, DataSource> entry : currentStorageNodes.entrySet()) {
if (!resource.getStaleStorageResource().getDataSourceMap().containsKey(entry.getKey())) {
if (!resource.getStaleStorageResource().getDataSources().containsKey(entry.getKey())) {
result.put(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -364,10 +364,10 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re
}

private StorageResource getMergedStorageResource(final ResourceMetaData currentResourceMetaData, final SwitchingResource switchingResource) {
Map<StorageNodeName, DataSource> storageNodeDataSources = currentResourceMetaData.getDataSourceMap();
Map<StorageNodeName, DataSource> storageNodeDataSources = currentResourceMetaData.getDataSources();
Map<String, StorageNode> storageUnitNodeMap = currentResourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap();
if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSourceMap().isEmpty()) {
storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSourceMap());
if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSources().isEmpty()) {
storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSources());
}
if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getStorageUnitNodeMap().isEmpty()) {
storageUnitNodeMap.putAll(switchingResource.getNewStorageResource().getStorageUnitNodeMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private StorageResource getRegisterNewStorageResource(final ResourceMetaData res
Map<StorageNodeName, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageUnitNodeMapUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNodeName, DataSource> newStorageNodes = new LinkedHashMap<>(storageNodeNames.size(), 1F);
for (StorageNodeName each : storageNodeNames) {
if (!resourceMetaData.getDataSourceMap().containsKey(each)) {
if (!resourceMetaData.getDataSources().containsKey(each)) {
newStorageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each)));
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ private StorageResource getAlterNewStorageResource(final Map<String, StorageNode
private StorageResource getStaleStorageResource(final ResourceMetaData resourceMetaData, final Map<String, StorageNode> storageUintNodeMap) {
Collection<StorageNodeName> toBeAlteredStorageNodeNames = storageUintNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet());
Map<StorageNodeName, DataSource> storageNodes = new LinkedHashMap<>(toBeAlteredStorageNodeNames.size(), 1F);
for (Entry<StorageNodeName, DataSource> entry : resourceMetaData.getDataSourceMap().entrySet()) {
for (Entry<StorageNodeName, DataSource> entry : resourceMetaData.getDataSources().entrySet()) {
if (toBeAlteredStorageNodeNames.contains(entry.getKey())) {
storageNodes.put(entry.getKey(), entry.getValue());
}
Expand Down Expand Up @@ -124,7 +124,7 @@ private StorageResource getToBeRemovedStaleStorageResource(final ResourceMetaDat
Map<String, StorageNode> reservedStorageUintNodeMap = resourceMetaData.getStorageUnitMetaData().getStorageUnitNodeMap();
Map<StorageNodeName, DataSource> storageNodes = new LinkedHashMap<>(1, 1F);
if (reservedStorageUintNodeMap.values().stream().noneMatch(each -> each.equals(storageNode))) {
storageNodes.put(storageNode.getName(), resourceMetaData.getDataSourceMap().get(storageNode.getName()));
storageNodes.put(storageNode.getName(), resourceMetaData.getDataSources().get(storageNode.getName()));
}
return new StorageResource(storageNodes, Collections.singletonMap(storageUnitName, storageNode));
}
Expand Down
Loading