This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 8667e1b3d20 Add RuleAndStorageMetaDataMismatchedException (#30854)
8667e1b3d20 is described below
commit 8667e1b3d20f3e7ffc1609ce9bdbe13e36841c57
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Apr 11 23:52:44 2024 +0800
Add RuleAndStorageMetaDataMismatchedException (#30854)
---
.../user-manual/error-code/sql-error-code.cn.md | 10 ++---
.../user-manual/error-code/sql-error-code.en.md | 10 ++---
.../DuplicateSharingActualDataNodeException.java | 2 +-
...InconsistentShardingTableMetaDataException.java | 45 ----------------------
.../metadata/InvalidBindingTablesException.java | 2 +-
...nvalidShardingStrategyConfigCountException.java | 2 +-
...singRequiredShardingConfigurationException.java | 4 +-
.../ShardingSchemaTableAggregationReviser.java | 15 ++++++--
.../RuleAndStorageMetaDataMismatchedException.java | 14 +++----
9 files changed, 34 insertions(+), 70 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 4226fccd2a0..d16182927c4 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
@@ -18,6 +18,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 10001 | 42S02 | Schema '%s' does not exist.
|
| 10002 | 42S02 | Table or view '%s' does not exist.
|
| 10003 | 42S02 | Unknown column '%s' in '%s'.
|
+| 10010 | HY000 | Rule and storage meta data mismatched, reason is:
%s. |
| 10100 | HY000 | Can not %s storage units '%s'.
|
| 10101 | 42S02 | There is no storage unit in database '%s'.
|
| 10102 | 44000 | Storage units '%s' do not exist in database '%s'.
|
@@ -139,7 +140,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| Vendor Code | SQL State | 错误信息
|
|-------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------|
-| 20000 | 44000 | Can not get uniformed table structure for logic
table '%s', it has different meta data of actual tables are as follows: %s
|
+| 20000 | 42S02 | %s configuration does not exist in database '%s'.
|
| 20001 | 42S02 | Can not find table rule with logic tables '%s'.
|
| 20002 | 42S02 | Can not find data source in sharding rule, invalid
actual data node '%s'.
|
| 20003 | 42S02 | Data nodes is required for sharding table '%s'.
|
@@ -149,10 +150,9 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 20007 | 42S01 | Index '%s' already exists.
|
| 20008 | 42S02 | Index '%s' does not exist.
|
| 20009 | 42S01 | View name has to bind to %s tables.
|
-| 20010 | 42S02 | %s configuration does not exist in database '%s'.
|
-| 20011 | 44000 | Invalid binding table configuration.
|
-| 20012 | 44000 | Only allowed 0 or 1 sharding strategy
configuration.
|
-| 20013 | 42S01 | Same actual data node cannot be configured in
multiple logic tables in same database, logical table '%s', actual data node
'%s.%s'. |
+| 20010 | 44000 | Invalid binding table configuration.
|
+| 20011 | 44000 | Only allowed 0 or 1 sharding strategy
configuration.
|
+| 20012 | 42S01 | Same actual data node cannot be configured in
multiple logic tables in same database, logical table '%s', actual data node
'%s.%s'. |
| 20020 | 44000 | Sharding value can not be null in SQL statement.
|
| 20021 | HY004 | Found different types for sharding value '%s'.
|
| 20022 | HY004 | Invalid %s, datetime pattern should be '%s', value
is '%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 ed6bb64eb86..b0db32715f8 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
@@ -18,6 +18,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 10001 | 42S02 | Schema '%s' does not exist.
|
| 10002 | 42S02 | Table or view '%s' does not exist.
|
| 10003 | 42S02 | Unknown column '%s' in '%s'.
|
+| 10010 | HY000 | Rule and storage meta data mismatched, reason is:
%s. |
| 10100 | HY000 | Can not %s storage units '%s'.
|
| 10101 | 42S02 | There is no storage unit in database '%s'.
|
| 10102 | 44000 | Storage units '%s' do not exist in database '%s'.
|
@@ -140,7 +141,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| Vendor Code | SQL State | Reason
|
|-------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------|
-| 20000 | 44000 | Can not get uniformed table structure for logic
table '%s', it has different meta data of actual tables are as follows: %s
|
+| 20000 | 42S02 | %s configuration does not exist in database '%s'.
|
| 20001 | 42S02 | Can not find table rule with logic tables '%s'.
|
| 20002 | 42S02 | Can not find data source in sharding rule, invalid
actual data node '%s'.
|
| 20003 | 42S02 | Data nodes is required for sharding table '%s'.
|
@@ -150,10 +151,9 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 20007 | 42S01 | Index '%s' already exists.
|
| 20008 | 42S02 | Index '%s' does not exist.
|
| 20009 | 42S01 | View name has to bind to %s tables.
|
-| 20010 | 42S02 | %s configuration does not exist in database '%s'.
|
-| 20011 | 44000 | Invalid binding table configuration.
|
-| 20012 | 44000 | Only allowed 0 or 1 sharding strategy
configuration.
|
-| 20013 | 42S01 | Same actual data node cannot be configured in
multiple logic tables in same database, logical table '%s', actual data node
'%s.%s'. |
+| 20010 | 44000 | Invalid binding table configuration.
|
+| 20011 | 44000 | Only allowed 0 or 1 sharding strategy
configuration.
|
+| 20012 | 42S01 | Same actual data node cannot be configured in
multiple logic tables in same database, logical table '%s', actual data node
'%s.%s'. |
| 20020 | 44000 | Sharding value can not be null in SQL statement.
|
| 20021 | HY004 | Found different types for sharding value '%s'.
|
| 20022 | HY004 | Invalid %s, datetime pattern should be '%s', value
is '%s'.
|
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/DuplicateSharingActualDataNodeException.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/DuplicateSharingActualDataNodeException.java
index b5946a68c0e..9ae794b0c17 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/DuplicateSharingActualDataNodeException.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/DuplicateSharingActualDataNodeException.java
@@ -28,7 +28,7 @@ public final class DuplicateSharingActualDataNodeException
extends ShardingSQLEx
private static final long serialVersionUID = 3503761639898230998L;
public DuplicateSharingActualDataNodeException(final String
logicalTableName, final String dataSourceName, final String tableName) {
- super(XOpenSQLState.DUPLICATE, 13,
+ super(XOpenSQLState.DUPLICATE, 12,
"Same actual data node cannot be configured in multiple logic
tables in same database, logical table '%s', actual data node '%s.%s'.",
logicalTableName, dataSourceName, tableName);
}
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InconsistentShardingTableMetaDataException.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InconsistentShardingTableMetaDataException.java
deleted file mode 100644
index 97266cff683..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InconsistentShardingTableMetaDataException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.metadata;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.sharding.exception.ShardingSQLException;
-import org.apache.shardingsphere.sharding.metadata.TableMetaDataViolation;
-
-import java.util.Collection;
-
-/**
- * Inconsistent sharding table meta data exception.
- */
-public final class InconsistentShardingTableMetaDataException extends
ShardingSQLException {
-
- private static final long serialVersionUID = -5450346946223396192L;
-
- public InconsistentShardingTableMetaDataException(final String
logicTableName, final Collection<TableMetaDataViolation> violations) {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0,
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/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
index 9f374309d3c..6cdb348ca72 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
@@ -28,6 +28,6 @@ public final class InvalidBindingTablesException extends
ShardingSQLException {
private static final long serialVersionUID = 6913516240331555395L;
public InvalidBindingTablesException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 11, "Invalid binding table
configuration.");
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 10, "Invalid binding table
configuration.");
}
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidShardingStrategyConfigCountException.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidShardingStrategyConfigCountException.java
index 65d8b33a26b..dcfb5960c5d 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidShardingStrategyConfigCountException.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidShardingStrategyConfigCountException.java
@@ -28,6 +28,6 @@ public final class
InvalidShardingStrategyConfigCountException extends ShardingS
private static final long serialVersionUID = 9006408233608414517L;
public InvalidShardingStrategyConfigCountException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 12, "Only allowed 0 or 1
sharding strategy configuration.");
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 11, "Only allowed 0 or 1
sharding strategy configuration.");
}
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/MissingRequiredShardingConfigurationException.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/MissingRequiredShardingConfigurationException.java
index 79175a27613..8c9111f698f 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/MissingRequiredShardingConfigurationException.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/MissingRequiredShardingConfigurationException.java
@@ -28,10 +28,10 @@ public final class
MissingRequiredShardingConfigurationException extends Shardin
private static final long serialVersionUID = -7307832800220432407L;
public MissingRequiredShardingConfigurationException(final String
configKey) {
- super(XOpenSQLState.NOT_FOUND, 10, "%s configuration does not exist.",
configKey);
+ super(XOpenSQLState.NOT_FOUND, 0, "%s configuration does not exist.",
configKey);
}
public MissingRequiredShardingConfigurationException(final String
configKey, final String databaseName) {
- super(XOpenSQLState.NOT_FOUND, 10, "%s configuration does not exist in
database '%s'.", configKey, databaseName);
+ super(XOpenSQLState.NOT_FOUND, 0, "%s configuration does not exist in
database '%s'.", configKey, databaseName);
}
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/schema/ShardingSchemaTableAggregationReviser.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/schema/ShardingSchemaTableAggregationReviser.java
index 97874f8bbce..6013e825c3f 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/schema/ShardingSchemaTableAggregationReviser.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/schema/ShardingSchemaTableAggregationReviser.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.sharding.metadata.reviser.schema;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.metadata.database.schema.reviser.schema.SchemaTableAggregationReviser;
import
org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.sharding.exception.metadata.InconsistentShardingTableMetaDataException;
+import
org.apache.shardingsphere.infra.exception.kernel.metadata.RuleAndStorageMetaDataMismatchedException;
+import
org.apache.shardingsphere.infra.metadata.database.schema.reviser.schema.SchemaTableAggregationReviser;
import org.apache.shardingsphere.sharding.metadata.TableMetaDataViolation;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -63,6 +63,15 @@ public final class ShardingSchemaTableAggregationReviser
implements SchemaTableA
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());
- ShardingSpherePreconditions.checkState(violations.isEmpty(), () -> new
InconsistentShardingTableMetaDataException(logicTableName, violations));
+ ShardingSpherePreconditions.checkState(violations.isEmpty(), () -> new
RuleAndStorageMetaDataMismatchedException(createErrorReason(logicTableName,
violations)));
+ }
+
+ private String createErrorReason(final String logicTableName, 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 String.format(result.toString(), logicTableName);
}
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/RuleAndStorageMetaDataMismatchedException.java
similarity index 61%
copy from
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/RuleAndStorageMetaDataMismatchedException.java
index 9f374309d3c..5b56e1f9d3e 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/exception/metadata/InvalidBindingTablesException.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/RuleAndStorageMetaDataMismatchedException.java
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.sharding.exception.metadata;
+package org.apache.shardingsphere.infra.exception.kernel.metadata;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.sharding.exception.ShardingSQLException;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
/**
- * Invalid binding tables exception.
+ * Rule and storage metadata mismatched exception.
*/
-public final class InvalidBindingTablesException extends ShardingSQLException {
+public final class RuleAndStorageMetaDataMismatchedException extends
MetaDataSQLException {
- private static final long serialVersionUID = 6913516240331555395L;
+ private static final long serialVersionUID = -1931359961875820757L;
- public InvalidBindingTablesException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 11, "Invalid binding table
configuration.");
+ public RuleAndStorageMetaDataMismatchedException(final String reason) {
+ super(XOpenSQLState.GENERAL_ERROR, 10, "Rule and storage meta data
mismatched, reason is: %s.", reason);
}
}