1
/*****************************************************************************\
2
* mysql_jobacct_process.c - functions the processing of
3
* information from the mysql jobacct
5
*****************************************************************************
7
* Copyright (C) 2008-2009 Lawrence Livermore National Security.
8
* Copyright (C) 2004-2007 The Regents of the University of California.
9
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
10
* Written by Danny Auble <da@llnl.gov>
12
* This file is part of SLURM, a resource management program.
13
* For details, see <https://computing.llnl.gov/linux/slurm/>.
14
* Please also read the included file: DISCLAIMER.
16
* SLURM is free software; you can redistribute it and/or modify it under
17
* the terms of the GNU General Public License as published by the Free
18
* Software Foundation; either version 2 of the License, or (at your option)
21
* In addition, as a special exception, the copyright holders give permission
22
* to link the code of portions of this program with the OpenSSL library under
23
* certain conditions as described in each individual source file, and
24
* distribute linked combinations including the two. You must obey the GNU
25
* General Public License in all respects for all of the code used other than
26
* OpenSSL. If you modify file(s) with this exception, you may extend this
27
* exception to your version of the file(s), but you are not obligated to do
28
* so. If you do not wish to do so, delete this exception statement from your
29
* version. If you delete this exception statement from all source files in
30
* the program, then also delete it here.
32
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
33
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
37
* You should have received a copy of the GNU General Public License along
38
* with SLURM; if not, write to the Free Software Foundation, Inc.,
39
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
41
* This file is patterned after jobcomp_linux.c, written by Morris Jette and
42
* Copyright (C) 2002 The Regents of the University of California.
43
\*****************************************************************************/
46
#include "src/common/env.h"
47
#include "src/common/xstring.h"
48
#include "mysql_jobacct_process.h"
51
static pthread_mutex_t local_file_lock = PTHREAD_MUTEX_INITIALIZER;
57
bitstr_t *asked_bitmap;
60
static void _state_time_string(char **extra, uint32_t state,
61
uint32_t start, uint32_t end)
63
int base_state = state & JOB_STATE_BASE;
66
xstrfmtcat(*extra, "t1.state='%u'", state);
75
"(t1.eligible && (!t1.start || "
77
"t1.eligible and t1.start)))",
81
"(t1.eligible && ((%d between "
82
"t1.eligible and t1.start) || "
83
"(t1.eligible between %d and %d)))",
88
xstrfmtcat(*extra, "(t1.eligible && t1.eligible < %d)",
93
/* FIX ME: this should do something with the suspended
94
table, but it doesn't right now. */
99
"(t1.start && (!t1.end || "
100
"(%d between t1.start and t1.end)))",
105
"((%d between t1.start and t1.end) "
106
"|| (t1.start between %d and %d)))",
111
xstrfmtcat(*extra, "(t1.start && t1.start < %d)", end);
120
xstrfmtcat(*extra, "(t1.state='%u' && (t1.end && ", state);
123
xstrfmtcat(*extra, "(t1.end >= %d)))", start);
126
"(t1.end between %d and %d)))",
130
xstrfmtcat(*extra, "(t1.end <= %d)))", end);
138
static void _destroy_local_cluster(void *object)
140
local_cluster_t *local_cluster = (local_cluster_t *)object;
142
if(local_cluster->hl)
143
hostlist_destroy(local_cluster->hl);
144
FREE_NULL_BITMAP(local_cluster->asked_bitmap);
145
xfree(local_cluster);
149
static int _write_to_file(int fd, char *data)
151
int pos = 0, nwrite = strlen(data), amount;
152
int rc = SLURM_SUCCESS;
155
amount = write(fd, &data[pos], nwrite);
156
if ((amount < 0) && (errno != EINTR)) {
157
error("Error writing file: %m");
167
static int _write_archive_file(MYSQL_RES *result, int start_col, int col_count,
168
time_t curr_end, char *arch_dir,
169
char *arch_type, char *insert,
172
time_t period_start = 0;
174
int rc = SLURM_SUCCESS;
177
char *old_file = NULL, *new_file = NULL, *reg_file = NULL;
186
slurm_mutex_lock(&local_file_lock);
187
while((row = mysql_fetch_row(result))) {
189
xstrcat(values, ",\n(");
191
period_start = atoi(row[start_col]);
192
localtime_r((time_t *)&period_start, &time_tm);
197
snprintf(start_char, sizeof(start_char),
199
"T%2.2u:%2.2u:%2.2u",
200
(time_tm.tm_year + 1900),
207
localtime_r((time_t *)&curr_end, &time_tm);
208
snprintf(end_char, sizeof(end_char),
210
"T%2.2u:%2.2u:%2.2u",
211
(time_tm.tm_year + 1900),
218
/* write the buffer to file */
219
reg_file = xstrdup_printf(
220
"%s/%s_archive_%s_%s.sql",
222
start_char, end_char);
223
debug("Storing event archive at %s", reg_file);
224
old_file = xstrdup_printf("%s.old", reg_file);
225
new_file = xstrdup_printf("%s.new", reg_file);
227
fd = creat(new_file, 0600);
229
error("Can't save archive, "
230
"create file %s error %m",
236
values = xstrdup_printf("%s\nvalues\n(", insert);
239
xstrfmtcat(values, "'%s'", row[0]);
240
for(i=1; i<col_count; i++) {
241
xstrfmtcat(values, ", '%s'", row[i]);
245
xstrcat(values, ", '1')");
247
xstrcat(values, ")");
250
|| ((rc = _write_to_file(fd, values)) != SLURM_SUCCESS)) {
258
rc = _write_to_file(fd,
259
" on duplicate key update deleted=1;");
261
rc = _write_to_file(fd,
262
" on duplicate key update "
263
"period_end=VALUES(period_end);");
264
// END_TIMER2("write file");
265
// info("write file took %s", TIME_STR);
271
(void) unlink(new_file);
272
else { /* file shuffle */
273
int ign; /* avoid warning */
274
(void) unlink(old_file);
275
ign = link(reg_file, old_file);
276
(void) unlink(reg_file);
277
ign = link(new_file, reg_file);
278
(void) unlink(new_file);
283
slurm_mutex_unlock(&local_file_lock);
288
static int _archive_script(acct_archive_cond_t *arch_cond, time_t last_submit)
290
char * args[] = {arch_cond->archive_script, NULL};
302
if (stat(arch_cond->archive_script, &st) < 0) {
304
error("mysql_jobacct_process_run_script: failed to stat %s: %m",
305
arch_cond->archive_script);
309
if (!(st.st_mode & S_IFREG)) {
311
error("mysql_jobacct_process_run_script: "
312
"%s isn't a regular file",
313
arch_cond->archive_script);
317
if (access(arch_cond->archive_script, X_OK) < 0) {
319
error("mysql_jobacct_process_run_script: "
320
"%s is not executable", arch_cond->archive_script);
324
env = env_array_create();
326
if(arch_cond->purge_event) {
327
/* use localtime to avoid any daylight savings issues */
328
if(!localtime_r(&last_submit, &time_tm)) {
329
error("Couldn't get localtime from "
330
"first event start %d",
334
time_tm.tm_mon -= arch_cond->purge_event;
335
time_tm.tm_isdst = -1;
336
curr_end = mktime(&time_tm);
337
env_array_append_fmt(&env, "SLURM_ARCHIVE_EVENTS", "%u",
338
arch_cond->archive_events);
339
env_array_append_fmt(&env, "SLURM_ARCHIVE_LAST_EVENT", "%d",
343
if(arch_cond->purge_job) {
344
/* use localtime to avoid any daylight savings issues */
345
if(!localtime_r(&last_submit, &time_tm)) {
346
error("Couldn't get localtime from first start %d",
350
time_tm.tm_mon -= arch_cond->purge_job;
351
time_tm.tm_isdst = -1;
352
curr_end = mktime(&time_tm);
354
env_array_append_fmt(&env, "SLURM_ARCHIVE_JOBS", "%u",
355
arch_cond->archive_jobs);
356
env_array_append_fmt (&env, "SLURM_ARCHIVE_LAST_JOB", "%d",
360
if(arch_cond->purge_step) {
361
/* use localtime to avoid any daylight savings issues */
362
if(!localtime_r(&last_submit, &time_tm)) {
363
error("Couldn't get localtime from first step start %d",
367
time_tm.tm_mon -= arch_cond->purge_step;
368
time_tm.tm_isdst = -1;
369
curr_end = mktime(&time_tm);
370
env_array_append_fmt(&env, "SLURM_ARCHIVE_STEPS", "%u",
371
arch_cond->archive_steps);
372
env_array_append_fmt(&env, "SLURM_ARCHIVE_LAST_STEP", "%d",
376
if(arch_cond->purge_suspend) {
377
/* use localtime to avoid any daylight savings issues */
378
if(!localtime_r(&last_submit, &time_tm)) {
379
error("Couldn't get localtime from first "
384
time_tm.tm_mon -= arch_cond->purge_suspend;
385
time_tm.tm_isdst = -1;
386
curr_end = mktime(&time_tm);
387
env_array_append_fmt(&env, "SLURM_ARCHIVE_SUSPEND", "%u",
388
arch_cond->archive_steps);
389
env_array_append_fmt(&env, "SLURM_ARCHIVE_LAST_SUSPEND", "%d",
394
env_array_append (&env, "PATH", _PATH_STDPATH);
396
env_array_append (&env, "PATH", "/bin:/usr/bin");
398
execve(arch_cond->archive_script, args, env);
402
return SLURM_SUCCESS;
405
extern List setup_cluster_list_with_inx(mysql_conn_t *mysql_conn,
406
acct_job_cond_t *job_cond,
409
List local_cluster_list = NULL;
410
time_t now = time(NULL);
411
MYSQL_RES *result = NULL;
413
hostlist_t temp_hl = NULL;
414
hostlist_iterator_t h_itr = NULL;
418
if(!job_cond || !job_cond->used_nodes)
421
if(!job_cond->cluster_list || list_count(job_cond->cluster_list) != 1) {
422
error("If you are doing a query against nodes "
423
"you must only have 1 cluster "
424
"you are asking for.");
428
temp_hl = hostlist_create(job_cond->used_nodes);
429
if(!hostlist_count(temp_hl)) {
430
error("we didn't get any real hosts to look for.");
433
h_itr = hostlist_iterator_create(temp_hl);
435
query = xstrdup_printf("select cluster_nodes, period_start, "
436
"period_end from %s where node_name='' "
437
"&& cluster_nodes !=''",
440
if((object = list_peek(job_cond->cluster_list)))
441
xstrfmtcat(query, " && cluster='%s'", object);
443
if(job_cond->usage_start) {
444
if(!job_cond->usage_end)
445
job_cond->usage_end = now;
448
" && ((period_start < %d) "
449
"&& (period_end >= %d || period_end = 0))",
450
job_cond->usage_end, job_cond->usage_start);
453
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
454
if(!(result = mysql_db_query_ret(mysql_conn->db_conn, query, 0))) {
456
hostlist_destroy(temp_hl);
461
local_cluster_list = list_create(_destroy_local_cluster);
462
while((row = mysql_fetch_row(result))) {
465
local_cluster_t *local_cluster =
466
xmalloc(sizeof(local_cluster_t));
467
local_cluster->hl = hostlist_create(row[0]);
468
local_cluster->start = atoi(row[1]);
469
local_cluster->end = atoi(row[2]);
470
local_cluster->asked_bitmap =
471
bit_alloc(hostlist_count(local_cluster->hl));
472
while((host = hostlist_next(h_itr))) {
473
if((loc = hostlist_find(
474
local_cluster->hl, host)) != -1)
475
bit_set(local_cluster->asked_bitmap, loc);
478
hostlist_iterator_reset(h_itr);
479
if(bit_ffs(local_cluster->asked_bitmap) != -1) {
480
list_append(local_cluster_list, local_cluster);
481
if(local_cluster->end == 0) {
482
local_cluster->end = now;
483
(*curr_cluster) = local_cluster;
486
_destroy_local_cluster(local_cluster);
488
mysql_free_result(result);
489
hostlist_iterator_destroy(h_itr);
490
if(!list_count(local_cluster_list)) {
491
hostlist_destroy(temp_hl);
492
list_destroy(local_cluster_list);
497
hostlist_destroy(temp_hl);
499
return local_cluster_list;
502
extern int good_nodes_from_inx(List local_cluster_list,
503
void **object, char *node_inx,
506
local_cluster_t **curr_cluster = (local_cluster_t **)object;
508
/* check the bitmap to see if this is one of the jobs
509
we are looking for */
511
bitstr_t *job_bitmap = NULL;
512
if(!node_inx || !node_inx[0])
514
if((submit < (*curr_cluster)->start)
515
|| (submit > (*curr_cluster)->end)) {
516
local_cluster_t *local_cluster = NULL;
519
list_iterator_create(local_cluster_list);
520
while((local_cluster = list_next(itr))) {
521
if((submit >= local_cluster->start)
522
&& (submit <= local_cluster->end)) {
523
*curr_cluster = local_cluster;
527
list_iterator_destroy(itr);
531
job_bitmap = bit_alloc(hostlist_count((*curr_cluster)->hl));
532
bit_unfmt(job_bitmap, node_inx);
533
if(!bit_overlap((*curr_cluster)->asked_bitmap, job_bitmap)) {
534
FREE_NULL_BITMAP(job_bitmap);
537
FREE_NULL_BITMAP(job_bitmap);
542
extern int setup_job_cond_limits(mysql_conn_t *mysql_conn,
543
acct_job_cond_t *job_cond, char **extra)
546
ListIterator itr = NULL;
548
char *table_level = "t2";
549
jobacct_selected_step_t *selected_step = NULL;
554
if(job_cond->associd_list && list_count(job_cond->associd_list)) {
557
xstrcat(*extra, " && (");
559
xstrcat(*extra, " where (");
560
itr = list_iterator_create(job_cond->associd_list);
561
while((object = list_next(itr))) {
563
xstrcat(*extra, " || ");
564
xstrfmtcat(*extra, "t1.associd='%s'", object);
567
list_iterator_destroy(itr);
568
xstrcat(*extra, ")");
571
if(job_cond->acct_list && list_count(job_cond->acct_list)) {
574
xstrcat(*extra, " && (");
576
xstrcat(*extra, " where (");
577
itr = list_iterator_create(job_cond->acct_list);
578
while((object = list_next(itr))) {
580
xstrcat(*extra, " || ");
581
xstrfmtcat(*extra, "t1.account='%s'", object);
584
list_iterator_destroy(itr);
585
xstrcat(*extra, ")");
588
if(job_cond->userid_list && list_count(job_cond->userid_list)) {
591
xstrcat(*extra, " && (");
593
xstrcat(*extra, " where (");
595
itr = list_iterator_create(job_cond->userid_list);
596
while((object = list_next(itr))) {
598
xstrcat(*extra, " || ");
599
xstrfmtcat(*extra, "t1.uid='%s'", object);
602
list_iterator_destroy(itr);
603
xstrcat(*extra, ")");
606
if(job_cond->groupid_list && list_count(job_cond->groupid_list)) {
609
xstrcat(*extra, " && (");
611
xstrcat(*extra, " where (");
612
itr = list_iterator_create(job_cond->groupid_list);
613
while((object = list_next(itr))) {
615
xstrcat(*extra, " || ");
616
xstrfmtcat(*extra, "t1.gid='%s'", object);
619
list_iterator_destroy(itr);
620
xstrcat(*extra, ")");
623
if(job_cond->partition_list && list_count(job_cond->partition_list)) {
626
xstrcat(*extra, " && (");
628
xstrcat(*extra, " where (");
629
itr = list_iterator_create(job_cond->partition_list);
630
while((object = list_next(itr))) {
632
xstrcat(*extra, " || ");
633
xstrfmtcat(*extra, "t1.partition='%s'", object);
636
list_iterator_destroy(itr);
637
xstrcat(*extra, ")");
640
/* this must be done before resvid_list since we set
641
resvid_list up here */
642
if(job_cond->resv_list && list_count(job_cond->resv_list)) {
643
char *query = xstrdup_printf(
644
"select distinct id from %s where (", job_table);
646
MYSQL_RES *result = NULL;
649
if(job_cond->cluster_list
650
&& list_count(job_cond->cluster_list)) {
652
itr = list_iterator_create(job_cond->cluster_list);
653
while((object = list_next(itr))) {
655
xstrcat(query, " || ");
656
xstrfmtcat(query, "cluster='%s'", object);
659
list_iterator_destroy(itr);
663
xstrcat(query, ") && (");
665
itr = list_iterator_create(job_cond->resv_list);
666
while((object = list_next(itr))) {
668
xstrcat(query, " || ");
669
xstrfmtcat(query, "name='%s'", object);
672
list_iterator_destroy(itr);
674
if(!(result = mysql_db_query_ret(
675
mysql_conn->db_conn, query, 0))) {
677
error("couldn't query the database");
681
if(!job_cond->resvid_list)
682
job_cond->resvid_list = list_create(slurm_destroy_char);
683
while((row = mysql_fetch_row(result))) {
684
list_append(job_cond->resvid_list, xstrdup(row[0]));
686
mysql_free_result(result);
690
if(job_cond->resvid_list && list_count(job_cond->resvid_list)) {
693
xstrcat(*extra, " && (");
695
xstrcat(*extra, " where (");
696
itr = list_iterator_create(job_cond->resvid_list);
697
while((object = list_next(itr))) {
699
xstrcat(*extra, " || ");
700
xstrfmtcat(*extra, "t1.resvid='%s'", object);
703
list_iterator_destroy(itr);
704
xstrcat(*extra, ")");
707
if(job_cond->step_list && list_count(job_cond->step_list)) {
710
xstrcat(*extra, " && (");
712
xstrcat(*extra, " where (");
713
itr = list_iterator_create(job_cond->step_list);
714
while((selected_step = list_next(itr))) {
716
xstrcat(*extra, " || ");
717
xstrfmtcat(*extra, "t1.jobid=%u", selected_step->jobid);
720
list_iterator_destroy(itr);
721
xstrcat(*extra, ")");
724
if(job_cond->cpus_min) {
726
xstrcat(*extra, " && (");
728
xstrcat(*extra, " where (");
730
if(job_cond->cpus_max) {
731
xstrfmtcat(*extra, "(t1.alloc_cpus between %u and %u))",
732
job_cond->cpus_min, job_cond->cpus_max);
735
xstrfmtcat(*extra, "(t1.alloc_cpus='%u'))",
741
if(job_cond->nodes_min) {
743
xstrcat(*extra, " && (");
745
xstrcat(*extra, " where (");
747
if(job_cond->nodes_max) {
749
"(t1.alloc_nodes between %u and %u))",
750
job_cond->nodes_min, job_cond->nodes_max);
753
xstrfmtcat(*extra, "(t1.alloc_nodes='%u'))",
754
job_cond->nodes_min);
758
if(job_cond->state_list && list_count(job_cond->state_list)) {
761
xstrcat(*extra, " && (");
763
xstrcat(*extra, " where (");
765
itr = list_iterator_create(job_cond->state_list);
766
while((object = list_next(itr))) {
768
xstrcat(*extra, " || ");
769
_state_time_string(extra, atoi(object),
770
job_cond->usage_start,
771
job_cond->usage_end);
774
list_iterator_destroy(itr);
775
xstrcat(*extra, ")");
777
/* Only do this (default of all eligible jobs) if no
779
if(job_cond->usage_start) {
781
xstrcat(*extra, " && (");
783
xstrcat(*extra, " where (");
785
if(!job_cond->usage_end)
787
"(t1.end >= %d || t1.end = 0))",
788
job_cond->usage_start);
792
"&& (t1.end >= %d || t1.end = 0)))",
794
job_cond->usage_start);
795
} else if(job_cond->usage_end) {
797
xstrcat(*extra, " && (");
799
xstrcat(*extra, " where (");
801
"(t1.eligible < %d))", job_cond->usage_end);
805
/* we need to put all the associations (t2) stuff together here */
806
if(job_cond->cluster_list && list_count(job_cond->cluster_list)) {
809
xstrcat(*extra, " && (");
811
xstrcat(*extra, " where (");
813
itr = list_iterator_create(job_cond->cluster_list);
814
while((object = list_next(itr))) {
816
xstrcat(*extra, " || ");
818
"(t1.cluster='%s' || %s.cluster='%s')",
819
object, table_level, object);
822
list_iterator_destroy(itr);
823
xstrcat(*extra, ")");
826
if(job_cond->wckey_list && list_count(job_cond->wckey_list)) {
829
xstrcat(*extra, " && (");
831
xstrcat(*extra, " where (");
833
itr = list_iterator_create(job_cond->wckey_list);
834
while((object = list_next(itr))) {
836
xstrcat(*extra, " || ");
837
xstrfmtcat(*extra, "t1.wckey='%s'", object);
840
list_iterator_destroy(itr);
841
xstrcat(*extra, ")");
846
extern List mysql_jobacct_process_get_jobs(mysql_conn_t *mysql_conn, uid_t uid,
847
acct_job_cond_t *job_cond)
853
jobacct_selected_step_t *selected_step = NULL;
854
ListIterator itr = NULL;
855
int set = 0, is_admin=1;
856
char *table_level="t2";
857
MYSQL_RES *result = NULL, *step_result = NULL;
858
MYSQL_ROW row, step_row;
859
int i, last_id = -1, curr_id = -1;
860
jobacct_job_rec_t *job = NULL;
861
jobacct_step_rec_t *step = NULL;
862
time_t now = time(NULL);
863
List job_list = list_create(destroy_jobacct_job_rec);
864
uint16_t private_data = 0;
865
acct_user_rec_t user;
866
local_cluster_t *curr_cluster = NULL;
867
List local_cluster_list = NULL;
868
int only_pending = 0;
870
/* if this changes you will need to edit the corresponding
871
* enum below also t1 is job_table */
872
char *job_req_inx[] = {
947
/* if this changes you will need to edit the corresponding
948
* enum below also t1 is step_table */
949
char *step_req_inx[] = {
995
STEP_REQ_KILL_REQUID,
1006
STEP_REQ_MAX_VSIZE_TASK,
1007
STEP_REQ_MAX_VSIZE_NODE,
1010
STEP_REQ_MAX_RSS_TASK,
1011
STEP_REQ_MAX_RSS_NODE,
1014
STEP_REQ_MAX_PAGES_TASK,
1015
STEP_REQ_MAX_PAGES_NODE,
1018
STEP_REQ_MIN_CPU_TASK,
1019
STEP_REQ_MIN_CPU_NODE,
1024
memset(&user, 0, sizeof(acct_user_rec_t));
1027
private_data = slurm_get_private_data();
1028
if (private_data & PRIVATE_DATA_JOBS) {
1029
/* This only works when running though the slurmdbd.
1030
* THERE IS NO AUTHENTICATION WHEN RUNNNING OUT OF THE
1035
/* we have to check the authentication here in the
1036
* plugin since we don't know what accounts are being
1037
* referenced until after the query. Here we will
1038
* set if they are an operator or greater and then
1039
* check it below after the query.
1041
if((uid == slurmdbd_conf->slurm_user_id || uid == 0)
1042
|| assoc_mgr_get_admin_level(mysql_conn, uid)
1043
>= ACCT_ADMIN_OPERATOR)
1046
assoc_mgr_fill_in_user(mysql_conn, &user, 1,
1053
/* Here we set up environment to check used nodes of jobs.
1054
Since we store the bitmap of the entire cluster we can use
1055
that to set up a hostlist and set up the bitmap to make
1056
things work. This should go before the setup of conds
1057
since we could update the start/end time.
1059
if(job_cond && job_cond->used_nodes) {
1060
local_cluster_list = setup_cluster_list_with_inx(
1061
mysql_conn, job_cond, (void **)&curr_cluster);
1062
if(!local_cluster_list) {
1063
list_destroy(job_list);
1068
if(job_cond->state_list && (list_count(job_cond->state_list) == 1)
1069
&& (atoi(list_peek(job_cond->state_list)) == JOB_PENDING))
1072
setup_job_cond_limits(mysql_conn, job_cond, &extra);
1075
xstrfmtcat(tmp, "%s", job_req_inx[0]);
1076
for(i=1; i<JOB_REQ_COUNT; i++) {
1077
xstrfmtcat(tmp, ", %s", job_req_inx[i]);
1080
/* This is here to make sure we are looking at only this user
1081
* if this flag is set. We also include any accounts they may be
1084
if(!is_admin && (private_data & PRIVATE_DATA_JOBS)) {
1085
query = xstrdup_printf("select lft from %s where user='%s'",
1086
assoc_table, user.name);
1087
if(user.coord_accts) {
1088
acct_coord_rec_t *coord = NULL;
1089
itr = list_iterator_create(user.coord_accts);
1090
while((coord = list_next(itr))) {
1091
xstrfmtcat(query, " || acct='%s'",
1094
list_iterator_destroy(itr);
1096
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
1097
if(!(result = mysql_db_query_ret(
1098
mysql_conn->db_conn, query, 0))) {
1101
list_destroy(job_list);
1102
if(local_cluster_list)
1103
list_destroy(local_cluster_list);
1108
while((row = mysql_fetch_row(result))) {
1111
" || (%s between %s.lft and %s.rgt)",
1112
row[0], table_level, table_level);
1117
" && ((%s between %s.lft "
1119
row[0], table_level,
1123
" where ((%s between %s.lft "
1125
row[0], table_level,
1131
mysql_free_result(result);
1134
query = xstrdup_printf("select %s from %s as t1 left join %s as t2 "
1135
"on t1.associd=t2.id",
1136
tmp, job_table, assoc_table);
1139
xstrcat(query, extra);
1143
/* Here we want to order them this way in such a way so it is
1144
easy to look for duplicates
1146
if(job_cond && !job_cond->duplicates)
1147
xstrcat(query, " order by t1.cluster, jobid, submit desc");
1149
xstrcat(query, " order by t1.cluster, submit desc");
1151
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
1152
if(!(result = mysql_db_query_ret(mysql_conn->db_conn, query, 0))) {
1154
list_destroy(job_list);
1155
if(local_cluster_list)
1156
list_destroy(local_cluster_list);
1161
while((row = mysql_fetch_row(result))) {
1162
char *id = row[JOB_REQ_ID];
1164
int submit = atoi(row[JOB_REQ_SUBMIT]);
1166
curr_id = atoi(row[JOB_REQ_JOBID]);
1168
if(job_cond && !job_cond->duplicates && curr_id == last_id)
1173
/* check the bitmap to see if this is one of the jobs
1174
we are looking for */
1175
if(!good_nodes_from_inx(local_cluster_list,
1176
(void **)&curr_cluster,
1177
row[JOB_REQ_NODE_INX], submit))
1180
job = create_jobacct_job_rec();
1181
list_append(job_list, job);
1183
job->state = atoi(row[JOB_REQ_STATE]);
1184
job->alloc_cpus = atoi(row[JOB_REQ_ALLOC_CPUS]);
1185
job->alloc_nodes = atoi(row[JOB_REQ_ALLOC_NODES]);
1186
job->associd = atoi(row[JOB_REQ_ASSOCID]);
1187
job->resvid = atoi(row[JOB_REQ_RESVID]);
1189
/* we want a blank wckey if the name is null */
1190
if(row[JOB_REQ_WCKEY])
1191
job->wckey = xstrdup(row[JOB_REQ_WCKEY]);
1193
job->wckey = xstrdup("");
1194
job->wckeyid = atoi(row[JOB_REQ_WCKEYID]);
1196
if(row[JOB_REQ_CLUSTER] && row[JOB_REQ_CLUSTER][0])
1197
job->cluster = xstrdup(row[JOB_REQ_CLUSTER]);
1198
else if(row[JOB_REQ_CLUSTER1] && row[JOB_REQ_CLUSTER1][0])
1199
job->cluster = xstrdup(row[JOB_REQ_CLUSTER1]);
1201
if(row[JOB_REQ_USER_NAME])
1202
job->user = xstrdup(row[JOB_REQ_USER_NAME]);
1204
job->uid = atoi(row[JOB_REQ_UID]);
1206
if(row[JOB_REQ_LFT])
1207
job->lft = atoi(row[JOB_REQ_LFT]);
1209
if(row[JOB_REQ_ACCOUNT] && row[JOB_REQ_ACCOUNT][0])
1210
job->account = xstrdup(row[JOB_REQ_ACCOUNT]);
1211
else if(row[JOB_REQ_ACCOUNT1] && row[JOB_REQ_ACCOUNT1][0])
1212
job->account = xstrdup(row[JOB_REQ_ACCOUNT1]);
1214
if(row[JOB_REQ_BLOCKID])
1215
job->blockid = xstrdup(row[JOB_REQ_BLOCKID]);
1217
job->eligible = atoi(row[JOB_REQ_ELIGIBLE]);
1218
job->submit = submit;
1219
job->start = atoi(row[JOB_REQ_START]);
1220
job->end = atoi(row[JOB_REQ_END]);
1222
/* since the job->end could be set later end it here */
1225
if(!job->start || (job->start > job->end))
1226
job->start = job->end;
1229
if(job_cond && !job_cond->without_usage_truncation
1230
&& job_cond->usage_start) {
1231
if(job->start && (job->start < job_cond->usage_start))
1232
job->start = job_cond->usage_start;
1234
if(!job->end || job->end > job_cond->usage_end)
1235
job->end = job_cond->usage_end;
1238
job->start = job->end;
1240
job->elapsed = job->end - job->start;
1242
if(row[JOB_REQ_SUSPENDED]) {
1243
MYSQL_RES *result2 = NULL;
1245
/* get the suspended time for this job */
1246
query = xstrdup_printf(
1247
"select start, end from %s where "
1248
"(start < %d && (end >= %d "
1249
"|| end = 0)) && id=%s "
1252
job_cond->usage_end,
1253
job_cond->usage_start,
1256
debug4("%d(%d) query\n%s",
1257
mysql_conn->conn, __LINE__, query);
1258
if(!(result2 = mysql_db_query_ret(
1259
mysql_conn->db_conn,
1261
list_destroy(job_list);
1266
while((row2 = mysql_fetch_row(result2))) {
1275
if(job->start > local_start)
1276
local_start = job->start;
1277
if(job->end < local_end)
1278
local_end = job->end;
1280
if((local_end - local_start) < 1)
1284
(local_end - local_start);
1286
(local_end - local_start);
1288
mysql_free_result(result2);
1292
job->suspended = atoi(row[JOB_REQ_SUSPENDED]);
1294
/* fix the suspended number to be correct */
1295
if(job->state == JOB_SUSPENDED)
1296
job->suspended = now - job->suspended;
1299
} else if(!job->end) {
1300
job->elapsed = now - job->start;
1302
job->elapsed = job->end - job->start;
1305
job->elapsed -= job->suspended;
1308
if((int)job->elapsed < 0)
1311
job->jobid = curr_id;
1312
job->jobname = xstrdup(row[JOB_REQ_NAME]);
1313
job->gid = atoi(row[JOB_REQ_GID]);
1314
job->exitcode = atoi(row[JOB_REQ_COMP_CODE]);
1316
if(row[JOB_REQ_PARTITION])
1317
job->partition = xstrdup(row[JOB_REQ_PARTITION]);
1319
if(row[JOB_REQ_NODELIST])
1320
job->nodes = xstrdup(row[JOB_REQ_NODELIST]);
1322
if (!job->nodes || !strcmp(job->nodes, "(null)")) {
1324
job->nodes = xstrdup("(unknown)");
1327
job->track_steps = atoi(row[JOB_REQ_TRACKSTEPS]);
1328
job->priority = atoi(row[JOB_REQ_PRIORITY]);
1329
job->req_cpus = atoi(row[JOB_REQ_REQ_CPUS]);
1330
job->requid = atoi(row[JOB_REQ_KILL_REQUID]);
1331
job->timelimit = atoi(row[JOB_REQ_TIMELIMIT]);
1332
job->qos = atoi(row[JOB_REQ_QOS]);
1335
if(only_pending || (job_cond && job_cond->without_steps))
1338
if(job_cond && job_cond->step_list
1339
&& list_count(job_cond->step_list)) {
1341
itr = list_iterator_create(job_cond->step_list);
1342
while((selected_step = list_next(itr))) {
1343
if(selected_step->jobid != job->jobid) {
1345
} else if (selected_step->stepid
1346
== (uint32_t)NO_VAL) {
1352
xstrcat(extra, " || ");
1354
xstrcat(extra, " && (");
1356
xstrfmtcat(extra, "t1.stepid=%u",
1357
selected_step->stepid);
1361
list_iterator_destroy(itr);
1363
xstrcat(extra, ")");
1365
for(i=0; i<STEP_REQ_COUNT; i++) {
1368
xstrcat(tmp, step_req_inx[i]);
1370
query = xstrdup_printf("select %s from %s t1 where t1.id=%s",
1371
tmp, step_table, id);
1375
xstrcat(query, extra);
1379
//info("query = %s", query);
1380
if(!(step_result = mysql_db_query_ret(
1381
mysql_conn->db_conn, query, 0))) {
1383
list_destroy(job_list);
1384
if(local_cluster_list)
1385
list_destroy(local_cluster_list);
1390
/* Querying the steps in the fashion was faster than
1391
doing only 1 query and then matching the steps up
1394
while ((step_row = mysql_fetch_row(step_result))) {
1395
/* check the bitmap to see if this is one of the steps
1396
we are looking for */
1397
if(!good_nodes_from_inx(local_cluster_list,
1398
(void **)&curr_cluster,
1399
step_row[STEP_REQ_NODE_INX],
1403
step = create_jobacct_step_rec();
1404
step->tot_cpu_sec = 0;
1405
step->tot_cpu_usec = 0;
1406
step->job_ptr = job;
1407
if(!job->first_step_ptr)
1408
job->first_step_ptr = step;
1409
list_append(job->steps, step);
1410
step->stepid = atoi(step_row[STEP_REQ_STEPID]);
1411
/* info("got step %u.%u", */
1412
/* job->header.jobnum, step->stepnum); */
1413
step->state = atoi(step_row[STEP_REQ_STATE]);
1414
step->exitcode = atoi(step_row[STEP_REQ_COMP_CODE]);
1415
step->ncpus = atoi(step_row[STEP_REQ_CPUS]);
1416
step->nnodes = atoi(step_row[STEP_REQ_NODES]);
1418
step->ntasks = atoi(step_row[STEP_REQ_TASKS]);
1419
step->task_dist = atoi(step_row[STEP_REQ_TASKDIST]);
1421
step->ntasks = step->ncpus;
1423
step->start = atoi(step_row[STEP_REQ_START]);
1425
step->end = atoi(step_row[STEP_REQ_END]);
1426
/* if the job has ended end the step also */
1427
if(!step->end && job_ended) {
1428
step->end = job->end;
1429
step->state = job->state;
1432
if(job_cond && !job_cond->without_usage_truncation
1433
&& job_cond->usage_start) {
1435
&& (step->start < job_cond->usage_start))
1436
step->start = job_cond->usage_start;
1438
if(!step->start && step->end)
1439
step->start = step->end;
1442
|| (step->end > job_cond->usage_end))
1443
step->end = job_cond->usage_end;
1446
/* figure this out by start stop */
1447
step->suspended = atoi(step_row[STEP_REQ_SUSPENDED]);
1449
step->elapsed = now - step->start;
1451
step->elapsed = step->end - step->start;
1453
step->elapsed -= step->suspended;
1455
if((int)step->elapsed < 0)
1458
step->user_cpu_sec = atoi(step_row[STEP_REQ_USER_SEC]);
1459
step->user_cpu_usec =
1460
atoi(step_row[STEP_REQ_USER_USEC]);
1461
step->sys_cpu_sec = atoi(step_row[STEP_REQ_SYS_SEC]);
1462
step->sys_cpu_usec = atoi(step_row[STEP_REQ_SYS_USEC]);
1463
step->tot_cpu_sec +=
1464
step->user_cpu_sec + step->sys_cpu_sec;
1465
step->tot_cpu_usec +=
1466
step->user_cpu_usec + step->sys_cpu_usec;
1467
step->sacct.max_vsize =
1468
atoi(step_row[STEP_REQ_MAX_VSIZE]);
1469
step->sacct.max_vsize_id.taskid =
1470
atoi(step_row[STEP_REQ_MAX_VSIZE_TASK]);
1471
step->sacct.ave_vsize =
1472
atof(step_row[STEP_REQ_AVE_VSIZE]);
1473
step->sacct.max_rss =
1474
atoi(step_row[STEP_REQ_MAX_RSS]);
1475
step->sacct.max_rss_id.taskid =
1476
atoi(step_row[STEP_REQ_MAX_RSS_TASK]);
1477
step->sacct.ave_rss =
1478
atof(step_row[STEP_REQ_AVE_RSS]);
1479
step->sacct.max_pages =
1480
atoi(step_row[STEP_REQ_MAX_PAGES]);
1481
step->sacct.max_pages_id.taskid =
1482
atoi(step_row[STEP_REQ_MAX_PAGES_TASK]);
1483
step->sacct.ave_pages =
1484
atof(step_row[STEP_REQ_AVE_PAGES]);
1485
step->sacct.min_cpu =
1486
atoi(step_row[STEP_REQ_MIN_CPU]);
1487
step->sacct.min_cpu_id.taskid =
1488
atoi(step_row[STEP_REQ_MIN_CPU_TASK]);
1489
step->sacct.ave_cpu = atof(step_row[STEP_REQ_AVE_CPU]);
1490
step->stepname = xstrdup(step_row[STEP_REQ_NAME]);
1491
step->nodes = xstrdup(step_row[STEP_REQ_NODELIST]);
1492
step->sacct.max_vsize_id.nodeid =
1493
atoi(step_row[STEP_REQ_MAX_VSIZE_NODE]);
1494
step->sacct.max_rss_id.nodeid =
1495
atoi(step_row[STEP_REQ_MAX_RSS_NODE]);
1496
step->sacct.max_pages_id.nodeid =
1497
atoi(step_row[STEP_REQ_MAX_PAGES_NODE]);
1498
step->sacct.min_cpu_id.nodeid =
1499
atoi(step_row[STEP_REQ_MIN_CPU_NODE]);
1501
step->requid = atoi(step_row[STEP_REQ_KILL_REQUID]);
1503
mysql_free_result(step_result);
1505
if(!job->track_steps) {
1506
/* If we don't have track_steps we want to see
1507
if we have multiple steps. If we only have
1508
1 step check the job name against the step
1509
name in most all cases it will be
1510
different. If it is different print out
1513
if(list_count(job->steps) > 1)
1514
job->track_steps = 1;
1515
else if(step && step->stepname && job->jobname) {
1516
if(strcmp(step->stepname, job->jobname))
1517
job->track_steps = 1;
1521
/* need to reset here to make the above test valid */
1524
mysql_free_result(result);
1525
if(local_cluster_list)
1526
list_destroy(local_cluster_list);
1531
extern int mysql_jobacct_process_archive(mysql_conn_t *mysql_conn,
1532
acct_archive_cond_t *arch_cond)
1534
int rc = SLURM_SUCCESS;
1536
time_t last_submit = time(NULL);
1544
/* if this changes you will need to edit the corresponding
1546
char *event_req_inx[] = {
1557
/* if this changes you will need to edit the corresponding
1559
char *job_req_inx[] = {
1592
/* if this changes you will need to edit the corresponding
1594
char *step_req_inx[] = {
1633
/* if this changes you will need to edit the corresponding
1635
char *suspend_req_inx[] = {
1679
JOB_REQ_ALLOC_NODES,
1682
JOB_REQ_KILL_REQUID,
1698
STEP_REQ_KILL_REQUID,
1709
STEP_REQ_MAX_VSIZE_TASK,
1710
STEP_REQ_MAX_VSIZE_NODE,
1713
STEP_REQ_MAX_RSS_TASK,
1714
STEP_REQ_MAX_RSS_NODE,
1717
STEP_REQ_MAX_PAGES_TASK,
1718
STEP_REQ_MAX_PAGES_NODE,
1721
STEP_REQ_MIN_CPU_TASK,
1722
STEP_REQ_MIN_CPU_NODE,
1729
SUSPEND_REQ_ASSOCID,
1736
error("No arch_cond was given to archive from. returning");
1740
if(!localtime_r(&last_submit, &time_tm)) {
1741
error("Couldn't get localtime from first start %d",
1746
/* get to the beginning of the current month */
1749
time_tm.tm_hour = 0;
1750
time_tm.tm_mday = 1;
1751
time_tm.tm_isdst = -1;
1752
last_submit = mktime(&time_tm);
1754
debug("archive: adjusted last submit is (%d)", last_submit);
1756
if(arch_cond->archive_script)
1757
return _archive_script(arch_cond, last_submit);
1758
else if(!arch_cond->archive_dir) {
1759
error("No archive dir given, can't process");
1763
if(arch_cond->purge_event) {
1764
/* remove all data from step table that was older than
1765
* period_start * arch_cond->purge_event.
1767
/* use localtime to avoid any daylight savings issues */
1768
if(!localtime_r(&last_submit, &time_tm)) {
1769
error("Couldn't get localtime from first submit %d",
1775
time_tm.tm_hour = 0;
1776
time_tm.tm_mday = 1;
1777
time_tm.tm_mon -= arch_cond->purge_event;
1778
time_tm.tm_isdst = -1;
1779
curr_end = mktime(&time_tm);
1782
debug4("from %d - %d months purging events from before %d",
1783
last_submit, arch_cond->purge_event, curr_end);
1785
if(arch_cond->archive_events) {
1786
char *insert = NULL;
1787
MYSQL_RES *result = NULL;
1790
xstrfmtcat(tmp, "%s", event_req_inx[0]);
1791
for(i=1; i<EVENT_REQ_COUNT; i++) {
1792
xstrfmtcat(tmp, ", %s", event_req_inx[i]);
1795
/* get all the events started before this time
1797
query = xstrdup_printf("select %s from %s where "
1798
"period_start <= %d "
1799
"&& period_end != 0 "
1800
"order by period_start asc",
1801
tmp, event_table, curr_end);
1803
insert = xstrdup_printf("insert into %s (%s) ",
1808
debug3("%d(%d) query\n%s", mysql_conn->conn,
1810
if(!(result = mysql_db_query_ret(
1811
mysql_conn->db_conn, query, 0))) {
1817
// END_TIMER2("step query");
1818
// info("event query took %s", TIME_STR);
1820
if(!mysql_num_rows(result)) {
1822
mysql_free_result(result);
1826
rc = _write_archive_file(
1827
result, EVENT_REQ_START, EVENT_REQ_COUNT,
1828
curr_end, arch_cond->archive_dir,
1829
"event", insert, false);
1832
mysql_free_result(result);
1834
if(rc != SLURM_SUCCESS)
1837
query = xstrdup_printf("delete from %s where "
1838
"period_start <= %d && period_end != 0",
1839
event_table, curr_end);
1840
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
1841
rc = mysql_db_query(mysql_conn->db_conn, query);
1843
if(rc != SLURM_SUCCESS) {
1844
error("Couldn't remove old event data");
1851
if(arch_cond->purge_suspend) {
1852
/* remove all data from step table that was older than
1853
* period_start * arch_cond->purge_suspend.
1855
/* use localtime to avoid any daylight savings issues */
1856
if(!localtime_r(&last_submit, &time_tm)) {
1857
error("Couldn't get localtime from first submit %d",
1863
time_tm.tm_hour = 0;
1864
time_tm.tm_mday = 1;
1865
time_tm.tm_mon -= arch_cond->purge_suspend;
1866
time_tm.tm_isdst = -1;
1867
curr_end = mktime(&time_tm);
1870
debug4("from %d - %d months purging suspend from before %d",
1871
last_submit, arch_cond->purge_suspend, curr_end);
1873
if(arch_cond->archive_suspend) {
1874
char *insert = NULL;
1875
MYSQL_RES *result = NULL;
1878
xstrfmtcat(tmp, "%s", suspend_req_inx[0]);
1879
for(i=1; i<SUSPEND_REQ_COUNT; i++) {
1880
xstrfmtcat(tmp, ", %s", suspend_req_inx[i]);
1883
/* get all the suspend started before this time
1885
query = xstrdup_printf("select %s from %s where "
1886
"start <= %d && end != 0 "
1887
"order by start asc",
1888
tmp, suspend_table, curr_end);
1890
insert = xstrdup_printf("insert into %s (%s) ",
1891
suspend_table, tmp);
1895
debug3("%d(%d) query\n%s", mysql_conn->conn,
1897
if(!(result = mysql_db_query_ret(
1898
mysql_conn->db_conn, query, 0))) {
1904
// END_TIMER2("step query");
1905
// info("suspend query took %s", TIME_STR);
1907
if(!mysql_num_rows(result)) {
1909
mysql_free_result(result);
1913
rc = _write_archive_file(
1914
result, SUSPEND_REQ_START, SUSPEND_REQ_COUNT,
1915
curr_end, arch_cond->archive_dir,
1916
"suspend", insert, false);
1919
mysql_free_result(result);
1921
if(rc != SLURM_SUCCESS)
1924
query = xstrdup_printf("delete from %s where start <= %d "
1926
suspend_table, curr_end);
1927
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
1928
rc = mysql_db_query(mysql_conn->db_conn, query);
1930
if(rc != SLURM_SUCCESS) {
1931
error("Couldn't remove old suspend data");
1938
if(arch_cond->purge_step) {
1939
/* remove all data from step table that was older than
1940
* start * arch_cond->purge_step.
1942
/* use localtime to avoid any daylight savings issues */
1943
if(!localtime_r(&last_submit, &time_tm)) {
1944
error("Couldn't get localtime from first start %d",
1950
time_tm.tm_hour = 0;
1951
time_tm.tm_mday = 1;
1952
time_tm.tm_mon -= arch_cond->purge_step;
1953
time_tm.tm_isdst = -1;
1954
curr_end = mktime(&time_tm);
1957
debug4("from %d - %d months purging steps from before %d",
1958
last_submit, arch_cond->purge_step, curr_end);
1960
if(arch_cond->archive_steps) {
1961
char *insert = NULL;
1962
MYSQL_RES *result = NULL;
1965
xstrfmtcat(tmp, "%s", step_req_inx[0]);
1966
for(i=1; i<STEP_REQ_COUNT; i++) {
1967
xstrfmtcat(tmp, ", %s", step_req_inx[i]);
1970
/* get all the steps submitted before this time
1972
query = xstrdup_printf("select %s from %s where "
1973
"start <= %d && end != 0 "
1975
"order by start asc",
1976
tmp, step_table, curr_end);
1978
xstrcat(tmp, ", deleted");
1979
insert = xstrdup_printf("insert into %s (%s) ",
1984
debug3("%d(%d) query\n%s", mysql_conn->conn,
1986
if(!(result = mysql_db_query_ret(
1987
mysql_conn->db_conn, query, 0))) {
1993
// END_TIMER2("step query");
1994
// info("step query took %s", TIME_STR);
1996
if(!mysql_num_rows(result)) {
1998
mysql_free_result(result);
2002
rc = _write_archive_file(
2003
result, STEP_REQ_START, STEP_REQ_COUNT,
2004
curr_end, arch_cond->archive_dir,
2005
"step", insert, true);
2008
mysql_free_result(result);
2010
if(rc != SLURM_SUCCESS)
2014
query = xstrdup_printf("delete from %s where start <= %d "
2016
step_table, curr_end);
2017
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
2018
rc = mysql_db_query(mysql_conn->db_conn, query);
2020
if(rc != SLURM_SUCCESS) {
2021
error("Couldn't remove old step data");
2027
if(arch_cond->purge_job) {
2028
/* remove all data from step table that was older than
2029
* last_submit * arch_cond->purge_job.
2031
/* use localtime to avoid any daylight savings issues */
2032
if(!localtime_r(&last_submit, &time_tm)) {
2033
error("Couldn't get localtime from first submit %d",
2039
time_tm.tm_hour = 0;
2040
time_tm.tm_mday = 1;
2041
time_tm.tm_mon -= arch_cond->purge_job;
2042
time_tm.tm_isdst = -1;
2043
curr_end = mktime(&time_tm);
2046
debug4("from %d - %d months purging jobs from before %d",
2047
last_submit, arch_cond->purge_job, curr_end);
2049
if(arch_cond->archive_jobs) {
2050
char *insert = NULL;
2051
MYSQL_RES *result = NULL;
2054
xstrfmtcat(tmp, "%s", job_req_inx[0]);
2055
for(i=1; i<JOB_REQ_COUNT; i++) {
2056
xstrfmtcat(tmp, ", %s", job_req_inx[i]);
2058
/* get all the jobs submitted before this time
2060
query = xstrdup_printf("select %s from %s where "
2061
"submit < %d && end != 0 "
2063
"order by submit asc",
2064
tmp, job_table, curr_end);
2066
xstrcat(tmp, ", deleted");
2067
insert = xstrdup_printf("insert into %s (%s) ",
2072
debug3("%d(%d) query\n%s", mysql_conn->conn,
2074
if(!(result = mysql_db_query_ret(
2075
mysql_conn->db_conn, query, 0))) {
2081
// END_TIMER2("job query");
2082
// info("job query took %s", TIME_STR);
2084
if(!mysql_num_rows(result)) {
2086
mysql_free_result(result);
2090
rc = _write_archive_file(
2091
result, JOB_REQ_SUBMIT, JOB_REQ_COUNT,
2092
curr_end, arch_cond->archive_dir,
2093
"job", insert, true);
2096
mysql_free_result(result);
2098
if(rc != SLURM_SUCCESS)
2102
query = xstrdup_printf("delete from %s where submit <= %d "
2104
job_table, curr_end);
2105
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, query);
2106
rc = mysql_db_query(mysql_conn->db_conn, query);
2108
if(rc != SLURM_SUCCESS) {
2109
error("Couldn't remove old job data");
2115
return SLURM_SUCCESS;
2118
extern int mysql_jobacct_process_archive_load(mysql_conn_t *mysql_conn,
2119
acct_archive_rec_t *arch_rec)
2122
int error_code = SLURM_SUCCESS;
2125
error("We need a acct_archive_rec to load anything.");
2129
if(arch_rec->insert) {
2130
data = xstrdup(arch_rec->insert);
2131
} else if(arch_rec->archive_file) {
2132
uint32_t data_size = 0;
2133
int data_allocated, data_read = 0;
2134
int state_fd = open(arch_rec->archive_file, O_RDONLY);
2136
info("No archive file (%s) to recover",
2137
arch_rec->archive_file);
2138
error_code = ENOENT;
2140
data_allocated = BUF_SIZE;
2141
data = xmalloc(data_allocated);
2143
data_read = read(state_fd, &data[data_size],
2145
if (data_read < 0) {
2149
error("Read error on %s: %m",
2150
arch_rec->archive_file);
2153
} else if (data_read == 0) /* eof */
2155
data_size += data_read;
2156
data_allocated += data_read;
2157
xrealloc(data, data_allocated);
2161
if(error_code != SLURM_SUCCESS) {
2166
error("Nothing was set in your "
2167
"acct_archive_rec so I am unable to process.");
2172
error("It doesn't appear we have anything to load.");
2176
debug3("%d(%d) query\n%s", mysql_conn->conn, __LINE__, data);
2177
error_code = mysql_db_query_check_after(mysql_conn->db_conn, data);
2179
if(error_code != SLURM_SUCCESS) {
2180
error("Couldn't load old data");
2184
return SLURM_SUCCESS;