This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 030cda89be1 Fix not route primary data source when only use
db-discovery (#18960)
030cda89be1 is described below
commit 030cda89be16ab83ec85bf266a50daef92e55bc4
Author: zhaojinchao <[email protected]>
AuthorDate: Fri Jul 8 18:59:28 2022 +0800
Fix not route primary data source when only use db-discovery (#18960)
* Fix not route primary data source when only use db-discovery
* fix
---
.../dbdiscovery/route/DatabaseDiscoverySQLRouter.java | 6 +++---
.../dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java | 2 +-
.../dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java | 3 +--
.../shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java | 3 +--
4 files changed, 6 insertions(+), 8 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
index 010bc01d8bb..aed1481843d 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
@@ -23,7 +23,6 @@ import
org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryDataSourceRul
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.DefaultDatabase;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -43,8 +42,9 @@ public final class DatabaseDiscoverySQLRouter implements
SQLRouter<DatabaseDisco
@Override
public RouteContext createRouteContext(final LogicSQL logicSQL, final
ShardingSphereDatabase database, final DatabaseDiscoveryRule rule, final
ConfigurationProperties props) {
RouteContext result = new RouteContext();
- String dataSourceName = new
DatabaseDiscoveryDataSourceRouter(rule.getSingleDataSourceRule()).route();
- result.getRouteUnits().add(new RouteUnit(new
RouteMapper(DefaultDatabase.LOGIC_NAME, dataSourceName),
Collections.emptyList()));
+ DatabaseDiscoveryDataSourceRule singleDataSourceRule =
rule.getSingleDataSourceRule();
+ String dataSourceName = new
DatabaseDiscoveryDataSourceRouter(singleDataSourceRule).route();
+ result.getRouteUnits().add(new RouteUnit(new
RouteMapper(singleDataSourceRule.getGroupName(), dataSourceName),
Collections.emptyList()));
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
index c4064f23434..162dec1ac8b 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
@@ -108,7 +108,7 @@ public final class DatabaseDiscoveryDataSourceRule {
public Map<String, Collection<String>> getDataSourceMapper() {
Map<String, Collection<String>> result = new
HashMap<>(dataSourceNames.size(), 1);
for (String each : dataSourceNames) {
- result.put(each, Collections.singletonList(each));
+ result.put(groupName, Collections.singletonList(each));
}
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
index 44cc24f579c..a5619b92976 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
@@ -67,8 +67,7 @@ public final class DatabaseDiscoveryDataSourceRuleTest {
private Map<String, Collection<String>> getExpectedDataSourceMapper() {
Map<String, Collection<String>> result = new LinkedHashMap<>(2, 1);
- result.put("ds_0", Collections.singletonList("ds_0"));
- result.put("ds_1", Collections.singletonList("ds_1"));
+ result.put("test_pr", Collections.singletonList("ds_1"));
return result;
}
}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index 69acbd0152a..deb7eb92d18 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -73,8 +73,7 @@ public final class DatabaseDiscoveryRuleTest {
private Map<String, Collection<String>> getDataSourceMapper() {
Map<String, Collection<String>> result = new HashMap<>(2, 1);
- result.put("ds_0", Collections.singletonList("ds_0"));
- result.put("ds_1", Collections.singletonList("ds_1"));
+ result.put("test_pr", Collections.singletonList("ds_1"));
return result;
}