Skip to content

Commit

Permalink
feat: 执行历史归档新增模式-只备份不删除 TencentBlueKing#3037
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jun 6, 2024
1 parent 7f579f7 commit 87635b0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jooq.Loader;
import org.jooq.LoaderError;
import org.jooq.TableRecord;
import org.jooq.impl.DSL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -54,11 +55,11 @@ public ExecuteArchiveDAOImpl(DSLContext context) {
public Integer batchInsert(List<? extends TableRecord<?>> recordList, int bulkSize) throws IOException {
long start = System.currentTimeMillis();
int successInsertedRecords = 0;
String table = recordList.get(0).getTable().getName();
String tableName = recordList.get(0).getTable().getName();
boolean success = true;
try {
Loader<?> loader =
context.loadInto(recordList.get(0).getTable())
context.loadInto(DSL.table(tableName))
// 由于这里是批量写入,jooq 不允许使用 onDuplicateKeyIgnore/onDuplicateKeyUpdate.
// 否则会报错"Cannot apply bulk loading with onDuplicateKey flags"
// 所以这里暂时使用 onDuplicateKeyError 错误处理方式,等后续流程进一步判断是否是主键冲突错误
Expand All @@ -72,7 +73,7 @@ public Integer batchInsert(List<? extends TableRecord<?>> recordList, int bulkSi
String bulkInsertResult = successInsertedRecords == recordList.size() ? "success" : "fail";
log.info(
"InsertBulk: Load {} data|result|{}|executed|{}|processed|{}|stored|{}|ignored|{}|errors|{}",
table,
tableName,
bulkInsertResult,
loader.executed(),
loader.processed(),
Expand All @@ -82,7 +83,7 @@ public Integer batchInsert(List<? extends TableRecord<?>> recordList, int bulkSi
);
if (CollectionUtils.isNotEmpty(loader.errors())) {
for (LoaderError error : loader.errors()) {
ARCHIVE_FAILED_LOGGER.error("Error while load {} data, exception: {}, error row: {}", table,
ARCHIVE_FAILED_LOGGER.error("Error while load {} data, exception: {}, error row: {}", tableName,
error.exception().getMessage(), error.row());
}
if (hasDuplicateError(loader.errors())) {
Expand All @@ -91,12 +92,12 @@ public Integer batchInsert(List<? extends TableRecord<?>> recordList, int bulkSi
}
}
} catch (IOException e) {
String errorMsg = String.format("Error while loading %s data!", table);
String errorMsg = String.format("Error while loading %s data!", tableName);
log.error(errorMsg, e);
success = false;
throw e;
} finally {
log.info("Load data to {} done! success: {}, total: {}, inserted: {}, cost: {}ms", table, success,
log.info("Load data to {} done! success: {}, total: {}, inserted: {}, cost: {}ms", tableName, success,
recordList.size(), successInsertedRecords, System.currentTimeMillis() - start);
}

Expand Down

0 comments on commit 87635b0

Please sign in to comment.