fix(iot): 修复日志批量删除功能中的表名错误和性能优化
- 修正了事件日志删除SQL中的表名从 iot_event log 到 iot_event_log - 将批量删除大小从5000调整为1000以提高性能稳定性 - 添加了批量删除过程中的进度日志记录功能 - 将删除批次间的休眠时间从100ms缩短到50ms - 增加了中断处理的日志警告信息 - 完善了删除任务完成后的统计日志输出 Signed-off-by: Gjm <你的邮箱>
This commit is contained in:
@@ -1876,70 +1876,94 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
|
||||
private long deleteDeviceLogBatch(Date cutoffDate) {
|
||||
long totalDeleted = 0;
|
||||
int batchSize = 5000;
|
||||
int batchSize = 1000;
|
||||
int batchCount = 0;
|
||||
|
||||
while (true) {
|
||||
int deleted = deviceMapper.deleteDeviceLogBatch(cutoffDate, batchSize);
|
||||
totalDeleted += deleted;
|
||||
batchCount++;
|
||||
|
||||
if (batchCount % 10 == 0) {
|
||||
log.info("设备日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
|
||||
}
|
||||
|
||||
if (deleted == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("设备日志删除任务被中断");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("设备日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
|
||||
return totalDeleted;
|
||||
}
|
||||
|
||||
private long deleteEventLogBatch(Date cutoffDate) {
|
||||
long totalDeleted = 0;
|
||||
int batchSize = 5000;
|
||||
int batchSize = 1000;
|
||||
int batchCount = 0;
|
||||
|
||||
while (true) {
|
||||
int deleted = deviceMapper.deleteEventLogBatch(cutoffDate, batchSize);
|
||||
totalDeleted += deleted;
|
||||
batchCount++;
|
||||
|
||||
if (batchCount % 10 == 0) {
|
||||
log.info("事件日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
|
||||
}
|
||||
|
||||
if (deleted == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("事件日志删除任务被中断");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("事件日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
|
||||
return totalDeleted;
|
||||
}
|
||||
|
||||
private long deleteFunctionLogBatch(Date cutoffDate) {
|
||||
long totalDeleted = 0;
|
||||
int batchSize = 5000;
|
||||
int batchSize = 1000;
|
||||
int batchCount = 0;
|
||||
|
||||
while (true) {
|
||||
int deleted = deviceMapper.deleteFunctionLogBatch(cutoffDate, batchSize);
|
||||
totalDeleted += deleted;
|
||||
batchCount++;
|
||||
|
||||
if (batchCount % 10 == 0) {
|
||||
log.info("告警日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
|
||||
}
|
||||
|
||||
if (deleted == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("告警日志删除任务被中断");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("告警日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
|
||||
return totalDeleted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -976,7 +976,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEventLogBatch">
|
||||
DELETE FROM iot_event log
|
||||
DELETE FROM iot_event_log
|
||||
WHERE create_time < #{cutoffDate}
|
||||
LIMIT #{batchSize}
|
||||
</delete>
|
||||
|
||||
Reference in New Issue
Block a user