This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ce5ef68 [DistSQL] Fix the display problem of `show
readwrite_splitting read resources` statement. (#13866)
ce5ef68 is described below
commit ce5ef68fda6b7ef0958dfb746a07d88f1c6c8a4a
Author: lanchengx <[email protected]>
AuthorDate: Tue Nov 30 04:04:41 2021 -0600
[DistSQL] Fix the display problem of `show readwrite_splitting read
resources` statement. (#13866)
* Use the read resource in the configuration.
* Update comment.
---
.../infra/metadata/rule/ShardingSphereRuleMetaData.java | 11 +++++++++++
.../executor/ShowReadwriteSplittingReadResourcesExecutor.java | 7 ++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/rule/ShardingSphereRuleMetaData.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/rule/ShardingSphereRuleMetaData.java
index e417311..7927a41 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/rule/ShardingSphereRuleMetaData.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/rule/ShardingSphereRuleMetaData.java
@@ -49,6 +49,17 @@ public final class ShardingSphereRuleMetaData {
}
/**
+ * Find rule configuration by class.
+ *
+ * @param clazz target class
+ * @param <T> type of rule configuration
+ * @return found rule configurations
+ */
+ public <T extends RuleConfiguration> Collection<T>
findRuleConfiguration(final Class<T> clazz) {
+ return configurations.stream().filter(each ->
clazz.isAssignableFrom(each.getClass())).map(clazz::cast).collect(Collectors.toList());
+ }
+
+ /**
* Find single rule by class.
*
* @param clazz target class
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
index 6bda0c1..ae68713 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
@@ -28,6 +28,8 @@ import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import
org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
@@ -35,6 +37,7 @@ import java.sql.Types;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
@@ -88,7 +91,9 @@ public final class
ShowReadwriteSplittingReadResourcesExecutor extends AbstractS
}
private Collection<List<Object>> buildResourceRows(final
ShardingSphereMetaData metaData, final String status) {
- Set<String> allResources =
metaData.getResource().getDataSources().keySet();
+ Collection<ReadwriteSplittingRuleConfiguration> ruleConfiguration =
metaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class);
+ Set<String> allResources =
ruleConfiguration.stream().map(ReadwriteSplittingRuleConfiguration::getDataSources).flatMap(Collection::stream)
+
.map(ReadwriteSplittingDataSourceRuleConfiguration::getReadDataSourceNames).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
return allResources.stream().map(each -> buildRow(each,
status)).collect(Collectors.toCollection(LinkedList::new));
}