Skip to content

Commit

Permalink
QTZ-315 : incliude both scheduled and fired time in recovery job data…
Browse files Browse the repository at this point in the history
… - align and correct various recovery job behaviors
  • Loading branch information
cdennis committed May 29, 2013
1 parent aef7623 commit 7d8ab77
Show file tree
Hide file tree
Showing 54 changed files with 147 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ create table qrtz_fired_triggers(
trigger_group varchar(200) not null,
instance_name varchar(200) not null,
fired_time longint not null,
sched_time longint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(200) null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ create table qrtz_fired_triggers(
trigger_group varchar(80) not null,
instance_name varchar(80) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(80) null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ create table qrtz_fired_triggers(
trigger_group varchar(80) not null,
instance_name varchar(80) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(80),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ trigger_name varchar(80) not null,
trigger_group varchar(80) not null,
instance_name varchar(80) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(80),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ trigger_name varchar(80) not null,
trigger_group varchar(80) not null,
instance_name varchar(80) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(80),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ trigger_name varchar(200) not null,
trigger_group varchar(200) not null,
instance_name varchar(200) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(200),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ trigger_name varchar(200) not null,
trigger_group varchar(200) not null,
instance_name varchar(200) not null,
fired_time bigint not null,
sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(200),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ CREATE TABLE QRTZ_FIRED_TRIGGERS (
TRIGGER_GROUP VARCHAR(60) NOT NULL,
INSTANCE_NAME VARCHAR(80) NOT NULL,
FIRED_TIME BIGINT NOT NULL,
SCHED_TIME BIGINT NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(60),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CREATE TABLE QRTZ_FIRED_TRIGGERS (
TRIGGER_GROUP VARCHAR (200) NOT NULL ,
INSTANCE_NAME VARCHAR (200) NOT NULL ,
FIRED_TIME BIGINT NOT NULL ,
SCHED_TIME BIGINT NOT NULL ,
PRIORITY INTEGER NOT NULL ,
STATE VARCHAR (16) NOT NULL,
JOB_NAME VARCHAR (200) NULL ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ TRIGGER_NAME VARCHAR(200) NOT NULL,
TRIGGER_GROUP VARCHAR(200) NOT NULL,
INSTANCE_NAME VARCHAR(200) NOT NULL,
FIRED_TIME NUMERIC(13) NOT NULL,
SCHED_TIME NUMERIC(13) NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ CREATE TABLE qrtz_fired_triggers
TRIGGER_GROUP LONGVARCHAR(80) NOT NULL,
INSTANCE_NAME LONGVARCHAR(80) NOT NULL,
FIRED_TIME NUMERIC(13) NOT NULL,
SCHED_TIME NUMERIC(13) NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE LONGVARCHAR(16) NOT NULL,
JOB_NAME LONGVARCHAR(80) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TRIGGER_NAME varchar(80) NOT NULL,
TRIGGER_GROUP varchar(80) NOT NULL,
INSTANCE_NAME varchar(80) NOT NULL,
FIRED_TIME numeric(13) NOT NULL,
SCHED_TIME numeric(13) NOT NULL,
PRIORITY integer NOT NULL,
STATE varchar(16) NOT NULL,
JOB_NAME varchar(80),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ CREATE TABLE QRTZ_FIRED_TRIGGERS
TRIGGER_GROUP VARCHAR(200) NOT NULL,
INSTANCE_NAME VARCHAR(200) NOT NULL,
FIRED_TIME BIGINT(13) NOT NULL,
SCHED_TIME BIGINT(13) NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ TRIGGER_NAME VARCHAR(200) NOT NULL,
TRIGGER_GROUP VARCHAR(200) NOT NULL,
INSTANCE_NAME VARCHAR(200) NOT NULL,
FIRED_TIME BIGINT(13) NOT NULL,
SCHED_TIME BIGINT(13) NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ CREATE TABLE qrtz_fired_triggers
TRIGGER_GROUP VARCHAR2(200) NOT NULL,
INSTANCE_NAME VARCHAR2(200) NOT NULL,
FIRED_TIME NUMBER(13) NOT NULL,
SCHED_TIME NUMBER(13) NOT NULL,
PRIORITY NUMBER(13) NOT NULL,
STATE VARCHAR2(16) NOT NULL,
JOB_NAME VARCHAR2(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ CREATE TABLE qrtz_fired_triggers
TRIGGER_GROUP VARCHAR2(80) NOT NULL,
INSTANCE_NAME VARCHAR2(80) NOT NULL,
FIRED_TIME NUMBER(13) NOT NULL,
SCHED_TIME NUMBER(13) NOT NULL,
PRIORITY NUMBER(13) NOT NULL,
STATE VARCHAR2(16) NOT NULL,
JOB_NAME VARCHAR2(80) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ CREATE TABLE qrtz_fired_triggers
TRIGGER_GROUP VARCHAR(200) NOT NULL,
INSTANCE_NAME VARCHAR(200) NOT NULL,
FIRED_TIME BIGINT NOT NULL,
SCHED_TIME BIGINT NOT NULL,
PRIORITY INTEGER NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ CREATE TABLE QRTZ_FIRED_TRIGGERS
TRIGGER_GROUP VARCHAR(200) NOT NULL,
INSTANCE_NAME VARCHAR(200) NOT NULL,
FIRED_TIME FIXED(13) NOT NULL,
SCHED_TIME FIXED(13) NOT NULL,
PRIORITY FIXED(13) NOT NULL,
STATE VARCHAR(16) NOT NULL,
JOB_NAME VARCHAR(200) NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ create table qrtz_fired_triggers(
trigger_group varchar(80) not null,
instance_name varchar(80) not null,
fired_time numeric(13) not null,
sched_time numeric(13) not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(80) null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ CREATE TABLE [dbo].[QRTZ_FIRED_TRIGGERS] (
[TRIGGER_GROUP] [VARCHAR] (200) NOT NULL ,
[INSTANCE_NAME] [VARCHAR] (200) NOT NULL ,
[FIRED_TIME] [BIGINT] NOT NULL ,
[SCHED_TIME] [BIGINT] NOT NULL ,
[PRIORITY] [INTEGER] NOT NULL ,
[STATE] [VARCHAR] (16) NOT NULL,
[JOB_NAME] [VARCHAR] (200) NULL ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ TRIGGER_NAME varchar(80) not null,
TRIGGER_GROUP varchar(80) not null,
INSTANCE_NAME varchar(80) not null,
FIRED_TIME numeric(13,0) not null,
SCHED_TIME numeric(13,0) not null,
PRIORITY int not null,
STATE varchar(16) not null,
JOB_NAME varchar(80) null,
Expand Down
15 changes: 15 additions & 0 deletions quartz-core/src/main/java/org/quartz/JobExecutionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public interface JobExecutionContext {
*/
public boolean isRecovering();

/**
* Return the {@code TriggerKey} of the originally scheduled and now recovering job.
* <p>
* When recovering a previously failed job execution this method returns the identity
* of the originally firing trigger. This recovering job will have been scheduled for
* the same firing time as the original job, and so is available via the
* {@link #getScheduledFireTime()} method. The original firing time of the job can be
* accessed via the {@link Scheduler#FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS}
* element of this job's {@code JobDataMap}.
*
* @return the recovering trigger details
* @throws IllegalStateException if this is not a recovering job.
*/
public TriggerKey getRecoveringTriggerKey() throws IllegalStateException;

public int getRefireCount();

/**
Expand Down
13 changes: 13 additions & 0 deletions quartz-core/src/main/java/org/quartz/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ public interface Scheduler {
*/
String FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS = "QRTZ_FAILED_JOB_ORIG_TRIGGER_FIRETIME_IN_MILLISECONDS_AS_STRING";

/**
* A constant <code>JobDataMap</code> key that can be used to retrieve the
* scheduled fire time of the original <code>Trigger</code> from a recovery
* trigger's data map in the case of a job recovering after a failed scheduler
* instance.
*
* <p>Note that this is the time the original firing was scheduled for,
* which may be different from the actual firing time - as a trigger doesn't
* always fire exactly on time.</p>
*
* @see org.quartz.JobDetail#requestsRecovery()
*/
String FAILED_JOB_ORIGINAL_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS = "QRTZ_FAILED_JOB_ORIG_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS_AS_STRING";

/*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerKey;
import org.quartz.spi.OperableTrigger;
import org.quartz.spi.TriggerFiredBundle;

Expand Down Expand Up @@ -141,6 +142,15 @@ public boolean isRecovering() {
return recovering;
}

public TriggerKey getRecoveringTriggerKey() {
if (isRecovering()) {
return new TriggerKey(jobDataMap.getString(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP),
jobDataMap.getString(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME));
} else {
throw new IllegalStateException("Not a recovering job");
}
}

public void incrementRefireCount() {
numRefires++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public interface Constants {

String COL_FIRED_TIME = "FIRED_TIME";

String COL_SCHED_TIME = "SCHED_TIME";

String COL_ENTRY_ID = "ENTRY_ID";

String COL_ENTRY_STATE = "STATE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class FiredTriggerRecord implements java.io.Serializable {

private long fireTimestamp;

private long scheduleTimestamp;

private String schedulerInstanceId;

private TriggerKey triggerKey;
Expand Down Expand Up @@ -73,6 +75,10 @@ public long getFireTimestamp() {
return fireTimestamp;
}

public long getScheduleTimestamp() {
return scheduleTimestamp;
}

public boolean isJobDisallowsConcurrentExecution() {
return jobDisallowsConcurrentExecution;
}
Expand Down Expand Up @@ -101,6 +107,10 @@ public void setFireTimestamp(long l) {
fireTimestamp = l;
}

public void setScheduleTimestamp(long l) {
scheduleTimestamp = l;
}

public void setJobDisallowsConcurrentExecution(boolean b) {
jobDisallowsConcurrentExecution = b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3439,15 +3439,16 @@ protected void clusterRecover(Connection conn, List<SchedulerStateRecord> failed
+ "_"
+ String.valueOf(recoverIds++),
Scheduler.DEFAULT_RECOVERY_GROUP,
new Date(ftRec.getFireTimestamp()));
new Date(ftRec.getScheduleTimestamp()));
rcvryTrig.setJobName(jKey.getName());
rcvryTrig.setJobGroup(jKey.getGroup());
rcvryTrig.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
rcvryTrig.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY);
rcvryTrig.setPriority(ftRec.getPriority());
JobDataMap jd = getDelegate().selectTriggerJobDataMap(conn, tKey.getName(), tKey.getGroup());
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME, tKey.getName());
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP, tKey.getGroup());
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(ftRec.getFireTimestamp()));
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS, String.valueOf(ftRec.getScheduleTimestamp()));
rcvryTrig.setJobDataMap(jd);

rcvryTrig.computeFirstFireTime(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,25 +520,19 @@ public interface StdJDBCConstants extends Constants {
+ TABLE_PREFIX_SUBST + TABLE_FIRED_TRIGGERS + " (" + COL_SCHEDULER_NAME + ", " + COL_ENTRY_ID
+ ", " + COL_TRIGGER_NAME + ", " + COL_TRIGGER_GROUP + ", "
+ COL_INSTANCE_NAME + ", "
+ COL_FIRED_TIME + ", " + COL_ENTRY_STATE + ", " + COL_JOB_NAME
+ COL_FIRED_TIME + ", " + COL_SCHED_TIME + ", " + COL_ENTRY_STATE + ", " + COL_JOB_NAME
+ ", " + COL_JOB_GROUP + ", " + COL_IS_NONCONCURRENT + ", "
+ COL_REQUESTS_RECOVERY + ", " + COL_PRIORITY
+ ") VALUES(" + SCHED_NAME_SUBST + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ ") VALUES(" + SCHED_NAME_SUBST + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

String UPDATE_FIRED_TRIGGER = "UPDATE "
+ TABLE_PREFIX_SUBST + TABLE_FIRED_TRIGGERS + " SET "
+ COL_INSTANCE_NAME + " = ?, "
+ COL_FIRED_TIME + " = ?, " + COL_ENTRY_STATE + " = ?, " + COL_JOB_NAME
+ COL_FIRED_TIME + " = ?, " + COL_SCHED_TIME + " = ?, " + COL_ENTRY_STATE + " = ?, " + COL_JOB_NAME
+ " = ?, " + COL_JOB_GROUP + " = ?, " + COL_IS_NONCONCURRENT + " = ?, "
+ COL_REQUESTS_RECOVERY + " = ? WHERE " + COL_SCHEDULER_NAME + " = " + SCHED_NAME_SUBST
+ " AND " + COL_ENTRY_ID + " = ?";

String UPDATE_INSTANCES_FIRED_TRIGGER_STATE = "UPDATE "
+ TABLE_PREFIX_SUBST + TABLE_FIRED_TRIGGERS + " SET "
+ COL_ENTRY_STATE + " = ? AND " + COL_FIRED_TIME + " = ? AND " + COL_PRIORITY+ " = ? WHERE "
+ COL_SCHEDULER_NAME + " = " + SCHED_NAME_SUBST
+ " AND " + COL_INSTANCE_NAME + " = ?";

String SELECT_INSTANCES_FIRED_TRIGGERS = "SELECT * FROM "
+ TABLE_PREFIX_SUBST
+ TABLE_FIRED_TRIGGERS
Expand Down
Loading

0 comments on commit 7d8ab77

Please sign in to comment.