Skip to content

Commit

Permalink
1. add more debug logs
Browse files Browse the repository at this point in the history
2. fix case-insensitive table name problem
  • Loading branch information
F-ca7 committed Jan 16, 2023
1 parent 8005394 commit c0e0118
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
7 changes: 5 additions & 2 deletions batch-tool/src/main/java/exec/ImportExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package exec;

import cmd.BaseOperateCommand;
import cmd.ImportCommand;
import com.alibaba.druid.pool.DruidDataSource;
import datasource.DataSourceConfig;
import exception.DatabaseException;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public String toString() {
", toUpdateColumns='" + toUpdateColumns + '\'' +
", updateWithFuncPattern='" + updateWithFuncPattern + '\'' +
", sqlEscapeEnabled=" + sqlEscapeEnabled +
", tableFieldMetaInfo=" + tableFieldMetaInfo +
'}';
}

Expand Down
3 changes: 2 additions & 1 deletion batch-tool/src/main/java/model/db/TableFieldMetaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package model.db;

import java.util.ArrayList;
import java.util.List;

public class TableFieldMetaInfo {

private List<FieldMetaInfo> fieldMetaInfoList;
private List<FieldMetaInfo> fieldMetaInfoList = new ArrayList<>();
/**
* 主键
*/
Expand Down
18 changes: 11 additions & 7 deletions batch-tool/src/main/java/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -272,12 +272,16 @@ public static Map<String, TableFieldMetaInfo> getDbFieldMetaInfo(Connection conn
String schemaName,
List<String> tableNames)
throws DatabaseException {
Map<String, TableFieldMetaInfo> resultMap = new HashMap<>();
for (String tableName : tableNames) {
TableFieldMetaInfo metaInfo = new TableFieldMetaInfo();
metaInfo.setFieldMetaInfoList(new ArrayList<>());
resultMap.put(tableName, metaInfo);
}

Map<String, TableFieldMetaInfo> 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);
Expand Down
3 changes: 3 additions & 0 deletions batch-tool/src/main/java/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ private static ArrayList<String> splitWithQuoteEscape(String line, String sep, f
// 结尾有分隔符则忽略
len -= sep.length();
}
if (estimateCount <= 0) {
estimateCount = 1;
}
ArrayList<String> subStrings = new ArrayList<>(estimateCount);
StringBuilder stringBuilder = new StringBuilder(line.length() / estimateCount);
char sepStart = sep.charAt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c0e0118

Please sign in to comment.