You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/10/27 02:43:29 UTC
[shardingsphere] branch master updated: fix wrong route result when
db-discovery and readwrite-splitting are integrated (#13286)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 741e283 fix wrong route result when db-discovery and readwrite-splitting are integrated (#13286)
741e283 is described below
commit 741e28347c1812eeba5778a1e08bb41ab1293ef3
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Oct 27 10:42:51 2021 +0800
fix wrong route result when db-discovery and readwrite-splitting are integrated (#13286)
* fix shadow getDataSourceMapper logic
* fix wrong route result when db-discovery and readwrite-splitting are integrated
---
.../dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java | 9 +++++----
.../dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java | 2 +-
.../dbdiscovery/rule/DatabaseDiscoveryRuleTest.java | 2 +-
.../java/org/apache/shardingsphere/shadow/rule/ShadowRule.java | 4 ++--
4 files changed, 9 insertions(+), 8 deletions(-)
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 74c736f..eb54338 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
@@ -24,9 +24,9 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -110,9 +110,10 @@ public final class DatabaseDiscoveryDataSourceRule {
* @return data source mapper
*/
public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>(1, 1);
- Collection<String> actualDataSourceNames = new LinkedList<>(dataSourceNames);
- result.put(name, actualDataSourceNames);
+ Map<String, Collection<String>> result = new HashMap<>(dataSourceNames.size(), 1);
+ for (String each : dataSourceNames) {
+ result.put(each, 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 fa9f645..fbe8832 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
@@ -77,7 +77,7 @@ public final class DatabaseDiscoveryDataSourceRuleTest {
@Test
public void assertGetDataSourceMapper() {
Map<String, Collection<String>> actual = databaseDiscoveryDataSourceRule.getDataSourceMapper();
- Map<String, Collection<String>> expected = ImmutableMap.of("test_pr", Arrays.asList("ds_0", "ds_1"));
+ Map<String, Collection<String>> expected = ImmutableMap.of("ds_0", Collections.singletonList("ds_0"), "ds_1", Collections.singletonList("ds_1"));
assertThat(actual, is(expected));
}
}
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 5665bd2..00ea6d0 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
@@ -90,7 +90,7 @@ public final class DatabaseDiscoveryRuleTest {
public void assertGetDataSourceMapper() {
DatabaseDiscoveryRule databaseDiscoveryRule = createRule();
Map<String, Collection<String>> actual = databaseDiscoveryRule.getDataSourceMapper();
- Map<String, Collection<String>> expected = ImmutableMap.of("test_pr", Arrays.asList("ds_0", "ds_1"));
+ Map<String, Collection<String>> expected = ImmutableMap.of("ds_0", Collections.singletonList("ds_0"), "ds_1", Collections.singletonList("ds_1"));
assertThat(actual, is(expected));
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 87eadb2..f8bef95 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -32,8 +32,8 @@ import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -199,7 +199,7 @@ public final class ShadowRule implements SchemaRule, DataSourceContainedRule {
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
return shadowDataSourceMappings.values().stream().collect(Collectors.toMap(ShadowDataSourceRule::getSourceDataSource, each ->
- Collections.singletonList(each.getShadowDataSource()), (key, value) -> value, () -> new HashMap<>(shadowDataSourceMappings.size(), 1)));
+ Arrays.asList(each.getSourceDataSource(), each.getShadowDataSource()), (key, value) -> value, () -> new HashMap<>(shadowDataSourceMappings.size(), 1)));
}
@Override