diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c index c2b8ff92e73c4cbc247cd9da9ab69db63d34549b..8af18ce718e9affb44f085ddb12f336267a07617 100644 --- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c +++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c @@ -1009,7 +1009,7 @@ extern int create_cluster_tables(MYSQL *db_conn, char *cluster_name) return SLURM_SUCCESS; } -extern int remove_cluster_tables(MYSQL *db_conn, char *cluster_name) +extern int remove_cluster_tables(mysql_conn_t *mysql_conn, char *cluster_name) { char *query = NULL; int rc = SLURM_SUCCESS; @@ -1017,15 +1017,23 @@ extern int remove_cluster_tables(MYSQL *db_conn, char *cluster_name) query = xstrdup_printf("select id_assoc from \"%s_%s\" limit 1;", cluster_name, assoc_table); - if(!(result = mysql_db_query_ret(db_conn, query, 0))) { + if(!(result = mysql_db_query_ret(mysql_conn->db_conn, query, 0))) { xfree(query); error("no result given when querying cluster %s", cluster_name); return SLURM_ERROR; } + debug4("%d(%s:%d) query\n%s", + mysql_conn->conn, THIS_FILE, __LINE__, query); xfree(query); if(mysql_num_rows(result)) { mysql_free_result(result); + /* If there were any associations removed fix it up + here since the table isn't going to be deleted. */ + xstrfmtcat(mysql_conn->auto_incr_query, + "alter table \"%s_%s\" AUTO_INCREMENT=0;", + cluster_name, assoc_table); + debug4("we still have associations, can't remove tables"); return SLURM_SUCCESS; } @@ -1051,7 +1059,10 @@ extern int remove_cluster_tables(MYSQL *db_conn, char *cluster_name) cluster_name, wckey_day_table, cluster_name, wckey_hour_table, cluster_name, wckey_month_table); - rc = mysql_db_query(db_conn, query); + debug3("%d(%s:%d) query\n%s", + mysql_conn->conn, THIS_FILE, __LINE__, query); + + rc = mysql_db_query(mysql_conn->db_conn, query); xfree(query); if(rc != SLURM_SUCCESS) error("Couldn't drop cluster tables"); @@ -1614,11 +1625,16 @@ just_update: "where (%s);", cluster_name, assoc_table, now, loc_assoc_char); - /* Make sure the next id we get doesn't create holes in the ids. */ - xstrfmtcat(mysql_conn->auto_incr_query, - "alter table \"%s_%s\" AUTO_INCREMENT=0;", - cluster_name, assoc_table); + /* if we are removing a cluster table this is handled in + remove_cluster_tables if table still exists. */ + if(table != cluster_table) { + /* Make sure the next id we get doesn't create holes + * in the ids. */ + xstrfmtcat(mysql_conn->auto_incr_query, + "alter table \"%s_%s\" AUTO_INCREMENT=0;", + cluster_name, assoc_table); + } if(table != assoc_table) xfree(loc_assoc_char); diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.h b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.h index 4a1dd9444b1c24f017ece041ab2c2fbd08d076af..cf392e48b0aa63455dc7acfc53bf5394a644738d 100644 --- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.h +++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.h @@ -113,7 +113,7 @@ extern char *fix_double_quotes(char *str); extern int last_affected_rows(MYSQL *mysql_db); extern void reset_mysql_conn(mysql_conn_t *mysql_conn); extern int create_cluster_tables(MYSQL *mysql_db, char *cluster_name); -extern int remove_cluster_tables(MYSQL *mysql_db, char *cluster_name); +extern int remove_cluster_tables(mysql_conn_t *mysql_conn, char *cluster_name); extern int setup_association_limits(slurmdb_association_rec_t *assoc, char **cols, char **vals, char **extra, qos_level_t qos_level, diff --git a/src/plugins/accounting_storage/mysql/as_mysql_cluster.c b/src/plugins/accounting_storage/mysql/as_mysql_cluster.c index 8f7b307b8ba40e8f72c2e099e574d6861d44f674..ab05d67668abf9a771a207a5eda26957df4b94ab 100644 --- a/src/plugins/accounting_storage/mysql/as_mysql_cluster.c +++ b/src/plugins/accounting_storage/mysql/as_mysql_cluster.c @@ -355,7 +355,7 @@ end_it: } extern List as_mysql_remove_clusters(mysql_conn_t *mysql_conn, uint32_t uid, - slurmdb_cluster_cond_t *cluster_cond) + slurmdb_cluster_cond_t *cluster_cond) { ListIterator itr = NULL, itr2 = NULL; List ret_list = NULL; @@ -487,7 +487,7 @@ extern List as_mysql_remove_clusters(mysql_conn_t *mysql_conn, uint32_t uid, } } list_iterator_reset(itr2); - if((rc = remove_cluster_tables(mysql_conn->db_conn, object)) + if((rc = remove_cluster_tables(mysql_conn, object)) != SLURM_SUCCESS) break; } diff --git a/src/plugins/accounting_storage/mysql/as_mysql_rollup.c b/src/plugins/accounting_storage/mysql/as_mysql_rollup.c index 625ccebefab59d408830b7b8765845d2b2d1ab90..f65e434966e333b324595abc0604cb8d694d904e 100644 --- a/src/plugins/accounting_storage/mysql/as_mysql_rollup.c +++ b/src/plugins/accounting_storage/mysql/as_mysql_rollup.c @@ -1072,6 +1072,10 @@ extern int as_mysql_daily_rollup(mysql_conn_t *mysql_conn, cluster_name, assoc_day_table, now, now, curr_start, cluster_name, assoc_hour_table, curr_end, curr_start, now); + /* We group on deleted here so if there are no entries + we don't get an error, just nothing is returned. + Else we get a bunch of NULL's + */ xstrfmtcat(query, "insert into \"%s_%s\" (creation_time, " "mod_time, time_start, cpu_count, " @@ -1086,6 +1090,7 @@ extern int as_mysql_daily_rollup(mysql_conn_t *mysql_conn, "@OSUM:=SUM(over_cpu_secs), " "@RSUM:=SUM(resv_cpu_secs) from \"%s_%s\" where " "(time_start < %d && time_start >= %d) " + "group by deleted " "on duplicate key update " "mod_time=%d, cpu_count=@CPU, " "alloc_cpu_secs=@ASUM, down_cpu_secs=@DSUM, " @@ -1181,6 +1186,10 @@ extern int as_mysql_monthly_rollup(mysql_conn_t *mysql_conn, cluster_name, assoc_month_table, now, now, curr_start, cluster_name, assoc_day_table, curr_end, curr_start, now); + /* We group on deleted here so if there are no entries + we don't get an error, just nothing is returned. + Else we get a bunch of NULL's + */ xstrfmtcat(query, "insert into \"%s_%s\" (creation_time, " "mod_time, time_start, cpu_count, " @@ -1195,6 +1204,7 @@ extern int as_mysql_monthly_rollup(mysql_conn_t *mysql_conn, "@OSUM:=SUM(over_cpu_secs), " "@RSUM:=SUM(resv_cpu_secs) from \"%s_%s\" where " "(time_start < %d && time_start >= %d) " + "group by deleted " "on duplicate key update " "mod_time=%d, cpu_count=@CPU, " "alloc_cpu_secs=@ASUM, down_cpu_secs=@DSUM, "