From 251d4e02d5ded0a8d7532e4054b9a3e2e7fac7bf Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Mon, 16 Oct 2023 13:39:31 +0800 Subject: [PATCH] Refactor ResourceSwitchManager --- .../manager/switcher/ResourceSwitchManager.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java index 9354d96412caa..6bbe82892610c 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java @@ -48,9 +48,8 @@ public final class ResourceSwitchManager { * @return created switching resource */ public SwitchingResource create(final ResourceMetaData resourceMetaData, final Map toBeChangedPropsMap) { - Map 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 mergedPropsMap = new LinkedHashMap<>(toBeChangedPropsMap.entrySet().stream() + .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); Map toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap); Map dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap); Map newDataSources = createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap); @@ -82,10 +81,8 @@ public SwitchingResource createByDropResource(final ResourceMetaData resourceMet * @return created switching resource */ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMetaData resourceMetaData, final Map toBeChangedPropsMap) { - Map 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 mergedPropsMap = new LinkedHashMap<>(toBeChangedPropsMap.entrySet().stream() + .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); Map toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap); Map staleStorageDataSources = getStaleDataSources(resourceMetaData, toBeChangedPropsMap); staleStorageDataSources.putAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageUnitNodeMap.values())); @@ -93,7 +90,7 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet staleStorageUnitNames.addAll(getToBeDeletedStorageUnitNames(resourceMetaData.getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet())); Map dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap); return new SwitchingResource( - createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, mergedDataSourcePoolPropsMap); + createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, mergedPropsMap); } private Map createNewDataSources(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageUnitNodeMap,