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 d609613f82a Add
UnsupportedCRC32DataConsistencyCalculateAlgorithmException (#21095)
d609613f82a is described below
commit d609613f82a2949df6cb6001b2f8ba791240c7be
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Sep 20 23:23:51 2022 +0800
Add UnsupportedCRC32DataConsistencyCalculateAlgorithmException (#21095)
* Add UnsupportedCRC32DataConsistencyCalculateAlgorithmException
* Add UnsupportedCRC32DataConsistencyCalculateAlgorithmException
* Add UnsupportedCRC32DataConsistencyCalculateAlgorithmException
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
...RC32MatchDataConsistencyCalculateAlgorithm.java | 8 +++---
...ipelineDataConsistencyCheckFailedException.java | 4 ---
...ataConsistencyCalculateAlgorithmException.java} | 17 ++++++------
.../migration/MigrationDataConsistencyChecker.java | 31 ++++++++++++++--------
6 files changed, 33 insertions(+), 29 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 35e2cd95e5a..8dd77285e90 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
@@ -94,6 +94,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 18020 | Failed to get DDL for table \`%s\` |
| HY000 | 18050 | Before data record is \`%s\`, after data record is
\`%s\` |
| 08000 | 18051 | Data check table \`%s\` failed |
+| 0A000 | 18053 | Unsupported CRC32 data consistency calculate
algorithm with database type \`%s\` |
| HY000 | 18080 | Can not find pipeline job \`%s\` |
| HY000 | 18081 | Job has already started |
| HY000 | 18082 | Sharding count of job \`%s\` is 0 |
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 4a17d52926b..45d5682f29d 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
@@ -94,6 +94,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 18020 | Failed to get DDL for table \`%s\` |
| HY000 | 18050 | Before data record is \`%s\`, after data record is
\`%s\` |
| 08000 | 18051 | Data check table \`%s\` failed |
+| 0A000 | 18053 | Unsupported CRC32 data consistency calculate
algorithm with database type \`%s\` |
| HY000 | 18080 | Can not find pipeline job \`%s\` |
| HY000 | 18081 | Job has already started |
| HY000 | 18082 | Sharding count of job \`%s\` is 0 |
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithm.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithm.java
index e797732bf0a..b2eeac94959 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithm.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithm.java
@@ -19,12 +19,13 @@ package
org.apache.shardingsphere.data.pipeline.core.check.consistency.algorithm
import lombok.Getter;
import
org.apache.shardingsphere.data.pipeline.api.check.consistency.DataConsistencyCalculateParameter;
-import
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineDataConsistencyCheckFailedException;
import
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineTableDataConsistencyCheckLoadingFailedException;
+import
org.apache.shardingsphere.data.pipeline.core.exception.data.UnsupportedCRC32DataConsistencyCalculateAlgorithmException;
import
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineSQLBuilderFactory;
import
org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCalculateAlgorithm;
import
org.apache.shardingsphere.data.pipeline.spi.sqlbuilder.PipelineSQLBuilder;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -62,10 +63,7 @@ public final class
CRC32MatchDataConsistencyCalculateAlgorithm implements DataCo
String logicTableName = parameter.getLogicTableName();
String schemaName =
parameter.getTableNameSchemaNameMapping().getSchemaName(logicTableName);
Optional<String> sql = sqlBuilder.buildCRC32SQL(schemaName,
logicTableName, columnName);
- if (!sql.isPresent()) {
- throw new PipelineDataConsistencyCheckFailedException(
- String.format("Unsupported CRC32 data consistency
calculate algorithm with database type `%s`", parameter.getDatabaseType()));
- }
+ ShardingSpherePreconditions.checkState(sql.isPresent(), () -> new
UnsupportedCRC32DataConsistencyCalculateAlgorithmException(parameter.getDatabaseType()));
return calculateCRC32(parameter.getDataSource(), logicTableName,
sql.get());
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
index afb0e656c61..f93ad157cc6 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
@@ -27,8 +27,4 @@ public final class
PipelineDataConsistencyCheckFailedException extends RuntimeEx
public PipelineDataConsistencyCheckFailedException(final String message) {
super(message);
}
-
- public PipelineDataConsistencyCheckFailedException(final String message,
final Throwable cause) {
- super(message, cause);
- }
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedCRC32DataConsistencyCalculateAlgorithmException.java
similarity index 57%
copy from
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
copy to
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedCRC32DataConsistencyCalculateAlgorithmException.java
index afb0e656c61..22f3f8a2b0c 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/PipelineDataConsistencyCheckFailedException.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/data/UnsupportedCRC32DataConsistencyCalculateAlgorithmException.java
@@ -17,18 +17,17 @@
package org.apache.shardingsphere.data.pipeline.core.exception.data;
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
/**
- * Pipeline data consistency check failed exception.
+ * Unsupported CRC32 data consistency calculate algorithm exception.
*/
-public final class PipelineDataConsistencyCheckFailedException extends
RuntimeException {
-
- private static final long serialVersionUID = -4100671584682823997L;
+public final class UnsupportedCRC32DataConsistencyCalculateAlgorithmException
extends PipelineSQLException {
- public PipelineDataConsistencyCheckFailedException(final String message) {
- super(message);
- }
+ private static final long serialVersionUID = 580323508713524816L;
- public PipelineDataConsistencyCheckFailedException(final String message,
final Throwable cause) {
- super(message, cause);
+ public UnsupportedCRC32DataConsistencyCalculateAlgorithmException(final
String databaseType) {
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 53, "Unsupported CRC32 data
consistency calculate algorithm with database type `%s`", databaseType);
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
index fbbdcca1389..df72c64d218 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationDataConsistencyChecker.java
@@ -31,13 +31,17 @@ import
org.apache.shardingsphere.data.pipeline.api.job.JobOperationType;
import
org.apache.shardingsphere.data.pipeline.api.metadata.model.PipelineColumnMetaData;
import
org.apache.shardingsphere.data.pipeline.api.metadata.model.PipelineTableMetaData;
import
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceFactory;
+import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineSQLException;
import
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineDataConsistencyCheckFailedException;
+import
org.apache.shardingsphere.data.pipeline.core.exception.data.PipelineTableDataConsistencyCheckLoadingFailedException;
import
org.apache.shardingsphere.data.pipeline.core.metadata.loader.StandardPipelineTableMetaDataLoader;
import
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineSQLBuilderFactory;
import
org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCalculateAlgorithm;
import
org.apache.shardingsphere.data.pipeline.spi.ratelimit.JobRateLimitAlgorithm;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorThreadFactoryBuilder;
+import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -116,15 +120,14 @@ public final class MigrationDataConsistencyChecker {
result.put(sourceTableName, checkCount(sourceDataSource,
targetDataSource, executor));
return result;
} catch (final SQLException ex) {
- throw new PipelineDataConsistencyCheckFailedException("Count check
failed", ex);
+ throw new SQLWrapperException(ex);
} finally {
executor.shutdown();
executor.shutdownNow();
}
}
- private DataConsistencyCountCheckResult checkCount(final
PipelineDataSourceWrapper sourceDataSource, final PipelineDataSourceWrapper
targetDataSource,
- final
ThreadPoolExecutor executor) {
+ private DataConsistencyCountCheckResult checkCount(final
PipelineDataSourceWrapper sourceDataSource, final PipelineDataSourceWrapper
targetDataSource, final ThreadPoolExecutor executor) {
Future<Long> sourceFuture = executor.submit(() ->
count(sourceDataSource, sourceTableName, sourceDataSource.getDatabaseType()));
Future<Long> targetFuture = executor.submit(() ->
count(targetDataSource, targetTableName, targetDataSource.getDatabaseType()));
long sourceCount;
@@ -132,12 +135,18 @@ public final class MigrationDataConsistencyChecker {
try {
sourceCount = sourceFuture.get();
} catch (final InterruptedException | ExecutionException ex) {
- throw new
PipelineDataConsistencyCheckFailedException(String.format("Count check failed
for source table '%s'", sourceTableName), ex);
+ if (ex.getCause() instanceof PipelineSQLException) {
+ throw (PipelineSQLException) ex.getCause();
+ }
+ throw new SQLWrapperException(new SQLException(ex));
}
try {
targetCount = targetFuture.get();
} catch (final InterruptedException | ExecutionException ex) {
- throw new
PipelineDataConsistencyCheckFailedException(String.format("Count check failed
for target table '%s'", targetTableName), ex);
+ if (ex.getCause() instanceof PipelineSQLException) {
+ throw (PipelineSQLException) ex.getCause();
+ }
+ throw new SQLWrapperException(new SQLException(ex));
}
return new DataConsistencyCountCheckResult(sourceCount, targetCount);
}
@@ -156,7 +165,7 @@ public final class MigrationDataConsistencyChecker {
resultSet.next();
return resultSet.getLong(1);
} catch (final SQLException ex) {
- throw new
PipelineDataConsistencyCheckFailedException(String.format("Count for table '%s'
failed", tableName), ex);
+ throw new
PipelineTableDataConsistencyCheckLoadingFailedException(tableName);
}
}
@@ -176,9 +185,7 @@ public final class MigrationDataConsistencyChecker {
StandardPipelineTableMetaDataLoader metaDataLoader = new
StandardPipelineTableMetaDataLoader(sourceDataSource);
for (String each : Collections.singletonList(sourceTableName)) {
PipelineTableMetaData tableMetaData =
metaDataLoader.getTableMetaData(tableNameSchemaNameMapping.getSchemaName(each),
each);
- if (null == tableMetaData) {
- throw new PipelineDataConsistencyCheckFailedException("Can
not get metadata for table " + each);
- }
+ ShardingSpherePreconditions.checkNotNull(tableMetaData, () ->
new PipelineTableDataConsistencyCheckLoadingFailedException(each));
Collection<String> columnNames =
tableMetaData.getColumnNames();
PipelineColumnMetaData uniqueKey =
jobConfig.getUniqueKeyColumn();
DataConsistencyCalculateParameter sourceParameter =
buildParameter(sourceDataSource, tableNameSchemaNameMapping, each, columnNames,
sourceDatabaseType, targetDatabaseType, uniqueKey);
@@ -202,8 +209,10 @@ public final class MigrationDataConsistencyChecker {
}
result.put(each, new
DataConsistencyContentCheckResult(contentMatched));
}
- } catch (final ExecutionException | InterruptedException |
SQLException ex) {
- throw new PipelineDataConsistencyCheckFailedException("Data check
failed", ex);
+ } catch (final SQLException ex) {
+ throw new SQLWrapperException(ex);
+ } catch (final ExecutionException | InterruptedException ex) {
+ throw new SQLWrapperException(new SQLException(ex.getCause()));
} finally {
executor.shutdown();
executor.shutdownNow();