From 075e97be873f8df69e26cd02bd2efbba9e1cb5b4 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Fri, 25 Jun 2010 21:39:00 +0000
Subject: [PATCH] fix for when a job is resized and it hadn't been started in
 the database yet

---
 src/plugins/accounting_storage/mysql/as_mysql_job.c | 7 ++++++-
 src/slurmctld/job_mgr.c                             | 6 ++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/plugins/accounting_storage/mysql/as_mysql_job.c b/src/plugins/accounting_storage/mysql/as_mysql_job.c
index e9ad6d042a5..44c17221415 100644
--- a/src/plugins/accounting_storage/mysql/as_mysql_job.c
+++ b/src/plugins/accounting_storage/mysql/as_mysql_job.c
@@ -240,7 +240,12 @@ extern int as_mysql_job_start(mysql_conn_t *mysql_conn,
 	 * be notified of the change also so make the state without
 	 * the resize. */
 	if(IS_JOB_RESIZING(job_ptr)) {
-		as_mysql_job_complete(mysql_conn, job_ptr);
+		/* If we have a db_index lets end the previous record. */
+		if(job_ptr->db_index)
+			as_mysql_job_complete(mysql_conn, job_ptr);
+		else
+			error("We don't have a db_index for job %u, "
+			      "this should never happen.", job_ptr->job_id);
 		job_state &= (~JOB_RESIZING);
 		job_ptr->db_index = 0;
 	}
diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c
index 8dda334519b..714444fbda7 100644
--- a/src/slurmctld/job_mgr.c
+++ b/src/slurmctld/job_mgr.c
@@ -6481,6 +6481,12 @@ int update_job(job_desc_msg_t * job_specs, uid_t uid)
 /* Record accounting information for a job immediately before changing size */
 extern void job_pre_resize_acctg(struct job_record *job_ptr)
 {
+	/* if we don't have a db_index go a start this one up since if
+	   running with the slurmDBD the job may not have started yet.
+	*/
+	if(!job_ptr->db_index)
+		jobacct_storage_g_job_start(acct_db_conn, job_ptr);
+
 	job_ptr->job_state |= JOB_RESIZING;
 	job_ptr->resize_time = time(NULL);
 	/* NOTE: job_completion_logger() calls
-- 
GitLab