Skip to content

Commit

Permalink
Refactor ResourceSwitchManager (#28767)
Browse files Browse the repository at this point in the history
* Refactor ResourceSwitchManager

* Fix ci

* Fix ci
  • Loading branch information
zhaojinchao95 authored Oct 16, 2023
1 parent dd5257d commit 291ee68
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ public final class ResourceSwitchManager {
* @return created switching resource
*/
public SwitchingResource create(final ResourceMetaData resourceMetaData, final Map<String, DataSourcePoolProperties> toBeChangedPropsMap) {
Map<String, DataSourcePoolProperties> mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
mergedPropsMap.putAll(toBeChangedPropsMap);
Map<String, StorageNode> toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap);
Map<StorageNode, DataSourcePoolProperties> dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap);
Map<StorageNode, DataSource> newDataSources = createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap);
Map<StorageNode, DataSource> staleDataSources = getStaleDataSources(resourceMetaData, mergedPropsMap);
return new SwitchingResource(newDataSources, staleDataSources, getStaleStorageUnitNames(resourceMetaData, toBeChangedStorageUnitNodeMap), mergedPropsMap);
Map<StorageNode, DataSource> staleDataSources = getStaleDataSources(resourceMetaData, toBeChangedPropsMap);
return new SwitchingResource(newDataSources, staleDataSources, getStaleStorageUnitNames(resourceMetaData, toBeChangedStorageUnitNodeMap), toBeChangedPropsMap);
}

/**
Expand All @@ -82,18 +79,14 @@ public SwitchingResource createByDropResource(final ResourceMetaData resourceMet
* @return created switching resource
*/
public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMetaData resourceMetaData, final Map<String, DataSourcePoolProperties> toBeChangedPropsMap) {
Map<String, DataSourcePoolProperties> mergedDataSourcePoolPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
mergedDataSourcePoolPropsMap.keySet().removeIf(each -> !toBeChangedPropsMap.containsKey(each));
mergedDataSourcePoolPropsMap.putAll(toBeChangedPropsMap);
Map<String, StorageNode> toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap);
Map<StorageNode, DataSource> staleStorageDataSources = getStaleDataSources(resourceMetaData, toBeChangedPropsMap);
staleStorageDataSources.putAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageUnitNodeMap.values()));
Collection<String> staleStorageUnitNames = getStaleStorageUnitNames(resourceMetaData, toBeChangedStorageUnitNodeMap);
staleStorageUnitNames.addAll(getToBeDeletedStorageUnitNames(resourceMetaData.getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet()));
Map<StorageNode, DataSourcePoolProperties> dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap);
return new SwitchingResource(
createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, mergedDataSourcePoolPropsMap);
createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, toBeChangedPropsMap);
}

private Map<StorageNode, DataSource> createNewDataSources(final ResourceMetaData resourceMetaData, final Map<String, StorageNode> toBeChangedStorageUnitNodeMap,
Expand Down
Loading

0 comments on commit 291ee68

Please sign in to comment.