Skip to content

Commit

Permalink
ttl: fix cancel job message for TTL (#55099)
Browse files Browse the repository at this point in the history
close #55098
  • Loading branch information
lcwangchao authored Jul 31, 2024
1 parent a690a77 commit 3a93c73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions pkg/ttl/ttlworker/job_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,23 @@ func (m *JobManager) rescheduleJobs(se session.Session, now time.Time) {
now = now.In(tz)
}

if !variable.EnableTTLJob.Load() || !timeutil.WithinDayTimePeriod(variable.TTLJobScheduleWindowStartTime.Load(), variable.TTLJobScheduleWindowEndTime.Load(), now) {
cancelJobs := false
cancelReason := ""
switch {
case !variable.EnableTTLJob.Load():
cancelJobs = true
cancelReason = "tidb_ttl_job_enable turned off"
case !timeutil.WithinDayTimePeriod(variable.TTLJobScheduleWindowStartTime.Load(), variable.TTLJobScheduleWindowEndTime.Load(), now):
cancelJobs = true
cancelReason = "out of TTL job schedule window"
}

if cancelJobs {
if len(m.runningJobs) > 0 {
for _, job := range m.runningJobs {
logutil.Logger(m.ctx).Info("cancel job because tidb_ttl_job_enable turned off", zap.String("jobID", job.id))
logutil.Logger(m.ctx).Info(fmt.Sprintf("cancel job because %s", cancelReason), zap.String("jobID", job.id))

summary, err := summarizeErr(errors.New("ttl job is disabled"))
summary, err := summarizeErr(errors.New(cancelReason))
if err != nil {
logutil.Logger(m.ctx).Info("fail to summarize job", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ttl/ttlworker/job_manager_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func TestRescheduleJobs(t *testing.T) {
tk.MustExec("set global tidb_ttl_job_schedule_window_start_time='23:58'")
tk.MustExec("set global tidb_ttl_job_schedule_window_end_time='23:59'")
anotherManager.RescheduleJobs(se, time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, now.Nanosecond(), now.Location()))
tk.MustQuery("select last_job_summary->>'$.scan_task_err' from mysql.tidb_ttl_table_status").Check(testkit.Rows("ttl job is disabled"))
tk.MustQuery("select last_job_summary->>'$.scan_task_err' from mysql.tidb_ttl_table_status").Check(testkit.Rows("out of TTL job schedule window"))
}

func TestRescheduleJobsAfterTableDropped(t *testing.T) {
Expand Down

0 comments on commit 3a93c73

Please sign in to comment.