This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 bf6957b61ed For #25871, support transactionalReadQueryStrategy for 
readwrite_splitting RDL. (#25875)
bf6957b61ed is described below

commit bf6957b61ed0c9630e27f0369776b1005bfcd18d
Author: Raigor <[email protected]>
AuthorDate: Thu May 25 10:06:35 2023 +0800

    For #25871, support transactionalReadQueryStrategy for readwrite_splitting 
RDL. (#25875)
---
 .../ReadwriteSplittingRuleStatementChecker.java    |  26 ++--
 .../ReadwriteSplittingRuleStatementConverter.java  |   7 +-
 ...ReadwriteSplittingRuleStatementUpdaterTest.java |  11 --
 ...ReadwriteSplittingRuleStatementUpdaterTest.java |   9 --
 .../antlr4/imports/readwrite-splitting/BaseRule.g4 |   4 -
 .../antlr4/imports/readwrite-splitting/Keyword.g4  |   4 +
 .../imports/readwrite-splitting/RDLStatement.g4    |  18 ++-
 .../ReadwriteSplittingDistSQLStatementVisitor.java |   5 +-
 .../segment/ReadwriteSplittingRuleSegment.java     |  23 +---
 infra/parser/pom.xml                               |   5 -
 .../test/resources/conf/convert/config-mix.yaml    | 149 +++++++++++----------
 .../src/test/resources/expected/convert-mix.yaml   |   6 +-
 .../distsql/rdl/ReadwriteSplittingRuleAssert.java  |  33 +++--
 .../rdl/ExceptedReadwriteSplittingRule.java        |   6 +-
 .../parser/src/main/resources/case/rdl/create.xml  |  14 +-
 .../main/resources/sql/supported/rdl/create.xml    |   5 +-
 16 files changed, 170 insertions(+), 155 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 d125dfb6990..4bf93c3847f 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
@@ -31,9 +31,11 @@ import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePrecondition
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
 import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -63,6 +65,7 @@ public final class ReadwriteSplittingRuleStatementChecker {
         String databaseName = database.getName();
         checkDataSourcesExist(databaseName, segments, database);
         checkDuplicatedDataSourceNames(databaseName, segments, 
currentRuleConfig, true);
+        checkTransactionalReadQueryStrategy(segments);
         checkLoadBalancers(segments);
     }
     
@@ -143,20 +146,12 @@ public final class ReadwriteSplittingRuleStatementChecker 
{
     
     private static void checkDataSourcesExist(final String databaseName, final 
Collection<ReadwriteSplittingRuleSegment> segments, final 
ShardingSphereDatabase database) {
         Collection<String> requiredDataSources = new LinkedHashSet<>();
-        Collection<String> requiredLogicalDataSources = new LinkedHashSet<>();
         segments.forEach(each -> {
-            if (Strings.isNullOrEmpty(each.getAutoAwareResource())) {
-                requiredDataSources.add(each.getWriteDataSource());
-                requiredDataSources.addAll(each.getReadDataSources());
-            } else {
-                requiredLogicalDataSources.add(each.getAutoAwareResource());
-            }
+            requiredDataSources.add(each.getWriteDataSource());
+            requiredDataSources.addAll(each.getReadDataSources());
         });
         Collection<String> notExistedDataSources = 
database.getResourceMetaData().getNotExistedDataSources(requiredDataSources);
         
ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () -> 
new MissingRequiredStorageUnitsException(databaseName, notExistedDataSources));
-        Collection<String> logicalDataSources = getLogicDataSources(database);
-        Collection<String> notExistedLogicalDataSources = 
requiredLogicalDataSources.stream().filter(each -> 
!logicalDataSources.contains(each)).collect(Collectors.toSet());
-        
ShardingSpherePreconditions.checkState(notExistedLogicalDataSources.isEmpty(), 
() -> new MissingRequiredStorageUnitsException(databaseName, 
notExistedLogicalDataSources));
     }
     
     private static Collection<String> getLogicDataSources(final 
ShardingSphereDatabase database) {
@@ -211,6 +206,17 @@ public final class ReadwriteSplittingRuleStatementChecker {
         }
     }
     
+    private static void checkTransactionalReadQueryStrategy(final 
Collection<ReadwriteSplittingRuleSegment> segments) {
+        Collection<String> validStrategyNames = 
Arrays.stream(TransactionalReadQueryStrategy.values()).map(Enum::name).collect(Collectors.toSet());
+        for (ReadwriteSplittingRuleSegment each : segments) {
+            if (null != each.getTransactionalReadQueryStrategy()) {
+                
ShardingSpherePreconditions.checkState(validStrategyNames.contains(each.getTransactionalReadQueryStrategy().toUpperCase()),
+                        () -> new InvalidRuleConfigurationException(
+                                "Readwrite-splitting", each.getName(), 
String.format("Invalid transactional read query strategy `%s`.", 
each.getTransactionalReadQueryStrategy())));
+            }
+        }
+    }
+    
     private static void checkLoadBalancers(final 
Collection<ReadwriteSplittingRuleSegment> segments) {
         
segments.stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).filter(Objects::nonNull)
                 .forEach(each -> 
TypedSPILoader.checkService(ReadQueryLoadBalanceAlgorithm.class, 
each.getName(), each.getProps()));
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
index eb881ac3cea..af4ae8cd450 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverter.java
@@ -22,9 +22,9 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -59,7 +59,10 @@ public final class ReadwriteSplittingRuleStatementConverter {
     
     private static ReadwriteSplittingDataSourceRuleConfiguration 
createDataSourceRuleConfiguration(final ReadwriteSplittingRuleSegment segment,
                                                                                
                    final String loadBalancerName) {
-        return new 
ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(), 
segment.getWriteDataSource(), new ArrayList<>(segment.getReadDataSources()), 
loadBalancerName);
+        return null == segment.getTransactionalReadQueryStrategy()
+                ? new 
ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(), 
segment.getWriteDataSource(), new LinkedList<>(segment.getReadDataSources()), 
loadBalancerName)
+                : new 
ReadwriteSplittingDataSourceRuleConfiguration(segment.getName(), 
segment.getWriteDataSource(), new LinkedList<>(segment.getReadDataSources()),
+                        
TransactionalReadQueryStrategy.valueOf(segment.getTransactionalReadQueryStrategy().toUpperCase()),
 loadBalancerName);
     }
     
     private static AlgorithmConfiguration createLoadBalancer(final 
ReadwriteSplittingRuleSegment ruleSegment) {
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
index acdd3640fbc..eb1fa4cc703 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java
@@ -23,7 +23,6 @@ import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRe
 import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
-import 
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
 import 
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -81,16 +80,6 @@ class AlterReadwriteSplittingRuleStatementUpdaterTest {
         assertThrows(MissingRequiredStorageUnitsException.class, () -> 
updater.checkSQLStatement(database, createSQLStatement("TEST"), 
createCurrentRuleConfiguration()));
     }
     
-    @Test
-    void assertCheckSQLStatementWithoutExistedAutoAwareResources() {
-        DataSourceContainedRule dataSourceContainedRule = 
mock(DataSourceContainedRule.class);
-        
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group",
 Collections.singleton("ds_0")));
-        
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
-        ReadwriteSplittingRuleSegment ruleSegment = new 
ReadwriteSplittingRuleSegment("readwrite_ds", "ha_group", new 
AlgorithmSegment("TEST", new Properties()));
-        assertThrows(MissingRequiredStorageUnitsException.class,
-                () -> updater.checkSQLStatement(database, new 
AlterReadwriteSplittingRuleStatement(Collections.singleton(ruleSegment)), 
createCurrentRuleConfiguration()));
-    }
-    
     @Test
     void assertCheckSQLStatementWithoutToBeAlteredLoadBalancers() {
         
when(database.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList());
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
index f628b643d7b..30f05426fec 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -100,15 +100,6 @@ class CreateReadwriteSplittingRuleStatementUpdaterTest {
         assertThrows(InvalidRuleConfigurationException.class, () -> 
updater.checkSQLStatement(database, createSQLStatement(false, ruleSegment), 
null));
     }
     
-    @Test
-    void assertCheckSQLStatementWithoutExistedAutoAwareResources() {
-        DataSourceContainedRule dataSourceContainedRule = 
mock(DataSourceContainedRule.class);
-        
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group",
 Collections.singleton("ds_0")));
-        
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
-        ReadwriteSplittingRuleSegment ruleSegment = new 
ReadwriteSplittingRuleSegment("dynamic_rule", "ha_group", new 
AlgorithmSegment("TEST", new Properties()));
-        assertThrows(MissingRequiredStorageUnitsException.class, () -> 
updater.checkSQLStatement(database, createSQLStatement(false, ruleSegment), 
null));
-    }
-    
     @Test
     void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() {
         
when(database.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList());
diff --git 
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
 
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
index 5c772a9a846..8b23e50147a 100644
--- 
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
+++ 
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
@@ -52,10 +52,6 @@ property
 databaseName
     : IDENTIFIER_
     ;
-    
-resourceName
-    : IDENTIFIER_
-    ;
 
 groupName
     : IDENTIFIER_
diff --git 
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
 
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
index 36fbfb88a1c..3965f963225 100644
--- 
a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
+++ 
b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
@@ -67,6 +67,10 @@ READ_STORAGE_UNITS
     : R E A D UL_ S T O R A G E UL_ U N I T S
     ;
 
+TRANSACTIONAL_READ_QUERY_STRATEGY
+    : T R A N S A C T I O N A L UL_ R E A D UL_ Q U E R Y UL_ S T R A T E G Y
+    ;
+
 TYPE
     : T Y P E
     ;
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 355c20261cd..344c43b4ef1 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,13 +32,25 @@ dropReadwriteSplittingRule
     ;
 
 readwriteSplittingRuleDefinition
-    : ruleName LP_ WRITE_STORAGE_UNIT EQ_ writeStorageUnitName COMMA_ 
READ_STORAGE_UNITS LP_ readStorageUnitsNames RP_ (COMMA_ algorithmDefinition)? 
RP_
+    : ruleName LP_ writeStorageUnit COMMA_ readStorageUnits (COMMA_ 
transactionalReadQueryStrategy)? (COMMA_ algorithmDefinition)? RP_
     ;
 
 ruleName
     : IDENTIFIER_
     ;
 
+writeStorageUnit
+    : WRITE_STORAGE_UNIT EQ_ writeStorageUnitName
+    ;
+
+readStorageUnits
+    : READ_STORAGE_UNITS LP_ readStorageUnitsNames RP_
+    ;
+
+transactionalReadQueryStrategy
+    : TRANSACTIONAL_READ_QUERY_STRATEGY EQ_ transactionalReadQueryStrategyName
+    ;
+
 writeStorageUnitName
     : storageUnitName
     ;
@@ -47,6 +59,10 @@ readStorageUnitsNames
     : storageUnitName (COMMA_ storageUnitName)*
     ;
 
+transactionalReadQueryStrategyName
+    : STRING_
+    ;
+
 ifExists
     : IF EXISTS
     ;
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 473488214ff..506880ac73a 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,9 @@ public final class ReadwriteSplittingDistSQLStatementVisitor 
extends ReadwriteSp
     
     @Override
     public ASTNode visitReadwriteSplittingRuleDefinition(final 
ReadwriteSplittingRuleDefinitionContext ctx) {
-        return new 
ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), 
getIdentifierValue(ctx.writeStorageUnitName()),
-                
ctx.readStorageUnitsNames().storageUnitName().stream().map(this::getIdentifierValue).collect(Collectors.toList()),
+        return new 
ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), 
getIdentifierValue(ctx.writeStorageUnit().writeStorageUnitName()),
+                
ctx.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/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/segment/ReadwriteSplittingRuleSegment.java
 
b/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/segment/ReadwriteSplittingRuleSegment.java
index efc7913a0de..8c176e4ac36 100644
--- 
a/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/segment/ReadwriteSplittingRuleSegment.java
+++ 
b/features/readwrite-splitting/distsql/statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/segment/ReadwriteSplittingRuleSegment.java
@@ -17,8 +17,6 @@
 
 package org.apache.shardingsphere.readwritesplitting.distsql.parser.segment;
 
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
@@ -29,34 +27,21 @@ import java.util.Collection;
 /**
  * Readwrite-splitting rule segment.
  */
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+@RequiredArgsConstructor
 @Getter
 public final class ReadwriteSplittingRuleSegment implements ASTNode {
     
     private final String name;
     
-    private final String autoAwareResource;
-    
     private final String writeDataSource;
     
     private final Collection<String> readDataSources;
     
-    private final AlgorithmSegment loadBalancer;
+    private final String transactionalReadQueryStrategy;
     
-    public ReadwriteSplittingRuleSegment(final String name, final String 
autoAwareResource, final AlgorithmSegment loadBalancer) {
-        this(name, autoAwareResource, null, null, loadBalancer);
-    }
+    private final AlgorithmSegment loadBalancer;
     
     public ReadwriteSplittingRuleSegment(final String name, final String 
writeDataSource, final Collection<String> readDataSources, final 
AlgorithmSegment loadBalancer) {
-        this(name, null, writeDataSource, readDataSources, loadBalancer);
-    }
-    
-    /**
-     * Is it an auto aware type.
-     *
-     * @return is auto ware or not
-     */
-    public boolean isAutoAware() {
-        return !Strings.isNullOrEmpty(autoAwareResource);
+        this(name, writeDataSource, readDataSources, null, loadBalancer);
     }
 }
diff --git a/infra/parser/pom.xml b/infra/parser/pom.xml
index a6d35263558..97bb78c5c06 100644
--- a/infra/parser/pom.xml
+++ b/infra/parser/pom.xml
@@ -33,11 +33,6 @@
             <artifactId>shardingsphere-parser-distsql-engine</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-infra-common</artifactId>
-            <version>${project.version}</version>
-        </dependency>
         
         <dependency>
             <groupId>com.github.ben-manes.caffeine</groupId>
diff --git a/proxy/backend/core/src/test/resources/conf/convert/config-mix.yaml 
b/proxy/backend/core/src/test/resources/conf/convert/config-mix.yaml
index 2d160978169..8999c74c0be 100644
--- a/proxy/backend/core/src/test/resources/conf/convert/config-mix.yaml
+++ b/proxy/backend/core/src/test/resources/conf/convert/config-mix.yaml
@@ -74,75 +74,80 @@ dataSources:
     minPoolSize: 1
 
 rules:
-  - !SHARDING
-    tables:
-      t_order:
-        actualDataNodes: replica_ds_${0..1}.t_order_${0..1}
-        tableStrategy:
-          standard:
-            shardingColumn: order_id
-            shardingAlgorithmName: t_order_inline
-        keyGenerateStrategy:
-          column: order_id
-          keyGeneratorName: snowflake
-    defaultDatabaseStrategy:
-      standard:
-        shardingColumn: user_id
-        shardingAlgorithmName: database_inline
-    shardingAlgorithms:
-      database_inline:
-        type: INLINE
-        props:
-          algorithm-expression: replica_ds_${user_id % 2}
-      t_order_inline:
-        type: INLINE
-        props:
-          algorithm-expression: t_order_${order_id % 2}
-      t_order_item_inline:
-        type: INLINE
-        props:
-          algorithm-expression: t_order_item_${order_id % 2}
-    keyGenerators:
-      snowflake:
-        type: SNOWFLAKE
-  - !READWRITE_SPLITTING
-    dataSources:
-      readwrite_ds_0:
-        writeDataSourceName: ds_0
-        readDataSourceNames:
-          - ds_1
-          - ds_2
-      readwrite_ds_1:
-        writeDataSourceName: ds_3
-        readDataSourceNames:
-          - ds_4
-          - ds_5
-  - !ENCRYPT
-    encryptors:
-      aes_encryptor:
-        type: AES
-        props:
-          aes-key-value: 123456abc
-      rc4_encryptor:
-        type: RC4
-        props:
-          rc4-key-value: 123456abc
-      like_encryptor:
-        type: CHAR_DIGEST_LIKE
-    tables:
-      t_encrypt:
-        columns:
-          user_id:
-            cipher:
-              name: user_cipher
-              encryptorName: aes_encryptor
-            assistedQuery:
-              name: user_assisted
-              encryptorName: rc4_encryptor
-            likeQuery:
-              name: user_like
-              encryptorName: like_encryptor
-          order_id:
-            cipher:
-              name: order_cipher
-              encryptorName: rc4_encryptor
+- !SHARDING
+  tables:
+    t_order:
+      actualDataNodes: replica_ds_${0..1}.t_order_${0..1}
+      tableStrategy:
+        standard:
+          shardingColumn: order_id
+          shardingAlgorithmName: t_order_inline
+      keyGenerateStrategy:
+        column: order_id
+        keyGeneratorName: snowflake
+  defaultDatabaseStrategy:
+    standard:
+      shardingColumn: user_id
+      shardingAlgorithmName: database_inline
+  shardingAlgorithms:
+    database_inline:
+      type: INLINE
+      props:
+        algorithm-expression: replica_ds_${user_id % 2}
+    t_order_inline:
+      type: INLINE
+      props:
+        algorithm-expression: t_order_${order_id % 2}
+    t_order_item_inline:
+      type: INLINE
+      props:
+        algorithm-expression: t_order_item_${order_id % 2}
+  keyGenerators:
+    snowflake:
+      type: SNOWFLAKE
+- !READWRITE_SPLITTING
+  dataSources:
+    readwrite_ds_0:
+      writeDataSourceName: ds_0
+      readDataSourceNames:
+        - ds_1
+        - ds_2
+      loadBalancerName: random
+    readwrite_ds_1:
+      writeDataSourceName: ds_3
+      readDataSourceNames:
+        - ds_4
+        - ds_5
+      loadBalancerName: random
+  loadBalancers:
+    random:
+      type: RANDOM
+- !ENCRYPT
+  encryptors:
+    aes_encryptor:
+      type: AES
+      props:
+        aes-key-value: 123456abc
+    rc4_encryptor:
+      type: RC4
+      props:
+        rc4-key-value: 123456abc
+    like_encryptor:
+      type: CHAR_DIGEST_LIKE
+  tables:
+    t_encrypt:
+      columns:
+        user_id:
+          cipher:
+            name: user_cipher
+            encryptorName: aes_encryptor
+          assistedQuery:
+            name: user_assisted
+            encryptorName: rc4_encryptor
+          likeQuery:
+            name: user_like
+            encryptorName: like_encryptor
+        order_id:
+          cipher:
+            name: order_cipher
+            encryptorName: rc4_encryptor
diff --git a/proxy/backend/core/src/test/resources/expected/convert-mix.yaml 
b/proxy/backend/core/src/test/resources/expected/convert-mix.yaml
index f5d20d85d4f..360977d1386 100644
--- a/proxy/backend/core/src/test/resources/expected/convert-mix.yaml
+++ b/proxy/backend/core/src/test/resources/expected/convert-mix.yaml
@@ -51,10 +51,12 @@ PROPERTIES('minPoolSize'='1', 
'connectionTimeoutMilliseconds'='30000', 'maxLifet
 
 CREATE READWRITE_SPLITTING RULE readwrite_ds_0 (
 WRITE_STORAGE_UNIT=ds_0,
-READ_STORAGE_UNITS(ds_1,ds_2)
+READ_STORAGE_UNITS(ds_1,ds_2),
+TYPE(NAME='random')
 ), readwrite_ds_1 (
 WRITE_STORAGE_UNIT=ds_3,
-READ_STORAGE_UNITS(ds_4,ds_5)
+READ_STORAGE_UNITS(ds_4,ds_5),
+TYPE(NAME='random')
 );
 
 CREATE ENCRYPT RULE t_encrypt (
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/distsql/rdl/ReadwriteSplittingRuleAssert.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/distsql/rdl/ReadwriteSplittingRuleAssert.java
index 5a3b7bb456b..d845125877f 100644
--- 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/distsql/rdl/ReadwriteSplittingRuleAssert.java
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/distsql/rdl/ReadwriteSplittingRuleAssert.java
@@ -19,9 +19,11 @@ package 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.di
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.distsql.PropertiesAssert;
+import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ExpectedAlgorithm;
 import 
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.rdl.ExceptedReadwriteSplittingRule;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -49,20 +51,31 @@ public final class ReadwriteSplittingRuleAssert {
             assertNotNull(actual, assertContext.getText("Actual 
readwrite-splitting rule should exit."));
             assertThat(assertContext.getText(String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
                     actual.getClass().getSimpleName())), actual.getName(), 
is(expected.getName()));
-            assertThat(assertContext.getText(String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
-                    actual.getClass().getSimpleName())), 
actual.getAutoAwareResource(), is(expected.getAutoAwareResource()));
             assertThat(assertContext.getText(String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
                     actual.getClass().getSimpleName())), 
actual.getWriteDataSource(), is(expected.getWriteDataSource()));
             assertThat(assertContext.getText(String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
                     actual.getClass().getSimpleName())), 
actual.getReadDataSources(), is(expected.getReadDataSources()));
-            if (null == actual.getLoadBalancer()) {
-                assertNull(expected.getLoadBalancer(), String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
-                        actual.getClass().getSimpleName()));
-            } else {
-                assertThat(assertContext.getText(String.format("`%s`'s 
readwrite-splitting rule segment assertion error: ",
-                        actual.getClass().getSimpleName())), 
actual.getLoadBalancer().getName(), is(expected.getLoadBalancer().getName()));
-                PropertiesAssert.assertIs(assertContext, 
actual.getLoadBalancer().getProps(), 
expected.getLoadBalancer().getProperties());
-            }
+            assertTransactionalReadQueryStrategy(assertContext, actual, 
expected);
+            assertLoadBalancer(assertContext, actual.getLoadBalancer(), 
expected.getLoadBalancer());
+        }
+    }
+    
+    private static void assertTransactionalReadQueryStrategy(final 
SQLCaseAssertContext assertContext, final ReadwriteSplittingRuleSegment actual, 
final ExceptedReadwriteSplittingRule expected) {
+        if (null == expected.getTransactionalReadQueryStrategy()) {
+            assertNull(actual.getTransactionalReadQueryStrategy(), 
assertContext.getText("Actual transactional read query strategy should not 
exist."));
+        } else {
+            assertNotNull(actual.getTransactionalReadQueryStrategy(), 
assertContext.getText("Actual transactional read query strategy should 
exist."));
+            assertThat(assertContext.getText("Transactional read query 
strategy assertion error"), actual.getTransactionalReadQueryStrategy(), 
is(expected.getTransactionalReadQueryStrategy()));
+        }
+    }
+    
+    private static void assertLoadBalancer(final SQLCaseAssertContext 
assertContext, final AlgorithmSegment actual, final ExpectedAlgorithm expected) 
{
+        if (null == expected) {
+            assertNull(actual, assertContext.getText("Actual load balancer 
should not exist."));
+        } else {
+            assertNotNull(actual, assertContext.getText("Actual load balancer 
should exist."));
+            assertThat(assertContext.getText("Load balancer assertion error"), 
actual.getName(), is(expected.getName()));
+            PropertiesAssert.assertIs(assertContext, actual.getProps(), 
expected.getProperties());
         }
     }
 }
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/distsql/rdl/ExceptedReadwriteSplittingRule.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/distsql/rdl/ExceptedReadwriteSplittingRule.java
index 4ca984fce6a..ad578bdb713 100644
--- 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/distsql/rdl/ExceptedReadwriteSplittingRule.java
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/distsql/rdl/ExceptedReadwriteSplittingRule.java
@@ -33,15 +33,15 @@ import java.util.List;
 @Setter
 public final class ExceptedReadwriteSplittingRule extends 
AbstractExpectedIdentifierSQLSegment {
     
-    @XmlAttribute(name = "auto-aware-resource")
-    private String autoAwareResource;
-    
     @XmlAttribute(name = "write-data-source")
     private String writeDataSource;
     
     @XmlElement(name = "read-data-source")
     private List<String> readDataSources;
     
+    @XmlAttribute(name = "transactional-read-query-strategy")
+    private String transactionalReadQueryStrategy;
+    
     @XmlElement(name = "load-balancer")
     private ExpectedAlgorithm loadBalancer;
 }
diff --git a/test/it/parser/src/main/resources/case/rdl/create.xml 
b/test/it/parser/src/main/resources/case/rdl/create.xml
index feadd28a59c..d1e44ab7660 100644
--- a/test/it/parser/src/main/resources/case/rdl/create.xml
+++ b/test/it/parser/src/main/resources/case/rdl/create.xml
@@ -320,7 +320,7 @@
         <table>t_2</table>
     </create-broadcast-table-rule>
     
-    <create-readwrite-splitting-rule 
sql-case-id="create-static-readwrite-splitting-rule">
+    <create-readwrite-splitting-rule 
sql-case-id="create-readwrite-splitting-rule">
         <rule name="ms_group_0" write-data-source="primary_ds">
             <read-data-source>replica_ds_0</read-data-source>
             <read-data-source>replica_ds_1</read-data-source>
@@ -328,14 +328,22 @@
         </rule>
     </create-readwrite-splitting-rule>
     
-    <create-readwrite-splitting-rule 
sql-case-id="create-static-readwrite-splitting-rule-if-not-exists" 
if-not-exists="true">
+    <create-readwrite-splitting-rule 
sql-case-id="create-readwrite-splitting-rule-if-not-exists" 
if-not-exists="true">
         <rule name="ms_group_0" write-data-source="primary_ds">
             <read-data-source>replica_ds_0</read-data-source>
             <read-data-source>replica_ds_1</read-data-source>
             <load-balancer algorithm-name="random" />
         </rule>
     </create-readwrite-splitting-rule>
-
+    
+    <create-readwrite-splitting-rule 
sql-case-id="create-readwrite-splitting-rule-with-transactional-read-query-strategy">
+        <rule name="ms_group_0" write-data-source="primary_ds" 
transactional-read-query-strategy="DYNAMIC">
+            <read-data-source>replica_ds_0</read-data-source>
+            <read-data-source>replica_ds_1</read-data-source>
+            <load-balancer algorithm-name="random" />
+        </rule>
+    </create-readwrite-splitting-rule>
+    
     <create-readwrite-splitting-rule 
sql-case-id="create-readwrite-splitting-rule-with-quota">
         <rule name="ms_group_0" write-data-source="primary_ds">
             <read-data-source>replica_ds_0</read-data-source>
diff --git a/test/it/parser/src/main/resources/sql/supported/rdl/create.xml 
b/test/it/parser/src/main/resources/sql/supported/rdl/create.xml
index 53076539569..7ba52f0ccef 100644
--- a/test/it/parser/src/main/resources/sql/supported/rdl/create.xml
+++ b/test/it/parser/src/main/resources/sql/supported/rdl/create.xml
@@ -36,8 +36,9 @@
     <sql-case id="create-sharding-table-reference-rule-with-quota" 
value="CREATE SHARDING TABLE REFERENCE RULE reference_0 
(`t_order`,`t_order_item`), reference_1 (t_1,t_2)" db-types="ShardingSphere" />
     <sql-case id="create-broadcast-table-rule" value="CREATE BROADCAST TABLE 
RULE t_1,t_2" db-types="ShardingSphere" />
     <sql-case id="create-broadcast-table-rule-if-not-exists" value="CREATE 
BROADCAST TABLE RULE IF NOT EXISTS t_1,t_2" db-types="ShardingSphere" />
-    <sql-case id="create-static-readwrite-splitting-rule" value="CREATE 
READWRITE_SPLITTING RULE ms_group_0 (WRITE_STORAGE_UNIT=primary_ds, 
READ_STORAGE_UNITS(replica_ds_0,replica_ds_1), TYPE(NAME='random'))" 
db-types="ShardingSphere" />
-    <sql-case id="create-static-readwrite-splitting-rule-if-not-exists" 
value="CREATE READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 
(WRITE_STORAGE_UNIT=primary_ds, READ_STORAGE_UNITS(replica_ds_0,replica_ds_1), 
TYPE(NAME='random'))" db-types="ShardingSphere" />
+    <sql-case id="create-readwrite-splitting-rule" value="CREATE 
READWRITE_SPLITTING RULE ms_group_0 (WRITE_STORAGE_UNIT=primary_ds, 
READ_STORAGE_UNITS(replica_ds_0,replica_ds_1), TYPE(NAME='random'))" 
db-types="ShardingSphere" />
+    <sql-case id="create-readwrite-splitting-rule-if-not-exists" value="CREATE 
READWRITE_SPLITTING RULE IF NOT EXISTS ms_group_0 
(WRITE_STORAGE_UNIT=primary_ds, READ_STORAGE_UNITS(replica_ds_0,replica_ds_1), 
TYPE(NAME='random'))" db-types="ShardingSphere" />
+    <sql-case 
id="create-readwrite-splitting-rule-with-transactional-read-query-strategy" 
value="CREATE READWRITE_SPLITTING RULE ms_group_0 
(WRITE_STORAGE_UNIT=primary_ds, READ_STORAGE_UNITS(replica_ds_0,replica_ds_1), 
TRANSACTIONAL_READ_QUERY_STRATEGY='DYNAMIC', TYPE(NAME='random'))" 
db-types="ShardingSphere" />
     <sql-case id="create-encrypt-rule" value="CREATE ENCRYPT RULE t_encrypt 
(COLUMNS((NAME=user_id,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
 (NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))))" 
db-types="ShardingSphere" />
     <sql-case id="create-encrypt-rule-if-not-exists" value="CREATE ENCRYPT 
RULE IF NOT EXISTS t_encrypt 
(COLUMNS((NAME=user_id,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
 (NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))))" 
db-types="ShardingSphere" />
     <sql-case id="create-encrypt-rule-with-assisted-query-column" 
value="CREATE ENCRYPT RULE t_encrypt 
(COLUMNS((NAME=user_id,CIPHER=user_cipher,ASSISTED_QUERY_COLUMN=assisted_column,
 ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))), 
ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5'))), (NAME=order_id, CIPHER 
=order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))))" db-types="ShardingSphere" 
/>


Reply via email to