diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java index 08966ba1036a2..97a3254e7d4b6 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java @@ -104,11 +104,12 @@ public T getSingleRule(final Class clazz) { */ public Map>> getInUsedStorageUnitNameAndRulesMap() { Map>> result = new LinkedHashMap<>(); - for (DataSourceContainedRule each : findRules(DataSourceContainedRule.class)) { - result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(each))); - } - for (DataNodeContainedRule each : findRules(DataNodeContainedRule.class)) { - result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(each))); + for (ShardingSphereRule each : rules) { + if (each instanceof DataSourceContainedRule) { + result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames((DataSourceContainedRule) each))); + } else if (each instanceof DataNodeContainedRule) { + result.putAll(getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames((DataNodeContainedRule) each))); + } } return result; } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java index 2952998e9585d..25604d8d3db42 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java @@ -98,16 +98,14 @@ private Map getDataSourcePoolPropertiesMap(fin if (usageCount.isPresent()) { Map>> inUsedStorageUnits = database.getRuleMetaData().getInUsedStorageUnitNameAndRulesMap(); for (Entry entry : database.getResourceMetaData().getStorageUnits().entrySet()) { - Integer currentUsageCount = inUsedStorageUnits.containsKey(entry.getKey()) ? inUsedStorageUnits.get(entry.getKey()).size() : 0; + int currentUsageCount = inUsedStorageUnits.containsKey(entry.getKey()) ? inUsedStorageUnits.get(entry.getKey()).size() : 0; if (usageCount.get().equals(currentUsageCount)) { - result.put(entry.getKey(), getDataSourcePoolProperties( - propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource())); + result.put(entry.getKey(), getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource())); } } } else { for (Entry entry : storageUnits.entrySet()) { - result.put(entry.getKey(), - getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource())); + result.put(entry.getKey(), getDataSourcePoolProperties(propsMap, entry.getKey(), storageUnits.get(entry.getKey()).getStorageType(), entry.getValue().getDataSource())); } } return result;