diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.cn.md index d4e55840abb6a..da9530ce52eba 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.cn.md @@ -15,9 +15,9 @@ weight = 3 rules: - !READWRITE_SPLITTING dataSources: - (+): # 读写分离逻辑数据源名称 - write_data_source_name: # 写库数据源名称 - read_data_source_names: # 读库数据源名称,多个从数据源用逗号分隔 + (+): # 读写分离逻辑数据源名称,默认使用 Groovy 的行表达式 SPI 实现来解析 + write_data_source_name: # 写库数据源名称,默认使用 Groovy 的行表达式 SPI 实现来解析 + read_data_source_names: # 读库数据源名称,多个从数据源用逗号分隔,默认使用 Groovy 的行表达式 SPI 实现来解析 transactionalReadQueryStrategy (?): # 事务内读请求的路由策略,可选值:PRIMARY(路由至主库)、FIXED(同一事务内路由至固定数据源)、DYNAMIC(同一事务内路由至非固定数据源)。默认值:DYNAMIC loadBalancerName: # 负载均衡算法名称 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.en.md index 774ee427215ba..9f353992a56a1 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/rules/readwrite-splitting.en.md @@ -14,9 +14,9 @@ Read/write splitting YAML configuration is highly readable. The YAML format enab rules: - !READWRITE_SPLITTING dataSources: - (+): # Logic data source name of readwrite-splitting - write_data_source_name: # Write data source name - read_data_source_names: # Read data source names, multiple data source names separated with comma + (+): # Logic data source name of readwrite-splitting, which uses Groovy's Row Value Expressions SPI implementation to parse by default + write_data_source_name: # Write data source name, which uses Groovy's Row Value Expressions SPI implementation to parse by default + read_data_source_names: # Read data source names, multiple data source names separated with comma, which uses Groovy's Row Value Expressions SPI implementation to parse by default transactionalReadQueryStrategy (?): # Routing strategy for read query within a transaction, values include: PRIMARY (to primary), FIXED (to fixed data source), DYNAMIC (to any data source), default value: DYNAMIC loadBalancerName: # Load balance algorithm name diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java index 47fe2566649c2..821015fb3ca98 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java @@ -102,4 +102,24 @@ void assertGetDataSourceMapper() { Map> expected = Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0", "read_ds_1")); assertThat(actual, is(expected)); } + + @Test + void assertCreateReadwriteSplittingRuleWithRowValueExpressionImpl() { + ReadwriteSplittingDataSourceRuleConfiguration config = new ReadwriteSplittingDataSourceRuleConfiguration( + "${['readwrite']}_ds", + "${['write']}_ds", + Arrays.asList("read_ds_${['0']}", "read_ds_${['1']}", "read_ds_2", "read_ds_3"), + "random"); + ReadwriteSplittingRule readwriteSplittingRule = new ReadwriteSplittingRule( + "logic_db", + new ReadwriteSplittingRuleConfiguration( + Collections.singleton(config), Collections.singletonMap("random", new AlgorithmConfiguration("RANDOM", new Properties()))), + mock(InstanceContext.class)); + Optional actual = readwriteSplittingRule.findDataSourceRule("readwrite_ds"); + assertTrue(actual.isPresent()); + assertThat(actual.get().getName(), is("readwrite_ds")); + assertThat(actual.get().getReadwriteSplittingGroup().getWriteDataSource(), is("write_ds")); + assertThat(actual.get().getReadwriteSplittingGroup().getReadDataSources(), is(Arrays.asList("read_ds_0", "read_ds_1", "read_ds_2", "read_ds_3"))); + assertThat(actual.get().getLoadBalancer().getType(), is("RANDOM")); + } }