From 71cf3f611f70e74f9f03569eed202bfe80a6cff7 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Tue, 19 Nov 2019 18:22:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83=E7=A7=BB?= =?UTF-8?q?=E9=99=A4SQL=E4=B8=AD=E7=9A=84=20"now()"=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=9B=E9=9B=86=E7=BE=A4=E9=83=A8=E7=BD=B2=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E4=BE=9D=E8=B5=96DB=E6=97=B6=E9=92=9F=EF=BC=8C?= =?UTF-8?q?=E4=BB=85=E9=9C=80=E8=A6=81=E4=BF=9D=E8=AF=81=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E5=BA=94=E7=94=A8=E8=8A=82=E7=82=B9=E6=97=B6?= =?UTF-8?q?=E9=92=9F=E4=B8=80=E8=87=B4=E5=8D=B3=E5=8F=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 10 +++++----- doc/db/tables_xxl_job.sql | 6 +++--- .../job/admin/controller/JobCodeController.java | 5 +++++ .../job/admin/controller/JobGroupController.java | 7 ++----- .../xxl/job/admin/core/model/XxlJobLogGlue.java | 14 ++++++++------ .../core/thread/JobRegistryMonitorHelper.java | 9 +++------ .../com/xxl/job/admin/dao/XxlJobRegistryDao.java | 13 +++++++++---- .../xxl/job/admin/service/impl/AdminBizImpl.java | 4 ++-- .../job/admin/service/impl/XxlJobServiceImpl.java | 7 +++++++ .../resources/mybatis-mapper/XxlJobInfoMapper.xml | 8 ++++---- .../mybatis-mapper/XxlJobLogGlueMapper.xml | 4 ++-- .../mybatis-mapper/XxlJobRegistryMapper.xml | 8 ++++---- .../com/xxl/job/admin/dao/XxlJobInfoDaoTest.java | 7 +++++-- .../xxl/job/admin/dao/XxlJobLogGlueDaoTest.java | 7 ++++--- .../xxl/job/admin/dao/XxlJobRegistryDaoTest.java | 7 ++++--- 15 files changed, 67 insertions(+), 49 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 87cbfd73..e9281bef 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -475,7 +475,6 @@ XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是 调度中心集群部署时,几点要求和建议: - DB配置保持一致; -- 登陆账号配置保持一致; - 集群机器时钟保持一致(单机集群忽视); - 建议:推荐通过nginx为调度中心集群做负载均衡,分配域名。调度中心访问、执行器回调配置、调用API服务等操作均通过该域名进行。 @@ -1588,10 +1587,11 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 16、任务告警组件分页参数无效问题修复; - 17、DB脚本默认编码改为utf8mb4,修复字符乱码问题(建议Mysql版本5.7+); - 18、调度中心任务平均分配,触发组件每次获取与线程池数量相关数量的任务,避免大量任务集中在单个调度中心集群节点; -- 19、[ING]xxl-rpc服务端线程优化,降低线程内存开销; -- 20、[ING]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表; -- 21、[ING]调度中心日志删除,改为分页获取ID,根据ID删除的方式; -- 22、[ING]任务回调改为restful方式; +- 19、调度中心移除SQL中的 "now()" 函数;集群部署时不再依赖DB时钟,仅需要保证调度中心应用节点时钟一致即可; +- 20、[ING]xxl-rpc服务端线程优化,降低线程内存开销; +- 21、[ING]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表; +- 22、[ING]调度中心日志删除,改为分页获取ID,根据ID删除的方式; +- 23、[ING]任务回调改为restful方式; ### TODO LIST diff --git a/doc/db/tables_xxl_job.sql b/doc/db/tables_xxl_job.sql index e3538cc8..c6c5386d 100644 --- a/doc/db/tables_xxl_job.sql +++ b/doc/db/tables_xxl_job.sql @@ -59,8 +59,8 @@ CREATE TABLE `xxl_job_logglue` ( `glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型', `glue_source` mediumtext COMMENT 'GLUE源代码', `glue_remark` varchar(128) NOT NULL COMMENT 'GLUE备注', - `add_time` timestamp NULL DEFAULT NULL, - `update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `add_time` datetime DEFAULT NULL, + `update_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -69,7 +69,7 @@ CREATE TABLE `xxl_job_registry` ( `registry_group` varchar(50) NOT NULL, `registry_key` varchar(255) NOT NULL, `registry_value` varchar(255) NOT NULL, - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobCodeController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobCodeController.java index 7fbf35b5..302b9bf9 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobCodeController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobCodeController.java @@ -72,6 +72,8 @@ public class JobCodeController { exists_jobInfo.setGlueSource(glueSource); exists_jobInfo.setGlueRemark(glueRemark); exists_jobInfo.setGlueUpdatetime(new Date()); + + exists_jobInfo.setUpdateTime(new Date()); xxlJobInfoDao.update(exists_jobInfo); // log old code @@ -80,6 +82,9 @@ public class JobCodeController { xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType()); xxlJobLogGlue.setGlueSource(glueSource); xxlJobLogGlue.setGlueRemark(glueRemark); + + xxlJobLogGlue.setAddTime(new Date()); + xxlJobLogGlue.setUpdateTime(new Date()); xxlJobLogGlueDao.save(xxlJobLogGlue); // remove code backup more than 30 diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobGroupController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobGroupController.java index bb130f65..9376eb75 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobGroupController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobGroupController.java @@ -14,10 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; /** * job group controller @@ -119,7 +116,7 @@ public class JobGroupController { private List findRegistryByAppName(String appNameParam){ HashMap> appAddressMap = new HashMap>(); - List list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT); + List list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date()); if (list != null) { for (XxlJobRegistry item: list) { if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLogGlue.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLogGlue.java index c617d425..7b1ca461 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLogGlue.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLogGlue.java @@ -1,5 +1,7 @@ package com.xxl.job.admin.core.model; +import java.util.Date; + /** * xxl-job log for glue, used to track job code process * @author xuxueli 2016-5-19 17:57:46 @@ -11,8 +13,8 @@ public class XxlJobLogGlue { private String glueType; // GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum private String glueSource; private String glueRemark; - private String addTime; - private String updateTime; + private Date addTime; + private Date updateTime; public int getId() { return id; @@ -54,19 +56,19 @@ public class XxlJobLogGlue { this.glueRemark = glueRemark; } - public String getAddTime() { + public Date getAddTime() { return addTime; } - public void setAddTime(String addTime) { + public void setAddTime(Date addTime) { this.addTime = addTime; } - public String getUpdateTime() { + public Date getUpdateTime() { return updateTime; } - public void setUpdateTime(String updateTime) { + public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryMonitorHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryMonitorHelper.java index 6c838e04..1e91014f 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryMonitorHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryMonitorHelper.java @@ -7,10 +7,7 @@ import com.xxl.job.core.enums.RegistryConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -38,14 +35,14 @@ public class JobRegistryMonitorHelper { if (groupList!=null && !groupList.isEmpty()) { // remove dead address (admin/executor) - List ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead(RegistryConfig.DEAD_TIMEOUT); + List ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead(RegistryConfig.DEAD_TIMEOUT, new Date()); if (ids!=null && ids.size()>0) { XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().removeDead(ids); } // fresh online address (admin/executor) HashMap> appAddressMap = new HashMap>(); - List list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll(RegistryConfig.DEAD_TIMEOUT); + List list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll(RegistryConfig.DEAD_TIMEOUT, new Date()); if (list != null) { for (XxlJobRegistry item: list) { if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java index 779200b2..333e2ae7 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobRegistryDao.java @@ -4,6 +4,7 @@ import com.xxl.job.admin.core.model.XxlJobRegistry; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Date; import java.util.List; /** @@ -12,19 +13,23 @@ import java.util.List; @Mapper public interface XxlJobRegistryDao { - public List findDead(@Param("timeout") int timeout); + public List findDead(@Param("timeout") int timeout, + @Param("nowTime") Date nowTime); public int removeDead(@Param("ids") List ids); - public List findAll(@Param("timeout") int timeout); + public List findAll(@Param("timeout") int timeout, + @Param("nowTime") Date nowTime); public int registryUpdate(@Param("registryGroup") String registryGroup, @Param("registryKey") String registryKey, - @Param("registryValue") String registryValue); + @Param("registryValue") String registryValue, + @Param("updateTime") Date updateTime); public int registrySave(@Param("registryGroup") String registryGroup, @Param("registryKey") String registryKey, - @Param("registryValue") String registryValue); + @Param("registryValue") String registryValue, + @Param("updateTime") Date updateTime); public int registryDelete(@Param("registryGroup") String registGroup, @Param("registryKey") String registryKey, diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java index 108f5df3..33d1e52d 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java @@ -126,9 +126,9 @@ public class AdminBizImpl implements AdminBiz { @Override public ReturnT registry(RegistryParam registryParam) { - int ret = xxlJobRegistryDao.registryUpdate(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); + int ret = xxlJobRegistryDao.registryUpdate(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date()); if (ret < 1) { - xxlJobRegistryDao.registrySave(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue()); + xxlJobRegistryDao.registrySave(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue(), new Date()); // fresh freshGroupRegistryInfo(registryParam); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index 1bd746ad..8d45efb6 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -117,6 +117,9 @@ public class XxlJobServiceImpl implements XxlJobService { } // add in db + jobInfo.setAddTime(new Date()); + jobInfo.setUpdateTime(new Date()); + jobInfo.setGlueUpdatetime(new Date()); xxlJobInfoDao.save(jobInfo); if (jobInfo.getId() < 1) { return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_add")+I18nUtil.getString("system_fail")) ); @@ -220,6 +223,8 @@ public class XxlJobServiceImpl implements XxlJobService { exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount()); exists_jobInfo.setChildJobId(jobInfo.getChildJobId()); exists_jobInfo.setTriggerNextTime(nextTriggerTime); + + exists_jobInfo.setUpdateTime(new Date()); xxlJobInfoDao.update(exists_jobInfo); @@ -260,6 +265,7 @@ public class XxlJobServiceImpl implements XxlJobService { xxlJobInfo.setTriggerLastTime(0); xxlJobInfo.setTriggerNextTime(nextTriggerTime); + xxlJobInfo.setUpdateTime(new Date()); xxlJobInfoDao.update(xxlJobInfo); return ReturnT.SUCCESS; } @@ -272,6 +278,7 @@ public class XxlJobServiceImpl implements XxlJobService { xxlJobInfo.setTriggerLastTime(0); xxlJobInfo.setTriggerNextTime(0); + xxlJobInfo.setUpdateTime(new Date()); xxlJobInfoDao.update(xxlJobInfo); return ReturnT.SUCCESS; } diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml index 93406452..cb9048d2 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml @@ -133,8 +133,8 @@ #{jobGroup}, #{jobCron}, #{jobDesc}, - NOW(), - NOW(), + #{addTime}, + #{updateTime}, #{author}, #{alarmEmail}, #{executorRouteStrategy}, @@ -146,7 +146,7 @@ #{glueType}, #{glueSource}, #{glueRemark}, - NOW(), + #{glueUpdatetime}, #{childJobId}, #{triggerStatus}, #{triggerLastTime}, @@ -170,7 +170,7 @@ job_group = #{jobGroup}, job_cron = #{jobCron}, job_desc = #{jobDesc}, - update_time = NOW(), + update_time = #{updateTime}, author = #{author}, alarm_email = #{alarmEmail}, executor_route_strategy = #{executorRouteStrategy}, diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml index 6a390ffb..2dd1a96a 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml @@ -36,8 +36,8 @@ #{glueType}, #{glueSource}, #{glueRemark}, - now(), - now() + #{addTime}, + #{updateTime} );