Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持xxl-job 数据存储使用虚谷数据库 #3450

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions doc/db/tables_xxl_job_xugu.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
use system;
create database xg_job CHARACTER SET utf8;
-- SYSDBA.UNDO_LOG definition
-- SYSDBA.UNDO_LOG definition
use xg_job;


create table "SYSDBA"."UNDO_LOG"(
"branch_id" bigint not null comment 'branch transaction id',
"xid" varchar(100) not null comment 'global transaction id',
"context" varchar(128) not null comment 'undo_log context,such as serialization',
"rollback_info" blob not null comment 'rollback info',
"log_status" integer not null comment '0:normal status,1:defense status',
"log_created" datetime not null comment 'create datetime',
"log_modified" datetime not null comment 'modify datetime'
) comment 'AT transaction mode undo table';


-- SYSDBA.XXL_JOB_GROUP definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_GROUP"(
"id" integer not null,
"app_name" varchar(64) not null comment '执行器AppName',
"title" varchar(12) not null comment '执行器名称',
"address_type" tinyint not null default 0 comment '执行器地址类型:0=自动注册、1=手动录入',
"address_list" clob comment '执行器地址列表,多地址逗号分隔',
"update_time" datetime
);

-- SYSDBA.XXL_JOB_INFO definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_INFO"(
"id" integer not null,
"job_group" integer not null comment '执行器主键ID',
"job_desc" varchar(255) not null,
"add_time" datetime,
"update_time" datetime,
"author" varchar(64) comment '作者',
"alarm_email" varchar(255) comment '报警邮件',
"schedule_type" varchar(50) not null default 'NONE' comment '调度类型',
"schedule_conf" varchar(128) comment '调度配置,值含义取决于调度类型',
"misfire_strategy" varchar(50) not null default 'DO_NOTHING' comment '调度过期策略',
"executor_route_strategy" varchar(50) comment '执行器路由策略',
"executor_handler" varchar(255) comment '执行器任务handler',
"executor_param" varchar comment '执行器任务参数',
"executor_block_strategy" varchar(50) comment '阻塞处理策略',
"executor_timeout" integer not null default 0 comment '任务执行超时时间,单位秒',
"executor_fail_retry_count" integer not null default 0 comment '失败重试次数',
"glue_type" varchar(50) not null comment 'GLUE类型',
"glue_source" clob comment 'GLUE源代码',
"glue_remark" varchar(128) comment 'GLUE备注',
"glue_updatetime" datetime comment 'GLUE更新时间',
"child_jobid" varchar(255) comment '子任务ID,多个逗号分隔',
"trigger_status" tinyint not null default 0 comment '调度状态:0-停止,1-运行',
"trigger_last_time" bigint not null default 0 comment '上次调度时间',
"trigger_next_time" bigint not null default 0 comment '下次调度时间'
);

-- SYSDBA.XXL_JOB_LOCK definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_LOCK"(
"lock_name" varchar(50) not null comment '锁名称'
);


-- SYSDBA.XXL_JOB_LOG definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_LOG"(
"id" bigint not null,
"job_group" integer not null comment '执行器主键ID',
"job_id" integer not null comment '任务,主键ID',
"executor_address" varchar(255) comment '执行器地址,本次执行的地址',
"executor_handler" varchar(255) comment '执行器任务handler',
"executor_param" varchar(512) comment '执行器任务参数',
"executor_sharding_param" varchar(20) comment '执行器任务分片参数,格式如 1/2',
"executor_fail_retry_count" integer not null default 0 comment '失败重试次数',
"trigger_time" datetime comment '调度-时间',
"trigger_code" integer not null comment '调度-结果',
"trigger_msg" clob comment '调度-日志',
"handle_time" datetime comment '执行-时间',
"handle_code" integer not null comment '执行-状态',
"handle_msg" clob comment '执行-日志',
"alarm_status" tinyint not null default 0 comment '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败'
);



-- SYSDBA.XXL_JOB_LOGGLUE definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_LOGGLUE"(
"id" integer not null,
"job_id" integer not null comment '任务,主键ID',
"glue_type" varchar(50) comment 'GLUE类型',
"glue_source" clob comment 'GLUE源代码',
"glue_remark" varchar(128) not null comment 'GLUE备注',
"add_time" datetime,
"update_time" datetime
);


-- SYSDBA.XXL_JOB_LOG_REPORT definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_LOG_REPORT"(
"id" integer not null,
"trigger_day" datetime comment '调度-时间',
"running_count" integer not null default 0 comment '运行中-日志数量',
"suc_count" integer not null default 0 comment '执行成功-日志数量',
"fail_count" integer not null default 0 comment '执行失败-日志数量',
"update_time" datetime
);


-- SYSDBA.XXL_JOB_REGISTRY definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_REGISTRY"(
"id" integer not null,
"registry_group" varchar(50) not null,
"registry_key" varchar(255) not null,
"registry_value" varchar(255) not null,
"update_time" datetime
);


-- SYSDBA.XXL_JOB_USER definition

-- Create Table --
create table "SYSDBA"."XXL_JOB_USER"(
"id" integer not null,
"username" varchar(50) not null comment '账号',
"password" varchar(50) not null comment '密码',
"role" tinyint not null comment '角色:0-普通用户、1-管理员',
"permission" varchar(255) comment '权限:执行器ID列表,多个逗号分割'
);



alter table "SYSDBA"."XXL_JOB_GROUP" alter column "id" INTEGER identity(2,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_INFO" alter column "id" INTEGER identity(3,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_LOG_REPORT" alter column "id" INTEGER identity(7,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_LOG" alter column "id" BIGINT identity(17,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_LOGGLUE" alter column "id" INTEGER identity(1,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_REGISTRY" alter column "id" INTEGER identity(3,1) CASCADE;
alter table "SYSDBA"."XXL_JOB_USER" alter column "id" INTEGER identity(2,1) CASCADE;

alter table "SYSDBA"."XXL_JOB_LOCK" add constraint "PRIMARY" primary key("lock_name");

alter table "SYSDBA"."UNDO_LOG" add constraint "UX_UNDO_LOG" unique("xid","branch_id");
alter table "SYSDBA"."XXL_JOB_LOG_REPORT" add constraint "I_TRIGGER_DAY" unique("trigger_day");
alter table "SYSDBA"."XXL_JOB_USER" add constraint "I_USERNAME" unique("username");



create index "I_HANDLE_CODE" on "SYSDBA"."XXL_JOB_LOG"("handle_code") indextype is btree;
create index "I_TRIGGER_TIME" on "SYSDBA"."XXL_JOB_LOG"("trigger_time") indextype is btree;
create index "I_G_K_V" on "SYSDBA"."XXL_JOB_REGISTRY"("registry_group","registry_key","registry_value") indextype is btree;

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');
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<mybatis-spring-boot-starter.version>2.3.2</mybatis-spring-boot-starter.version>
<mysql-connector-j.version>8.3.0</mysql-connector-j.version>
<xugu-connector-java.version>12.2.2</xugu-connector-java.version>

<slf4j-api.version>2.0.13</slf4j-api.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
Expand Down
8 changes: 8 additions & 0 deletions xxl-job-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
<version>${mysql-connector-j.version}</version>
</dependency>

<dependency>
<groupId>com.xugu</groupId>
<artifactId>xugu-jdbc</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/xugu-jdbc-12.2.2.jar</systemPath>
<version>${xugu-connector-java.version}</version>
</dependency>

<!-- xxl-job-core -->
<dependency>
<groupId>com.xuxueli</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public ReturnT<String> update(XxlJobGroup xxlJobGroup){

private List<String> findRegistryByAppName(String appnameParam){
HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll("'"+RegistryConfig.DEAD_TIMEOUT+"'");
if (list != null) {
for (XxlJobRegistry item: list) {
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public void run() {
if (groupList!=null && !groupList.isEmpty()) {

// remove dead address (admin/executor)
List<Integer> ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead(RegistryConfig.DEAD_TIMEOUT, new Date());
List<Integer> ids = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findDead("'"+RegistryConfig.DEAD_TIMEOUT+"'");
if (ids!=null && ids.size()>0) {
XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().removeDead(ids);
}

// fresh online address (admin/executor)
HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
List<XxlJobRegistry> list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
List<XxlJobRegistry> list = XxlJobAdminConfig.getAdminConfig().getXxlJobRegistryDao().findAll("'"+RegistryConfig.DEAD_TIMEOUT+"'");
if (list != null) {
for (XxlJobRegistry item: list) {
if (RegistryConfig.RegistType.EXECUTOR.name().equals(item.getRegistryGroup())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
@Mapper
public interface XxlJobRegistryDao {

public List<Integer> findDead(@Param("timeout") int timeout,
@Param("nowTime") Date nowTime);
public List<Integer> findDead(@Param("timeout") String timeout);

public int removeDead(@Param("ids") List<Integer> ids);

public List<XxlJobRegistry> findAll(@Param("timeout") int timeout,
@Param("nowTime") Date nowTime);
public List<XxlJobRegistry> findAll(@Param("timeout") String timeout);

public int registryUpdate(@Param("registryGroup") String registryGroup,
@Param("registryKey") String registryKey,
Expand Down
65 changes: 65 additions & 0 deletions xxl-job-admin/src/main/resources/application-xugu.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### web
server.port=8080
server.servlet.context-path=/xxl-job-admin

### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false

### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/

### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########

### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model

### xxl-job, datasource
spring.datasource.url=jdbc:xugu://127.0.0.1:5138/XXL_JOB
spring.datasource.username=SYSDBA
spring.datasource.password=SYSDBA
spring.datasource.driver-class-name=com.xugu.cloudjdbc.Driver

### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.max-lifetime=900000
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000

### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
[email protected]
[email protected]
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

### xxl-job, access token
xxl.job.accessToken=default_token

### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN

## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100

### xxl-job, log retention days
xxl.job.logretentiondays=30
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@
</delete>

<select id="findFailJobLogIds" resultType="long" >
SELECT id FROM `xxl_job_log`
WHERE !(
(trigger_code in (0, 200) and handle_code = 0)
OR
(handle_code = 200)
)
AND `alarm_status` = 0
SELECT id FROM xxl_job_log
WHERE (
(trigger_code not in (0, 200) and handle_code != 0)
OR
(handle_code != 200)
)
AND `alarm_status` = 0
ORDER BY id ASC
LIMIT #{pagesize}
LIMIT #{pagesize}
</select>

<update id="updateAlarmStatus" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<select id="findDead" parameterType="java.util.HashMap" resultType="java.lang.Integer" >
SELECT t.id
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ < ]]> DATE_ADD(#{nowTime},INTERVAL -#{timeout} SECOND)
WHERE t.update_time <![CDATA[ < ]]> (sysdate-INTERVAL ${timeout} SECOND)
</select>

<delete id="removeDead" parameterType="java.lang.Integer" >
Expand All @@ -36,7 +36,7 @@
<select id="findAll" parameterType="java.util.HashMap" resultMap="XxlJobRegistry">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(#{nowTime},INTERVAL -#{timeout} SECOND)
WHERE t.update_time <![CDATA[ > ]]> (sysdate-INTERVAL ${timeout} SECOND)
</select>

<update id="registryUpdate" >
Expand Down