add debug info

This commit is contained in:
zyyang 2024-04-24 21:26:11 +08:00
parent e5e34c3a66
commit 4c542f5436
2 changed files with 31 additions and 2 deletions

View File

@ -264,6 +264,9 @@ public class DefaultDataHandler implements DataHandler {
*/
private int writeBatchToSupTableBySQL(Connection conn, String table, List<Record> recordBatch) throws SQLException {
List<ColumnMeta> columnMetas = this.schemaCache.getColumnMetaList(table);
if (columnMetas.isEmpty()) {
throw DataXException.asDataXException("table: " + table + " metadata is empty!");
}
StringBuilder sb = new StringBuilder("insert into");
for (Record record : recordBatch) {
@ -292,7 +295,13 @@ public class DefaultDataHandler implements DataHandler {
}
String sql = sb.toString();
return executeUpdate(conn, sql);
try {
return executeUpdate(conn, sql);
} catch (SQLException e) {
LOG.error("failed to writeBatchToSupTableBySQL, table: " + table + ", column meta: " + columnMetas +
", cause: " + e.getMessage(), e);
throw e;
}
}
private int executeUpdate(Connection conn, String sql) throws SQLException {

View File

@ -22,6 +22,8 @@ public final class SchemaCache {
private static Configuration config;
private static Connection conn;
private static String dbname;
// table name -> TableMeta
private static final Map<String, TableMeta> tableMetas = new LinkedHashMap<>();
// table name ->List<ColumnMeta>
@ -44,7 +46,7 @@ public final class SchemaCache {
"failed to connect to url: " + url + ", cause: {" + e.getMessage() + "}");
}
final String dbname = TDengineWriter.parseDatabaseFromJdbcUrl(url);
dbname = TDengineWriter.parseDatabaseFromJdbcUrl(url);
SchemaManager schemaManager = new Schema3_0Manager(SchemaCache.conn, dbname);
// init table meta cache and load
@ -70,6 +72,24 @@ public final class SchemaCache {
}
public TableMeta getTableMeta(String table_name) {
//if (tableMetas.get(table_name) == null) {
// synchronized (SchemaCache.class) {
// if (tableMetas.get(table_name) == null) {
// SchemaManager schemaManager = new Schema3_0Manager(SchemaCache.conn, dbname);
//
// List<String> tables = new ArrayList<>();
// tables.add(table_name);
// Map<String, TableMeta> metas = schemaManager.loadTableMeta(tables);
//
// tableMetas.putAll(metas);
// }
// }
//}
if (!tableMetas.containsKey(table_name)) {
throw DataXException.asDataXException(TDengineWriterErrorCode.RUNTIME_EXCEPTION,
"table metadata of " + table_name + " is empty!");
}
return tableMetas.get(table_name);
}