调度中心日志删除优化,改为分页获取ID并根据ID删除的方式,避免批量删除海量日志导致死锁问题

2.1.2
xuxueli 5 years ago
parent ada47e5aef
commit e73be8175c

@ -1590,8 +1590,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 19、调度中心移除SQL中的 "now()" 函数集群部署时不再依赖DB时钟仅需要保证调度中心应用节点时钟一致即可 - 19、调度中心移除SQL中的 "now()" 函数集群部署时不再依赖DB时钟仅需要保证调度中心应用节点时钟一致即可
- 20、xxl-rpc服务端线程优化降低线程内存开销 - 20、xxl-rpc服务端线程优化降低线程内存开销
- 21、调度中心回调API服务改为restful方式 - 21、调度中心回调API服务改为restful方式
- 22、[ING]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表 - 22、调度中心日志删除优化改为分页获取ID并根据ID删除的方式避免批量删除海量日志导致死锁问题
- 23、[ING]调度中心日志删除改为分页获取ID根据ID删除的方式 - 23、[ING]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表
@ -1632,6 +1632,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 34、通讯调整双向HTTP回调和其他API自定义AccessTokenRestful执行器复用容器端口 - 34、通讯调整双向HTTP回调和其他API自定义AccessTokenRestful执行器复用容器端口
- 35、父子任务参数传递流程任务等透传动态参数 - 35、父子任务参数传递流程任务等透传动态参数
- 36、任务操作API服务调整为和回调服务一致降低接入成本 - 36、任务操作API服务调整为和回调服务一致降低接入成本
- 37、新增执行器描述、任务描述属性
## 七、其他 ## 七、其他

@ -216,7 +216,14 @@ public class JobLogController {
return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid")); return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
} }
xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum); List<Long> logIds = null;
do {
logIds = xxlJobLogDao.findClearLogIds(jobGroup, jobId, clearBeforeTime, clearBeforeNum, 1000);
if (logIds!=null && logIds.size()>0) {
xxlJobLogDao.clearLog(logIds);
}
} while (logIds!=null && logIds.size()>0);
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }

@ -46,10 +46,12 @@ public interface XxlJobLogDao {
public List<Map<String, Object>> triggerCountByDay(@Param("from") Date from, public List<Map<String, Object>> triggerCountByDay(@Param("from") Date from,
@Param("to") Date to); @Param("to") Date to);
public int clearLog(@Param("jobGroup") int jobGroup, public List<Long> findClearLogIds(@Param("jobGroup") int jobGroup,
@Param("jobId") int jobId, @Param("jobId") int jobId,
@Param("clearBeforeTime") Date clearBeforeTime, @Param("clearBeforeTime") Date clearBeforeTime,
@Param("clearBeforeNum") int clearBeforeNum); @Param("clearBeforeNum") int clearBeforeNum,
@Param("pagesize") int pagesize);
public int clearLog(@Param("logIds") List<Long> logIds);
public List<Long> findFailJobLogIds(@Param("pagesize") int pagesize); public List<Long> findFailJobLogIds(@Param("pagesize") int pagesize);

@ -186,8 +186,8 @@
ORDER BY triggerDay ORDER BY triggerDay
</select> </select>
<delete id="clearLog" > <select id="findClearLogIds" resultType="long" >
delete from xxl_job_log SELECT id FROM xxl_job_log
<trim prefix="WHERE" prefixOverrides="AND | OR" > <trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0"> <if test="jobGroup gt 0">
AND job_group = #{jobGroup} AND job_group = #{jobGroup}
@ -200,22 +200,32 @@
</if> </if>
<if test="clearBeforeNum gt 0"> <if test="clearBeforeNum gt 0">
AND id NOT in( AND id NOT in(
SELECT id FROM( SELECT id FROM(
SELECT id FROM xxl_job_log AS t SELECT id FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" > <trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0"> <if test="jobGroup gt 0">
AND t.job_group = #{jobGroup} AND t.job_group = #{jobGroup}
</if> </if>
<if test="jobId gt 0"> <if test="jobId gt 0">
AND t.job_id = #{jobId} AND t.job_id = #{jobId}
</if> </if>
</trim> </trim>
ORDER BY t.trigger_time desc ORDER BY t.trigger_time desc
LIMIT 0, #{clearBeforeNum} LIMIT 0, #{clearBeforeNum}
) t1 ) t1
) )
</if> </if>
</trim> </trim>
order by id asc
LIMIT #{pagesize}
</select>
<delete id="clearLog" >
delete from xxl_job_log
WHERE id in
<foreach collection="logIds" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</delete> </delete>
<select id="findFailJobLogIds" resultType="long" > <select id="findFailJobLogIds" resultType="long" >

Loading…
Cancel
Save