quartz-scheduler / quartz

Code for Quartz Scheduler
http://www.quartz-scheduler.org
Apache License 2.0
6.29k stars 1.94k forks source link

Issue with the quartz scheduler #1133

Closed sri-yan closed 1 month ago

sri-yan commented 6 months ago

We are trying to schedule a simple job trigger from our Springboot application in kubernetes but we are getting the following error,

org.quartz.JobPersistenceException: Couldn't acquire next trigger: Couldn't retrieve trigger: No record found for selection of Trigger with key: 'ERICSSON_POLLING_JOB.10.81.100.3' and statement: SELECT FROM QRTZ_SIMPLE_TRIGGERS WHERE SCHED_NAME = 'quartzScheduler' AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ? at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2923) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2805) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2803) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3864) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTriggers(JobStoreSupport.java:2802) ~[quartz-2.3.2.jar:na] at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:287) ~[quartz-2.3.2.jar:na] Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: No record found for selection of Trigger with key: 'ERICSSON_POLLING_JOB.10.81.100.3' and statement: SELECT FROM QRTZ_SIMPLE_TRIGGERS WHERE SCHED_NAME = 'quartzScheduler' AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ? at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1538) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2854) ~[quartz-2.3.2.jar:na] ... 5 common frames omitted Caused by: java.lang.IllegalStateException: No record found for selection of Trigger with key: 'ERICSSON_POLLING_JOB.10.81.100.3' and statement: SELECT * FROM QRTZ_SIMPLE_TRIGGERS WHERE SCHED_NAME = 'quartzScheduler' AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ? at org.quartz.impl.jdbcjobstore.SimpleTriggerPersistenceDelegate.loadExtendedTriggerProperties(SimpleTriggerPersistenceDelegate.java:110) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectTrigger(StdJDBCDelegate.java:1819) ~[quartz-2.3.2.jar:na] at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1536) ~[quartz-2.3.2.jar:na] ... 6 common frames omitted

We are using a simple code only to schedule but encountering the above error

if (!scheduler.checkExists(JobKey.jobKey(host + COLON + filecollectorHost, ERICSSON_POLLING_JOB))) { JobDetail job = newJob(FtpsEricssonJobExecutor.class) .withIdentity(host + COLON + filecollectorHost, ERICSSON_POLLING_JOB).usingJobData("host", host) .requestRecovery().build(); Trigger trigger = newTrigger().withIdentity(host + COLON + filecollectorHost, ERICSSON_POLLING_JOB) .withSchedule(simpleSchedule()).build(); try { scheduler.scheduleJob(job, trigger); } catch (SchedulerException e) { log.error(e); } log.info("Scheduled job/trigger: " + job + "/" + trigger); }

We don't have any stale data in our quartz tables. This error is not occurring always, but at times. Can you please give a solution? We are using quartz 2.3.2

In continuation to the issue mentioned above, I've extended the JobStore to Synchronize the threads

import java.util.List;

import org.quartz.JobDetail; import org.quartz.JobPersistenceException; import org.quartz.spi.JobStore; import org.quartz.spi.OperableTrigger; import org.springframework.scheduling.quartz.LocalDataSourceJobStore; import org.springframework.stereotype.Component;

import lombok.extern.log4j.Log4j2;

/**

}

Is there any better approach to fix this issue?

jhouserizer commented 1 month ago

LocalDataSourceJobStore is part of the Spring project, not part of Quartz. Quartz' job stores use row locking in the database to avoid this concurrency.