From 7d8ab77947ba2b5bcdbd9850e7a1a3cb7b11ef24 Mon Sep 17 00:00:00 2001 From: cdennis Date: Wed, 29 May 2013 14:57:16 +0000 Subject: [PATCH] QTZ-315 : incliude both scheduled and fired time in recovery job data - align and correct various recovery job behaviors --- .../root/docs/dbTables/tables_cloudscape.sql | 1 + .../root/docs/dbTables/tables_db2.sql | 1 + .../root/docs/dbTables/tables_db2_v72.sql | 1 + .../root/docs/dbTables/tables_db2_v8.sql | 1 + .../root/docs/dbTables/tables_db2_v95.sql | 1 + .../root/docs/dbTables/tables_derby.sql | 1 + .../docs/dbTables/tables_derby_previous.sql | 1 + .../root/docs/dbTables/tables_firebird.sql | 1 + .../assembly/root/docs/dbTables/tables_h2.sql | 1 + .../root/docs/dbTables/tables_hsqldb.sql | 1 + .../root/docs/dbTables/tables_hsqldb_old.sql | 1 + .../root/docs/dbTables/tables_informix.sql | 1 + .../root/docs/dbTables/tables_mysql.sql | 1 + .../docs/dbTables/tables_mysql_innodb.sql | 1 + .../root/docs/dbTables/tables_oracle.sql | 1 + .../root/docs/dbTables/tables_pointbase.sql | 1 + .../root/docs/dbTables/tables_postgres.sql | 1 + .../root/docs/dbTables/tables_sapdb.sql | 1 + .../root/docs/dbTables/tables_solid.sql | 1 + .../root/docs/dbTables/tables_sqlServer.sql | 1 + .../root/docs/dbTables/tables_sybase.sql | 1 + .../java/org/quartz/JobExecutionContext.java | 15 ++++++ .../src/main/java/org/quartz/Scheduler.java | 13 +++++ .../quartz/impl/JobExecutionContextImpl.java | 10 ++++ .../quartz/impl/jdbcjobstore/Constants.java | 2 + .../impl/jdbcjobstore/FiredTriggerRecord.java | 10 ++++ .../impl/jdbcjobstore/JobStoreSupport.java | 5 +- .../impl/jdbcjobstore/StdJDBCConstants.java | 12 ++--- .../impl/jdbcjobstore/StdJDBCDelegate.java | 49 ++++++++++--------- .../src/test/resources/tables_derby.sql | 1 + .../root/docs/dbTables/tables_cloudscape.sql | 1 + .../root/docs/dbTables/tables_cubrid.sql | 1 + .../root/docs/dbTables/tables_db2.sql | 1 + .../root/docs/dbTables/tables_db2_v72.sql | 1 + .../root/docs/dbTables/tables_db2_v8.sql | 1 + .../root/docs/dbTables/tables_db2_v95.sql | 1 + .../root/docs/dbTables/tables_derby.sql | 1 + .../docs/dbTables/tables_derby_previous.sql | 1 + .../root/docs/dbTables/tables_firebird.sql | 1 + .../assembly/root/docs/dbTables/tables_h2.sql | 1 + .../root/docs/dbTables/tables_hsqldb.sql | 1 + .../root/docs/dbTables/tables_hsqldb_old.sql | 1 + .../root/docs/dbTables/tables_informix.sql | 1 + .../root/docs/dbTables/tables_mysql.sql | 1 + .../docs/dbTables/tables_mysql_innodb.sql | 1 + .../root/docs/dbTables/tables_oracle.sql | 1 + .../root/docs/dbTables/tables_pointbase.sql | 1 + .../root/docs/dbTables/tables_postgres.sql | 1 + .../root/docs/dbTables/tables_sapdb.sql | 1 + .../root/docs/dbTables/tables_solid.sql | 1 + .../root/docs/dbTables/tables_sqlServer.sql | 1 + .../root/docs/dbTables/tables_sybase.sql | 1 + .../quartz/DefaultClusteredJobStore.java | 21 ++++---- .../quartz/wrappers/FiredTrigger.java | 10 +++- 54 files changed, 147 insertions(+), 44 deletions(-) diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql index 0d814348e..70eb8e27b 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_db2.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_db2.sql index 15813775e..f56ddda80 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_db2.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_db2.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql index ba6032793..2be28e08a 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql index abf73c4df..2c7b637e2 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql index 5f752a200..05670b025 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_derby.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_derby.sql index 325330bbc..538e577f6 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_derby.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_derby.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql index 6af22e84c..910b6ecf3 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_firebird.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_firebird.sql index 40396d609..e236c2815 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_firebird.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_firebird.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_h2.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_h2.sql index b59382c92..cc23d3c95 100755 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_h2.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_h2.sql @@ -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 , diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql index c95217ae2..a2fede815 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql index 0f32ada8f..2b24f02f9 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_informix.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_informix.sql index fb07ad893..aa69dfee9 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_informix.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_informix.sql @@ -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), diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_mysql.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_mysql.sql index 2573566a1..ba85d2c5e 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_mysql.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_mysql.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql index 1790f2670..92c8dfce0 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_oracle.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_oracle.sql index d3a6dcd1a..33e0399f2 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_oracle.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_oracle.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_pointbase.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_pointbase.sql index c02651c49..debc93f16 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_pointbase.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_pointbase.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_postgres.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_postgres.sql index 13a4b79cb..512a9b1ed 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_postgres.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_postgres.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_sapdb.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_sapdb.sql index 210b4e746..16a404f1b 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_sapdb.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_sapdb.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_solid.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_solid.sql index aabc0a5fb..e02c8b4ac 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_solid.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_solid.sql @@ -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, diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql index bea63e5a1..47982cf9d 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql @@ -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 , diff --git a/distribution/src/main/assembly/root/docs/dbTables/tables_sybase.sql b/distribution/src/main/assembly/root/docs/dbTables/tables_sybase.sql index 025605768..0af3f9851 100644 --- a/distribution/src/main/assembly/root/docs/dbTables/tables_sybase.sql +++ b/distribution/src/main/assembly/root/docs/dbTables/tables_sybase.sql @@ -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, diff --git a/quartz-core/src/main/java/org/quartz/JobExecutionContext.java b/quartz-core/src/main/java/org/quartz/JobExecutionContext.java index 605381a3f..4dcfde0aa 100644 --- a/quartz-core/src/main/java/org/quartz/JobExecutionContext.java +++ b/quartz-core/src/main/java/org/quartz/JobExecutionContext.java @@ -94,6 +94,21 @@ public interface JobExecutionContext { */ public boolean isRecovering(); + /** + * Return the {@code TriggerKey} of the originally scheduled and now recovering job. + *

+ * 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(); /** diff --git a/quartz-core/src/main/java/org/quartz/Scheduler.java b/quartz-core/src/main/java/org/quartz/Scheduler.java index 6a6541135..17e05a1ca 100644 --- a/quartz-core/src/main/java/org/quartz/Scheduler.java +++ b/quartz-core/src/main/java/org/quartz/Scheduler.java @@ -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 JobDataMap key that can be used to retrieve the + * scheduled fire time of the original Trigger from a recovery + * trigger's data map in the case of a job recovering after a failed scheduler + * instance. + * + *

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.

+ * + * @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"; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/quartz-core/src/main/java/org/quartz/impl/JobExecutionContextImpl.java b/quartz-core/src/main/java/org/quartz/impl/JobExecutionContextImpl.java index 6fc7d8351..aa59e0657 100644 --- a/quartz-core/src/main/java/org/quartz/impl/JobExecutionContextImpl.java +++ b/quartz-core/src/main/java/org/quartz/impl/JobExecutionContextImpl.java @@ -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; @@ -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++; } diff --git a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/Constants.java b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/Constants.java index 2e570a87f..448bb7a54 100644 --- a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/Constants.java +++ b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/Constants.java @@ -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"; diff --git a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/FiredTriggerRecord.java b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/FiredTriggerRecord.java index 726ddefc0..6b44adef4 100644 --- a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/FiredTriggerRecord.java +++ b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/FiredTriggerRecord.java @@ -43,6 +43,8 @@ public class FiredTriggerRecord implements java.io.Serializable { private long fireTimestamp; + private long scheduleTimestamp; + private String schedulerInstanceId; private TriggerKey triggerKey; @@ -73,6 +75,10 @@ public long getFireTimestamp() { return fireTimestamp; } + public long getScheduleTimestamp() { + return scheduleTimestamp; + } + public boolean isJobDisallowsConcurrentExecution() { return jobDisallowsConcurrentExecution; } @@ -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; } diff --git a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 5fe0f252f..92102afe8 100644 --- a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -3439,15 +3439,16 @@ protected void clusterRecover(Connection conn, List 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); diff --git a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java index c73a79f0e..ffbf2d637 100644 --- a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java +++ b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCConstants.java @@ -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 diff --git a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 49a86f45f..1e53a2162 100644 --- a/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz-core/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -480,20 +480,22 @@ public List selectTriggersForRecoveringJobs(Connection conn) String trigName = rs.getString(COL_TRIGGER_NAME); String trigGroup = rs.getString(COL_TRIGGER_GROUP); long firedTime = rs.getLong(COL_FIRED_TIME); + long scheduledTime = rs.getLong(COL_SCHED_TIME); int priority = rs.getInt(COL_PRIORITY); @SuppressWarnings("deprecation") SimpleTriggerImpl rcvryTrig = new SimpleTriggerImpl("recover_" + instanceId + "_" + String.valueOf(dumId++), - Scheduler.DEFAULT_RECOVERY_GROUP, new Date(firedTime)); + Scheduler.DEFAULT_RECOVERY_GROUP, new Date(scheduledTime)); rcvryTrig.setJobName(jobName); rcvryTrig.setJobGroup(jobGroup); rcvryTrig.setPriority(priority); - rcvryTrig.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW); + rcvryTrig.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY); JobDataMap jd = selectTriggerJobDataMap(conn, trigName, trigGroup); jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME, trigName); jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP, trigGroup); jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(firedTime)); + jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS, String.valueOf(scheduledTime)); rcvryTrig.setJobDataMap(jd); list.add(rcvryTrig); @@ -2602,21 +2604,21 @@ public int insertFiredTrigger(Connection conn, OperableTrigger trigger, ps.setString(2, trigger.getKey().getName()); ps.setString(3, trigger.getKey().getGroup()); ps.setString(4, instanceId); - ps.setBigDecimal(5, new BigDecimal(String.valueOf(trigger - .getNextFireTime().getTime()))); - ps.setString(6, state); + ps.setBigDecimal(5, new BigDecimal(String.valueOf(System.currentTimeMillis()))); + ps.setBigDecimal(6, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime()))); + ps.setString(7, state); if (job != null) { - ps.setString(7, trigger.getJobKey().getName()); - ps.setString(8, trigger.getJobKey().getGroup()); - setBoolean(ps, 9, job.isConcurrentExectionDisallowed()); - setBoolean(ps, 10, job.requestsRecovery()); + ps.setString(8, trigger.getJobKey().getName()); + ps.setString(9, trigger.getJobKey().getGroup()); + setBoolean(ps, 10, job.isConcurrentExectionDisallowed()); + setBoolean(ps, 11, job.requestsRecovery()); } else { - ps.setString(7, null); ps.setString(8, null); - setBoolean(ps, 9, false); + ps.setString(9, null); setBoolean(ps, 10, false); + setBoolean(ps, 11, false); } - ps.setInt(11, trigger.getPriority()); + ps.setInt(12, trigger.getPriority()); return ps.executeUpdate(); } finally { @@ -2645,23 +2647,23 @@ public int updateFiredTrigger(Connection conn, OperableTrigger trigger, ps.setString(1, instanceId); - ps.setBigDecimal(2, new BigDecimal(String.valueOf(trigger - .getNextFireTime().getTime()))); - ps.setString(3, state); + ps.setBigDecimal(2, new BigDecimal(String.valueOf(System.currentTimeMillis()))); + ps.setBigDecimal(3, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime()))); + ps.setString(4, state); if (job != null) { - ps.setString(4, trigger.getJobKey().getName()); - ps.setString(5, trigger.getJobKey().getGroup()); - setBoolean(ps, 6, job.isConcurrentExectionDisallowed()); - setBoolean(ps, 7, job.requestsRecovery()); + ps.setString(5, trigger.getJobKey().getName()); + ps.setString(6, trigger.getJobKey().getGroup()); + setBoolean(ps, 7, job.isConcurrentExectionDisallowed()); + setBoolean(ps, 8, job.requestsRecovery()); } else { - ps.setString(4, null); ps.setString(5, null); - setBoolean(ps, 6, false); + ps.setString(6, null); setBoolean(ps, 7, false); + setBoolean(ps, 8, false); } - ps.setString(8, trigger.getFireInstanceId()); + ps.setString(9, trigger.getFireInstanceId()); return ps.executeUpdate(); @@ -2700,6 +2702,7 @@ public List selectFiredTriggerRecords(Connection conn, Strin rec.setFireInstanceId(rs.getString(COL_ENTRY_ID)); rec.setFireInstanceState(rs.getString(COL_ENTRY_STATE)); rec.setFireTimestamp(rs.getLong(COL_FIRED_TIME)); + rec.setScheduleTimestamp(rs.getLong(COL_SCHED_TIME)); rec.setPriority(rs.getInt(COL_PRIORITY)); rec.setSchedulerInstanceId(rs.getString(COL_INSTANCE_NAME)); rec.setTriggerKey(triggerKey(rs.getString(COL_TRIGGER_NAME), rs @@ -2752,6 +2755,7 @@ public List selectFiredTriggerRecordsByJob(Connection conn, rec.setFireInstanceId(rs.getString(COL_ENTRY_ID)); rec.setFireInstanceState(rs.getString(COL_ENTRY_STATE)); rec.setFireTimestamp(rs.getLong(COL_FIRED_TIME)); + rec.setScheduleTimestamp(rs.getLong(COL_SCHED_TIME)); rec.setPriority(rs.getInt(COL_PRIORITY)); rec.setSchedulerInstanceId(rs.getString(COL_INSTANCE_NAME)); rec.setTriggerKey(triggerKey(rs.getString(COL_TRIGGER_NAME), rs @@ -2791,6 +2795,7 @@ public List selectInstancesFiredTriggerRecords(Connection co rec.setFireInstanceId(rs.getString(COL_ENTRY_ID)); rec.setFireInstanceState(rs.getString(COL_ENTRY_STATE)); rec.setFireTimestamp(rs.getLong(COL_FIRED_TIME)); + rec.setScheduleTimestamp(rs.getLong(COL_SCHED_TIME)); rec.setSchedulerInstanceId(rs.getString(COL_INSTANCE_NAME)); rec.setTriggerKey(triggerKey(rs.getString(COL_TRIGGER_NAME), rs .getString(COL_TRIGGER_GROUP))); diff --git a/quartz-core/src/test/resources/tables_derby.sql b/quartz-core/src/test/resources/tables_derby.sql index 325330bbc..538e577f6 100644 --- a/quartz-core/src/test/resources/tables_derby.sql +++ b/quartz-core/src/test/resources/tables_derby.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql index 0d814348e..70eb8e27b 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_cloudscape.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_cubrid.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_cubrid.sql index 61443d064..8706deceb 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_cubrid.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_cubrid.sql @@ -137,6 +137,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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_db2.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_db2.sql index 15813775e..f56ddda80 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_db2.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_db2.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql index ba6032793..2be28e08a 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v72.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql index abf73c4df..2c7b637e2 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v8.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql index 5f752a200..05670b025 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_db2_v95.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_derby.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_derby.sql index 325330bbc..538e577f6 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_derby.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_derby.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql index 6af22e84c..910b6ecf3 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_derby_previous.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_firebird.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_firebird.sql index 40396d609..e236c2815 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_firebird.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_firebird.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_h2.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_h2.sql index b59382c92..cc23d3c95 100755 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_h2.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_h2.sql @@ -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 , diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql index c95217ae2..a2fede815 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql index 0f32ada8f..2b24f02f9 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_hsqldb_old.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_informix.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_informix.sql index fb07ad893..aa69dfee9 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_informix.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_informix.sql @@ -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), diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_mysql.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_mysql.sql index 2573566a1..ba85d2c5e 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_mysql.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_mysql.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql index dc490878e..6213e6126 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_mysql_innodb.sql @@ -129,6 +129,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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_oracle.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_oracle.sql index a80d4e52d..0f23e5a48 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_oracle.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_oracle.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_pointbase.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_pointbase.sql index c02651c49..debc93f16 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_pointbase.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_pointbase.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_postgres.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_postgres.sql index 13a4b79cb..512a9b1ed 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_postgres.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_postgres.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_sapdb.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_sapdb.sql index 210b4e746..16a404f1b 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_sapdb.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_sapdb.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_solid.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_solid.sql index aabc0a5fb..e02c8b4ac 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_solid.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_solid.sql @@ -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, diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql index 1940e3c2a..480c9278d 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_sqlServer.sql @@ -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 , diff --git a/quartz/src/main/assembly/root/docs/dbTables/tables_sybase.sql b/quartz/src/main/assembly/root/docs/dbTables/tables_sybase.sql index 025605768..0af3f9851 100644 --- a/quartz/src/main/assembly/root/docs/dbTables/tables_sybase.sql +++ b/quartz/src/main/assembly/root/docs/dbTables/tables_sybase.sql @@ -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, diff --git a/terracotta/bootstrap/src/main/java/org/terracotta/quartz/DefaultClusteredJobStore.java b/terracotta/bootstrap/src/main/java/org/terracotta/quartz/DefaultClusteredJobStore.java index 97b3a8e1c..4418ca5c3 100644 --- a/terracotta/bootstrap/src/main/java/org/terracotta/quartz/DefaultClusteredJobStore.java +++ b/terracotta/bootstrap/src/main/java/org/terracotta/quartz/DefaultClusteredJobStore.java @@ -240,7 +240,7 @@ public void schedulerStarted() throws SchedulerException { continue; } - scheduleRecoveryIfNeeded(tw, ft.getFireTime()); + scheduleRecoveryIfNeeded(tw, ft); } } } finally { @@ -307,7 +307,7 @@ private void evalOrphanedTrigger(TriggerWrapper tw, boolean newNode) { } } - private void scheduleRecoveryIfNeeded(TriggerWrapper tw, long origFireTime) { + private void scheduleRecoveryIfNeeded(TriggerWrapper tw, FiredTrigger recovering) { JobWrapper jobWrapper = jobFacade.get(tw.getJobKey()); if (jobWrapper == null) { @@ -317,14 +317,13 @@ private void scheduleRecoveryIfNeeded(TriggerWrapper tw, long origFireTime) { if (jobWrapper.requestsRecovery()) { OperableTrigger recoveryTrigger = createRecoveryTrigger(tw, jobWrapper, "recover_" + terracottaClientId + "_" - + ftrCtr++); + + ftrCtr++, recovering); - recoveryTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW); - recoveryTrigger.setPriority(tw.getPriority()); JobDataMap jd = tw.getTriggerClone().getJobDataMap(); jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME, tw.getKey().getName()); jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP, tw.getKey().getGroup()); - jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(origFireTime)); + jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(recovering.getFireTime())); + jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS, String.valueOf(recovering.getScheduledFireTime())); recoveryTrigger.setJobDataMap(jd); jobWrapper.setJobDataMap(jd, jobFacade); @@ -344,10 +343,12 @@ private void scheduleRecoveryIfNeeded(TriggerWrapper tw, long origFireTime) { } protected OperableTrigger createRecoveryTrigger(TriggerWrapper tw, JobWrapper jw, - String name) { - final SimpleTriggerImpl recoveryTrigger = new SimpleTriggerImpl(name, Scheduler.DEFAULT_RECOVERY_GROUP, new Date()); + String name, FiredTrigger recovering) { + final SimpleTriggerImpl recoveryTrigger = new SimpleTriggerImpl(name, Scheduler.DEFAULT_RECOVERY_GROUP, new Date(recovering.getScheduledFireTime())); recoveryTrigger.setJobName(jw.getKey().getName()); recoveryTrigger.setJobGroup(jw.getKey().getGroup()); + recoveryTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY); + recoveryTrigger.setPriority(tw.getPriority()); return recoveryTrigger; } @@ -1642,7 +1643,7 @@ public List triggersFired(List triggersFire String fireInstanceId = trigger.getFireInstanceId(); FiredTrigger prev = triggerFacade.getFiredTrigger(fireInstanceId); - triggerFacade.putFiredTrigger(fireInstanceId, new FiredTrigger(terracottaClientId, tw.getKey())); + triggerFacade.putFiredTrigger(fireInstanceId, new FiredTrigger(terracottaClientId, tw.getKey(), trigger.getPreviousFireTime().getTime())); getLog().trace("Tracking " + trigger + " has fired on " + fireInstanceId); if (prev != null) { // this shouldn't happen @@ -1842,7 +1843,7 @@ public void nodeLeft(ClusterEvent event) { continue; } - scheduleRecoveryIfNeeded(tw, ft.getFireTime()); + scheduleRecoveryIfNeeded(tw, ft); } } } finally { diff --git a/terracotta/bootstrap/src/main/java/org/terracotta/quartz/wrappers/FiredTrigger.java b/terracotta/bootstrap/src/main/java/org/terracotta/quartz/wrappers/FiredTrigger.java index 1e997f61f..ac79c0cb2 100644 --- a/terracotta/bootstrap/src/main/java/org/terracotta/quartz/wrappers/FiredTrigger.java +++ b/terracotta/bootstrap/src/main/java/org/terracotta/quartz/wrappers/FiredTrigger.java @@ -25,11 +25,13 @@ public class FiredTrigger implements Serializable { private final String clientId; private final TriggerKey triggerKey; + private final long scheduledFireTime; private final long fireTime; - public FiredTrigger(String clientId, TriggerKey triggerKey) { + public FiredTrigger(String clientId, TriggerKey triggerKey, long scheduledFireTime) { this.clientId = clientId; this.triggerKey = triggerKey; + this.scheduledFireTime = scheduledFireTime; this.fireTime = System.currentTimeMillis(); } @@ -41,6 +43,10 @@ public TriggerKey getTriggerKey() { return triggerKey; } + public long getScheduledFireTime() { + return scheduledFireTime; + } + public long getFireTime() { return fireTime; } @@ -55,6 +61,7 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((clientId == null) ? 0 : clientId.hashCode()); + result = prime * result + (int) (scheduledFireTime ^ (scheduledFireTime >>> 32)); result = prime * result + (int) (fireTime ^ (fireTime >>> 32)); result = prime * result + ((triggerKey == null) ? 0 : triggerKey.hashCode()); return result; @@ -69,6 +76,7 @@ public boolean equals(Object obj) { if (clientId == null) { if (other.clientId != null) return false; } else if (!clientId.equals(other.clientId)) return false; + if (scheduledFireTime != other.scheduledFireTime) return false; if (fireTime != other.fireTime) return false; if (triggerKey == null) { if (other.triggerKey != null) return false;