You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Pace2Car (via GitHub)" <gi...@apache.org> on 2023/03/20 07:57:51 UTC

[GitHub] [shardingsphere] Pace2Car opened a new pull request, #24688: Refactor check algorithms in DistSQL

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

   For #24686.
   
   Changes proposed in this pull request:
     - Refactor check algorithms in DistSQL
     - Update related test cases
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] 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] RaigorJiang commented on a diff in pull request #24688: Refactor check algorithms in DistSQL

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141787971


##########
kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java:
##########
@@ -59,21 +58,10 @@ private Collection<String> getNotExistRuleNames(final TrafficRuleConfiguration c
     }
     
     private void checkAlgorithmNames(final AlterTrafficRuleStatement sqlStatement) {
-        Collection<String> invalidAlgorithmNames = getInvalidAlgorithmNames(sqlStatement);
-        ShardingSpherePreconditions.checkState(invalidAlgorithmNames.isEmpty(), () -> new InvalidAlgorithmConfigurationException("Traffic", invalidAlgorithmNames));
-    }
-    
-    private Collection<String> getInvalidAlgorithmNames(final AlterTrafficRuleStatement sqlStatement) {
-        Collection<String> result = new LinkedList<>();
-        for (TrafficRuleSegment each : sqlStatement.getSegments()) {
-            if (!TypedSPILoader.contains(TrafficAlgorithm.class, each.getAlgorithm().getName())) {
-                result.add(each.getAlgorithm().getName());
-            }
-            if (null != each.getLoadBalancer() && !TypedSPILoader.contains(TrafficLoadBalanceAlgorithm.class, each.getLoadBalancer().getName())) {
-                result.add(each.getLoadBalancer().getName());
-            }
-        }
-        return result;
+        sqlStatement.getSegments().forEach(each -> {
+            TypedSPILoader.checkService(TrafficAlgorithm.class, each.getAlgorithm().getName(), each.getAlgorithm().getProps());
+            TypedSPILoader.checkService(TrafficLoadBalanceAlgorithm.class, each.getLoadBalancer().getName(), each.getLoadBalancer().getProps());

Review Comment:
   `each.getLoadBalancer()` may be null.



-- 
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 #24688: Refactor check algorithms in DistSQL

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141776343


##########
features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java:
##########
@@ -76,14 +79,23 @@ public void assertCheckSQLStatementWithIncompleteDataType() {
     @Test
     public void assertCreateEncryptRuleWithIfNotExists() {
         EncryptRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
-        CreateEncryptRuleStatement sqlStatement = createSQLStatement(true, "AES");
+        CreateEncryptRuleStatement sqlStatement = createAESEncryptRuleSQLStatement(true);
         updater.checkSQLStatement(database, sqlStatement, currentRuleConfig);
         EncryptRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement);
         updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
         assertThat(currentRuleConfig.getTables().size(), is(2));
         assertTrue(currentRuleConfig.getEncryptors().isEmpty());
     }
     
+    private CreateEncryptRuleStatement createAESEncryptRuleSQLStatement(final boolean ifNotExists) {
+        EncryptColumnSegment tEncryptColumnSegment = new EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column", "like_column",
+                new AlgorithmSegment("AES", PropertiesBuilder.build(new Property("aes-key-value", "abc"))), null, null, null);
+        EncryptRuleSegment tEncryptRuleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(tEncryptColumnSegment), null);
+        Collection<EncryptRuleSegment> rules = new LinkedList<>();

Review Comment:
   Can `Collections.singletonList` be used instead?



-- 
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] Pace2Car commented on a diff in pull request #24688: Refactor check algorithms in DistSQL

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141827737


##########
features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java:
##########
@@ -76,14 +79,23 @@ public void assertCheckSQLStatementWithIncompleteDataType() {
     @Test
     public void assertCreateEncryptRuleWithIfNotExists() {
         EncryptRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
-        CreateEncryptRuleStatement sqlStatement = createSQLStatement(true, "AES");
+        CreateEncryptRuleStatement sqlStatement = createAESEncryptRuleSQLStatement(true);
         updater.checkSQLStatement(database, sqlStatement, currentRuleConfig);
         EncryptRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement);
         updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
         assertThat(currentRuleConfig.getTables().size(), is(2));
         assertTrue(currentRuleConfig.getEncryptors().isEmpty());
     }
     
+    private CreateEncryptRuleStatement createAESEncryptRuleSQLStatement(final boolean ifNotExists) {
+        EncryptColumnSegment tEncryptColumnSegment = new EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column", "like_column",
+                new AlgorithmSegment("AES", PropertiesBuilder.build(new Property("aes-key-value", "abc"))), null, null, null);
+        EncryptRuleSegment tEncryptRuleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(tEncryptColumnSegment), null);
+        Collection<EncryptRuleSegment> rules = new LinkedList<>();

Review Comment:
   It may call `removeIf` when use `ifNotExists`, so it can not be singleton.



-- 
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 #24688: Refactor check algorithms in DistSQL

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang merged PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688


-- 
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] Pace2Car commented on a diff in pull request #24688: Refactor check algorithms in DistSQL

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141776825


##########
features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java:
##########
@@ -93,10 +94,13 @@ private Collection<String> getInvalidColumns(final String tableName, final Colle
     }
     
     private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) {
-        Collection<String> encryptors = new LinkedHashSet<>();
-        sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
-        Collection<String> notExistedEncryptors = encryptors.stream().filter(each -> !TypedSPILoader.contains(EncryptAlgorithm.class, each)).collect(Collectors.toList());
-        ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("encryptor", notExistedEncryptors));
+        Collection<AlgorithmSegment> encryptors = new LinkedHashSet<>();
+        sqlStatement.getRules().forEach(each -> each.getColumns().forEach(column -> {
+            encryptors.add(column.getEncryptor());
+            encryptors.add(column.getAssistedQueryEncryptor());
+            encryptors.add(column.getLikeQueryEncryptor());
+        }));
+        encryptors.stream().filter(Objects::nonNull).forEach(each -> TypedSPILoader.getService(EncryptAlgorithm.class, each.getName(), each.getProps()));

Review Comment:
   Fixed, thanks.



-- 
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] Pace2Car commented on a diff in pull request #24688: Refactor check algorithms in DistSQL

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141828113


##########
kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java:
##########
@@ -59,21 +58,10 @@ private Collection<String> getNotExistRuleNames(final TrafficRuleConfiguration c
     }
     
     private void checkAlgorithmNames(final AlterTrafficRuleStatement sqlStatement) {
-        Collection<String> invalidAlgorithmNames = getInvalidAlgorithmNames(sqlStatement);
-        ShardingSpherePreconditions.checkState(invalidAlgorithmNames.isEmpty(), () -> new InvalidAlgorithmConfigurationException("Traffic", invalidAlgorithmNames));
-    }
-    
-    private Collection<String> getInvalidAlgorithmNames(final AlterTrafficRuleStatement sqlStatement) {
-        Collection<String> result = new LinkedList<>();
-        for (TrafficRuleSegment each : sqlStatement.getSegments()) {
-            if (!TypedSPILoader.contains(TrafficAlgorithm.class, each.getAlgorithm().getName())) {
-                result.add(each.getAlgorithm().getName());
-            }
-            if (null != each.getLoadBalancer() && !TypedSPILoader.contains(TrafficLoadBalanceAlgorithm.class, each.getLoadBalancer().getName())) {
-                result.add(each.getLoadBalancer().getName());
-            }
-        }
-        return result;
+        sqlStatement.getSegments().forEach(each -> {
+            TypedSPILoader.checkService(TrafficAlgorithm.class, each.getAlgorithm().getName(), each.getAlgorithm().getProps());
+            TypedSPILoader.checkService(TrafficLoadBalanceAlgorithm.class, each.getLoadBalancer().getName(), each.getLoadBalancer().getProps());

Review Comment:
   Fixed, thanks.



-- 
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 #24688: Refactor check algorithms in DistSQL

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141774628


##########
features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java:
##########
@@ -93,10 +94,13 @@ private Collection<String> getInvalidColumns(final String tableName, final Colle
     }
     
     private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) {
-        Collection<String> encryptors = new LinkedHashSet<>();
-        sqlStatement.getRules().forEach(each -> encryptors.addAll(each.getColumns().stream().map(column -> column.getEncryptor().getName()).collect(Collectors.toSet())));
-        Collection<String> notExistedEncryptors = encryptors.stream().filter(each -> !TypedSPILoader.contains(EncryptAlgorithm.class, each)).collect(Collectors.toList());
-        ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("encryptor", notExistedEncryptors));
+        Collection<AlgorithmSegment> encryptors = new LinkedHashSet<>();
+        sqlStatement.getRules().forEach(each -> each.getColumns().forEach(column -> {
+            encryptors.add(column.getEncryptor());
+            encryptors.add(column.getAssistedQueryEncryptor());
+            encryptors.add(column.getLikeQueryEncryptor());
+        }));
+        encryptors.stream().filter(Objects::nonNull).forEach(each -> TypedSPILoader.getService(EncryptAlgorithm.class, each.getName(), each.getProps()));

Review Comment:
   Maybe `TypedSPILoader.checkService` here.



-- 
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 #24688: Refactor check algorithms in DistSQL

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on code in PR #24688:
URL: https://github.com/apache/shardingsphere/pull/24688#discussion_r1141834613


##########
features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java:
##########
@@ -76,14 +79,23 @@ public void assertCheckSQLStatementWithIncompleteDataType() {
     @Test
     public void assertCreateEncryptRuleWithIfNotExists() {
         EncryptRuleConfiguration currentRuleConfig = getCurrentRuleConfig();
-        CreateEncryptRuleStatement sqlStatement = createSQLStatement(true, "AES");
+        CreateEncryptRuleStatement sqlStatement = createAESEncryptRuleSQLStatement(true);
         updater.checkSQLStatement(database, sqlStatement, currentRuleConfig);
         EncryptRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement);
         updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
         assertThat(currentRuleConfig.getTables().size(), is(2));
         assertTrue(currentRuleConfig.getEncryptors().isEmpty());
     }
     
+    private CreateEncryptRuleStatement createAESEncryptRuleSQLStatement(final boolean ifNotExists) {
+        EncryptColumnSegment tEncryptColumnSegment = new EncryptColumnSegment("user_id", "user_cipher", "user_plain", "assisted_column", "like_column",
+                new AlgorithmSegment("AES", PropertiesBuilder.build(new Property("aes-key-value", "abc"))), null, null, null);
+        EncryptRuleSegment tEncryptRuleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(tEncryptColumnSegment), null);
+        Collection<EncryptRuleSegment> rules = new LinkedList<>();

Review Comment:
   OK, thank you.



-- 
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