Skip to content

Commit

Permalink
mxq_job: Add new intermediate status CANCELLING(989)
Browse files Browse the repository at this point in the history
This state is needed to cancel a single job while
joining mysql tables mxq_job and mxq_group to not activate triggers
on mxq_group.

valid status changes are:

INQ -> CANCELLING -> CANCELLED
INQ -> CANCELLED

MySQL will block those requests to prevent loops and deadlocks.

error would be:

ERROR 1442 (HY000): Can't update table 'mxq_group' in stored
	function/trigger because it is already used by
	statement which invoked this stored function/trigger.
  • Loading branch information
mariux committed Aug 13, 2015
1 parent 58fb8ce commit f055cb5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mxq_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ char *mxq_job_status_to_name(uint64_t status)
return "unknownpre";
case MXQ_JOB_STATUS_CANCELLED:
return "cancelled";
case MXQ_JOB_STATUS_CANCELLING:
return "cancelling";
case MXQ_JOB_STATUS_UNKNOWN:
return "unknown";
case MXQ_JOB_STATUS_FINISHED:
Expand Down
1 change: 1 addition & 0 deletions mxq_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct mxq_job {
#define MXQ_JOB_STATUS_FAILED 750
#define MXQ_JOB_STATUS_UNKNOWN_PRE 755

#define MXQ_JOB_STATUS_CANCELLING 989
#define MXQ_JOB_STATUS_CANCELLED 990
#define MXQ_JOB_STATUS_UNKNOWN 999
#define MXQ_JOB_STATUS_FINISHED 1000
Expand Down
4 changes: 2 additions & 2 deletions mysql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
stats_total_real_sec=stats_total_real_sec+NEW.stats_real_sec,
group_mtime=NULL
WHERE group_id=NEW.group_id;
ELSEIF NEW.job_status = 990 AND OLD.job_status = 0 THEN
ELSEIF NEW.job_status = 990 AND OLD.job_status IN (0, 989) THEN
UPDATE mxq_group SET
group_jobs_inq=group_jobs_inq-1,
group_jobs_cancelled=group_jobs_cancelled+1,
Expand Down Expand Up @@ -250,7 +250,7 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
stats_total_real_sec_finished=stats_total_real_sec_finished+NEW.stats_real_sec,
group_mtime=NULL
WHERE group_id=NEW.group_id;
ELSEIF NEW.job_status != 990 AND NEW.job_status != 755 THEN
ELSEIF NEW.job_status NOT IN (755, 989, 990) THEN
UPDATE mxq_group SET
stats_max_maxrss=GREATEST(stats_max_maxrss, NEW.stats_maxrss),
stats_max_utime_sec=GREATEST(stats_max_utime_sec, NEW.stats_utime_sec),
Expand Down
1 change: 1 addition & 0 deletions web/pages/mxq/mxq.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ sub db_init {
KILLED => 400,
FAILED => 750,
UNKNOWN_PRE => 755,
CANCELLING => 989,
CANCELLED => 990,
UNKNOWN => 999,
FINISHED => 1000,
Expand Down

0 comments on commit f055cb5

Please sign in to comment.