This is an automated email from the ASF dual-hosted git repository.
panjuan 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 5d8a69395be Add InconsistentShardingTableMetaDataException (#20541)
5d8a69395be is described below
commit 5d8a69395be431ef7daf1c1c642ec1f488ce08a4
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 13:08:30 2022 +0800
Add InconsistentShardingTableMetaDataException (#20541)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
...InconsistentShardingTableMetaDataException.java | 45 ++++++++++++++++++++++
.../metadata/ShardingSchemaMetaDataDecorator.java | 24 +-----------
.../sharding/metadata/TableMetaDataViolation.java | 34 ++++++++++++++++
5 files changed, 83 insertions(+), 22 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 592ae8a904a..19eb2d96e39 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
@@ -37,6 +37,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
| 44000 | 20001 | Sharding value can't be null in insert statement |
+| 44000 | 20002 | Can not get uniformed table structure for logic
table \`%s\`, it has different meta data of actual tables are as follows: %s |
| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
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 be17827fd97..fb93dd0180f 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
@@ -37,6 +37,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
| 44000 | 20001 | Sharding value can't be null in insert statement |
+| 44000 | 20002 | Can not get uniformed table structure for logic
table \`%s\`, it has different meta data of actual tables are as follows: %s |
| 44000 | 20012 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` are not match |
| HY004 | 24000 | Encrypt algorithm \`%s\` initialize failed, reason
is: %s |
| HY004 | 24001 | The SQL clause \`%s\` is unsupported in encrypt
rule |
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/InconsistentShardingTableMetaDataException.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/InconsistentShardingTableMetaDataException.java
new file mode 100644
index 00000000000..d713c3b7962
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/InconsistentShardingTableMetaDataException.java
@@ -0,0 +1,45 @@
+/*
+ * 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.sharding.exception;
+
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.sharding.metadata.TableMetaDataViolation;
+
+import java.util.Collection;
+
+/**
+ * Inconsistent sharding table meta data exception.
+ */
+public final class InconsistentShardingTableMetaDataException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = -5450346946223396192L;
+
+ public InconsistentShardingTableMetaDataException(final String
logicTableName, final Collection<TableMetaDataViolation> violations) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20002,
createReason(violations), logicTableName);
+ }
+
+ private static String createReason(final
Collection<TableMetaDataViolation> violations) {
+ StringBuilder result = new StringBuilder(
+ "Can not get uniformed table structure for logic table `%s`,
it has different meta data of actual tables are as follows:
").append(System.lineSeparator());
+ for (TableMetaDataViolation each : violations) {
+ result.append("actual table:
").append(each.getActualTableName()).append(", meta data:
").append(each.getTableMetaData()).append(System.lineSeparator());
+ }
+ return result.toString();
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecorator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecorator.java
index 715d3bb9a96..efae95cb4b2 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecorator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingSchemaMetaDataDecorator.java
@@ -17,11 +17,8 @@
package org.apache.shardingsphere.sharding.metadata;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.datanode.DataNode;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator;
import
org.apache.shardingsphere.infra.metadata.database.schema.loader.model.ColumnMetaData;
@@ -30,6 +27,7 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.loader.model.Ind
import
org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData;
import
org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
+import
org.apache.shardingsphere.sharding.exception.InconsistentShardingTableMetaDataException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -89,17 +87,8 @@ public final class ShardingSchemaMetaDataDecorator
implements RuleBasedSchemaMet
TableMetaData sample = tableMetaDataList.iterator().next();
Collection<TableMetaDataViolation> violations =
tableMetaDataList.stream()
.filter(each -> !sample.equals(each)).map(each -> new
TableMetaDataViolation(each.getName(), each)).collect(Collectors.toList());
- throwExceptionIfNecessary(violations, logicTableName);
- }
-
- private void throwExceptionIfNecessary(final
Collection<TableMetaDataViolation> violations, final String logicTableName) {
if (!violations.isEmpty()) {
- StringBuilder errorMessage = new StringBuilder(
- "Cannot get uniformed table structure for logic table
`%s`, it has different meta data of actual tables are as
follows:").append(System.lineSeparator());
- for (TableMetaDataViolation each : violations) {
- errorMessage.append("actual table:
").append(each.getActualTableName()).append(", meta data:
").append(each.getTableMetaData()).append(System.lineSeparator());
- }
- throw new ShardingSphereException(errorMessage.toString(),
logicTableName);
+ throw new
InconsistentShardingTableMetaDataException(logicTableName, violations);
}
}
@@ -148,13 +137,4 @@ public final class ShardingSchemaMetaDataDecorator
implements RuleBasedSchemaMet
public Class<ShardingRule> getTypeClass() {
return ShardingRule.class;
}
-
- @RequiredArgsConstructor
- @Getter
- private static final class TableMetaDataViolation {
-
- private final String actualTableName;
-
- private final TableMetaData tableMetaData;
- }
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/TableMetaDataViolation.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/TableMetaDataViolation.java
new file mode 100644
index 00000000000..f09ac8f2b48
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/TableMetaDataViolation.java
@@ -0,0 +1,34 @@
+/*
+ * 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.sharding.metadata;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData;
+
+/**
+ * Table meta data violation.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class TableMetaDataViolation {
+
+ private final String actualTableName;
+
+ private final TableMetaData tableMetaData;
+}