Skip to content

Commit

Permalink
Copy scheduled_jobs list before sorting it
Browse files Browse the repository at this point in the history
The start_scheduled_jobs function mistakenly sorts the scheduled_jobs
list in-place. As a result, when the ts_update_scheduled_jobs_list
function compares the updated list of scheduled jobs with the existing
scheduled jobs list, it is comparing a list that is sorted by job_id to
one that is sorted by next_start time. Fix that by properly copying the
scheduled_jobs list into a new list and use that for sorting.

Fixes timescale#5537
  • Loading branch information
lkshminarayanan committed Apr 11, 2023
1 parent 04f4333 commit b0a7822
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/bgw/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ start_scheduled_jobs(register_background_worker_callback_type bgw_register)
ordered_scheduled_jobs = list_qsort(scheduled_jobs, cmp_next_start);
#else
/* PG13 does in-place sort */
ordered_scheduled_jobs = scheduled_jobs;
ordered_scheduled_jobs = list_copy(scheduled_jobs);
list_sort(ordered_scheduled_jobs, cmp_next_start);
#endif

Expand All @@ -588,9 +588,7 @@ start_scheduled_jobs(register_background_worker_callback_type bgw_register)
scheduled_ts_bgw_job_start(sjob, bgw_register);
}

#if PG13_LT
list_free(ordered_scheduled_jobs);
#endif
}

/* Returns the earliest time the scheduler should start a job that is waiting to be started */
Expand Down

0 comments on commit b0a7822

Please sign in to comment.