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 2022/12/06 13:23:18 UTC

[shardingsphere] branch master updated: fix create encrypt rule error when no storage nodes (#22700)

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 21d52476766 fix create encrypt rule error when no storage nodes (#22700)
21d52476766 is described below

commit 21d52476766014f3a1bd5e16bbe144912ca9ea96
Author: jiangML <10...@qq.com>
AuthorDate: Tue Dec 6 21:22:59 2022 +0800

    fix create encrypt rule error when no storage nodes (#22700)
---
 .../distsql/handler/update/CreateEncryptRuleStatementUpdater.java  | 7 ++++++-
 .../infra/distsql/exception/resource/EmptyResourceException.java   | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
index 05cd8cffa79..bcdd62f6e59 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSeg
 import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
 import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
 import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
+import org.apache.shardingsphere.infra.distsql.exception.resource.EmptyResourceException;
 import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
 import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
 import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException;
@@ -46,7 +47,7 @@ public final class CreateEncryptRuleStatementUpdater implements RuleDefinitionCr
         checkDuplicateRuleNames(database.getName(), sqlStatement, currentRuleConfig);
         checkDataType(sqlStatement);
         checkToBeCreatedEncryptors(sqlStatement);
-        // TODO check resource
+        checkDataSources(database);
     }
     
     private void checkDuplicateRuleNames(final String databaseName, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws DuplicateRuleException {
@@ -74,6 +75,10 @@ public final class CreateEncryptRuleStatementUpdater implements RuleDefinitionCr
         ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(), () -> new InvalidAlgorithmConfigurationException("encryptor", notExistedEncryptors));
     }
     
+    private void checkDataSources(final ShardingSphereDatabase database) {
+        ShardingSpherePreconditions.checkState(!database.getResourceMetaData().getDataSources().isEmpty(), () -> new EmptyResourceException(database.getName()));
+    }
+    
     @Override
     public EncryptRuleConfiguration buildToBeCreatedRuleConfiguration(final CreateEncryptRuleStatement sqlStatement) {
         return EncryptRuleStatementConverter.convert(sqlStatement.getRules());
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/resource/EmptyResourceException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/resource/EmptyResourceException.java
index 9f5f6cfb104..c312c76998c 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/resource/EmptyResourceException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/resource/EmptyResourceException.java
@@ -27,6 +27,6 @@ public final class EmptyResourceException extends ResourceDefinitionViolationExc
     private static final long serialVersionUID = 1704331180489268L;
     
     public EmptyResourceException(final String databaseName) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "There is no resource in the database `%s`.", databaseName);
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "There is no storage unit in the database `%s`.", databaseName);
     }
 }