diff --git a/dbswitch-common/pom.xml b/dbswitch-common/pom.xml
index fd1a79e7..d6a8b9b7 100644
--- a/dbswitch-common/pom.xml
+++ b/dbswitch-common/pom.xml
@@ -5,7 +5,7 @@
com.gitee
dbswitch
- 1.5.5
+ 1.5.6
dbswitch-common
diff --git a/dbswitch-core/pom.xml b/dbswitch-core/pom.xml
index 1bf27188..a9a72eee 100644
--- a/dbswitch-core/pom.xml
+++ b/dbswitch-core/pom.xml
@@ -5,7 +5,7 @@
com.gitee
dbswitch
- 1.5.5
+ 1.5.6
dbswitch-core
diff --git a/dbswitch-data/pom.xml b/dbswitch-data/pom.xml
index 110b308f..8a7ca69f 100644
--- a/dbswitch-data/pom.xml
+++ b/dbswitch-data/pom.xml
@@ -5,7 +5,7 @@
com.gitee
dbswitch
- 1.5.5
+ 1.5.6
dbswitch-data
diff --git a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/config/DbswichProperties.java b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/config/DbswichProperties.java
index 52f158db..ce073ff8 100644
--- a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/config/DbswichProperties.java
+++ b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/config/DbswichProperties.java
@@ -11,6 +11,8 @@ package com.gitee.dbswitch.data.config;
import java.util.ArrayList;
import java.util.List;
+
+import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@@ -25,6 +27,7 @@ import lombok.NoArgsConstructor;
*/
@Configuration
@Data
+@ToString
@ConfigurationProperties(prefix = "dbswitch", ignoreInvalidFields=false, ignoreUnknownFields = false)
@PropertySource("classpath:config.properties")
public class DbswichProperties {
diff --git a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/domain/PerfStat.java b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/domain/PerfStat.java
new file mode 100644
index 00000000..2ce6dab5
--- /dev/null
+++ b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/domain/PerfStat.java
@@ -0,0 +1,36 @@
+// Copyright tang. All rights reserved.
+// https://gitee.com/inrgihc/dbswitch
+//
+// Use of this source code is governed by a BSD-style license
+//
+// Author: tang (inrgihc@126.com)
+// Date : 2020/1/2
+// Location: beijing , china
+/////////////////////////////////////////////////////////////
+package com.gitee.dbswitch.data.domain;
+
+import com.gitee.dbswitch.data.util.BytesUnitUtils;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * 统计信息
+ *
+ * @Author: tang
+ */
+@Data
+@AllArgsConstructor
+public class PerfStat {
+ private Integer index;
+ private Integer total;
+ private Integer failure;
+ private Long bytes;
+
+ @Override
+ public String toString() {
+ return "Data Source Index: \t" + index + "\n" +
+ "Total Tables Count: \t" + total + "\n" +
+ "Failure Tables count: \t" + failure + "\n" +
+ "Total Transfer Size: \t" + BytesUnitUtils.bytesSizeToHuman(bytes);
+ }
+}
diff --git a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/handler/MigrationHandler.java b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/handler/MigrationHandler.java
index d38fc939..4276457e 100644
--- a/dbswitch-data/src/main/java/com/gitee/dbswitch/data/handler/MigrationHandler.java
+++ b/dbswitch-data/src/main/java/com/gitee/dbswitch/data/handler/MigrationHandler.java
@@ -1,3 +1,12 @@
+// Copyright tang. All rights reserved.
+// https://gitee.com/inrgihc/dbswitch
+//
+// Use of this source code is governed by a BSD-style license
+//
+// Author: tang (inrgihc@126.com)
+// Date : 2020/1/2
+// Location: beijing , china
+/////////////////////////////////////////////////////////////
package com.gitee.dbswitch.data.handler;
import com.carrotsearch.sizeof.RamUsageEstimator;
@@ -31,6 +40,8 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicLong;
/**
* 在一个线程内的单表迁移处理逻辑
@@ -38,10 +49,11 @@ import java.util.Map;
* @author tang
*/
@Slf4j
-public class MigrationHandler implements Runnable {
+public class MigrationHandler implements Callable {
private final long MAX_CACHE_BYTES_SIZE = 512 * 1024 * 1024;
+ private int fetchSize = 100;
private TableDescription tableDescription;
private DbswichProperties properties;
private DbswichProperties.SourceDataSourceProperties sourceProperties;
@@ -61,11 +73,15 @@ public class MigrationHandler implements Runnable {
this.sourceMetaDataSerice = new MigrationMetaDataServiceImpl();
this.targetDataSource = tds;
+ if (sourceProperties.getFetchSize() >= fetchSize) {
+ fetchSize = sourceProperties.getFetchSize();
+ }
+
this.sourceMetaDataSerice.setDatabaseConnection(JdbcTemplateUtils.getDatabaseProduceName(sourceDataSource));
}
@Override
- public void run() {
+ public Long call() {
log.info("Migrate table for {}.{} ", tableDescription.getSchemaName(), tableDescription.getTableName());
JdbcTemplate targetJdbcTemplate = new JdbcTemplate(targetDataSource);
@@ -102,7 +118,7 @@ public class MigrationHandler implements Runnable {
targetJdbcTemplate.execute(sqlCreateTable);
log.info("Execute SQL: \n{}", sqlCreateTable);
- this.doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
+ return doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
} else {
// 判断是否具备变化量同步的条件:(1)两端表结构一致,且都有一样的主键字段;(2)MySQL使用Innodb引擎;
if (properties.getTarget().getChangeDataSynch().booleanValue()) {
@@ -118,16 +134,16 @@ public class MigrationHandler implements Runnable {
if (targetDatabaseType == DatabaseTypeEnum.MYSQL
&& !JdbcTemplateUtils.isMysqlInodbStorageEngine(properties.getTarget().getTargetSchema(),
sourceProperties.getPrefixTable() + tableDescription.getTableName(), targetDataSource)) {
- this.doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
+ return doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
} else {
List fields = mds.queryTableColumnName(tableDescription.getSchemaName(), tableDescription.getTableName());
- this.doIncreaseSynchronize(tableDescription, sourceProperties, sourceDataSource, writer, pks1, fields);
+ return doIncreaseSynchronize(tableDescription, sourceProperties, sourceDataSource, writer, pks1, fields);
}
} else {
- this.doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
+ return doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
}
} else {
- this.doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
+ return doFullCoverSynchronize(tableDescription, sourceProperties, sourceDataSource, writer);
}
}
}
@@ -138,14 +154,10 @@ public class MigrationHandler implements Runnable {
* @param tableDescription 表的描述信息,可能是视图表,可能是物理表
* @param writer 目的端的写入器
*/
- private void doFullCoverSynchronize(TableDescription tableDescription,
+ private Long doFullCoverSynchronize(TableDescription tableDescription,
DbswichProperties.SourceDataSourceProperties sourceProperties,
HikariDataSource sourceDataSource,
IDatabaseWriter writer) {
- int fetchSize = 100;
- if (sourceProperties.getFetchSize() >= fetchSize) {
- fetchSize = sourceProperties.getFetchSize();
- }
final int BATCH_SIZE = fetchSize;
// 准备目的端的数据写入操作
@@ -166,15 +178,13 @@ public class MigrationHandler implements Runnable {
fullTableName);
List fields = new ArrayList<>(columnMetaData.keySet());
- StatementResultSet srs = sourceOperator.queryTableData(tableDescription.getSchemaName(),
- tableDescription.getTableName(), fields);
+ StatementResultSet srs = sourceOperator.queryTableData(tableDescription.getSchemaName(), tableDescription.getTableName(), fields);
List