This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 9a3d47ef774 Fixes #29459, support shadow data source in
ReadwriteSplittingRuleConfigurationChecker (#29461)
9a3d47ef774 is described below
commit 9a3d47ef77441a78181e5bbf0f8b53eb5315316c
Author: Raigor <[email protected]>
AuthorDate: Wed Dec 20 08:55:47 2023 +0800
Fixes #29459, support shadow data source in
ReadwriteSplittingRuleConfigurationChecker (#29461)
---
.../ReadwriteSplittingRuleConfigurationChecker.java | 15 ++++++++-------
...eption.java => DataSourceNameNotExistedException.java} | 6 +++---
.../ReadwriteSplittingRuleConfigurationCheckerTest.java | 4 ++--
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
index 984a472bb09..932396f5ea7 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
@@ -19,17 +19,17 @@ package
org.apache.shardingsphere.readwritesplitting.checker;
import com.google.common.base.Strings;
import
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
+import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightReadQueryLoadBalanceAlgorithm;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
import
org.apache.shardingsphere.readwritesplitting.exception.algorithm.MissingRequiredReadDatabaseWeightException;
-import
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameExistedException;
+import
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameNotExistedException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.InvalidWeightLoadBalancerConfigurationException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.LoadBalancerAlgorithmNotFoundException;
@@ -73,7 +73,7 @@ public final class ReadwriteSplittingRuleConfigurationChecker
implements RuleCon
ShardingSpherePreconditions.checkState(!config.getReadDataSourceNames().isEmpty(),
() -> new MissingRequiredReadDataSourceNamesException(databaseName));
checkWriteDataSourceNames(databaseName, dataSourceMap,
addedWriteDataSourceNames, config, rules);
for (String each : config.getReadDataSourceNames()) {
- checkReadeDataSourceNames(databaseName, dataSourceMap,
readDataSourceNames, each);
+ checkReadeDataSourceNames(databaseName, dataSourceMap,
readDataSourceNames, each, rules);
}
}
@@ -81,7 +81,7 @@ public final class ReadwriteSplittingRuleConfigurationChecker
implements RuleCon
final
ReadwriteSplittingDataSourceRuleConfiguration config, final
Collection<ShardingSphereRule> rules) {
for (String each :
InlineExpressionParserFactory.newInstance(config.getWriteDataSourceName()).splitAndEvaluate())
{
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each) ||
containsInOtherRules(each, rules),
- () -> new
DataSourceNameExistedException(String.format("Write data source name `%s` not
in database `%s`.", each, databaseName)));
+ () -> new
DataSourceNameNotExistedException(String.format("Write data source name `%s`
not in database `%s`.", each, databaseName)));
ShardingSpherePreconditions.checkState(addedWriteDataSourceNames.add(each),
() -> new DuplicateDataSourceException(String.format("Can
not config duplicate write data source `%s` in database `%s`.", each,
databaseName)));
}
@@ -96,10 +96,11 @@ public final class
ReadwriteSplittingRuleConfigurationChecker implements RuleCon
return false;
}
- private void checkReadeDataSourceNames(final String databaseName, final
Map<String, DataSource> dataSourceMap, final Collection<String>
addedReadDataSourceNames, final String readDataSourceName) {
+ private void checkReadeDataSourceNames(final String databaseName, final
Map<String, DataSource> dataSourceMap,
+ final Collection<String>
addedReadDataSourceNames, final String readDataSourceName, final
Collection<ShardingSphereRule> rules) {
for (String each :
InlineExpressionParserFactory.newInstance(readDataSourceName).splitAndEvaluate())
{
-
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each),
- () -> new
DataSourceNameExistedException(String.format("Read data source name `%s` not in
database `%s`.", each, databaseName)));
+
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each) ||
containsInOtherRules(each, rules),
+ () -> new
DataSourceNameNotExistedException(String.format("Read data source name `%s` not
in database `%s`.", each, databaseName)));
ShardingSpherePreconditions.checkState(addedReadDataSourceNames.add(each),
() -> new DuplicateDataSourceException(String.format("Can
not config duplicate read data source `%s` in database `%s`.", each,
databaseName)));
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameExistedException.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameNotExistedException.java
similarity index 85%
rename from
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameExistedException.java
rename to
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameNotExistedException.java
index fe584542673..fea4dd5e33c 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameExistedException.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/DataSourceNameNotExistedException.java
@@ -21,13 +21,13 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
import
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
/**
- * Data source name existed exception.
+ * Data source name not existed exception.
*/
-public final class DataSourceNameExistedException extends
ReadwriteSplittingSQLException {
+public final class DataSourceNameNotExistedException extends
ReadwriteSplittingSQLException {
private static final long serialVersionUID = 1284608200400804784L;
- public DataSourceNameExistedException(final String reason) {
+ public DataSourceNameNotExistedException(final String reason) {
super(XOpenSQLState.NOT_FOUND, 94, reason);
}
}
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
index 49333d4424b..a57462250e0 100644
---
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java
@@ -23,7 +23,7 @@ import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedR
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameExistedException;
+import
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameNotExistedException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.InvalidWeightLoadBalancerConfigurationException;
import
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredWriteDataSourceNameException;
@@ -71,7 +71,7 @@ class ReadwriteSplittingRuleConfigurationCheckerTest {
"write_ds_0", Arrays.asList("read_ds_0", "read_ds_1")),
createDataSourceRuleConfig("write_ds_2", Arrays.asList("read_ds_0",
"read_ds_1")));
when(config.getDataSources()).thenReturn(configs);
RuleConfigurationChecker checker =
OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class,
Collections.singleton(config.getClass())).get(config.getClass());
- assertThrows(DataSourceNameExistedException.class, () ->
checker.check("test", config, mockDataSources(), Collections.emptyList()));
+ assertThrows(DataSourceNameNotExistedException.class, () ->
checker.check("test", config, mockDataSources(), Collections.emptyList()));
}
@SuppressWarnings({"rawtypes", "unchecked"})