You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/05/25 10:18:20 UTC
[shardingsphere] branch master updated: Update result of SHOW READWRITE_SPLITTING RULES (#25884)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 711514e2c16 Update result of SHOW READWRITE_SPLITTING RULES (#25884)
711514e2c16 is described below
commit 711514e2c16ea354df23055a673561c6d01a6042
Author: Raigor <ra...@gmail.com>
AuthorDate: Thu May 25 18:18:12 2023 +0800
Update result of SHOW READWRITE_SPLITTING RULES (#25884)
* For #25871, update result of SHOW READWRITE_SPLITTING RULES
* Update test cases.
* Update test cases.
---
.../ReadwriteSplittingRuleStatementChecker.java | 1 +
.../query/ShowReadwriteSplittingRuleExecutor.java | 8 ++++--
.../ShowReadwriteSplittingRuleExecutorTest.java | 33 +++++++---------------
.../imports/readwrite-splitting/RALStatement.g4 | 4 ---
.../imports/readwrite-splitting/RDLStatement.g4 | 6 +++-
.../ReadwriteSplittingDistSQLStatementVisitor.java | 4 +--
.../show_readwrite_splitting_rules.xml | 21 +++++++-------
.../show_readwrite_splitting_rules.xml | 21 +++++++-------
.../show_readwrite_splitting_rules.xml | 3 +-
.../show_readwrite_splitting_rules.xml | 3 +-
10 files changed, 49 insertions(+), 55 deletions(-)
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 4bf93c3847f..3666cc3adf4 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -83,6 +83,7 @@ public final class ReadwriteSplittingRuleStatementChecker {
checkRuleNamesExist(segments, currentRuleConfig, databaseName);
checkDataSourcesExist(databaseName, segments, database);
checkDuplicatedDataSourceNames(databaseName, segments, currentRuleConfig, false);
+ checkTransactionalReadQueryStrategy(segments);
checkLoadBalancers(segments);
}
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
index f4c183b0568..7f41911cdeb 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java
@@ -63,8 +63,9 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
private Collection<LocalDataQueryResultRow> buildData(final ReadwriteSplittingRule rule, final ShowReadwriteSplittingRulesStatement sqlStatement) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- ((ReadwriteSplittingRuleConfiguration) rule.getConfiguration()).getDataSources().forEach(each -> {
- LocalDataQueryResultRow dataItem = buildDataItem(each, getLoadBalancers((ReadwriteSplittingRuleConfiguration) rule.getConfiguration()));
+ ReadwriteSplittingRuleConfiguration ruleConfig = (ReadwriteSplittingRuleConfiguration) rule.getConfiguration();
+ ruleConfig.getDataSources().forEach(each -> {
+ LocalDataQueryResultRow dataItem = buildDataItem(each, getLoadBalancers(ruleConfig));
if (null == sqlStatement.getRuleName() || sqlStatement.getRuleName().equalsIgnoreCase(each.getName())) {
result.add(dataItem);
}
@@ -79,6 +80,7 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
return new LocalDataQueryResultRow(name,
getWriteDataSourceName(dataSourceRuleConfig, exportDataSources),
getReadDataSourceNames(dataSourceRuleConfig, exportDataSources),
+ dataSourceRuleConfig.getTransactionalReadQueryStrategy().name(),
loadBalancer.map(AlgorithmConfiguration::getType).orElse(""),
loadBalancer.map(each -> PropertiesConverter.convert(each.getProps())).orElse(""));
}
@@ -100,7 +102,7 @@ public final class ShowReadwriteSplittingRuleExecutor implements RQLExecutor<Sho
@Override
public Collection<String> getColumnNames() {
- return Arrays.asList("name", "write_storage_unit_name", "read_storage_unit_names", "load_balancer_type", "load_balancer_props");
+ return Arrays.asList("name", "write_storage_unit_name", "read_storage_unit_names", "transactional_read_query_strategy", "load_balancer_type", "load_balancer_props");
}
@Override
diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
index f9c86abeef9..840bf64aae0 100644
--- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
+++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryRes
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingRulesStatement;
@@ -38,7 +37,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -74,8 +72,9 @@ class ShowReadwriteSplittingRuleExecutorTest {
assertThat(row.getCell(1), is("readwrite_ds"));
assertThat(row.getCell(2), is("ds_primary"));
assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1"));
- assertThat(row.getCell(4), is("random"));
- assertThat(row.getCell(5), is("read_weight=2:1"));
+ assertThat(row.getCell(4), is("DYNAMIC"));
+ assertThat(row.getCell(5), is("random"));
+ assertThat(row.getCell(6), is("read_weight=2:1"));
}
@Test
@@ -93,8 +92,9 @@ class ShowReadwriteSplittingRuleExecutorTest {
assertThat(row.getCell(1), is("readwrite_ds"));
assertThat(row.getCell(2), is("ds_primary"));
assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1"));
- assertThat(row.getCell(4), is("random"));
- assertThat(row.getCell(5), is("read_weight=2:1"));
+ assertThat(row.getCell(4), is("DYNAMIC"));
+ assertThat(row.getCell(5), is("random"));
+ assertThat(row.getCell(6), is("read_weight=2:1"));
}
private Map<String, Object> createExportedData() {
@@ -126,8 +126,9 @@ class ShowReadwriteSplittingRuleExecutorTest {
assertThat(row.getCell(1), is("readwrite_ds"));
assertThat(row.getCell(2), is("write_ds"));
assertThat(row.getCell(3), is("read_ds_0,read_ds_1"));
- assertThat(row.getCell(4), is(""));
+ assertThat(row.getCell(4), is("DYNAMIC"));
assertThat(row.getCell(5), is(""));
+ assertThat(row.getCell(6), is(""));
}
private RuleConfiguration createRuleConfigurationWithoutLoadBalancer() {
@@ -140,27 +141,13 @@ class ShowReadwriteSplittingRuleExecutorTest {
void assertGetColumnNames() {
RQLExecutor<ShowReadwriteSplittingRulesStatement> executor = new ShowReadwriteSplittingRuleExecutor();
Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(5));
+ assertThat(columns.size(), is(6));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("name"));
assertThat(iterator.next(), is("write_storage_unit_name"));
assertThat(iterator.next(), is("read_storage_unit_names"));
+ assertThat(iterator.next(), is("transactional_read_query_strategy"));
assertThat(iterator.next(), is("load_balancer_type"));
assertThat(iterator.next(), is("load_balancer_props"));
}
-
- private Map<String, Object> getExportData() {
- Map<String, Object> result = new HashMap<>(2, 1F);
- result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
- return result;
- }
-
- private Map<String, Map<String, String>> exportStaticDataSources() {
- Map<String, Map<String, String>> result = new LinkedHashMap<>();
- Map<String, String> staticRule = new LinkedHashMap<>(2, 1F);
- staticRule.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "ds_0");
- staticRule.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "ds_1");
- result.put("static_rule_1", staticRule);
- return result;
- }
}
diff --git a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4 b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
index 72130ee1c5d..d94b56d3a99 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
+++ b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
@@ -26,7 +26,3 @@ alterReadwriteSplittingStorageUnitStatus
showStatusFromReadwriteSplittingRules
: SHOW STATUS FROM READWRITE_SPLITTING (RULES | RULE groupName) (FROM databaseName)?
;
-
-sourceValue
- : IDENTIFIER_
- ;
diff --git a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4 b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
index 344c43b4ef1..0b49507f937 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
+++ b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
@@ -32,7 +32,11 @@ dropReadwriteSplittingRule
;
readwriteSplittingRuleDefinition
- : ruleName LP_ writeStorageUnit COMMA_ readStorageUnits (COMMA_ transactionalReadQueryStrategy)? (COMMA_ algorithmDefinition)? RP_
+ : ruleName LP_ dataSourceDefinition (COMMA_ transactionalReadQueryStrategy)? (COMMA_ algorithmDefinition)? RP_
+ ;
+
+dataSourceDefinition
+ : writeStorageUnit COMMA_ readStorageUnits
;
ruleName
diff --git a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
index 506880ac73a..688364c2b71 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++ b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -86,8 +86,8 @@ public final class ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitReadwriteSplittingRuleDefinition(final ReadwriteSplittingRuleDefinitionContext ctx) {
- return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.writeStorageUnit().writeStorageUnitName()),
- ctx.readStorageUnits().readStorageUnitsNames().storageUnitName().stream().map(this::getIdentifierValue).collect(Collectors.toList()),
+ return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.dataSourceDefinition().writeStorageUnit().writeStorageUnitName()),
+ ctx.dataSourceDefinition().readStorageUnits().readStorageUnitsNames().storageUnitName().stream().map(this::getIdentifierValue).collect(Collectors.toList()),
null == ctx.transactionalReadQueryStrategy() ? null : getIdentifierValue(ctx.transactionalReadQueryStrategy().transactionalReadQueryStrategyName()),
null == ctx.algorithmDefinition() ? null : (AlgorithmSegment) visitAlgorithmDefinition(ctx.algorithmDefinition()));
}
diff --git a/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml b/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
index 590da7c2fbf..aa3c02be03a 100644
--- a/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
+++ b/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting/show_readwrite_splitting_rules.xml
@@ -20,17 +20,18 @@
<column name="name" />
<column name="write_storage_unit_name" />
<column name="read_storage_unit_names" />
+ <column name="transactional_read_query_strategy" />
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| write_ds_0| read_ds_0| ROUND_ROBIN| " />
- <row values="readwrite_ds_1| write_ds_1| read_ds_1| ROUND_ROBIN| " />
- <row values="readwrite_ds_2| write_ds_2| read_ds_2| ROUND_ROBIN| " />
- <row values="readwrite_ds_3| write_ds_3| read_ds_3| ROUND_ROBIN| " />
- <row values="readwrite_ds_4| write_ds_4| read_ds_4| ROUND_ROBIN| " />
- <row values="readwrite_ds_5| write_ds_5| read_ds_5| ROUND_ROBIN| " />
- <row values="readwrite_ds_6| write_ds_6| read_ds_6| ROUND_ROBIN| " />
- <row values="readwrite_ds_7| write_ds_7| read_ds_7| ROUND_ROBIN| " />
- <row values="readwrite_ds_8| write_ds_8| read_ds_8| ROUND_ROBIN| " />
- <row values="readwrite_ds_9| write_ds_9| read_ds_9| ROUND_ROBIN| " />
+ <row values="readwrite_ds_0| write_ds_0| read_ds_0| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| write_ds_1| read_ds_1| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_2| write_ds_2| read_ds_2| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_3| write_ds_3| read_ds_3| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_4| write_ds_4| read_ds_4| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_5| write_ds_5| read_ds_5| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_6| write_ds_6| read_ds_6| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_7| write_ds_7| read_ds_7| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_8| write_ds_8| read_ds_8| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_9| write_ds_9| read_ds_9| DYNAMIC| ROUND_ROBIN| " />
</dataset>
diff --git a/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml b/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
index adfbb584a52..99c9b1d65f1 100644
--- a/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
+++ b/test/e2e/sql/src/test/resources/cases/rql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/show_readwrite_splitting_rules.xml
@@ -20,17 +20,18 @@
<column name="name" />
<column name="write_storage_unit_name" />
<column name="read_storage_unit_names" />
+ <column name="transactional_read_query_strategy" />
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds_0| encrypt_write_ds_0| encrypt_read_ds_0| ROUND_ROBIN| " />
- <row values="readwrite_ds_1| encrypt_write_ds_1| encrypt_read_ds_1| ROUND_ROBIN| " />
- <row values="readwrite_ds_2| encrypt_write_ds_2| encrypt_read_ds_2| ROUND_ROBIN| " />
- <row values="readwrite_ds_3| encrypt_write_ds_3| encrypt_read_ds_3| ROUND_ROBIN| " />
- <row values="readwrite_ds_4| encrypt_write_ds_4| encrypt_read_ds_4| ROUND_ROBIN| " />
- <row values="readwrite_ds_5| encrypt_write_ds_5| encrypt_read_ds_5| ROUND_ROBIN| " />
- <row values="readwrite_ds_6| encrypt_write_ds_6| encrypt_read_ds_6| ROUND_ROBIN| " />
- <row values="readwrite_ds_7| encrypt_write_ds_7| encrypt_read_ds_7| ROUND_ROBIN| " />
- <row values="readwrite_ds_8| encrypt_write_ds_8| encrypt_read_ds_8| ROUND_ROBIN| " />
- <row values="readwrite_ds_9| encrypt_write_ds_9| encrypt_read_ds_9| ROUND_ROBIN| " />
+ <row values="readwrite_ds_0| encrypt_write_ds_0| encrypt_read_ds_0| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_1| encrypt_write_ds_1| encrypt_read_ds_1| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_2| encrypt_write_ds_2| encrypt_read_ds_2| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_3| encrypt_write_ds_3| encrypt_read_ds_3| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_4| encrypt_write_ds_4| encrypt_read_ds_4| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_5| encrypt_write_ds_5| encrypt_read_ds_5| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_6| encrypt_write_ds_6| encrypt_read_ds_6| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_7| encrypt_write_ds_7| encrypt_read_ds_7| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_8| encrypt_write_ds_8| encrypt_read_ds_8| DYNAMIC| ROUND_ROBIN| " />
+ <row values="readwrite_ds_9| encrypt_write_ds_9| encrypt_read_ds_9| DYNAMIC| ROUND_ROBIN| " />
</dataset>
diff --git a/test/e2e/sql/src/test/resources/cases/rql/dataset/encrypt_and_readwrite_splitting/show_readwrite_splitting_rules.xml b/test/e2e/sql/src/test/resources/cases/rql/dataset/encrypt_and_readwrite_splitting/show_readwrite_splitting_rules.xml
index d79df1cf3c4..c8200396280 100644
--- a/test/e2e/sql/src/test/resources/cases/rql/dataset/encrypt_and_readwrite_splitting/show_readwrite_splitting_rules.xml
+++ b/test/e2e/sql/src/test/resources/cases/rql/dataset/encrypt_and_readwrite_splitting/show_readwrite_splitting_rules.xml
@@ -20,8 +20,9 @@
<column name="name" />
<column name="write_storage_unit_name" />
<column name="read_storage_unit_names" />
+ <column name="transactional_read_query_strategy" />
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="readwrite_ds| encrypt_write_ds| encrypt_read_ds| ROUND_ROBIN| " />
+ <row values="readwrite_ds| encrypt_write_ds| encrypt_read_ds| DYNAMIC| ROUND_ROBIN| " />
</dataset>
diff --git a/test/e2e/sql/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml b/test/e2e/sql/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
index 8a764131c53..6cad618f6a0 100644
--- a/test/e2e/sql/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
+++ b/test/e2e/sql/src/test/resources/cases/rql/dataset/readwrite_splitting/show_readwrite_splitting_rules.xml
@@ -20,8 +20,9 @@
<column name="name" />
<column name="write_storage_unit_name" />
<column name="read_storage_unit_names" />
+ <column name="transactional_read_query_strategy" />
<column name="load_balancer_type" />
<column name="load_balancer_props" />
</metadata>
- <row values="write-read-ds| write_ds| read_0,read_1| | " />
+ <row values="write-read-ds| write_ds| read_0,read_1| DYNAMIC| | " />
</dataset>