update document

master
xuxueli 6 years ago
parent 17d986521f
commit ba3a695a3b
  1. 16
      doc/XXL-JOB官方文档.md
  2. 22
      doc/db/tables_xxl_job.sql
  3. 2
      xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java
  4. 12
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobGroupMapper.xml
  5. 20
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
  6. 10
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml
  7. 26
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
  8. 10
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobRegistryMapper.xml
  9. 12
      xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobUserMapper.xml

@ -778,13 +778,13 @@ try{
### 5.2 “调度数据库”配置
XXL-JOB调度模块基于自研调度组件并支持集群部署,调度数据库表说明如下:
- XXL_JOB_LOCK:任务调度锁表;
- XXL_JOB_GROUP:执行器信息表,维护任务执行器信息;
- XXL_JOB_INFO:调度扩展信息表: 用于保存XXL-JOB调度任务的扩展信息,如任务分组、任务名、机器地址、执行器、执行入参和报警邮件等等;
- XXL_JOB_LOG:调度日志表: 用于保存XXL-JOB任务调度的历史信息,如调度结果、执行结果、调度入参、调度机器和执行器等等;
- XXL_JOB_LOGGLUE:任务GLUE日志:用于保存GLUE更新历史,用于支持GLUE的版本回溯功能;
- XXL_JOB_REGISTRY:执行器注册表,维护在线的执行器和调度中心机器地址信息;
- XXL_JOB_USER:系统用户表;
- xxl_job_lock:任务调度锁表;
- xxl_job_group:执行器信息表,维护任务执行器信息;
- xxl_job_info:调度扩展信息表: 用于保存XXL-JOB调度任务的扩展信息,如任务分组、任务名、机器地址、执行器、执行入参和报警邮件等等;
- xxl_job_log:调度日志表: 用于保存XXL-JOB任务调度的历史信息,如调度结果、执行结果、调度入参、调度机器和执行器等等;
- xxl_job_logglue:任务GLUE日志:用于保存GLUE更新历史,用于支持GLUE的版本回溯功能;
- xxl_job_registry:执行器注册表,维护在线的执行器和调度中心机器地址信息;
- xxl_job_user:系统用户表;
### 5.3 架构设计
@ -958,7 +958,7 @@ XXL-JOB会为每次调度请求生成一个单独的日志文件,需要通过
自v1.5版本之后, 任务取消了"任务执行机器"属性, 改为通过任务注册和自动发现的方式, 动态获取远程执行器地址并执行。
AppName: 每个执行器机器集群的唯一标示, 任务注册以 "执行器" 为最小粒度进行注册; 每个任务通过其绑定的执行器可感知对应的执行器机器列表;
注册表: 见"XXL_JOB_REGISTRY"表, "执行器" 在进行任务注册时将会周期性维护一条注册记录,即机器地址和AppName的绑定关系; "调度中心" 从而可以动态感知每个AppName在线的机器列表;
注册表: 见"xxl_job_registry"表, "执行器" 在进行任务注册时将会周期性维护一条注册记录,即机器地址和AppName的绑定关系; "调度中心" 从而可以动态感知每个AppName在线的机器列表;
执行器注册: 任务注册Beat周期默认30s; 执行器以一倍Beat进行执行器注册, 调度中心以一倍Beat进行动态任务发现; 注册信息的失效时间被三倍Beat;
执行器注册摘除:执行器销毁时,将会主动上报调度中心并摘除对应的执行器机器信息,提高心跳注册的实时性;

@ -3,7 +3,7 @@ use `xxl-job`;
CREATE TABLE `XXL_JOB_INFO` (
CREATE TABLE `xxl_job_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_cron` varchar(128) NOT NULL COMMENT '任务执行CRON',
@ -29,7 +29,7 @@ CREATE TABLE `XXL_JOB_INFO` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_LOG` (
CREATE TABLE `xxl_job_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_id` int(11) NOT NULL COMMENT '任务,主键ID',
@ -50,7 +50,7 @@ CREATE TABLE `XXL_JOB_LOG` (
KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_LOGGLUE` (
CREATE TABLE `xxl_job_logglue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_id` int(11) NOT NULL COMMENT '任务,主键ID',
`glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型',
@ -61,7 +61,7 @@ CREATE TABLE `XXL_JOB_LOGGLUE` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_REGISTRY` (
CREATE TABLE `xxl_job_registry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`registry_group` varchar(255) NOT NULL,
`registry_key` varchar(255) NOT NULL,
@ -71,7 +71,7 @@ CREATE TABLE `XXL_JOB_REGISTRY` (
KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_GROUP` (
CREATE TABLE `xxl_job_group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_name` varchar(64) NOT NULL COMMENT '执行器AppName',
`title` varchar(12) NOT NULL COMMENT '执行器名称',
@ -81,7 +81,7 @@ CREATE TABLE `XXL_JOB_GROUP` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_USER` (
CREATE TABLE `xxl_job_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL COMMENT '账号',
`password` varchar(50) NOT NULL COMMENT '密码',
@ -91,16 +91,16 @@ CREATE TABLE `XXL_JOB_USER` (
UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `XXL_JOB_LOCK` (
CREATE TABLE `xxl_job_lock` (
`lock_name` varchar(50) NOT NULL COMMENT '锁名称',
PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `XXL_JOB_GROUP`(`id`, `app_name`, `title`, `order`, `address_type`, `address_list`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 1, 0, NULL);
INSERT INTO `XXL_JOB_INFO`(`id`, `job_group`, `job_cron`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '0 0 0 * * ? *', '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `XXL_JOB_USER`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `XXL_JOB_LOCK` ( `lock_name`) VALUES ( 'schedule_lock');
INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `order`, `address_type`, `address_list`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 1, 0, NULL);
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_cron`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '0 0 0 * * ? *', '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');
commit;

@ -58,7 +58,7 @@ public class JobScheduleHelper {
}
conn.setAutoCommit(false);
preparedStatement = conn.prepareStatement( "select * from XXL_JOB_LOCK where lock_name = 'schedule_lock' for update" );
preparedStatement = conn.prepareStatement( "select * from xxl_job_lock where lock_name = 'schedule_lock' for update" );
preparedStatement.execute();
// tx start

@ -23,24 +23,24 @@
<select id="findAll" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_GROUP AS t
FROM xxl_job_group AS t
ORDER BY t.order ASC
</select>
<select id="findByAddressType" parameterType="java.lang.Integer" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_GROUP AS t
FROM xxl_job_group AS t
WHERE t.address_type = #{addressType}
ORDER BY t.order ASC
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobGroup" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO XXL_JOB_GROUP ( `app_name`, `title`, `order`, `address_type`, `address_list`)
INSERT INTO xxl_job_group ( `app_name`, `title`, `order`, `address_type`, `address_list`)
values ( #{appName}, #{title}, #{order}, #{addressType}, #{addressList});
</insert>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobGroup" >
UPDATE XXL_JOB_GROUP
UPDATE xxl_job_group
SET `app_name` = #{appName},
`title` = #{title},
`order` = #{order},
@ -50,13 +50,13 @@
</update>
<delete id="remove" parameterType="java.lang.Integer" >
DELETE FROM XXL_JOB_GROUP
DELETE FROM xxl_job_group
WHERE id = #{id}
</delete>
<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_GROUP AS t
FROM xxl_job_group AS t
WHERE t.id = #{id}
</select>

@ -62,7 +62,7 @@
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_INFO AS t
FROM xxl_job_info AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
AND t.job_group = #{jobGroup}
@ -83,7 +83,7 @@
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
SELECT count(1)
FROM XXL_JOB_INFO AS t
FROM xxl_job_info AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
AND t.job_group = #{jobGroup}
@ -101,7 +101,7 @@
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO XXL_JOB_INFO (
INSERT INTO xxl_job_info (
job_group,
job_cron,
job_desc,
@ -154,12 +154,12 @@
<select id="loadById" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_INFO AS t
FROM xxl_job_info AS t
WHERE t.id = #{id}
</select>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE XXL_JOB_INFO
UPDATE xxl_job_info
SET
job_group = #{jobGroup},
job_cron = #{jobCron},
@ -186,31 +186,31 @@
<delete id="delete" parameterType="java.util.HashMap">
DELETE
FROM XXL_JOB_INFO
FROM xxl_job_info
WHERE id = #{id}
</delete>
<select id="getJobsByGroup" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_INFO AS t
FROM xxl_job_info AS t
WHERE t.job_group = #{jobGroup}
</select>
<select id="findAllCount" resultType="int">
SELECT count(1)
FROM XXL_JOB_INFO
FROM xxl_job_info
</select>
<select id="scheduleJobQuery" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_INFO AS t
FROM xxl_job_info AS t
WHERE t.trigger_status = 1
and t.trigger_next_time<![CDATA[ < ]]> #{maxNextTime}
</select>
<update id="scheduleUpdate" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE XXL_JOB_INFO
UPDATE xxl_job_info
SET
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime}

@ -24,7 +24,7 @@
</sql>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLogGlue" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO XXL_JOB_LOGGLUE (
INSERT INTO xxl_job_logglue (
`job_id`,
`glue_type`,
`glue_source`,
@ -46,16 +46,16 @@
<select id="findByJobId" parameterType="java.lang.Integer" resultMap="XxlJobLogGlue">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_LOGGLUE AS t
FROM xxl_job_logglue AS t
WHERE t.job_id = #{jobId}
ORDER BY id DESC
</select>
<delete id="removeOld" >
DELETE FROM XXL_JOB_LOGGLUE
DELETE FROM xxl_job_logglue
WHERE id NOT in(
SELECT id FROM(
SELECT id FROM XXL_JOB_LOGGLUE
SELECT id FROM xxl_job_logglue
WHERE `job_id` = #{jobId}
ORDER BY update_time desc
LIMIT 0, #{limit}
@ -64,7 +64,7 @@
</delete>
<delete id="deleteByJobId" parameterType="java.lang.Integer" >
DELETE FROM XXL_JOB_LOGGLUE
DELETE FROM xxl_job_logglue
WHERE `job_id` = #{jobId}
</delete>

@ -46,7 +46,7 @@
<select id="pageList" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_LOG AS t
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
@ -80,7 +80,7 @@
<select id="pageListCount" resultType="int">
SELECT count(1)
FROM XXL_JOB_LOG AS t
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
@ -112,13 +112,13 @@
<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_LOG AS t
FROM xxl_job_log AS t
WHERE t.id = #{id}
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO XXL_JOB_LOG (
INSERT INTO xxl_job_log (
`job_group`,
`job_id`,
`trigger_time`,
@ -137,7 +137,7 @@
</insert>
<update id="updateTriggerInfo" >
UPDATE XXL_JOB_LOG
UPDATE xxl_job_log
SET
`trigger_time`= #{triggerTime},
`trigger_code`= #{triggerCode},
@ -151,7 +151,7 @@
</update>
<update id="updateHandleInfo">
UPDATE XXL_JOB_LOG
UPDATE xxl_job_log
SET
`handle_time`= #{handleTime},
`handle_code`= #{handleCode},
@ -160,13 +160,13 @@
</update>
<delete id="delete" >
delete from XXL_JOB_LOG
delete from xxl_job_log
WHERE job_id = #{jobId}
</delete>
<select id="triggerCountByHandleCode" resultType="int" >
SELECT count(1)
FROM XXL_JOB_LOG AS t
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="handleCode gt 0">
AND t.handle_code = #{handleCode}
@ -180,13 +180,13 @@
COUNT(handle_code) triggerDayCount,
SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
FROM XXL_JOB_LOG
FROM xxl_job_log
WHERE trigger_time BETWEEN #{from} and #{to}
GROUP BY triggerDay;
</select>
<delete id="clearLog" >
delete from XXL_JOB_LOG
delete from xxl_job_log
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
AND job_group = #{jobGroup}
@ -200,7 +200,7 @@
<if test="clearBeforeNum gt 0">
AND id NOT in(
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" >
<if test="jobGroup gt 0">
AND t.job_group = #{jobGroup}
@ -218,7 +218,7 @@
</delete>
<select id="findFailJobLogIds" resultType="int" >
SELECT id FROM `XXL_JOB_LOG`
SELECT id FROM `xxl_job_log`
WHERE !(
(trigger_code in (0, 200) and handle_code = 0)
OR
@ -229,7 +229,7 @@
</select>
<update id="updateAlarmStatus" >
UPDATE XXL_JOB_LOG
UPDATE xxl_job_log
SET
`alarm_status` = #{newAlarmStatus}
WHERE `id`= #{logId} AND `alarm_status` = #{oldAlarmStatus}

@ -20,18 +20,18 @@
</sql>
<delete id="removeDead" parameterType="java.lang.Integer" >
DELETE FROM XXL_JOB_REGISTRY
DELETE FROM xxl_job_registry
WHERE update_time <![CDATA[ < ]]> DATE_ADD(NOW(),INTERVAL -#{timeout} SECOND)
</delete>
<select id="findAll" parameterType="java.lang.Integer" resultMap="XxlJobRegistry">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_REGISTRY AS t
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(NOW(),INTERVAL -#{timeout} SECOND)
</select>
<update id="registryUpdate" >
UPDATE XXL_JOB_REGISTRY
UPDATE xxl_job_registry
SET `update_time` = NOW()
WHERE `registry_group` = #{registryGroup}
AND `registry_key` = #{registryKey}
@ -39,12 +39,12 @@
</update>
<insert id="registrySave" >
INSERT INTO XXL_JOB_REGISTRY( `registry_group` , `registry_key` , `registry_value`, `update_time`)
INSERT INTO xxl_job_registry( `registry_group` , `registry_key` , `registry_value`, `update_time`)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW())
</insert>
<delete id="registryDelete" >
DELETE FROM XXL_JOB_REGISTRY
DELETE FROM xxl_job_registry
WHERE registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}

@ -21,7 +21,7 @@
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobUser">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_USER AS t
FROM xxl_job_user AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="username != null and username != ''">
AND t.username like CONCAT(CONCAT('%', #{username}), '%')
@ -36,7 +36,7 @@
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
SELECT count(1)
FROM XXL_JOB_USER AS t
FROM xxl_job_user AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="username != null and username != ''">
AND t.username like CONCAT(CONCAT('%', #{username}), '%')
@ -49,12 +49,12 @@
<select id="loadByUserName" parameterType="java.util.HashMap" resultMap="XxlJobUser">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_USER AS t
FROM xxl_job_user AS t
WHERE t.username = #{username}
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobUser" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO XXL_JOB_USER (
INSERT INTO xxl_job_user (
username,
password,
role,
@ -68,7 +68,7 @@
</insert>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobUser" >
UPDATE XXL_JOB_USER
UPDATE xxl_job_user
SET
<if test="password != null and password != ''">
password = #{password},
@ -80,7 +80,7 @@
<delete id="delete" parameterType="java.util.HashMap">
DELETE
FROM XXL_JOB_USER
FROM xxl_job_user
WHERE id = #{id}
</delete>

Loading…
Cancel
Save