Skip to content

Commit

Permalink
[Fix](Job)Fix redundant job scheduling by preventing same state trans…
Browse files Browse the repository at this point in the history
…itions (e.g., RUNNING → RUNNING) (#45495)

### What problem does this PR solve?


In the current job scheduling logic, invalid state transitions (e.g.,
RUNNING to RUNNING) are not filtered, which causes redundant scheduling
during resume operations. This PR adds a check to ensure that jobs
cannot transition to the same state, preventing duplicate scheduling
triggers and improving state consistency.
  • Loading branch information
CalvinKirs authored Dec 19, 2024
1 parent ea6958c commit 549abf4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ public void alterJobStatus(String jobName, JobStatus jobStatus) throws JobExcept
for (T a : jobMap.values()) {
if (a.getJobName().equals(jobName)) {
try {
if (jobStatus.equals(a.getJobStatus())) {
throw new JobException("Can't change job status to the same status");
}
alterJobStatus(a.getJobId(), jobStatus);
} catch (JobException e) {
throw new JobException("unregister job error, jobName:" + jobName);
throw new JobException("Alter job status error, jobName is %s, errorMsg is %s",
jobName, e.getMessage());
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions regression-test/suites/job_p0/test_base_insert_job.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ suite("test_base_insert_job") {
// check job status and succeed task count is 1
pressJob.size() == 1 && '1' == onceJob.get(0).get(0)
})
assertThrows(Exception) {
sql """
RESUME JOB where jobName='press'
"""
}

sql """
DROP JOB IF EXISTS where jobname = 'past_start_time'
Expand Down Expand Up @@ -299,12 +304,10 @@ suite("test_base_insert_job") {
assert e.getMessage().contains("Invalid interval time unit: years")
}
// assert interval time unit is -1
try {
assertThrows(Exception) {
sql """
CREATE JOB test_error_starts ON SCHEDULE every -1 second comment 'test' DO insert into ${tableName} (timestamp, type, user_id) values ('2023-03-18','1','12213');
"""
} catch (Exception e) {
assert e.getMessage().contains("expecting INTEGER_VALUE")
}

// test keyword as job name
Expand Down

0 comments on commit 549abf4

Please sign in to comment.