From c0e0118b06562b236ea3972ade44fa7be72bd4e6 Mon Sep 17 00:00:00 2001 From: F-ca7 <627955292@qq.com> Date: Mon, 16 Jan 2023 11:53:35 +0800 Subject: [PATCH] 1. add more debug logs 2. fix case-insensitive table name problem --- .../src/main/java/exec/ImportExecutor.java | 7 +++++-- .../java/model/ConsumerExecutionContext.java | 1 + .../main/java/model/db/TableFieldMetaInfo.java | 3 ++- batch-tool/src/main/java/util/DbUtil.java | 18 +++++++++++------- batch-tool/src/main/java/util/FileUtil.java | 3 +++ .../worker/common/BaseDefaultConsumer.java | 3 +++ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/batch-tool/src/main/java/exec/ImportExecutor.java b/batch-tool/src/main/java/exec/ImportExecutor.java index 257d4d4..8d0fe36 100644 --- a/batch-tool/src/main/java/exec/ImportExecutor.java +++ b/batch-tool/src/main/java/exec/ImportExecutor.java @@ -17,7 +17,6 @@ package exec; import cmd.BaseOperateCommand; -import cmd.ImportCommand; import com.alibaba.druid.pool.DruidDataSource; import datasource.DataSourceConfig; import exception.DatabaseException; @@ -114,9 +113,13 @@ public void execute() { producerExecutionContext.getDdlMode()); } configureFieldMetaInfo(); + + logger.debug(producerExecutionContext.toString()); + logger.debug(consumerExecutionContext.toString()); + for (String tableName : tableNames) { if (producerExecutionContext.isSingleThread() - && consumerExecutionContext.isSingleThread()) { + && consumerExecutionContext.isSingleThread()) { // 使用按行读取insert模式 doSingleThreadImport(tableName); } else { diff --git a/batch-tool/src/main/java/model/ConsumerExecutionContext.java b/batch-tool/src/main/java/model/ConsumerExecutionContext.java index 6353bb6..0f285eb 100644 --- a/batch-tool/src/main/java/model/ConsumerExecutionContext.java +++ b/batch-tool/src/main/java/model/ConsumerExecutionContext.java @@ -313,6 +313,7 @@ public String toString() { ", toUpdateColumns='" + toUpdateColumns + '\'' + ", updateWithFuncPattern='" + updateWithFuncPattern + '\'' + ", sqlEscapeEnabled=" + sqlEscapeEnabled + + ", tableFieldMetaInfo=" + tableFieldMetaInfo + '}'; } diff --git a/batch-tool/src/main/java/model/db/TableFieldMetaInfo.java b/batch-tool/src/main/java/model/db/TableFieldMetaInfo.java index 8696258..67a2e51 100644 --- a/batch-tool/src/main/java/model/db/TableFieldMetaInfo.java +++ b/batch-tool/src/main/java/model/db/TableFieldMetaInfo.java @@ -16,11 +16,12 @@ package model.db; +import java.util.ArrayList; import java.util.List; public class TableFieldMetaInfo { - private List fieldMetaInfoList; + private List fieldMetaInfoList = new ArrayList<>(); /** * 主键 */ diff --git a/batch-tool/src/main/java/util/DbUtil.java b/batch-tool/src/main/java/util/DbUtil.java index 89a15f9..8a73245 100644 --- a/batch-tool/src/main/java/util/DbUtil.java +++ b/batch-tool/src/main/java/util/DbUtil.java @@ -31,9 +31,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.stream.Collectors; public class DbUtil { @@ -272,12 +272,16 @@ public static Map getDbFieldMetaInfo(Connection conn String schemaName, List tableNames) throws DatabaseException { - Map resultMap = new HashMap<>(); - for (String tableName : tableNames) { - TableFieldMetaInfo metaInfo = new TableFieldMetaInfo(); - metaInfo.setFieldMetaInfoList(new ArrayList<>()); - resultMap.put(tableName, metaInfo); - } + + Map resultMap = tableNames.stream() + .collect(Collectors.toMap( + tableName -> tableName, + tableName -> new TableFieldMetaInfo(), + (u, v) -> { + throw new IllegalStateException(String.format("Duplicate key %s", u)); + }, + () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER))); + Statement stmt = null; ResultSet resultSet = null; String metaInfoSql = String.format(DB_FIELD_INFO_SQL_PATTERN, schemaName); diff --git a/batch-tool/src/main/java/util/FileUtil.java b/batch-tool/src/main/java/util/FileUtil.java index d720338..09c7f80 100644 --- a/batch-tool/src/main/java/util/FileUtil.java +++ b/batch-tool/src/main/java/util/FileUtil.java @@ -178,6 +178,9 @@ private static ArrayList splitWithQuoteEscape(String line, String sep, f // 结尾有分隔符则忽略 len -= sep.length(); } + if (estimateCount <= 0) { + estimateCount = 1; + } ArrayList subStrings = new ArrayList<>(estimateCount); StringBuilder stringBuilder = new StringBuilder(line.length() / estimateCount); char sepStart = sep.charAt(0); diff --git a/batch-tool/src/main/java/worker/common/BaseDefaultConsumer.java b/batch-tool/src/main/java/worker/common/BaseDefaultConsumer.java index 8d4c3b1..66bd8c6 100644 --- a/batch-tool/src/main/java/worker/common/BaseDefaultConsumer.java +++ b/batch-tool/src/main/java/worker/common/BaseDefaultConsumer.java @@ -73,6 +73,9 @@ public void onProxyEvent(BatchLineEvent event) { } catch (Exception e) { consumerContext.setException(e); logger.error("Failed in table [{}], due to {}", tableName, e.getMessage()); + if (e.getStackTrace().length > 0) { + logger.error("{}", e.getStackTrace()[0]); + } // 认为无法恢复 throw new RuntimeException(e); } finally {