This is an automated email from the ASF dual-hosted git repository.
yx9o 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 d728704e1bf Add InvalidMGRGroupNameConfigurationException (#20754)
d728704e1bf is described below
commit d728704e1bf73394db65be4e4b7f8932a867ac58
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Sep 4 00:28:10 2022 +0800
Add InvalidMGRGroupNameConfigurationException (#20754)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../InvalidMGRGroupNameConfigurationException.java | 33 ++++++++++++++++++++++
...MGRMySQLDatabaseDiscoveryProviderAlgorithm.java | 10 +++----
.../exception/ShardingSpherePreconditions.java | 4 +--
5 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 9f64e5e8edb..f1059488c29 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -70,6 +70,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 23000 | MGR plugin is not active in database \`%s\` |
| 44000 | 23001 | MGR is not in single primary mode in database
\`%s\` |
| 44000 | 23002 | \`%s\` is not in MGR replication group member in
database \`%s\` |
+| 44000 | 23003 | Group name in MGR is not same with configured one
\`%s\` in database \`%s\` |
| HY004 | 27000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| 0A000 | 27001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 27002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 0e9e91454e4..650a2fffdf5 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -70,6 +70,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 23000 | MGR plugin is not active in database \`%s\` |
| 44000 | 23001 | MGR is not in single primary mode in database
\`%s\` |
| 44000 | 23002 | \`%s\` is not in MGR replication group member in
database \`%s\` |
+| 44000 | 23003 | Group name in MGR is not same with configured one
\`%s\` in database \`%s\` |
| HY004 | 27000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| 0A000 | 27001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
| 44000 | 27002 | Altered column \`%s\` must use same encrypt
algorithm with previous column \`%s\` in table \`%s\` |
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/InvalidMGRGroupNameConfigurationException.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/InvalidMGRGroupNameConfigurationException.java
new file mode 100644
index 00000000000..9ffc7304a45
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/exception/InvalidMGRGroupNameConfigurationException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.dbdiscovery.mysql.exception;
+
+import
org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Invalid MGR group name configuration exception.
+ */
+public final class InvalidMGRGroupNameConfigurationException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = -2585442998454509788L;
+
+ public InvalidMGRGroupNameConfigurationException(final String groupName,
final String databaseName) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 23003, "Group name in MGR
is not same with configured one `%s` in database `%s`", groupName,
databaseName);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
index 7719e1cf642..38dc99387f3 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.dbdiscovery.mysql.type;
-import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import
org.apache.shardingsphere.dbdiscovery.mysql.exception.InvalidMGRGroupNameConfigurationException;
import
org.apache.shardingsphere.dbdiscovery.mysql.exception.InvalidMGRModeException;
import
org.apache.shardingsphere.dbdiscovery.mysql.exception.InvalidMGRPluginException;
import
org.apache.shardingsphere.dbdiscovery.mysql.exception.InvalidMGRReplicationGroupMemberException;
@@ -107,20 +107,20 @@ public final class
MGRMySQLDatabaseDiscoveryProviderAlgorithm implements Databas
private void checkPluginActive(final String databaseName, final Statement
statement) throws SQLException {
try (ResultSet resultSet =
statement.executeQuery(QUERY_PLUGIN_STATUS)) {
- ShardingSpherePreconditions.checkStatus(resultSet.next() &&
"ACTIVE".equals(resultSet.getString("PLUGIN_STATUS")), new
InvalidMGRPluginException(databaseName));
+ ShardingSpherePreconditions.checkState(resultSet.next() &&
"ACTIVE".equals(resultSet.getString("PLUGIN_STATUS")), new
InvalidMGRPluginException(databaseName));
}
}
private void checkSinglePrimaryMode(final String databaseName, final
Statement statement) throws SQLException {
try (ResultSet resultSet =
statement.executeQuery(QUERY_SINGLE_PRIMARY_MODE)) {
- ShardingSpherePreconditions.checkStatus(resultSet.next() &&
"ON".equals(resultSet.getString("VARIABLE_VALUE")), new
InvalidMGRModeException(databaseName));
+ ShardingSpherePreconditions.checkState(resultSet.next() &&
"ON".equals(resultSet.getString("VARIABLE_VALUE")), new
InvalidMGRModeException(databaseName));
}
}
private void checkGroupName(final String databaseName, final Statement
statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery(QUERY_GROUP_NAME)) {
- Preconditions.checkState(resultSet.next() &&
props.getProperty("group-name",
"").equals(resultSet.getString("VARIABLE_VALUE")),
- "Group name in MGR is not same with configured one `%s` in
database `%s`.", props.getProperty("group-name"), databaseName);
+ ShardingSpherePreconditions.checkState(resultSet.next() &&
props.getProperty("group-name",
"").equals(resultSet.getString("VARIABLE_VALUE")),
+ new
InvalidMGRGroupNameConfigurationException(props.getProperty("group-name"),
databaseName));
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
index 1537b450aca..8457a6dcdf9 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditions.java
@@ -34,7 +34,7 @@ public final class ShardingSpherePreconditions {
* @param expectedExpression expected expression
* @param exceptionIfUnexpected exception thrown if expression is
unexpected
*/
- public static void checkStatus(final boolean expectedExpression, final
ShardingSphereExternalException exceptionIfUnexpected) {
+ public static void checkState(final boolean expectedExpression, final
ShardingSphereExternalException exceptionIfUnexpected) {
if (!expectedExpression) {
throw exceptionIfUnexpected;
}
@@ -47,7 +47,7 @@ public final class ShardingSpherePreconditions {
* @param exceptionIfUnexpected exception thrown if expression is
unexpected
* @throws ShardingSphereInternalException ShardingSphere internal
exception
*/
- public static void checkStatus(final boolean expectedExpression, final
ShardingSphereInternalException exceptionIfUnexpected) throws
ShardingSphereInternalException {
+ public static void checkState(final boolean expectedExpression, final
ShardingSphereInternalException exceptionIfUnexpected) throws
ShardingSphereInternalException {
if (!expectedExpression) {
throw exceptionIfUnexpected;
}