You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/09 10:17:28 UTC

[GitHub] [shardingsphere] jiangML opened a new pull request, #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

jiangML opened a new pull request, #22040:
URL: https://github.com/apache/shardingsphere/pull/22040

   For#22039
   
   Changes proposed in this pull request:
     - Enhanced distsql verification of rdl type in storage unit and readwrite splitting
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] codecov-commenter commented on pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040#issuecomment-1309704905

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/22040?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#22040](https://codecov.io/gh/apache/shardingsphere/pull/22040?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1bdec28) into [master](https://codecov.io/gh/apache/shardingsphere/commit/2d12f9f5045ba75fae024caa3b3db895ef691afe?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2d12f9f) will **increase** coverage by `0.14%`.
   > The diff coverage is `89.74%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #22040      +/-   ##
   ============================================
   + Coverage     60.87%   61.01%   +0.14%     
   - Complexity     2467     2548      +81     
   ============================================
     Files          4104     4109       +5     
     Lines         57212    57236      +24     
     Branches       9686     9678       -8     
   ============================================
   + Hits          34825    34920      +95     
   + Misses        19448    19371      -77     
   - Partials       2939     2945       +6     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/22040?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...itory/cluster/ClusterPersistRepositoryFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvcmVwb3NpdG9yeS9jbHVzdGVyL0NsdXN0ZXJQZXJzaXN0UmVwb3NpdG9yeUZhY3RvcnkuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...de/repository/cluster/consul/ConsulRepository.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9wcm92aWRlci9jb25zdWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvcmVwb3NpdG9yeS9jbHVzdGVyL2NvbnN1bC9Db25zdWxSZXBvc2l0b3J5LmphdmE=) | `46.91% <ø> (ø)` | |
   | [...e/mode/repository/cluster/etcd/EtcdRepository.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9wcm92aWRlci9ldGNkL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL3JlcG9zaXRvcnkvY2x1c3Rlci9ldGNkL0V0Y2RSZXBvc2l0b3J5LmphdmE=) | `66.17% <ø> (ø)` | |
   | [...mode/repository/cluster/nacos/NacosRepository.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9wcm92aWRlci9uYWNvcy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvbW9kZS9yZXBvc2l0b3J5L2NsdXN0ZXIvbmFjb3MvTmFjb3NSZXBvc2l0b3J5LmphdmE=) | `74.46% <ø> (ø)` | |
   | [...ository/cluster/zookeeper/ZookeeperRepository.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9wcm92aWRlci96b29rZWVwZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvcmVwb3NpdG9yeS9jbHVzdGVyL3pvb2tlZXBlci9ab29rZWVwZXJSZXBvc2l0b3J5LmphdmE=) | `57.62% <0.00%> (-0.36%)` | :arrow_down: |
   | [.../zookeeper/listener/SessionConnectionListener.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bW9kZS90eXBlL2NsdXN0ZXIvcmVwb3NpdG9yeS9wcm92aWRlci96b29rZWVwZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvcmVwb3NpdG9yeS9jbHVzdGVyL3pvb2tlZXBlci9saXN0ZW5lci9TZXNzaW9uQ29ubmVjdGlvbkxpc3RlbmVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [.../resource/UnregisterStorageUnitBackendHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmRsL3Jlc291cmNlL1VucmVnaXN0ZXJTdG9yYWdlVW5pdEJhY2tlbmRIYW5kbGVyLmphdmE=) | `94.44% <0.00%> (ø)` | |
   | [...l/rdl/resource/AlterStorageUnitBackendHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmRsL3Jlc291cmNlL0FsdGVyU3RvcmFnZVVuaXRCYWNrZW5kSGFuZGxlci5qYXZh) | `81.63% <85.71%> (+0.38%)` | :arrow_up: |
   | [...dl/resource/RegisterStorageUnitBackendHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHJveHkvYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmRsL3Jlc291cmNlL1JlZ2lzdGVyU3RvcmFnZVVuaXRCYWNrZW5kSGFuZGxlci5qYXZh) | `90.90% <90.90%> (+8.30%)` | :arrow_up: |
   | [...hecker/ReadwriteSplittingRuleStatementChecker.java](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZmVhdHVyZXMvcmVhZHdyaXRlLXNwbGl0dGluZy9kaXN0c3FsL2hhbmRsZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9kaXN0c3FsL2hhbmRsZXIvY2hlY2tlci9SZWFkd3JpdGVTcGxpdHRpbmdSdWxlU3RhdGVtZW50Q2hlY2tlci5qYXZh) | `95.00% <96.00%> (+1.89%)` | :arrow_up: |
   | ... and [40 more](https://codecov.io/gh/apache/shardingsphere/pull/22040/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040#discussion_r1018576237


##########
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java:
##########
@@ -67,7 +192,7 @@ private static void checkDuplicateWriteResourceNames(final String databaseName,
         for (final ReadwriteSplittingRuleSegment each : segments) {
             if (!Strings.isNullOrEmpty(each.getWriteDataSource())) {
                 String writeDataSource = each.getWriteDataSource();
-                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("readwrite splitting", each.getName(),
+                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("Readwrite splitting", each.getName(),
                         String.format("Can not config duplicate write resource `%s` in database `%s`", writeDataSource, databaseName)));

Review Comment:
   Should `resource` be replaced with `storage unit`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang merged pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
RaigorJiang merged PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] jiangML commented on a diff in pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
jiangML commented on code in PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040#discussion_r1018588697


##########
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java:
##########
@@ -35,15 +50,125 @@
 public final class ReadwriteSplittingRuleStatementChecker {
     
     /**
-     * Check duplicate resource names for readwrite-splitting rule statement.
+     * Check create readwrite splitting rule statement.
+     *
+     * @param database database
+     * @param segments segments
+     * @param currentRuleConfig current rule config
+     */
+    public static void checkCreation(final ShardingSphereDatabase database, final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        String databaseName = database.getName();
+        checkDuplicateRuleNames(databaseName, segments, currentRuleConfig, database.getResourceMetaData());
+        checkResourcesExist(databaseName, segments, database);
+        checkDuplicateResourceNames(databaseName, segments, currentRuleConfig, true);
+        checkLoadBalancers(segments);
+    }
+    
+    /**
+     *  Check alter readwrite splitting rule statement.
      * 
-     * @param databaseName database name
+     * @param database database
      * @param segments segments
      * @param currentRuleConfig current rule config
-     * @param isCreating whether is creating
      */
-    public static void checkDuplicateResourceNames(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments,
-                                                   final ReadwriteSplittingRuleConfiguration currentRuleConfig, final boolean isCreating) {
+    public static void checkAlteration(final ShardingSphereDatabase database, final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        String databaseName = database.getName();
+        checkRuleConfigurationExist(database, currentRuleConfig);
+        checkDuplicateRuleNamesWithSelf(databaseName, segments);
+        checkRuleNamesExist(segments, currentRuleConfig, databaseName);
+        checkResourcesExist(databaseName, segments, database);
+        checkDuplicateResourceNames(databaseName, segments, currentRuleConfig, false);
+        checkLoadBalancers(segments);
+    }
+    
+    /**
+     *  Check current rule configuration exist.
+     * 
+     * @param database database
+     * @param currentRuleConfig current rule config
+     */
+    public static void checkRuleConfigurationExist(final ShardingSphereDatabase database, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException("Readwrite splitting", database.getName()));
+    }
+    
+    private static void checkRuleNamesExist(final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig, final String databaseName) {
+        Collection<String> requiredRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toList());
+        Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+        Collection<String> notExistRuleNames = requiredRuleNames.stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toSet());
+        ShardingSpherePreconditions.checkState(notExistRuleNames.isEmpty(), () -> new MissingRequiredRuleException(databaseName, notExistRuleNames));
+    }
+    
+    private static void checkDuplicateRuleNames(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments,
+                                                final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResourceMetaData resourceMetaData) {
+        checkDuplicateRuleNamesWithSelf(databaseName, segments);
+        checkDuplicateRuleNamesWithResourceMetaData(segments, resourceMetaData);
+        checkDuplicateRuleNamesWithRuleConfiguration(databaseName, segments, currentRuleConfig);
+    }
+    
+    private static void checkDuplicateRuleNamesWithSelf(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments) {
+        Collection<String> requiredRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toList());
+        Collection<String> duplicateRuleNames = getDuplicate(requiredRuleNames);
+        ShardingSpherePreconditions.checkState(duplicateRuleNames.isEmpty(), () -> new DuplicateRuleException("Readwrite splitting", databaseName, duplicateRuleNames));
+    }
+    
+    private static Collection<String> getDuplicate(final Collection<String> require) {
+        return require.stream().collect(Collectors.groupingBy(each -> each, Collectors.counting())).entrySet().stream()
+                .filter(each -> each.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toSet());
+    }
+    
+    private static void checkDuplicateRuleNamesWithResourceMetaData(final Collection<ReadwriteSplittingRuleSegment> segments, final ShardingSphereResourceMetaData resourceMetaData) {
+        Collection<String> currentRuleNames = new LinkedList<>();
+        if (null != resourceMetaData && null != resourceMetaData.getDataSources()) {
+            currentRuleNames.addAll(resourceMetaData.getDataSources().keySet());
+        }
+        Collection<String> duplicateRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).filter(currentRuleNames::contains).collect(Collectors.toList());
+        ShardingSpherePreconditions.checkState(duplicateRuleNames.isEmpty(), () -> new InvalidRuleConfigurationException("Readwrite splitting", duplicateRuleNames,
+                Collections.singleton(String.format("%s already exists in resource", duplicateRuleNames))));

Review Comment:
   ok, i'll change resource to storage unit



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on code in PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040#discussion_r1018575891


##########
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java:
##########
@@ -35,15 +50,125 @@
 public final class ReadwriteSplittingRuleStatementChecker {
     
     /**
-     * Check duplicate resource names for readwrite-splitting rule statement.
+     * Check create readwrite splitting rule statement.
+     *
+     * @param database database
+     * @param segments segments
+     * @param currentRuleConfig current rule config
+     */
+    public static void checkCreation(final ShardingSphereDatabase database, final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        String databaseName = database.getName();
+        checkDuplicateRuleNames(databaseName, segments, currentRuleConfig, database.getResourceMetaData());
+        checkResourcesExist(databaseName, segments, database);
+        checkDuplicateResourceNames(databaseName, segments, currentRuleConfig, true);
+        checkLoadBalancers(segments);
+    }
+    
+    /**
+     *  Check alter readwrite splitting rule statement.
      * 
-     * @param databaseName database name
+     * @param database database
      * @param segments segments
      * @param currentRuleConfig current rule config
-     * @param isCreating whether is creating
      */
-    public static void checkDuplicateResourceNames(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments,
-                                                   final ReadwriteSplittingRuleConfiguration currentRuleConfig, final boolean isCreating) {
+    public static void checkAlteration(final ShardingSphereDatabase database, final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        String databaseName = database.getName();
+        checkRuleConfigurationExist(database, currentRuleConfig);
+        checkDuplicateRuleNamesWithSelf(databaseName, segments);
+        checkRuleNamesExist(segments, currentRuleConfig, databaseName);
+        checkResourcesExist(databaseName, segments, database);
+        checkDuplicateResourceNames(databaseName, segments, currentRuleConfig, false);
+        checkLoadBalancers(segments);
+    }
+    
+    /**
+     *  Check current rule configuration exist.
+     * 
+     * @param database database
+     * @param currentRuleConfig current rule config
+     */
+    public static void checkRuleConfigurationExist(final ShardingSphereDatabase database, final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
+        ShardingSpherePreconditions.checkNotNull(currentRuleConfig, () -> new MissingRequiredRuleException("Readwrite splitting", database.getName()));
+    }
+    
+    private static void checkRuleNamesExist(final Collection<ReadwriteSplittingRuleSegment> segments, final ReadwriteSplittingRuleConfiguration currentRuleConfig, final String databaseName) {
+        Collection<String> requiredRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toList());
+        Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toList());
+        Collection<String> notExistRuleNames = requiredRuleNames.stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toSet());
+        ShardingSpherePreconditions.checkState(notExistRuleNames.isEmpty(), () -> new MissingRequiredRuleException(databaseName, notExistRuleNames));
+    }
+    
+    private static void checkDuplicateRuleNames(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments,
+                                                final ReadwriteSplittingRuleConfiguration currentRuleConfig, final ShardingSphereResourceMetaData resourceMetaData) {
+        checkDuplicateRuleNamesWithSelf(databaseName, segments);
+        checkDuplicateRuleNamesWithResourceMetaData(segments, resourceMetaData);
+        checkDuplicateRuleNamesWithRuleConfiguration(databaseName, segments, currentRuleConfig);
+    }
+    
+    private static void checkDuplicateRuleNamesWithSelf(final String databaseName, final Collection<ReadwriteSplittingRuleSegment> segments) {
+        Collection<String> requiredRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).collect(Collectors.toList());
+        Collection<String> duplicateRuleNames = getDuplicate(requiredRuleNames);
+        ShardingSpherePreconditions.checkState(duplicateRuleNames.isEmpty(), () -> new DuplicateRuleException("Readwrite splitting", databaseName, duplicateRuleNames));
+    }
+    
+    private static Collection<String> getDuplicate(final Collection<String> require) {
+        return require.stream().collect(Collectors.groupingBy(each -> each, Collectors.counting())).entrySet().stream()
+                .filter(each -> each.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toSet());
+    }
+    
+    private static void checkDuplicateRuleNamesWithResourceMetaData(final Collection<ReadwriteSplittingRuleSegment> segments, final ShardingSphereResourceMetaData resourceMetaData) {
+        Collection<String> currentRuleNames = new LinkedList<>();
+        if (null != resourceMetaData && null != resourceMetaData.getDataSources()) {
+            currentRuleNames.addAll(resourceMetaData.getDataSources().keySet());
+        }
+        Collection<String> duplicateRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).filter(currentRuleNames::contains).collect(Collectors.toList());
+        ShardingSpherePreconditions.checkState(duplicateRuleNames.isEmpty(), () -> new InvalidRuleConfigurationException("Readwrite splitting", duplicateRuleNames,
+                Collections.singleton(String.format("%s already exists in resource", duplicateRuleNames))));

Review Comment:
   The prompt information needs to be optimized



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] jiangML commented on a diff in pull request #22040: Enhanced DistSQL verification of RDL type in storage and readwrite splitting

Posted by GitBox <gi...@apache.org>.
jiangML commented on code in PR #22040:
URL: https://github.com/apache/shardingsphere/pull/22040#discussion_r1018588060


##########
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java:
##########
@@ -67,7 +192,7 @@ private static void checkDuplicateWriteResourceNames(final String databaseName,
         for (final ReadwriteSplittingRuleSegment each : segments) {
             if (!Strings.isNullOrEmpty(each.getWriteDataSource())) {
                 String writeDataSource = each.getWriteDataSource();
-                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("readwrite splitting", each.getName(),
+                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("Readwrite splitting", each.getName(),
                         String.format("Can not config duplicate write resource `%s` in database `%s`", writeDataSource, databaseName)));

Review Comment:
   ok, i'll change it



##########
features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java:
##########
@@ -67,7 +192,7 @@ private static void checkDuplicateWriteResourceNames(final String databaseName,
         for (final ReadwriteSplittingRuleSegment each : segments) {
             if (!Strings.isNullOrEmpty(each.getWriteDataSource())) {
                 String writeDataSource = each.getWriteDataSource();
-                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("readwrite splitting", each.getName(),
+                ShardingSpherePreconditions.checkState(writeDataSourceNames.add(writeDataSource), () -> new InvalidRuleConfigurationException("Readwrite splitting", each.getName(),
                         String.format("Can not config duplicate write resource `%s` in database `%s`", writeDataSource, databaseName)));

Review Comment:
   ok, i'll change it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org