修复 xxl_job_log 主键id类型为 bigint(20) , 防止 int(11) 位溢出导致调度任务不能正常调度。

pull/10/head
bwh 5 years ago
parent 3d951f2bc6
commit 3afd579dcf

@ -30,7 +30,7 @@ CREATE TABLE `xxl_job_info` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `xxl_job_log` ( CREATE TABLE `xxl_job_log` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` bigint(20) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID', `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_id` int(11) NOT NULL COMMENT '任务主键ID', `job_id` int(11) NOT NULL COMMENT '任务主键ID',
`executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址', `executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址',

@ -8,7 +8,7 @@ import java.util.Date;
*/ */
public class XxlJobLog { public class XxlJobLog {
private int id; private long id;
// job info // job info
private int jobGroup; private int jobGroup;
@ -34,11 +34,11 @@ public class XxlJobLog {
// alarm info // alarm info
private int alarmStatus; private int alarmStatus;
public int getId() { public long getId() {
return id; return id;
} }
public void setId(int id) { public void setId(long id) {
this.id = id; this.id = id;
} }

@ -46,9 +46,9 @@ public class JobFailMonitorHelper {
while (!toStop) { while (!toStop) {
try { try {
List<Integer> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000); List<Long> failLogIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findFailJobLogIds(1000);
if (failLogIds!=null && !failLogIds.isEmpty()) { if (failLogIds!=null && !failLogIds.isEmpty()) {
for (int failLogId: failLogIds) { for (long failLogId: failLogIds) {
// lock log // lock log
int lockRet = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, 0, -1); int lockRet = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateAlarmStatus(failLogId, 0, -1);

@ -35,7 +35,7 @@ public interface XxlJobInfoDao {
public int update(XxlJobInfo xxlJobInfo); public int update(XxlJobInfo xxlJobInfo);
public int delete(@Param("id") int id); public int delete(@Param("id") long id);
public List<XxlJobInfo> getJobsByGroup(@Param("jobGroup") int jobGroup); public List<XxlJobInfo> getJobsByGroup(@Param("jobGroup") int jobGroup);

@ -31,9 +31,9 @@ public interface XxlJobLogDao {
@Param("triggerTimeEnd") Date triggerTimeEnd, @Param("triggerTimeEnd") Date triggerTimeEnd,
@Param("logStatus") int logStatus); @Param("logStatus") int logStatus);
public XxlJobLog load(@Param("id") int id); public XxlJobLog load(@Param("id") long id);
public int save(XxlJobLog xxlJobLog); public long save(XxlJobLog xxlJobLog);
public int updateTriggerInfo(XxlJobLog xxlJobLog); public int updateTriggerInfo(XxlJobLog xxlJobLog);
@ -51,9 +51,9 @@ public interface XxlJobLogDao {
@Param("clearBeforeTime") Date clearBeforeTime, @Param("clearBeforeTime") Date clearBeforeTime,
@Param("clearBeforeNum") int clearBeforeNum); @Param("clearBeforeNum") int clearBeforeNum);
public List<Integer> findFailJobLogIds(@Param("pagesize") int pagesize); public List<Long> findFailJobLogIds(@Param("pagesize") int pagesize);
public int updateAlarmStatus(@Param("logId") int logId, public int updateAlarmStatus(@Param("logId") long logId,
@Param("oldAlarmStatus") int oldAlarmStatus, @Param("oldAlarmStatus") int oldAlarmStatus,
@Param("newAlarmStatus") int newAlarmStatus); @Param("newAlarmStatus") int newAlarmStatus);

@ -110,7 +110,7 @@
</trim> </trim>
</select> </select>
<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobLog"> <select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" /> SELECT <include refid="Base_Column_List" />
FROM xxl_job_log AS t FROM xxl_job_log AS t
WHERE t.id = #{id} WHERE t.id = #{id}
@ -218,7 +218,7 @@
</trim> </trim>
</delete> </delete>
<select id="findFailJobLogIds" resultType="int" > <select id="findFailJobLogIds" resultType="long" >
SELECT id FROM `xxl_job_log` SELECT id FROM `xxl_job_log`
WHERE !( WHERE !(
(trigger_code in (0, 200) and handle_code = 0) (trigger_code in (0, 200) and handle_code = 0)

@ -3,16 +3,17 @@ package com.xxl.job.admin.controller;
import org.junit.Before; import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
@WebAppConfiguration @RunWith(SpringRunner.class)
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(locations = {"classpath*:spring/*.xml"})
public class AbstractSpringMvcTest { public class AbstractSpringMvcTest {
@Autowired @Autowired

@ -4,14 +4,16 @@ import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.dao.XxlJobGroupDao; import com.xxl.job.admin.dao.XxlJobGroupDao;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobGroupDaoTest { public class XxlJobGroupDaoTest {
@Resource @Resource

@ -3,15 +3,17 @@ package com.xxl.job.admin.dao;
import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobInfo;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobInfoDaoTest { public class XxlJobInfoDaoTest {
@Resource @Resource

@ -3,16 +3,18 @@ package com.xxl.job.admin.dao;
import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.model.XxlJobLog;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobLogDaoTest { public class XxlJobLogDaoTest {
@Resource @Resource
@ -27,7 +29,7 @@ public class XxlJobLogDaoTest {
log.setJobGroup(1); log.setJobGroup(1);
log.setJobId(1); log.setJobId(1);
int ret1 = xxlJobLogDao.save(log); long ret1 = xxlJobLogDao.save(log);
XxlJobLog dto = xxlJobLogDao.load(log.getId()); XxlJobLog dto = xxlJobLogDao.load(log.getId());
log.setTriggerTime(new Date()); log.setTriggerTime(new Date());

@ -4,14 +4,16 @@ import com.xxl.job.admin.core.model.XxlJobLogGlue;
import com.xxl.job.admin.dao.XxlJobLogGlueDao; import com.xxl.job.admin.dao.XxlJobLogGlueDao;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobLogGlueDaoTest { public class XxlJobLogGlueDaoTest {
@Resource @Resource

@ -10,7 +10,7 @@ import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobRegistryDaoTest { public class XxlJobRegistryDaoTest {
@Resource @Resource

@ -3,16 +3,18 @@ package com.xxl.job.admin.util;
import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.core.util.I18nUtil;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/** /**
* email util test * email util test
* *
* @author xuxueli 2017-12-22 17:16:23 * @author xuxueli 2017-12-22 17:16:23
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class I18nUtilTest { public class I18nUtilTest {
@Test @Test

@ -37,7 +37,7 @@ public interface ExecutorBiz {
* @param fromLineNum * @param fromLineNum
* @return * @return
*/ */
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum); public ReturnT<LogResult> log(long logDateTim, long logId, int fromLineNum);
/** /**
* run * run

@ -58,7 +58,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
} }
@Override @Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) { public ReturnT<LogResult> log(long logDateTim, long logId, int fromLineNum) {
// log filename: logPath/yyyy-MM-dd/9999.log // log filename: logPath/yyyy-MM-dd/9999.log
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId); String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);

@ -8,19 +8,19 @@ import java.io.Serializable;
public class HandleCallbackParam implements Serializable { public class HandleCallbackParam implements Serializable {
private static final long serialVersionUID = 42L; private static final long serialVersionUID = 42L;
private int logId; private long logId;
private long logDateTim; private long logDateTim;
private ReturnT<String> executeResult; private ReturnT<String> executeResult;
public HandleCallbackParam(){} public HandleCallbackParam(){}
public HandleCallbackParam(int logId, long logDateTim, ReturnT<String> executeResult) { public HandleCallbackParam(long logId, long logDateTim, ReturnT<String> executeResult) {
this.logId = logId; this.logId = logId;
this.logDateTim = logDateTim; this.logDateTim = logDateTim;
this.executeResult = executeResult; this.executeResult = executeResult;
} }
public int getLogId() { public long getLogId() {
return logId; return logId;
} }

@ -15,7 +15,7 @@ public class TriggerParam implements Serializable{
private String executorBlockStrategy; private String executorBlockStrategy;
private int executorTimeout; private int executorTimeout;
private int logId; private long logId;
private long logDateTim; private long logDateTim;
private String glueType; private String glueType;
@ -66,11 +66,11 @@ public class TriggerParam implements Serializable{
this.executorTimeout = executorTimeout; this.executorTimeout = executorTimeout;
} }
public int getLogId() { public long getLogId() {
return logId; return logId;
} }
public void setLogId(int logId) { public void setLogId(long logId) {
this.logId = logId; this.logId = logId;
} }

@ -68,7 +68,7 @@ public class XxlJobFileAppender {
* @param logId * @param logId
* @return * @return
*/ */
public static String makeLogFileName(Date triggerDate, int logId) { public static String makeLogFileName(Date triggerDate, long logId) {
// filePath/yyyy-MM-dd // filePath/yyyy-MM-dd
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // avoid concurrent problem, can not be static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // avoid concurrent problem, can not be static

@ -30,7 +30,7 @@ public class JobThread extends Thread{
private int jobId; private int jobId;
private IJobHandler handler; private IJobHandler handler;
private LinkedBlockingQueue<TriggerParam> triggerQueue; private LinkedBlockingQueue<TriggerParam> triggerQueue;
private Set<Integer> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID private Set<Long> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID
private volatile boolean toStop = false; private volatile boolean toStop = false;
private String stopReason; private String stopReason;
@ -43,7 +43,7 @@ public class JobThread extends Thread{
this.jobId = jobId; this.jobId = jobId;
this.handler = handler; this.handler = handler;
this.triggerQueue = new LinkedBlockingQueue<TriggerParam>(); this.triggerQueue = new LinkedBlockingQueue<TriggerParam>();
this.triggerLogIdSet = Collections.synchronizedSet(new HashSet<Integer>()); this.triggerLogIdSet = Collections.synchronizedSet(new HashSet<Long>());
} }
public IJobHandler getHandler() { public IJobHandler getHandler() {
return handler; return handler;

Loading…
Cancel
Save