From 12255c7c4b48fa63432bde0d79d135924c68c23e Mon Sep 17 00:00:00 2001 From: inrgihc Date: Mon, 20 Sep 2021 12:46:36 +0800 Subject: [PATCH] Fix Bug: issues-I4AU42 --- README.md | 16 +- dbswitch-admin/pom.xml | 3 +- .../admin/service/JobExecutorService.java | 20 +- .../admin/type/SupportDbTypeEnum.java | 2 +- dbswitch-common/pom.xml | 2 +- dbswitch-core/pom.xml | 9 +- .../core/database/impl/DatabaseMysqlImpl.java | 2 +- dbswitch-data/pom.xml | 24 +- .../dbswitch/data/DataSyncApplication.java | 35 +- .../gitee/dbswitch/data/core/MainService.java | 352 +++++++++--------- dbswitch-dbchange/pom.xml | 2 +- dbswitch-dbcommon/pom.xml | 2 +- dbswitch-dbsynch/pom.xml | 2 +- dbswitch-dbwriter/pom.xml | 2 +- dbswitch-pgwriter/pom.xml | 2 +- dbswitch-sql/pom.xml | 2 +- package-tool/pom.xml | 2 +- pom.xml | 154 ++++---- version.cmd | 2 +- 19 files changed, 339 insertions(+), 296 deletions(-) diff --git a/README.md b/README.md index 91e0d625..952c134c 100644 --- a/README.md +++ b/README.md @@ -387,7 +387,19 @@ bin/startup.sh ![admin_06.png](images/admin_06.png) -## 四、文档博客 +## 四、常见问题解决 + +### 1、执行启动脚本报错 + +- (1)在Windows下,执行startup.cmd或datasync.cmd脚本报错 + +> 解决办法:将脚本的内容复制后,删除原脚本文件,然后再创建一个同名脚本文件后,将原内容粘贴进去后,再执行脚本。 + +- (2)在Linux下,执行startup.sh或datasync.sh脚本报错 + +> 解决办法:用vi/vim工具打开脚本,然后命令模式下设置 ```set ff=unix```后,然后保存退出,再执行脚本。 + +## 五、文档博客 (1)https://blog.csdn.net/inrgihc/article/details/103739629 @@ -397,7 +409,7 @@ bin/startup.sh (4)https://blog.csdn.net/inrgihc/article/details/103738656 -## 五、问题反馈 +## 六、问题反馈 如果您看到并使用了本工具,或您觉得本工具对您有价值,请为此项目**点个赞**,以表示对本项目的支持,多谢!如果您在使用时遇到了bug,欢迎在issue中反馈。也可扫描下方二维码入群讨论:(加好友请注明:"程序交流") diff --git a/dbswitch-admin/pom.xml b/dbswitch-admin/pom.xml index 12655dea..9ba312b2 100644 --- a/dbswitch-admin/pom.xml +++ b/dbswitch-admin/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-admin @@ -54,6 +54,7 @@ mysql mysql-connector-java + 5.1.47 runtime diff --git a/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/service/JobExecutorService.java b/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/service/JobExecutorService.java index dbcbdf82..a2196a56 100644 --- a/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/service/JobExecutorService.java +++ b/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/service/JobExecutorService.java @@ -1,4 +1,3 @@ -package com.gitee.dbswitch.admin.service; // Copyright tang. All rights reserved. // https://gitee.com/inrgihc/dbswitch // @@ -8,6 +7,8 @@ package com.gitee.dbswitch.admin.service; // Date : 2020/1/2 // Location: beijing , china ///////////////////////////////////////////////////////////// +package com.gitee.dbswitch.admin.service; + import cn.hutool.core.exceptions.ExceptionUtil; import com.gitee.dbswitch.admin.dao.AssignmentConfigDAO; import com.gitee.dbswitch.admin.dao.AssignmentJobDAO; @@ -108,14 +109,21 @@ public class JobExecutorService extends QuartzJobBean implements InterruptableJo try { DbswichProperties properties = JsonUtil .toBeanObject(task.getContent(), DbswichProperties.class); + if (!assignmentConfigEntity.getFirstFlag()) { + properties.getTarget().setTargetDrop(false); + properties.getTarget().setChangeDataSynch(true); + } + MainService mainService = new MainService(properties); mainService.run(); - AssignmentConfigEntity config = new AssignmentConfigEntity(); - config.setId(assignmentConfigEntity.getId()); - config.setTargetDropTable(Boolean.FALSE); - config.setFirstFlag(Boolean.FALSE); - assignmentConfigDAO.updateSelective(config); + if (assignmentConfigEntity.getFirstFlag()) { + AssignmentConfigEntity config = new AssignmentConfigEntity(); + config.setId(assignmentConfigEntity.getId()); + config.setTargetDropTable(Boolean.FALSE); + config.setFirstFlag(Boolean.FALSE); + assignmentConfigDAO.updateSelective(config); + } assignmentJobEntity.setStatus(JobStatusEnum.PASS.getValue()); log.info("Execute Assignment Success [taskId={}],Task Name: {}", task.getId(), diff --git a/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/type/SupportDbTypeEnum.java b/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/type/SupportDbTypeEnum.java index f3842ecd..947055e0 100644 --- a/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/type/SupportDbTypeEnum.java +++ b/dbswitch-admin/src/main/java/com/gitee/dbswitch/admin/type/SupportDbTypeEnum.java @@ -17,7 +17,7 @@ import org.springframework.util.StringUtils; @AllArgsConstructor public enum SupportDbTypeEnum { - MYSQL(1, "mysql", "com.mysql.cj.jdbc.Driver", "/* ping */ SELECT 1", + MYSQL(1, "mysql", "com.mysql.jdbc.Driver", "/* ping */ SELECT 1", "jdbc:mysql://{host}:{port>/{name}?useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&tinyInt1isBit=false"), MARIADB(2, "mariadb", "org.mariadb.jdbc.Driver", "SELECT 1", "jdbc:mariadb://{host}:{port}/{name}?useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&tinyInt1isBit=false"), diff --git a/dbswitch-common/pom.xml b/dbswitch-common/pom.xml index 57d7f94e..275691a5 100644 --- a/dbswitch-common/pom.xml +++ b/dbswitch-common/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-common diff --git a/dbswitch-core/pom.xml b/dbswitch-core/pom.xml index 3d1092de..e41bc1f0 100644 --- a/dbswitch-core/pom.xml +++ b/dbswitch-core/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-core @@ -21,16 +21,19 @@ mysql mysql-connector-java + 5.1.47 org.postgresql postgresql + runtime com.oracle.ojdbc ojdbc8 + runtime @@ -38,12 +41,14 @@ com.oracle.database.nls orai18n 19.7.0.0 + runtime com.microsoft.sqlserver sqljdbc4 4.0 + runtime @@ -97,12 +102,14 @@ org.mariadb.jdbc mariadb-java-client + runtime com.ibm.db2.jcc db2jcc db2jcc4 + runtime diff --git a/dbswitch-core/src/main/java/com/gitee/dbswitch/core/database/impl/DatabaseMysqlImpl.java b/dbswitch-core/src/main/java/com/gitee/dbswitch/core/database/impl/DatabaseMysqlImpl.java index 515131d8..80d5985c 100644 --- a/dbswitch-core/src/main/java/com/gitee/dbswitch/core/database/impl/DatabaseMysqlImpl.java +++ b/dbswitch-core/src/main/java/com/gitee/dbswitch/core/database/impl/DatabaseMysqlImpl.java @@ -36,7 +36,7 @@ import org.springframework.util.CollectionUtils; public class DatabaseMysqlImpl extends AbstractDatabase implements IDatabaseInterface { public DatabaseMysqlImpl() { - super("com.mysql.cj.jdbc.Driver"); + super("com.mysql.jdbc.Driver"); } public DatabaseMysqlImpl(String driverClassName) { diff --git a/dbswitch-data/pom.xml b/dbswitch-data/pom.xml index b93862b4..4dda4c7b 100644 --- a/dbswitch-data/pom.xml +++ b/dbswitch-data/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-data @@ -22,6 +22,18 @@ com.gitee.dbswitch dbswitch-core ${project.version} + + + mysql + mysql-connector-java + + + + + + mysql + mysql-connector-java + 5.1.47 @@ -52,16 +64,6 @@ jackson-databind - - mysql - mysql-connector-java - - - - org.postgresql - postgresql - - org.ehcache sizeof diff --git a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/DataSyncApplication.java b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/DataSyncApplication.java index e28443ed..04d3f845 100644 --- a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/DataSyncApplication.java +++ b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/DataSyncApplication.java @@ -11,6 +11,7 @@ package com.gitee.dbswitch.data; import com.gitee.dbswitch.data.config.DbswichProperties; import com.gitee.dbswitch.data.core.MainService; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; @@ -20,28 +21,28 @@ import org.springframework.context.ConfigurableApplicationContext; /** * DATA模块启动类 - * - * @author tang * + * @author tang */ +@Slf4j @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class DataSyncApplication { - public static void main(String[] args) { - SpringApplication springApplication = new SpringApplication(DataSyncApplication.class); - springApplication.setWebApplicationType(WebApplicationType.NONE); - springApplication.setBannerMode(Banner.Mode.OFF); - ConfigurableApplicationContext applicationContext = springApplication.run(args); - try { - DbswichProperties properties = applicationContext.getBean(DbswichProperties.class); - MainService mainService = new MainService(properties); - mainService.run(); - }catch (Exception e){ + public static void main(String[] args) { + SpringApplication springApplication = new SpringApplication(DataSyncApplication.class); + springApplication.setWebApplicationType(WebApplicationType.NONE); + springApplication.setBannerMode(Banner.Mode.OFF); + ConfigurableApplicationContext applicationContext = springApplication.run(args); + try { + DbswichProperties properties = applicationContext.getBean(DbswichProperties.class); + MainService mainService = new MainService(properties); + mainService.run(); + } catch (Exception e) { + log.error("error:", e); + } finally { + applicationContext.close(); + } - } finally { - applicationContext.close(); - } - - } + } } diff --git a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/core/MainService.java b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/core/MainService.java index 5f591a92..526f4517 100644 --- a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/core/MainService.java +++ b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/core/MainService.java @@ -9,6 +9,18 @@ ///////////////////////////////////////////////////////////// package com.gitee.dbswitch.data.core; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.gitee.dbswitch.core.model.TableDescription; +import com.gitee.dbswitch.core.service.IMetaDataService; +import com.gitee.dbswitch.core.service.impl.MigrationMetaDataServiceImpl; +import com.gitee.dbswitch.data.config.DbswichProperties; +import com.gitee.dbswitch.data.domain.PerfStat; +import com.gitee.dbswitch.data.handler.MigrationHandler; +import com.gitee.dbswitch.data.util.BytesUnitUtils; +import com.gitee.dbswitch.data.util.DataSouceUtils; +import com.gitee.dbswitch.data.util.JdbcTemplateUtils; +import com.gitee.dbswitch.data.util.StrUtils; +import com.zaxxer.hikari.HikariDataSource; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -17,20 +29,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.function.Supplier; import java.util.regex.Pattern; -import com.gitee.dbswitch.data.domain.PerfStat; -import com.gitee.dbswitch.data.handler.MigrationHandler; -import com.gitee.dbswitch.data.util.BytesUnitUtils; -import com.gitee.dbswitch.data.util.DataSouceUtils; -import com.gitee.dbswitch.data.util.StrUtils; -import com.gitee.dbswitch.core.service.impl.MigrationMetaDataServiceImpl; -import org.springframework.util.StopWatch; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.gitee.dbswitch.core.model.TableDescription; -import com.gitee.dbswitch.core.service.IMetaDataService; -import com.gitee.dbswitch.data.config.DbswichProperties; -import com.gitee.dbswitch.data.util.JdbcTemplateUtils; -import com.zaxxer.hikari.HikariDataSource; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StopWatch; /** * 数据迁移主逻辑类 @@ -40,183 +40,195 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class MainService { - /** - * JSON序列化工具 - */ - private final ObjectMapper jackson = new ObjectMapper(); + /** + * JSON序列化工具 + */ + private final ObjectMapper jackson = new ObjectMapper(); - /** - * 性能统计记录表 - */ - private final List perfStats = new ArrayList<>(); + /** + * 性能统计记录表 + */ + private final List perfStats = new ArrayList<>(); - /** - * 配置参数 - */ - private DbswichProperties properties; + /** + * 配置参数 + */ + private final DbswichProperties properties; - /** - * 构造函数 - * - * @param properties 配置信息 - */ - public MainService(DbswichProperties properties){ - this.properties=properties; - } + /** + * 构造函数 + * + * @param properties 配置信息 + */ + public MainService(DbswichProperties properties) { + this.properties = properties; + } - /** - * 执行主逻辑 - */ - public void run() throws Exception { - StopWatch watch = new StopWatch(); - watch.start(); + /** + * 执行主逻辑 + */ + public void run() throws Exception { + StopWatch watch = new StopWatch(); + watch.start(); - log.info("dbswitch data service is started...."); + log.info("dbswitch data service is started...."); + //log.info("Application properties configuration \n{}", properties); - try { - //log.info("Application properties configuration \n{}", properties); - List sourcesProperties = properties.getSource(); + try (HikariDataSource targetDataSource = DataSouceUtils + .createTargetDataSource(properties.getTarget())) { + int sourcePropertiesIndex = 0; + int totalTableCount = 0; + List sourcesProperties = properties.getSource(); + for (DbswichProperties.SourceDataSourceProperties sourceProperties : sourcesProperties) { - HikariDataSource targetDataSource = DataSouceUtils.createTargetDataSource(properties.getTarget()); + try (HikariDataSource sourceDataSource = DataSouceUtils + .createSourceDataSource(sourceProperties)) { + IMetaDataService sourceMetaDataService = new MigrationMetaDataServiceImpl(); - int sourcePropertiesIndex = 0; - int totalTableCount = 0; - for (DbswichProperties.SourceDataSourceProperties sourceProperties : sourcesProperties) { + sourceMetaDataService + .setDatabaseConnection(JdbcTemplateUtils.getDatabaseProduceName(sourceDataSource)); - try (HikariDataSource sourceDataSource = DataSouceUtils.createSourceDataSource(sourceProperties)) { - IMetaDataService sourceMetaDataService = new MigrationMetaDataServiceImpl(); + // 判断处理的策略:是排除还是包含 + List includes = StrUtils.stringToList(sourceProperties.getSourceIncludes()); + log.info("Includes tables is :{}", jackson.writeValueAsString(includes)); + List filters = StrUtils.stringToList(sourceProperties.getSourceExcludes()); + log.info("Filter tables is :{}", jackson.writeValueAsString(filters)); - sourceMetaDataService.setDatabaseConnection(JdbcTemplateUtils.getDatabaseProduceName(sourceDataSource)); + boolean useExcludeTables = includes.isEmpty(); + if (useExcludeTables) { + log.info("!!!! Use dbswitch.source[{}].source-excludes parameter to filter tables", + sourcePropertiesIndex); + } else { + log.info("!!!! Use dbswitch.source[{}].source-includes parameter to filter tables", + sourcePropertiesIndex); + } - // 判断处理的策略:是排除还是包含 - List includes = StrUtils.stringToList(sourceProperties.getSourceIncludes()); - log.info("Includes tables is :{}", jackson.writeValueAsString(includes)); - List filters = StrUtils.stringToList(sourceProperties.getSourceExcludes()); - log.info("Filter tables is :{}", jackson.writeValueAsString(filters)); + List> futures = new ArrayList<>(); - boolean useExcludeTables = includes.isEmpty(); - if (useExcludeTables) { - log.info("!!!! Use dbswitch.source[{}].source-excludes parameter to filter tables", sourcePropertiesIndex); - } else { - log.info("!!!! Use dbswitch.source[{}].source-includes parameter to filter tables", sourcePropertiesIndex); + List schemas = StrUtils.stringToList(sourceProperties.getSourceSchema()); + log.info("Source schema names is :{}", jackson.writeValueAsString(schemas)); + + AtomicInteger numberOfFailures = new AtomicInteger(0); + AtomicLong totalBytesSize = new AtomicLong(0L); + final int indexInternal = sourcePropertiesIndex; + for (String schema : schemas) { + List tableList = sourceMetaDataService + .queryTableList(sourceProperties.getUrl(), + sourceProperties.getUsername(), sourceProperties.getPassword(), schema); + if (tableList.isEmpty()) { + log.warn("### Find source database table list empty for schema name is : {}", schema); + } else { + for (TableDescription td : tableList) { + String tableName = td.getTableName(); + + if (useExcludeTables) { + if (!filters.contains(tableName)) { + futures.add( + makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, + numberOfFailures, totalBytesSize)); + } + } else { + if (includes.size() == 1 && (includes.get(0).contains("*") || includes.get(0) + .contains("?"))) { + if (Pattern.matches(includes.get(0), tableName)) { + futures.add( + makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, + numberOfFailures, totalBytesSize)); } - - List> futures = new ArrayList<>(); - - List schemas = StrUtils.stringToList(sourceProperties.getSourceSchema()); - log.info("Source schema names is :{}", jackson.writeValueAsString(schemas)); - - AtomicInteger numberOfFailures = new AtomicInteger(0); - AtomicLong totalBytesSize = new AtomicLong(0L); - final int indexInternal = sourcePropertiesIndex; - for (String schema : schemas) { - // 读取源库指定schema里所有的表 - List tableList = sourceMetaDataService.queryTableList(sourceProperties.getUrl(), - sourceProperties.getUsername(), sourceProperties.getPassword(), schema); - if (tableList.isEmpty()) { - log.warn("### Find source database table list empty for schema name is : {}", schema); - } else { - for (TableDescription td : tableList) { - String tableName = td.getTableName(); - - if (useExcludeTables) { - if (!filters.contains(tableName)) { - futures.add(makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, numberOfFailures, totalBytesSize)); - } - } else { - if (includes.size() == 1 && (includes.get(0).contains("*") || includes.get(0).contains("?"))) { - if (Pattern.matches(includes.get(0), tableName)) { - futures.add(makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, numberOfFailures, totalBytesSize)); - } - } else if (includes.contains(tableName)) { - futures.add(makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, numberOfFailures, totalBytesSize)); - } - } - - } - - } - - } - - CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join(); - log.info("#### Complete data migration for the [ {} ] data source:\ntotal count={}\nfailure count={}\ntotal bytes size={}", - sourcePropertiesIndex, futures.size(), numberOfFailures.get(), BytesUnitUtils.bytesSizeToHuman(totalBytesSize.get())); - - perfStats.add(new PerfStat(sourcePropertiesIndex, futures.size(), numberOfFailures.get(), totalBytesSize.get())); - - ++sourcePropertiesIndex; - totalTableCount += futures.size(); + } else if (includes.contains(tableName)) { + futures.add( + makeFutureTask(td, indexInternal, sourceDataSource, targetDataSource, + numberOfFailures, totalBytesSize)); + } } + + } + } - log.info("service run all success, total migrate table count={} ", totalTableCount); - } catch (Exception e) { - log.error("error:", e); - throw e; - } finally { - watch.stop(); - log.info("total elipse = {} s", watch.getTotalTimeSeconds()); - StringBuilder sb = new StringBuilder(); - sb.append("===================================\n"); - sb.append(String.format("total elipse time:\t %f s\n", watch.getTotalTimeSeconds())); - sb.append("-------------------------------------\n"); - perfStats.forEach(st -> { - sb.append(st); - if(perfStats.size()>1){ - sb.append("-------------------------------------\n"); - } - }); - sb.append("===================================\n"); - log.info("\n\n" + sb.toString()); + } + + CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).join(); + log.info( + "#### Complete data migration for the [ {} ] data source:\ntotal count={}\nfailure count={}\ntotal bytes size={}", + sourcePropertiesIndex, futures.size(), numberOfFailures.get(), + BytesUnitUtils.bytesSizeToHuman(totalBytesSize.get())); + + perfStats.add(new PerfStat(sourcePropertiesIndex, futures.size(), numberOfFailures.get(), + totalBytesSize.get())); + + ++sourcePropertiesIndex; + totalTableCount += futures.size(); } - } + } + log.info("service run all success, total migrate table count={} ", totalTableCount); + } finally { + watch.stop(); + log.info("total ellipse = {} s", watch.getTotalTimeSeconds()); - /** - * 构造一个异步执行任务 - * - * @param td 表描述上下文 - * @param indexInternal 源端索引号 - * @param sds 源端的DataSource数据源 - * @param tds 目的端的DataSource数据源 - * @param numberOfFailures 失败的数量 - * @param totalBytesSize 同步的字节大小 - * @return CompletableFuture - */ - private CompletableFuture makeFutureTask(TableDescription td, Integer indexInternal, - HikariDataSource sds, HikariDataSource tds, - AtomicInteger numberOfFailures, AtomicLong totalBytesSize) { - return CompletableFuture.supplyAsync(getMigrateHandler(td, indexInternal, sds, tds)) - .exceptionally(getExceptHandler(td, numberOfFailures)) - .thenAccept(totalBytesSize::addAndGet); + StringBuilder sb = new StringBuilder(); + sb.append("===================================\n"); + sb.append(String.format("total ellipse time:\t %f s\n", watch.getTotalTimeSeconds())); + sb.append("-------------------------------------\n"); + perfStats.forEach(st -> { + sb.append(st); + if (perfStats.size() > 1) { + sb.append("-------------------------------------\n"); + } + }); + sb.append("===================================\n"); + log.info("\n\n" + sb.toString()); } + } - /** - * 单表迁移处理方法 - * - * @param td 表描述上下文 - * @param indexInternal 源端索引号 - * @param sds 源端的DataSource数据源 - * @param tds 目的端的DataSource数据源 - * @return Supplier - */ - private Supplier getMigrateHandler(TableDescription td, Integer indexInternal, HikariDataSource sds, HikariDataSource tds) { - return () -> MigrationHandler.createInstance(td, properties, indexInternal, sds, tds).get(); - } + /** + * 构造一个异步执行任务 + * + * @param td 表描述上下文 + * @param indexInternal 源端索引号 + * @param sds 源端的DataSource数据源 + * @param tds 目的端的DataSource数据源 + * @param numberOfFailures 失败的数量 + * @param totalBytesSize 同步的字节大小 + * @return CompletableFuture + */ + private CompletableFuture makeFutureTask(TableDescription td, Integer indexInternal, + HikariDataSource sds, HikariDataSource tds, + AtomicInteger numberOfFailures, AtomicLong totalBytesSize) { + return CompletableFuture.supplyAsync(getMigrateHandler(td, indexInternal, sds, tds)) + .exceptionally(getExceptHandler(td, numberOfFailures)) + .thenAccept(totalBytesSize::addAndGet); + } - /** - * 异常处理函数方法 - * - * @param td 表描述上下文 - * @param numberOfFailures 失败记录数 - * @return Function - */ - private Function getExceptHandler(TableDescription td, AtomicInteger numberOfFailures) { - return (e) -> { - log.error("Error migration for table: {}.{}, error message:", td.getSchemaName(), td.getTableName(), e); - numberOfFailures.incrementAndGet(); - throw new RuntimeException(e); - }; - } + /** + * 单表迁移处理方法 + * + * @param td 表描述上下文 + * @param indexInternal 源端索引号 + * @param sds 源端的DataSource数据源 + * @param tds 目的端的DataSource数据源 + * @return Supplier + */ + private Supplier getMigrateHandler(TableDescription td, Integer indexInternal, + HikariDataSource sds, HikariDataSource tds) { + return () -> MigrationHandler.createInstance(td, properties, indexInternal, sds, tds).get(); + } + + /** + * 异常处理函数方法 + * + * @param td 表描述上下文 + * @param numberOfFailures 失败记录数 + * @return Function + */ + private Function getExceptHandler(TableDescription td, + AtomicInteger numberOfFailures) { + return (e) -> { + log.error("Error migration for table: {}.{}, error message:", td.getSchemaName(), + td.getTableName(), e); + numberOfFailures.incrementAndGet(); + throw new RuntimeException(e); + }; + } } diff --git a/dbswitch-dbchange/pom.xml b/dbswitch-dbchange/pom.xml index 6ad41db7..e9da1f1f 100644 --- a/dbswitch-dbchange/pom.xml +++ b/dbswitch-dbchange/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-dbchange diff --git a/dbswitch-dbcommon/pom.xml b/dbswitch-dbcommon/pom.xml index 1e936f94..373790ea 100644 --- a/dbswitch-dbcommon/pom.xml +++ b/dbswitch-dbcommon/pom.xml @@ -3,7 +3,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-dbcommon diff --git a/dbswitch-dbsynch/pom.xml b/dbswitch-dbsynch/pom.xml index 61044436..fd627cf8 100644 --- a/dbswitch-dbsynch/pom.xml +++ b/dbswitch-dbsynch/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-dbsynch diff --git a/dbswitch-dbwriter/pom.xml b/dbswitch-dbwriter/pom.xml index 0e80424a..88082f28 100644 --- a/dbswitch-dbwriter/pom.xml +++ b/dbswitch-dbwriter/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-dbwriter diff --git a/dbswitch-pgwriter/pom.xml b/dbswitch-pgwriter/pom.xml index ed15b9d0..4e069f05 100644 --- a/dbswitch-pgwriter/pom.xml +++ b/dbswitch-pgwriter/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-pgwriter diff --git a/dbswitch-sql/pom.xml b/dbswitch-sql/pom.xml index 451bc732..9b5e02bf 100644 --- a/dbswitch-sql/pom.xml +++ b/dbswitch-sql/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 dbswitch-sql diff --git a/package-tool/pom.xml b/package-tool/pom.xml index 2c60a069..b592fc27 100644 --- a/package-tool/pom.xml +++ b/package-tool/pom.xml @@ -5,7 +5,7 @@ com.gitee.dbswitch dbswitch-parent - 1.6.0 + 1.6.1 package-tool diff --git a/pom.xml b/pom.xml index 6acbd183..b1a5a3cc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,85 +1,85 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.0.RELEASE - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.RELEASE + + - com.gitee.dbswitch - dbswitch-parent - 1.6.0 - pom - dbswitch - database switch project + com.gitee.dbswitch + dbswitch-parent + 1.6.1 + pom + dbswitch + database switch project - - 1.8 - 3.1.1 - true - 1.8 - 1.8 - UTF-8 - UTF-8 - + + 1.8 + 3.1.1 + true + 1.8 + 1.8 + UTF-8 + UTF-8 + - - dbswitch-common - dbswitch-core - dbswitch-pgwriter - dbswitch-dbwriter - dbswitch-dbcommon - dbswitch-dbchange - dbswitch-dbsynch - dbswitch-data - dbswitch-sql - dbswitch-admin - package-tool - + + dbswitch-common + dbswitch-core + dbswitch-pgwriter + dbswitch-dbwriter + dbswitch-dbcommon + dbswitch-dbchange + dbswitch-dbsynch + dbswitch-data + dbswitch-sql + dbswitch-admin + package-tool + - - - org.springframework.boot - spring-boot-starter - - + + + org.springframework.boot + spring-boot-starter + + - - - - org.apache.maven.plugins - maven-jar-plugin - - - **/*.xml - **/*.yml - **/*.properties - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${basedir}/target - false - false - - - - - - + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/*.xml + **/*.yml + **/*.properties + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${basedir}/target + false + false + + + + + + diff --git a/version.cmd b/version.cmd index c6617f3f..96c79dd4 100644 --- a/version.cmd +++ b/version.cmd @@ -1,6 +1,6 @@ @echo off -set APP_VERSION=1.6.0 +set APP_VERSION=1.6.1 echo "Clean Project ..." call mvn clean -f pom.xml