PageRenderTime 120ms CodeModel.GetById 3ms app.highlight 106ms RepoModel.GetById 1ms app.codeStats 0ms

/src/plugins/accounting_storage/mysql/as_mysql_archive.c

https://github.com/cfenoy/slurm
C | 2093 lines | 1809 code | 159 blank | 125 comment | 407 complexity | 08164dd7b0d1106427118a0224e7b672 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*****************************************************************************\
   2 *  as_mysql_archive.c - functions dealing with the archiving.
   3 *****************************************************************************
   4 *
   5 *  Copyright (C) 2004-2007 The Regents of the University of California.
   6 *  Copyright (C) 2008-2010 Lawrence Livermore National Security.
   7 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
   8 *  Written by Danny Auble <da@llnl.gov>
   9 *
  10 *  This file is part of SLURM, a resource management program.
  11 *  For details, see <http://www.schedmd.com/slurmdocs/>.
  12 *  Please also read the included file: DISCLAIMER.
  13 *
  14 *  SLURM is free software; you can redistribute it and/or modify it under
  15 *  the terms of the GNU General Public License as published by the Free
  16 *  Software Foundation; either version 2 of the License, or (at your option)
  17 *  any later version.
  18 *
  19 *  In addition, as a special exception, the copyright holders give permission
  20 *  to link the code of portions of this program with the OpenSSL library under
  21 *  certain conditions as described in each individual source file, and
  22 *  distribute linked combinations including the two. You must obey the GNU
  23 *  General Public License in all respects for all of the code used other than
  24 *  OpenSSL. If you modify file(s) with this exception, you may extend this
  25 *  exception to your version of the file(s), but you are not obligated to do
  26 *  so. If you do not wish to do so, delete this exception statement from your
  27 *  version.  If you delete this exception statement from all source files in
  28 *  the program, then also delete it here.
  29 *
  30 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
  31 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  32 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  33 *  details.
  34 *
  35 *  You should have received a copy of the GNU General Public License along
  36 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
  37 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
  38\*****************************************************************************/
  39
  40#include <fcntl.h>
  41#include <sys/types.h>
  42#include <sys/stat.h>
  43#include <unistd.h>
  44
  45#include "as_mysql_archive.h"
  46#include "src/common/slurmdbd_defs.h"
  47#include "src/common/env.h"
  48
  49typedef struct {
  50	char *cluster_nodes;
  51	char *cpu_count;
  52	char *node_name;
  53	char *period_end;
  54	char *period_start;
  55	char *reason;
  56	char *reason_uid;
  57	char *state;
  58} local_event_t;
  59
  60typedef struct {
  61	char *account;
  62	char *alloc_cpus;
  63	char *alloc_nodes;
  64	char *associd;
  65	char *blockid;
  66	char *derived_ec;
  67	char *derived_es;
  68	char *exit_code;
  69	char *eligible;
  70	char *end;
  71	char *gid;
  72	char *id;
  73	char *jobid;
  74	char *kill_requid;
  75	char *name;
  76	char *nodelist;
  77	char *node_inx;
  78	char *partition;
  79	char *priority;
  80	char *qos;
  81	char *req_cpus;
  82	char *resvid;
  83	char *start;
  84	char *state;
  85	char *submit;
  86	char *suspended;
  87	char *timelimit;
  88	char *track_steps;
  89	char *uid;
  90	char *wckey;
  91	char *wckey_id;
  92} local_job_t;
  93
  94typedef struct {
  95	char *ave_cpu;
  96	char *ave_pages;
  97	char *ave_rss;
  98	char *ave_vsize;
  99	char *exit_code;
 100	char *cpus;
 101	char *id;
 102	char *kill_requid;
 103	char *max_pages;
 104	char *max_pages_node;
 105	char *max_pages_task;
 106	char *max_rss;
 107	char *max_rss_node;
 108	char *max_rss_task;
 109	char *max_vsize;
 110	char *max_vsize_node;
 111	char *max_vsize_task;
 112	char *min_cpu;
 113	char *min_cpu_node;
 114	char *min_cpu_task;
 115	char *name;
 116	char *nodelist;
 117	char *nodes;
 118	char *node_inx;
 119	char *period_end;
 120	char *period_start;
 121	char *period_suspended;
 122	char *state;
 123	char *stepid;
 124	char *sys_sec;
 125	char *sys_usec;
 126	char *tasks;
 127	char *task_dist;
 128	char *user_sec;
 129	char *user_usec;
 130	char *act_cpufreq;
 131	char *consumed_energy;
 132} local_step_t;
 133
 134typedef struct {
 135	char *associd;
 136	char *id;
 137	char *period_end;
 138	char *period_start;
 139} local_suspend_t;
 140
 141/* if this changes you will need to edit the corresponding
 142 * enum below */
 143char *event_req_inx[] = {
 144	"time_start",
 145	"time_end",
 146	"node_name",
 147	"cluster_nodes",
 148	"cpu_count",
 149	"reason",
 150	"reason_uid",
 151	"state",
 152};
 153
 154enum {
 155	EVENT_REQ_START,
 156	EVENT_REQ_END,
 157	EVENT_REQ_NODE,
 158	EVENT_REQ_CNODES,
 159	EVENT_REQ_CPU,
 160	EVENT_REQ_REASON,
 161	EVENT_REQ_REASON_UID,
 162	EVENT_REQ_STATE,
 163	EVENT_REQ_COUNT
 164};
 165
 166/* if this changes you will need to edit the corresponding
 167 * enum below */
 168static char *job_req_inx[] = {
 169	"account",
 170	"cpus_alloc",
 171	"nodes_alloc",
 172	"id_assoc",
 173	"id_block",
 174	"derived_ec",
 175	"derived_es",
 176	"exit_code",
 177	"timelimit",
 178	"time_eligible",
 179	"time_end",
 180	"id_group",
 181	"job_db_inx",
 182	"id_job",
 183	"kill_requid",
 184	"job_name",
 185	"nodelist",
 186	"node_inx",
 187	"partition",
 188	"priority",
 189	"id_qos",
 190	"cpus_req",
 191	"id_resv",
 192	"time_start",
 193	"state",
 194	"time_submit",
 195	"time_suspended",
 196	"track_steps",
 197	"id_user",
 198	"wckey",
 199	"id_wckey"
 200};
 201
 202enum {
 203	JOB_REQ_ACCOUNT,
 204	JOB_REQ_ALLOC_CPUS,
 205	JOB_REQ_ALLOC_NODES,
 206	JOB_REQ_ASSOCID,
 207	JOB_REQ_BLOCKID,
 208	JOB_REQ_DERIVED_EC,
 209	JOB_REQ_DERIVED_ES,
 210	JOB_REQ_EXIT_CODE,
 211	JOB_REQ_TIMELIMIT,
 212	JOB_REQ_ELIGIBLE,
 213	JOB_REQ_END,
 214	JOB_REQ_GID,
 215	JOB_REQ_ID,
 216	JOB_REQ_JOBID,
 217	JOB_REQ_KILL_REQUID,
 218	JOB_REQ_NAME,
 219	JOB_REQ_NODELIST,
 220	JOB_REQ_NODE_INX,
 221	JOB_REQ_RESVID,
 222	JOB_REQ_PARTITION,
 223	JOB_REQ_PRIORITY,
 224	JOB_REQ_QOS,
 225	JOB_REQ_REQ_CPUS,
 226	JOB_REQ_START,
 227	JOB_REQ_STATE,
 228	JOB_REQ_SUBMIT,
 229	JOB_REQ_SUSPENDED,
 230	JOB_REQ_TRACKSTEPS,
 231	JOB_REQ_UID,
 232	JOB_REQ_WCKEY,
 233	JOB_REQ_WCKEYID,
 234	JOB_REQ_COUNT
 235};
 236
 237/* if this changes you will need to edit the corresponding
 238 * enum below */
 239static char *step_req_inx[] = {
 240	"job_db_inx",
 241	"id_step",
 242	"time_start",
 243	"time_end",
 244	"time_suspended",
 245	"step_name",
 246	"nodelist",
 247	"node_inx",
 248	"state",
 249	"kill_requid",
 250	"exit_code",
 251	"nodes_alloc",
 252	"cpus_alloc",
 253	"task_cnt",
 254	"task_dist",
 255	"user_sec",
 256	"user_usec",
 257	"sys_sec",
 258	"sys_usec",
 259	"max_vsize",
 260	"max_vsize_task",
 261	"max_vsize_node",
 262	"ave_vsize",
 263	"max_rss",
 264	"max_rss_task",
 265	"max_rss_node",
 266	"ave_rss",
 267	"max_pages",
 268	"max_pages_task",
 269	"max_pages_node",
 270	"ave_pages",
 271	"min_cpu",
 272	"min_cpu_task",
 273	"min_cpu_node",
 274	"ave_cpu",
 275	"act_cpufreq",
 276	"consumed_energy"
 277};
 278
 279
 280enum {
 281	STEP_REQ_ID,
 282	STEP_REQ_STEPID,
 283	STEP_REQ_START,
 284	STEP_REQ_END,
 285	STEP_REQ_SUSPENDED,
 286	STEP_REQ_NAME,
 287	STEP_REQ_NODELIST,
 288	STEP_REQ_NODE_INX,
 289	STEP_REQ_STATE,
 290	STEP_REQ_KILL_REQUID,
 291	STEP_REQ_EXIT_CODE,
 292	STEP_REQ_NODES,
 293	STEP_REQ_CPUS,
 294	STEP_REQ_TASKS,
 295	STEP_REQ_TASKDIST,
 296	STEP_REQ_USER_SEC,
 297	STEP_REQ_USER_USEC,
 298	STEP_REQ_SYS_SEC,
 299	STEP_REQ_SYS_USEC,
 300	STEP_REQ_MAX_VSIZE,
 301	STEP_REQ_MAX_VSIZE_TASK,
 302	STEP_REQ_MAX_VSIZE_NODE,
 303	STEP_REQ_AVE_VSIZE,
 304	STEP_REQ_MAX_RSS,
 305	STEP_REQ_MAX_RSS_TASK,
 306	STEP_REQ_MAX_RSS_NODE,
 307	STEP_REQ_AVE_RSS,
 308	STEP_REQ_MAX_PAGES,
 309	STEP_REQ_MAX_PAGES_TASK,
 310	STEP_REQ_MAX_PAGES_NODE,
 311	STEP_REQ_AVE_PAGES,
 312	STEP_REQ_MIN_CPU,
 313	STEP_REQ_MIN_CPU_TASK,
 314	STEP_REQ_MIN_CPU_NODE,
 315	STEP_REQ_AVE_CPU,
 316	STEP_REQ_ACT_CPUFREQ,
 317	STEP_REQ_CONSUMED_ENERGY,
 318	STEP_REQ_COUNT
 319};
 320
 321/* if this changes you will need to edit the corresponding
 322 * enum below */
 323static char *suspend_req_inx[] = {
 324	"job_db_inx",
 325	"id_assoc",
 326	"time_start",
 327	"time_end",
 328};
 329
 330enum {
 331	SUSPEND_REQ_ID,
 332	SUSPEND_REQ_ASSOCID,
 333	SUSPEND_REQ_START,
 334	SUSPEND_REQ_END,
 335	SUSPEND_REQ_COUNT
 336};
 337
 338static int high_buffer_size = (1024 * 1024);
 339
 340static void _pack_local_event(local_event_t *object,
 341			      uint16_t rpc_version, Buf buffer)
 342{
 343	packstr(object->cluster_nodes, buffer);
 344	packstr(object->cpu_count, buffer);
 345	packstr(object->node_name, buffer);
 346	packstr(object->period_end, buffer);
 347	packstr(object->period_start, buffer);
 348	packstr(object->reason, buffer);
 349	packstr(object->reason_uid, buffer);
 350	packstr(object->state, buffer);
 351}
 352
 353/* this needs to be allocated before calling, and since we aren't
 354 * doing any copying it needs to be used before destroying buffer */
 355static int _unpack_local_event(local_event_t *object,
 356			       uint16_t rpc_version, Buf buffer)
 357{
 358	uint32_t tmp32;
 359
 360	unpackstr_ptr(&object->cluster_nodes, &tmp32, buffer);
 361	unpackstr_ptr(&object->cpu_count, &tmp32, buffer);
 362	unpackstr_ptr(&object->node_name, &tmp32, buffer);
 363	unpackstr_ptr(&object->period_end, &tmp32, buffer);
 364	unpackstr_ptr(&object->period_start, &tmp32, buffer);
 365	unpackstr_ptr(&object->reason, &tmp32, buffer);
 366	unpackstr_ptr(&object->reason_uid, &tmp32, buffer);
 367	unpackstr_ptr(&object->state, &tmp32, buffer);
 368
 369	return SLURM_SUCCESS;
 370}
 371
 372static void _pack_local_job(local_job_t *object,
 373			    uint16_t rpc_version, Buf buffer)
 374{
 375	packstr(object->account, buffer);
 376	packstr(object->alloc_cpus, buffer);
 377	packstr(object->alloc_nodes, buffer);
 378	packstr(object->associd, buffer);
 379	packstr(object->blockid, buffer);
 380	packstr(object->derived_ec, buffer);
 381	packstr(object->derived_es, buffer);
 382	packstr(object->exit_code, buffer);
 383	packstr(object->timelimit, buffer);
 384	packstr(object->eligible, buffer);
 385	packstr(object->end, buffer);
 386	packstr(object->gid, buffer);
 387	packstr(object->id, buffer);
 388	packstr(object->jobid, buffer);
 389	packstr(object->kill_requid, buffer);
 390	packstr(object->name, buffer);
 391	packstr(object->nodelist, buffer);
 392	packstr(object->node_inx, buffer);
 393	packstr(object->partition, buffer);
 394	packstr(object->priority, buffer);
 395	packstr(object->qos, buffer);
 396	packstr(object->req_cpus, buffer);
 397	packstr(object->resvid, buffer);
 398	packstr(object->start, buffer);
 399	packstr(object->state, buffer);
 400	packstr(object->submit, buffer);
 401	packstr(object->suspended, buffer);
 402	packstr(object->track_steps, buffer);
 403	packstr(object->uid, buffer);
 404	packstr(object->wckey, buffer);
 405	packstr(object->wckey_id, buffer);
 406}
 407
 408/* this needs to be allocated before calling, and since we aren't
 409 * doing any copying it needs to be used before destroying buffer */
 410static int _unpack_local_job(local_job_t *object,
 411			     uint16_t rpc_version, Buf buffer)
 412{
 413	uint32_t tmp32;
 414
 415	unpackstr_ptr(&object->account, &tmp32, buffer);
 416	unpackstr_ptr(&object->alloc_cpus, &tmp32, buffer);
 417	unpackstr_ptr(&object->alloc_nodes, &tmp32, buffer);
 418	unpackstr_ptr(&object->associd, &tmp32, buffer);
 419	unpackstr_ptr(&object->blockid, &tmp32, buffer);
 420	unpackstr_ptr(&object->derived_ec, &tmp32, buffer);
 421	unpackstr_ptr(&object->derived_es, &tmp32, buffer);
 422	unpackstr_ptr(&object->exit_code, &tmp32, buffer);
 423	unpackstr_ptr(&object->timelimit, &tmp32, buffer);
 424	unpackstr_ptr(&object->eligible, &tmp32, buffer);
 425	unpackstr_ptr(&object->end, &tmp32, buffer);
 426	unpackstr_ptr(&object->gid, &tmp32, buffer);
 427	unpackstr_ptr(&object->id, &tmp32, buffer);
 428	unpackstr_ptr(&object->jobid, &tmp32, buffer);
 429	unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
 430	unpackstr_ptr(&object->name, &tmp32, buffer);
 431	unpackstr_ptr(&object->nodelist, &tmp32, buffer);
 432	unpackstr_ptr(&object->node_inx, &tmp32, buffer);
 433	unpackstr_ptr(&object->partition, &tmp32, buffer);
 434	unpackstr_ptr(&object->priority, &tmp32, buffer);
 435	unpackstr_ptr(&object->qos, &tmp32, buffer);
 436	unpackstr_ptr(&object->req_cpus, &tmp32, buffer);
 437	unpackstr_ptr(&object->resvid, &tmp32, buffer);
 438	unpackstr_ptr(&object->start, &tmp32, buffer);
 439	unpackstr_ptr(&object->state, &tmp32, buffer);
 440	unpackstr_ptr(&object->submit, &tmp32, buffer);
 441	unpackstr_ptr(&object->suspended, &tmp32, buffer);
 442	unpackstr_ptr(&object->track_steps, &tmp32, buffer);
 443	unpackstr_ptr(&object->uid, &tmp32, buffer);
 444	unpackstr_ptr(&object->wckey, &tmp32, buffer);
 445	unpackstr_ptr(&object->wckey_id, &tmp32, buffer);
 446
 447	return SLURM_SUCCESS;
 448}
 449
 450static void _pack_local_step(local_step_t *object,
 451			     uint16_t rpc_version, Buf buffer)
 452{
 453	if (rpc_version >= SLURMDBD_2_5_VERSION) {
 454		packstr(object->act_cpufreq, buffer);
 455		packstr(object->ave_cpu, buffer);
 456		packstr(object->ave_pages, buffer);
 457		packstr(object->ave_rss, buffer);
 458		packstr(object->ave_vsize, buffer);
 459		packstr(object->exit_code, buffer);
 460		packstr(object->consumed_energy, buffer);
 461		packstr(object->cpus, buffer);
 462		packstr(object->id, buffer);
 463		packstr(object->kill_requid, buffer);
 464		packstr(object->max_pages, buffer);
 465		packstr(object->max_pages_node, buffer);
 466		packstr(object->max_pages_task, buffer);
 467		packstr(object->max_rss, buffer);
 468		packstr(object->max_rss_node, buffer);
 469		packstr(object->max_rss_task, buffer);
 470		packstr(object->max_vsize, buffer);
 471		packstr(object->max_vsize_node, buffer);
 472		packstr(object->max_vsize_task, buffer);
 473		packstr(object->min_cpu, buffer);
 474		packstr(object->min_cpu_node, buffer);
 475		packstr(object->min_cpu_task, buffer);
 476		packstr(object->name, buffer);
 477		packstr(object->nodelist, buffer);
 478		packstr(object->nodes, buffer);
 479		packstr(object->node_inx, buffer);
 480		packstr(object->period_end, buffer);
 481		packstr(object->period_start, buffer);
 482		packstr(object->period_suspended, buffer);
 483		packstr(object->state, buffer);
 484		packstr(object->stepid, buffer);
 485		packstr(object->sys_sec, buffer);
 486		packstr(object->sys_usec, buffer);
 487		packstr(object->tasks, buffer);
 488		packstr(object->task_dist, buffer);
 489		packstr(object->user_sec, buffer);
 490		packstr(object->user_usec, buffer);
 491	} else if (rpc_version >= SLURMDBD_VERSION_MIN) {
 492		packstr(object->ave_cpu, buffer);
 493		packstr(object->ave_pages, buffer);
 494		packstr(object->ave_rss, buffer);
 495		packstr(object->ave_vsize, buffer);
 496		packstr(object->exit_code, buffer);
 497		packstr(object->cpus, buffer);
 498		packstr(object->id, buffer);
 499		packstr(object->kill_requid, buffer);
 500		packstr(object->max_pages, buffer);
 501		packstr(object->max_pages_node, buffer);
 502		packstr(object->max_pages_task, buffer);
 503		packstr(object->max_rss, buffer);
 504		packstr(object->max_rss_node, buffer);
 505		packstr(object->max_rss_task, buffer);
 506		packstr(object->max_vsize, buffer);
 507		packstr(object->max_vsize_node, buffer);
 508		packstr(object->max_vsize_task, buffer);
 509		packstr(object->min_cpu, buffer);
 510		packstr(object->min_cpu_node, buffer);
 511		packstr(object->min_cpu_task, buffer);
 512		packstr(object->name, buffer);
 513		packstr(object->nodelist, buffer);
 514		packstr(object->nodes, buffer);
 515		packstr(object->node_inx, buffer);
 516		packstr(object->period_end, buffer);
 517		packstr(object->period_start, buffer);
 518		packstr(object->period_suspended, buffer);
 519		packstr(object->state, buffer);
 520		packstr(object->stepid, buffer);
 521		packstr(object->sys_sec, buffer);
 522		packstr(object->sys_usec, buffer);
 523		packstr(object->tasks, buffer);
 524		packstr(object->task_dist, buffer);
 525		packstr(object->user_sec, buffer);
 526		packstr(object->user_usec, buffer);
 527	}
 528}
 529
 530/* this needs to be allocated before calling, and since we aren't
 531 * doing any copying it needs to be used before destroying buffer */
 532static int _unpack_local_step(local_step_t *object,
 533			      uint16_t rpc_version, Buf buffer)
 534{
 535	uint32_t tmp32;
 536
 537	if (rpc_version >= SLURMDBD_2_5_VERSION) {
 538		unpackstr_ptr(&object->act_cpufreq, &tmp32, buffer);
 539		unpackstr_ptr(&object->ave_cpu, &tmp32, buffer);
 540		unpackstr_ptr(&object->ave_pages, &tmp32, buffer);
 541		unpackstr_ptr(&object->ave_rss, &tmp32, buffer);
 542		unpackstr_ptr(&object->ave_vsize, &tmp32, buffer);
 543		unpackstr_ptr(&object->exit_code, &tmp32, buffer);
 544		unpackstr_ptr(&object->consumed_energy, &tmp32, buffer);
 545		unpackstr_ptr(&object->cpus, &tmp32, buffer);
 546		unpackstr_ptr(&object->id, &tmp32, buffer);
 547		unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
 548		unpackstr_ptr(&object->max_pages, &tmp32, buffer);
 549		unpackstr_ptr(&object->max_pages_node, &tmp32, buffer);
 550		unpackstr_ptr(&object->max_pages_task, &tmp32, buffer);
 551		unpackstr_ptr(&object->max_rss, &tmp32, buffer);
 552		unpackstr_ptr(&object->max_rss_node, &tmp32, buffer);
 553		unpackstr_ptr(&object->max_rss_task, &tmp32, buffer);
 554		unpackstr_ptr(&object->max_vsize, &tmp32, buffer);
 555		unpackstr_ptr(&object->max_vsize_node, &tmp32, buffer);
 556		unpackstr_ptr(&object->max_vsize_task, &tmp32, buffer);
 557		unpackstr_ptr(&object->min_cpu, &tmp32, buffer);
 558		unpackstr_ptr(&object->min_cpu_node, &tmp32, buffer);
 559		unpackstr_ptr(&object->min_cpu_task, &tmp32, buffer);
 560		unpackstr_ptr(&object->name, &tmp32, buffer);
 561		unpackstr_ptr(&object->nodelist, &tmp32, buffer);
 562		unpackstr_ptr(&object->nodes, &tmp32, buffer);
 563		unpackstr_ptr(&object->node_inx, &tmp32, buffer);
 564		unpackstr_ptr(&object->period_end, &tmp32, buffer);
 565		unpackstr_ptr(&object->period_start, &tmp32, buffer);
 566		unpackstr_ptr(&object->period_suspended, &tmp32, buffer);
 567		unpackstr_ptr(&object->state, &tmp32, buffer);
 568		unpackstr_ptr(&object->stepid, &tmp32, buffer);
 569		unpackstr_ptr(&object->sys_sec, &tmp32, buffer);
 570		unpackstr_ptr(&object->sys_usec, &tmp32, buffer);
 571		unpackstr_ptr(&object->tasks, &tmp32, buffer);
 572		unpackstr_ptr(&object->task_dist, &tmp32, buffer);
 573		unpackstr_ptr(&object->user_sec, &tmp32, buffer);
 574		unpackstr_ptr(&object->user_usec, &tmp32, buffer);
 575	} else if (rpc_version >= SLURMDBD_VERSION_MIN) {
 576		unpackstr_ptr(&object->ave_cpu, &tmp32, buffer);
 577		unpackstr_ptr(&object->ave_pages, &tmp32, buffer);
 578		unpackstr_ptr(&object->ave_rss, &tmp32, buffer);
 579		unpackstr_ptr(&object->ave_vsize, &tmp32, buffer);
 580		unpackstr_ptr(&object->exit_code, &tmp32, buffer);
 581		unpackstr_ptr(&object->cpus, &tmp32, buffer);
 582		unpackstr_ptr(&object->id, &tmp32, buffer);
 583		unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
 584		unpackstr_ptr(&object->max_pages, &tmp32, buffer);
 585		unpackstr_ptr(&object->max_pages_node, &tmp32, buffer);
 586		unpackstr_ptr(&object->max_pages_task, &tmp32, buffer);
 587		unpackstr_ptr(&object->max_rss, &tmp32, buffer);
 588		unpackstr_ptr(&object->max_rss_node, &tmp32, buffer);
 589		unpackstr_ptr(&object->max_rss_task, &tmp32, buffer);
 590		unpackstr_ptr(&object->max_vsize, &tmp32, buffer);
 591		unpackstr_ptr(&object->max_vsize_node, &tmp32, buffer);
 592		unpackstr_ptr(&object->max_vsize_task, &tmp32, buffer);
 593		unpackstr_ptr(&object->min_cpu, &tmp32, buffer);
 594		unpackstr_ptr(&object->min_cpu_node, &tmp32, buffer);
 595		unpackstr_ptr(&object->min_cpu_task, &tmp32, buffer);
 596		unpackstr_ptr(&object->name, &tmp32, buffer);
 597		unpackstr_ptr(&object->nodelist, &tmp32, buffer);
 598		unpackstr_ptr(&object->nodes, &tmp32, buffer);
 599		unpackstr_ptr(&object->node_inx, &tmp32, buffer);
 600		unpackstr_ptr(&object->period_end, &tmp32, buffer);
 601		unpackstr_ptr(&object->period_start, &tmp32, buffer);
 602		unpackstr_ptr(&object->period_suspended, &tmp32, buffer);
 603		unpackstr_ptr(&object->state, &tmp32, buffer);
 604		unpackstr_ptr(&object->stepid, &tmp32, buffer);
 605		unpackstr_ptr(&object->sys_sec, &tmp32, buffer);
 606		unpackstr_ptr(&object->sys_usec, &tmp32, buffer);
 607		unpackstr_ptr(&object->tasks, &tmp32, buffer);
 608		unpackstr_ptr(&object->task_dist, &tmp32, buffer);
 609		unpackstr_ptr(&object->user_sec, &tmp32, buffer);
 610		unpackstr_ptr(&object->user_usec, &tmp32, buffer);
 611	}
 612
 613	return SLURM_SUCCESS;
 614}
 615
 616static void _pack_local_suspend(local_suspend_t *object,
 617				uint16_t rpc_version, Buf buffer)
 618{
 619	packstr(object->associd, buffer);
 620	packstr(object->id, buffer);
 621	packstr(object->period_end, buffer);
 622	packstr(object->period_start, buffer);
 623}
 624
 625/* this needs to be allocated before calling, and since we aren't
 626 * doing any copying it needs to be used before destroying buffer */
 627static int _unpack_local_suspend(local_suspend_t *object,
 628				 uint16_t rpc_version, Buf buffer)
 629{
 630	uint32_t tmp32;
 631
 632	unpackstr_ptr(&object->associd, &tmp32, buffer);
 633	unpackstr_ptr(&object->id, &tmp32, buffer);
 634	unpackstr_ptr(&object->period_end, &tmp32, buffer);
 635	unpackstr_ptr(&object->period_start, &tmp32, buffer);
 636
 637	return SLURM_SUCCESS;
 638}
 639
 640static int _process_old_sql_line(const char *data_in, char **data_full_out)
 641{
 642	int start = 0, i = 0;
 643	char *beginning = NULL;
 644	char *ending = NULL;
 645	char *data_out = *data_full_out;
 646	char *table = NULL;
 647	char *fields = NULL;
 648	char *new_vals = NULL;
 649	char *vals = NULL;
 650	char *new_cluster_name = NULL;
 651	char *cluster_name = NULL;
 652	int rc = SLURM_SUCCESS;
 653	int cnt = 0, cluster_inx = -1, ending_start = 0, ending_end = 0;
 654	bool delete = 0;
 655	bool new_cluster = 0;
 656
 657	while (data_in[i]) {
 658		if (!strncmp("insert into ", data_in+i, 12)) {
 659			beginning = xstrndup(data_in+i, 11);
 660			i+=12;
 661			break;
 662		} else if (!strncmp("delete from ", data_in+i, 12)) {
 663			beginning = xstrndup(data_in+i, 11);
 664			i+=12;
 665			delete = 1;
 666			break;
 667		} else if (!strncmp("drop table ", data_in+i, 11)) {
 668			start = i;
 669			i+=11;
 670			while (data_in[i] && data_in[i-1] != ';')
 671				i++;
 672			xstrncat(data_out, data_in+start, i-start);
 673			goto end_it;
 674		} else if (!strncmp("truncate table ", data_in+i, 15)) {
 675			start = i;
 676			i+=15;
 677			while (data_in[i] && data_in[i-1] != ';')
 678				i++;
 679			xstrncat(data_out, data_in+start, i-start);
 680			goto end_it;
 681		}
 682		i++;
 683	}
 684
 685	if (!data_in[i])
 686		goto end_it;
 687
 688	//info("processing %s", data_in);
 689	/* get table name */
 690	if (!strncmp("cluster_event_table", data_in+i, 19)) {
 691		i+=19;
 692		table = event_table;
 693	} else if (!strncmp("job_table", data_in+i, 9)) {
 694		i+=9;
 695		table = job_table;
 696	} else if (!strncmp("step_table", data_in+i, 10)) {
 697		i+=10;
 698		table = step_table;
 699	} else if (!strncmp("suspend_table", data_in+i, 13)) {
 700		i+=13;
 701		table = suspend_table;
 702	} else if (!strncmp("cluster_day_usage_table", data_in+i, 23)) {
 703		i+=23;
 704		table = cluster_day_table;
 705	} else if (!strncmp("cluster_hour_usage_table", data_in+i, 24)) {
 706		i+=24;
 707		table = cluster_hour_table;
 708	} else if (!strncmp("cluster_month_usage_table", data_in+i, 25)) {
 709		i+=25;
 710		table = cluster_month_table;
 711	} else if (!strncmp("assoc_day_usage_table", data_in+i, 21)) {
 712		i+=21;
 713		table = assoc_day_table;
 714	} else if (!strncmp("assoc_hour_usage_table", data_in+i, 22)) {
 715		i+=22;
 716		table = assoc_hour_table;
 717	} else if (!strncmp("assoc_month_usage_table", data_in+i, 23)) {
 718		i+=23;
 719		table = assoc_month_table;
 720	} else {
 721		error("unknown table in sql '%s'", data_in);
 722		rc = SLURM_ERROR;
 723		goto end_it;
 724	}
 725	/* get to the columns */
 726	if (!delete)
 727		while (data_in[i] && data_in[i-1] != '(' && data_in[i-1] != ';')
 728			i++;
 729	else
 730		while (data_in[i] && data_in[i-1] != ' ')
 731			i++;
 732	//info("table is %s '%s'", table, data_in+i);
 733	while (data_in[i] && data_in[i] != ')') {
 734		if (delete && !strncmp("where ", data_in+i, 6)) {
 735			i+=6;
 736			continue;
 737		} else if (!strncmp("period_start", data_in+i, 12)) {
 738			xstrcat(fields, "time_start");
 739			i+=12;
 740		} else if (!strncmp("period_end", data_in+i, 10)) {
 741			xstrcat(fields, "time_end");
 742			i+=10;
 743		} else if (!strncmp("jobid", data_in+i, 5)) {
 744			xstrcat(fields, "id_job");
 745			i+=5;
 746		} else if (!strncmp("stepid", data_in+i, 6)) {
 747			xstrcat(fields, "id_step");
 748			i+=6;
 749		} else if (!strncmp("associd", data_in+i, 7)) {
 750			xstrcat(fields, "id_assoc");
 751			i+=7;
 752		} else if (!strncmp("blockid", data_in+i, 7)) {
 753			xstrcat(fields, "id_block");
 754			i+=7;
 755		} else if (!strncmp("wckeyid", data_in+i, 7)) {
 756			xstrcat(fields, "id_wckey");
 757			i+=7;
 758		} else if (!strncmp("qos", data_in+i, 3)) {
 759			xstrcat(fields, "id_qos");
 760			i+=3;
 761		} else if (!strncmp("uid", data_in+i, 3)) {
 762			xstrcat(fields, "id_user");
 763			i+=3;
 764		} else if (!strncmp("gid", data_in+i, 3)) {
 765			xstrcat(fields, "id_group");
 766			i+=3;
 767		} else if (!strncmp("submit", data_in+i, 6)) {
 768			xstrcat(fields, "time_submit");
 769			i+=6;
 770		} else if (!strncmp("eligible", data_in+i, 8)) {
 771			xstrcat(fields, "time_eligible");
 772			i+=8;
 773		} else if (!strncmp("start", data_in+i, 5)) {
 774			xstrcat(fields, "time_start");
 775			i+=5;
 776		} else if (!strncmp("suspended", data_in+i, 9)) {
 777			xstrcat(fields, "time_suspended");
 778			i+=9;
 779		} else if (!strncmp("end", data_in+i, 3)) {
 780			xstrcat(fields, "time_end");
 781			i+=3;
 782		} else if (!strncmp("comp_code", data_in+i, 9)) {
 783			xstrcat(fields, "exit_code");
 784			i+=9;
 785		} else if (!strncmp("alloc_cpus", data_in+i, 10)) {
 786			xstrcat(fields, "cpus_alloc");
 787			i+=10;
 788		} else if (!strncmp("req_cpus", data_in+i, 8)) {
 789			xstrcat(fields, "cpus_req");
 790			i+=8;
 791		} else if (!strncmp("alloc_nodes", data_in+i, 11)) {
 792			xstrcat(fields, "nodes_alloc");
 793			i+=11;
 794		} else if (!strncmp("name", data_in+i, 4)) {
 795			if (table == job_table)
 796				xstrcat(fields, "job_name");
 797			else if (table == step_table)
 798				xstrcat(fields, "step_name");
 799			i+=4;
 800		} else if (!strncmp("id", data_in+i, 2)) {
 801			i+=2;
 802			if ((table == assoc_day_table)
 803			    || (table == assoc_hour_table)
 804			    || (table == assoc_month_table)) {
 805				char *id_assoc = NULL;
 806				while (data_in[i] && data_in[i-1] != '=') {
 807					i++;
 808				}
 809				start = i;
 810				while (data_in[i]
 811				       && data_in[i] != ' '
 812				       && data_in[i] != ';') {
 813					i++;
 814				}
 815				if (!data_in[i]) {
 816					error("returning at id_assoc");
 817					rc = SLURM_ERROR;
 818					goto end_it;
 819				}
 820				if (data_in[i] == ' ') {
 821					while (data_in[i] && data_in[i] == ' ')
 822						i++;
 823					while (data_in[i] && data_in[i] == '|')
 824						i++;
 825					while (data_in[i] && data_in[i] == ' ')
 826						i++;
 827				}
 828				xstrncat(id_assoc, data_in+start, (i-start));
 829				if (!fields)
 830					xstrcat(fields, "where ");
 831				xstrfmtcat(fields, "id_assoc=%s", id_assoc);
 832				xfree(id_assoc);
 833			} else
 834				xstrcat(fields, "job_db_inx");
 835		} else if (!strncmp("cluster_nodes", data_in+i, 13)) {
 836			/* this is here just to make it easier to
 837			   handle the cluster field. */
 838			xstrcat(fields, "cluster_nodes");
 839			i+=13;
 840		} else if (!strncmp("cluster", data_in+i, 7)) {
 841			i+=7;
 842			if (!delete) {
 843				cluster_inx = cnt;
 844				if (cnt)
 845					fields[strlen(fields)-2] = '\0';
 846			} else {
 847				while (data_in[i] && data_in[i-1] != '\'')
 848					i++;
 849				start = i;
 850				while (data_in[i] && data_in[i] != '\'')
 851					i++;
 852				if (!data_in[i]) {
 853					error("returning here cluster");
 854					rc = SLURM_ERROR;
 855					goto end_it;
 856				}
 857
 858				cluster_name = xstrndup(data_in+start,
 859							(i-start));
 860				i++;
 861			}
 862		} else {
 863			start = i;
 864			while (data_in[i]
 865			       && data_in[i] != ',' && data_in[i] != ')') {
 866				i++;
 867			}
 868			if (!data_in[i]) {
 869				error("returning here end");
 870				rc = SLURM_ERROR;
 871				goto end_it;
 872			}
 873			xstrncat(fields, data_in+start, (i-start));
 874		}
 875		if (data_in[i]) {
 876			if (!delete || ((table != assoc_day_table)
 877					&& (table != assoc_hour_table)
 878					&& (table != assoc_month_table))) {
 879				if (data_in[i] == ',')
 880					xstrcat(fields, ", ");
 881				else if (data_in[i] == ')'
 882					 || data_in[i] == ';') {
 883					break;
 884				} else {
 885					error("unknown char '%s'", data_in+i);
 886					rc = SLURM_ERROR;
 887					goto end_it;
 888				}
 889				i++;
 890			} else {
 891				if (data_in[i] == ';')
 892					break;
 893			}
 894			while (data_in[i] && data_in[i] == ' ')
 895				i++;
 896		}
 897		cnt++;
 898	}
 899
 900	if (data_in[i] && data_in[i] == ')') {
 901		ending_end = i;
 902		ending_start = 0;
 903		while (data_in[ending_end] && data_in[ending_end-1] != ';') {
 904			if (!strncmp(data_in+ending_end,
 905				     "on duplicate key", 16)) {
 906				ending_start = ending_end;
 907			}
 908			if (ending_start) {
 909				if (!strncmp("period_start",
 910					     data_in+ending_end, 12)) {
 911					xstrcat(ending, "time_start");
 912					ending_end+=12;
 913				} else if (!strncmp("period_end",
 914						    data_in+ending_end, 10)) {
 915					xstrcat(ending, "time_end");
 916					ending_end+=10;
 917				} else if (!strncmp("jobid",
 918						    data_in+ending_end, 5)) {
 919					xstrcat(ending, "id_job");
 920					ending_end+=5;
 921				} else if (!strncmp("stepid",
 922						    data_in+ending_end, 6)) {
 923					xstrcat(ending, "id_step");
 924					ending_end+=6;
 925				} else if (!strncmp("associd",
 926						    data_in+ending_end, 7)) {
 927					xstrcat(ending, "id_assoc");
 928					ending_end+=7;
 929				} else if (!strncmp("blockid",
 930						    data_in+ending_end, 7)) {
 931					xstrcat(ending, "id_block");
 932					ending_end+=7;
 933				} else if (!strncmp("wckeyid",
 934						    data_in+ending_end, 7)) {
 935					xstrcat(ending, "id_wckey");
 936					ending_end+=7;
 937				} else if (!strncmp("uid",
 938						    data_in+ending_end, 3)) {
 939					xstrcat(ending, "id_user");
 940					ending_end+=3;
 941				} else if (!strncmp("gid",
 942						    data_in+ending_end, 3)) {
 943					xstrcat(ending, "id_group");
 944					ending_end+=3;
 945				} else if (!strncmp("submit",
 946						    data_in+ending_end, 6)) {
 947					xstrcat(ending, "time_submit");
 948					ending_end+=6;
 949				} else if (!strncmp("eligible",
 950						    data_in+ending_end, 8)) {
 951					xstrcat(ending, "time_eligible");
 952					ending_end+=8;
 953				} else if (!strncmp("start",
 954						    data_in+ending_end, 5)) {
 955					xstrcat(ending, "time_start");
 956					ending_end+=5;
 957				} else if (!strncmp("suspended",
 958						    data_in+ending_end, 9)) {
 959					xstrcat(ending, "time_suspended");
 960					ending_end+=9;
 961				} else if (!strncmp("end",
 962						    data_in+ending_end, 3)) {
 963					xstrcat(ending, "time_end");
 964					ending_end+=3;
 965				} else if (!strncmp("comp_code",
 966						    data_in+ending_end, 9)) {
 967					xstrcat(ending, "exit_code");
 968					ending_end+=9;
 969				} else if (!strncmp("alloc_cpus",
 970						    data_in+ending_end, 10)) {
 971					xstrcat(ending, "cpus_alloc");
 972					ending_end+=10;
 973				} else if (!strncmp("req_cpus",
 974						    data_in+ending_end, 8)) {
 975					xstrcat(ending, "cpus_req");
 976					ending_end+=8;
 977				} else if (!strncmp("alloc_nodes",
 978						    data_in+ending_end, 11)) {
 979					xstrcat(ending, "nodes_alloc");
 980					ending_end+=11;
 981				} else if (!strncmp("name",
 982						    data_in+ending_end, 4)) {
 983					if (table == job_table)
 984						xstrcat(ending, "job_name");
 985					else if (table == step_table)
 986						xstrcat(ending, "step_name");
 987					ending_end+=4;
 988				} else if (!strncmp("id",
 989						    data_in+ending_end, 2)) {
 990					if ((table == assoc_day_table)
 991					    || (table == assoc_hour_table)
 992					    || (table == assoc_month_table))
 993						xstrcat(ending, "id_assoc");
 994					else
 995						xstrcat(ending, "job_db_inx");
 996					ending_end+=2;
 997				}
 998
 999				if (data_in[ending_end])
1000					xstrcatchar(ending,
1001						    data_in[ending_end]);
1002			}
1003			ending_end++;
1004		}
1005
1006		/* get values */
1007		while ((i < ending_start) && i < ending_start) {
1008			/* get to the start of the values */
1009			while ((i < ending_start) && data_in[i-1] != '(')
1010				i++;
1011
1012			/* find the values */
1013			cnt = 0;
1014			while ((i < ending_start) && data_in[i] != ')') {
1015				start = i;
1016				while ((i < ending_start)
1017				       && data_in[i] != ','
1018				       && data_in[i] != ')') {
1019					i++;
1020				}
1021				if (!data_in[i]) {
1022					rc = SLURM_ERROR;
1023					goto end_it;
1024				}
1025				if (cnt == cluster_inx) {
1026					/* get the cluster name and remove the
1027					   ticks */
1028					xstrncat(new_cluster_name,
1029						 data_in+start+1, (i-start-2));
1030					if (cluster_name) {
1031						if (strcmp(cluster_name,
1032							   new_cluster_name))
1033							new_cluster = 1;
1034						else
1035							xfree(new_cluster_name);
1036					} else {
1037						cluster_name = new_cluster_name;
1038						new_cluster_name = NULL;
1039					}
1040				} else {
1041					xstrncat(new_vals, data_in+start,
1042						 (i-start));
1043					if (data_in[i]) {
1044						if (data_in[i] == ',')
1045							xstrcat(new_vals, ", ");
1046						else if (data_in[i] == ')'
1047							 || data_in[i] == ';') {
1048							i++;
1049							break;
1050						} else {
1051							error("unknown char "
1052							      "'%s'",
1053							      data_in+i);
1054							rc = SLURM_ERROR;
1055							goto end_it;
1056						}
1057					}
1058				}
1059				i++;
1060				while ((i < ending_start) && data_in[i] == ' ')
1061					i++;
1062				cnt++;
1063			}
1064			if (new_cluster) {
1065				/* info("new cluster, adding insert\n%s " */
1066				/*      "\"%s_%s\" (%s) values %s %s", */
1067				/*      beginning, cluster_name, table, */
1068				/*      fields, vals, ending); */
1069				xstrfmtcat(data_out,
1070					   "%s \"%s_%s\" (%s) values %s %s",
1071					   beginning, cluster_name,
1072					   table, fields, vals, ending);
1073				new_cluster = 0;
1074				xfree(vals);
1075				xfree(cluster_name);
1076				cluster_name = new_cluster_name;
1077				new_cluster_name = NULL;
1078			}
1079
1080			if (new_vals) {
1081				if (vals)
1082					xstrfmtcat(vals, ", (%s)", new_vals);
1083				else
1084					xstrfmtcat(vals, "(%s)", new_vals);
1085				xfree(new_vals);
1086			}
1087		}
1088		i = ending_end;
1089	}
1090
1091	if (!cluster_name) {
1092		error("No cluster given for %s", table);
1093		goto end_it;
1094	}
1095
1096	if (!delete) {
1097		/* info("adding insert\n%s \"%s_%s\" (%s) values %s %s",
1098		   beginning, cluster_name, table, fields, vals, ending); */
1099		xstrfmtcat(data_out, "%s \"%s_%s\" (%s) values %s %s",
1100			   beginning, cluster_name, table, fields,
1101			   vals, ending);
1102	} else {
1103		if (fields) {
1104			/* info("adding delete\n%s \"%s_%s\" %s", */
1105			/*      beginning, cluster_name, table, fields); */
1106			xstrfmtcat(data_out, "%s \"%s_%s\" %s",
1107				   beginning, cluster_name, table, fields);
1108		} else {
1109			/* info("adding drop\ndrop table \"%s_%s\";", */
1110			/*      cluster_name, table); */
1111			xstrfmtcat(data_out, "drop table \"%s_%s\";",
1112				   cluster_name, table);
1113		}
1114	}
1115
1116end_it:
1117	xfree(cluster_name);
1118	xfree(beginning);
1119	xfree(ending);
1120	xfree(fields);
1121	xfree(vals);
1122	*data_full_out = data_out;
1123	//info("returning\n%s", data_out);
1124	if (rc == SLURM_ERROR)
1125		return -1;
1126	return i;
1127}
1128
1129static int _process_old_sql(char **data)
1130{
1131	int i = 0;
1132	char *data_in = *data;
1133	char *data_out = NULL;
1134	int rc = SLURM_SUCCESS;
1135
1136	while (data_in[i]) {
1137		if ((rc = _process_old_sql_line(data_in+i, &data_out)) == -1)
1138			break;
1139		i += rc;
1140	}
1141	//rc = -1;
1142
1143	xfree(data_in);
1144	if (rc == -1)
1145		xfree(data_out);
1146	//info("returning\n%s", data_out);
1147	*data = data_out;
1148	return rc;
1149}
1150
1151/* returns count of events archived or SLURM_ERROR on error */
1152static uint32_t _archive_events(mysql_conn_t *mysql_conn, char *cluster_name,
1153				time_t period_end, char *arch_dir,
1154				uint32_t archive_period)
1155{
1156	MYSQL_RES *result = NULL;
1157	MYSQL_ROW row;
1158	char *tmp = NULL, *query = NULL;
1159	time_t period_start = 0;
1160	uint32_t cnt = 0;
1161	local_event_t event;
1162	Buf buffer;
1163	int error_code = 0, i = 0;
1164
1165	xfree(tmp);
1166	xstrfmtcat(tmp, "%s", event_req_inx[0]);
1167	for(i=1; i<EVENT_REQ_COUNT; i++) {
1168		xstrfmtcat(tmp, ", %s", event_req_inx[i]);
1169	}
1170
1171	/* get all the events started before this time listed */
1172	query = xstrdup_printf("select %s from \"%s_%s\" where "
1173			       "time_start <= %ld "
1174			       "&& time_end != 0 order by time_start asc",
1175			       tmp, cluster_name, event_table, period_end);
1176	xfree(tmp);
1177
1178//	START_TIMER;
1179	debug3("%d(%s:%d) query\n%s",
1180	       mysql_conn->conn, THIS_FILE, __LINE__, query);
1181	if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
1182		xfree(query);
1183		return SLURM_ERROR;
1184	}
1185	xfree(query);
1186
1187	if (!(cnt = mysql_num_rows(result))) {
1188		mysql_free_result(result);
1189		return 0;
1190	}
1191
1192	buffer = init_buf(high_buffer_size);
1193	pack16(SLURMDBD_VERSION, buffer);
1194	pack_time(time(NULL), buffer);
1195	pack16(DBD_GOT_EVENTS, buffer);
1196	packstr(cluster_name, buffer);
1197	pack32(cnt, buffer);
1198
1199	while ((row = mysql_fetch_row(result))) {
1200		if (!period_start)
1201			period_start = slurm_atoul(row[EVENT_REQ_START]);
1202
1203		memset(&event, 0, sizeof(local_event_t));
1204
1205		event.cluster_nodes = row[EVENT_REQ_CNODES];
1206		event.cpu_count = row[EVENT_REQ_CPU];
1207		event.node_name = row[EVENT_REQ_NODE];
1208		event.period_end = row[EVENT_REQ_END];
1209		event.period_start = row[EVENT_REQ_START];
1210		event.reason = row[EVENT_REQ_REASON];
1211		event.reason_uid = row[EVENT_REQ_REASON_UID];
1212		event.state = row[EVENT_REQ_STATE];
1213
1214		_pack_local_event(&event, SLURMDBD_VERSION, buffer);
1215	}
1216	mysql_free_result(result);
1217
1218//	END_TIMER2("step query");
1219//	info("event query took %s", TIME_STR);
1220
1221	error_code = archive_write_file(buffer, cluster_name,
1222					period_start, period_end,
1223					arch_dir, "event", archive_period);
1224	free_buf(buffer);
1225
1226	if (error_code != SLURM_SUCCESS)
1227		return error_code;
1228
1229	return cnt;
1230}
1231
1232/* returns sql statement from archived data or NULL on error */
1233static char *
1234_load_events(uint16_t rpc_version, Buf buffer, char *cluster_name,
1235	     uint32_t rec_cnt)
1236{
1237	char *insert = NULL, *format = NULL;
1238	local_event_t object;
1239	int i = 0;
1240
1241	xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
1242		   cluster_name, event_table, event_req_inx[0]);
1243	xstrcat(format, "('%s'");
1244	for(i=1; i<EVENT_REQ_COUNT; i++) {
1245		xstrfmtcat(insert, ", %s", event_req_inx[i]);
1246		xstrcat(format, ", '%s'");
1247	}
1248	xstrcat(insert, ") values ");
1249	xstrcat(format, ")");
1250	for(i=0; i<rec_cnt; i++) {
1251		memset(&object, 0, sizeof(local_event_t));
1252		if (_unpack_local_event(&object, rpc_version, buffer)
1253		    != SLURM_SUCCESS) {
1254			error("issue unpacking");
1255			xfree(format);
1256			xfree(insert);
1257			break;
1258		}
1259		if (i)
1260			xstrcat(insert, ", ");
1261
1262		xstrfmtcat(insert, format,
1263			   object.cluster_nodes,
1264			   object.cpu_count,
1265			   object.node_name,
1266			   object.period_end,
1267			   object.period_start,
1268			   object.reason,
1269			   object.reason_uid,
1270			   object.state);
1271
1272	}
1273//	END_TIMER2("step query");
1274//	info("event query took %s", TIME_STR);
1275	xfree(format);
1276
1277	return insert;
1278}
1279
1280/* returns count of jobs archived or SLURM_ERROR on error */
1281static uint32_t _archive_jobs(mysql_conn_t *mysql_conn, char *cluster_name,
1282			      time_t period_end, char *arch_dir,
1283			      uint32_t archive_period)
1284{
1285	MYSQL_RES *result = NULL;
1286	MYSQL_ROW row;
1287	char *tmp = NULL, *query = NULL;
1288	time_t period_start = 0;
1289	uint32_t cnt = 0;
1290	local_job_t job;
1291	Buf buffer;
1292	int error_code = 0, i = 0;
1293
1294	xfree(tmp);
1295	xstrfmtcat(tmp, "%s", job_req_inx[0]);
1296	for(i=1; i<JOB_REQ_COUNT; i++) {
1297		xstrfmtcat(tmp, ", %s", job_req_inx[i]);
1298	}
1299
1300	/* get all the events started before this time listed */
1301	query = xstrdup_printf("select %s from \"%s_%s\" where "
1302			       "time_submit < %ld && time_end != 0 && !deleted "
1303			       "order by time_submit asc",
1304			       tmp, cluster_name, job_table, period_end);
1305	xfree(tmp);
1306
1307//	START_TIMER;
1308	debug3("%d(%s:%d) query\n%s",
1309	       mysql_conn->conn, THIS_FILE, __LINE__, query);
1310	if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
1311		xfree(query);
1312		return SLURM_ERROR;
1313	}
1314	xfree(query);
1315
1316	if (!(cnt = mysql_num_rows(result))) {
1317		mysql_free_result(result);
1318		return 0;
1319	}
1320
1321	buffer = init_buf(high_buffer_size);
1322	pack16(SLURMDBD_VERSION, buffer);
1323	pack_time(time(NULL), buffer);
1324	pack16(DBD_GOT_JOBS, buffer);
1325	packstr(cluster_name, buffer);
1326	pack32(cnt, buffer);
1327
1328	while ((row = mysql_fetch_row(result))) {
1329		if (!period_start)
1330			period_start = slurm_atoul(row[JOB_REQ_SUBMIT]);
1331
1332		memset(&job, 0, sizeof(local_job_t));
1333
1334		job.account = row[JOB_REQ_ACCOUNT];
1335		job.alloc_cpus = row[JOB_REQ_ALLOC_CPUS];
1336		job.alloc_nodes = row[JOB_REQ_ALLOC_NODES];
1337		job.associd = row[JOB_REQ_ASSOCID];
1338		job.blockid = row[JOB_REQ_BLOCKID];
1339		job.derived_ec = row[JOB_REQ_DERIVED_EC];
1340		job.derived_es = row[JOB_REQ_DERIVED_ES];
1341		job.exit_code = row[JOB_REQ_EXIT_CODE];
1342		job.timelimit = row[JOB_REQ_TIMELIMIT];
1343		job.eligible = row[JOB_REQ_ELIGIBLE];
1344		job.end = row[JOB_REQ_END];
1345		job.gid = row[JOB_REQ_GID];
1346		job.id = row[JOB_REQ_ID];
1347		job.jobid = row[JOB_REQ_JOBID];
1348		job.kill_requid = row[JOB_REQ_KILL_REQUID];
1349		job.name = row[JOB_REQ_NAME];
1350		job.nodelist = row[JOB_REQ_NODELIST];
1351		job.node_inx = row[JOB_REQ_NODE_INX];
1352		job.partition = row[JOB_REQ_PARTITION];
1353		job.priority = row[JOB_REQ_PRIORITY];
1354		job.qos = row[JOB_REQ_QOS];
1355		job.req_cpus = row[JOB_REQ_REQ_CPUS];
1356		job.resvid = row[JOB_REQ_RESVID];
1357		job.start = row[JOB_REQ_START];
1358		job.state = row[JOB_REQ_STATE];
1359		job.submit = row[JOB_REQ_SUBMIT];
1360		job.suspended = row[JOB_REQ_SUSPENDED];
1361		job.track_steps = row[JOB_REQ_TRACKSTEPS];
1362		job.uid = row[JOB_REQ_UID];
1363		job.wckey = row[JOB_REQ_WCKEY];
1364		job.wckey_id = row[JOB_REQ_WCKEYID];
1365
1366		_pack_local_job(&job, SLURMDBD_VERSION, buffer);
1367	}
1368	mysql_free_result(result);
1369
1370//	END_TIMER2("step query");
1371//	info("event query took %s", TIME_STR);
1372
1373	error_code = archive_write_file(buffer, cluster_name,
1374					period_start, period_end,
1375					arch_dir, "job", archive_period);
1376	free_buf(buffer);
1377
1378	if (error_code != SLURM_SUCCESS)
1379		return error_code;
1380
1381	return cnt;
1382}
1383
1384/* returns sql statement from archived data or NULL on error */
1385static char *_load_jobs(uint16_t rpc_version, Buf buffer,
1386			char *cluster_name, uint32_t rec_cnt)
1387{
1388	char *insert = NULL, *format = NULL;
1389	local_job_t object;
1390	int i = 0;
1391
1392	xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
1393		   cluster_name, job_table, job_req_inx[0]);
1394	xstrcat(format, "('%s'");
1395	for(i=1; i<JOB_REQ_COUNT; i++) {
1396		xstrfmtcat(insert, ", %s", job_req_inx[i]);
1397		xstrcat(format, ", '%s'");
1398	}
1399	xstrcat(insert, ") values ");
1400	xstrcat(format, ")");
1401	for(i=0; i<rec_cnt; i++) {
1402		memset(&object, 0, sizeof(local_job_t));
1403		if (_unpack_local_job(&object, rpc_version, buffer)
1404		    != SLURM_SUCCESS) {
1405			error("issue unpacking");
1406			xfree(format);
1407			xfree(insert);
1408			break;
1409		}
1410		if (i)
1411			xstrcat(insert, ", ");
1412
1413		xstrfmtcat(insert, format,
1414			   object.account,
1415			   object.alloc_cpus,
1416			   object.alloc_nodes,
1417			   object.associd,
1418			   object.blockid,
1419			   object.derived_ec,
1420			   object.derived_es,
1421			   object.exit_code,
1422			   object.timelimit,
1423			   object.eligible,
1424			   object.end,
1425			   object.gid,
1426			   object.id,
1427			   object.jobid,
1428			   object.kill_requid,
1429			   object.name,
1430			   object.nodelist,
1431			   object.node_inx,
1432			   object.partition,
1433			   object.priority,
1434			   object.qos,
1435			   object.req_cpus,
1436			   object.resvid,
1437			   object.start,
1438			   object.state,
1439			   object.submit,
1440			   object.suspended,
1441			   object.track_steps,
1442			   object.uid,
1443			   object.wckey,
1444			   object.wckey_id);
1445
1446	}
1447//	END_TIMER2("step query");
1448//	info("job query took %s", TIME_STR);
1449	xfree(format);
1450
1451	return insert;
1452}
1453
1454/* returns count of steps archived or SLURM_ERROR on error */
1455static uint32_t _archive_steps(mysql_conn_t *mysql_conn, char *cluster_name,
1456			       time_t period_end, char *arch_dir,
1457			       uint32_t archive_period)
1458{
1459	MYSQL_RES *result = NULL;
1460	MYSQL_ROW row;
1461	char *tmp = NULL, *query = NULL;
1462	time_t period_start = 0;
1463	uint32_t cnt = 0;
1464	local_step_t step;
1465	Buf buffer;
1466	int error_code = 0, i = 0;
1467
1468	xfree(tmp);
1469	xstrfmtcat(tmp, "%s", step_req_inx[0]);
1470	for(i=1; i<STEP_REQ_COUNT; i++) {
1471		xstrfmtcat(tmp, ", %s", step_req_inx[i]);
1472	}
1473
1474	/* get all the events started before this time listed */
1475	query = xstrdup_printf("select %s from \"%s_%s\" where "
1476			       "time_start <= %ld && time_end != 0 "
1477			       "&& !deleted order by time_start asc",
1478			       tmp, cluster_name, step_table, period_end);
1479	xfree(tmp);
1480
1481//	START_TIMER;
1482	debug3("%d(%s:%d) query\n%s",
1483	       mysql_conn->conn, THIS_FILE, __LINE__, query);
1484	if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
1485		xfree(query);
1486		return SLURM_ERROR;
1487	}
1488	xfree(query);
1489
1490	if (!(cnt = mysql_num_rows(result))) {
1491		mysql_free_result(result);
1492		return 0;
1493	}
1494
1495	buffer = init_buf(high_buffer_size);
1496	pack16(SLURMDBD_VERSION, buffer);
1497	pack_time(time(NULL), buffer);
1498	pack16(DBD_STEP_START, buffer);
1499	packstr(cluster_name, buffer);
1500	pack32(cnt, buffer);
1501
1502	while ((row = mysql_fetch_row(result))) {
1503		if (!period_start)
1504			period_start = slurm_atoul(row[STEP_REQ_START]);
1505
1506		memset(&step, 0, sizeof(local_step_t));
1507
1508		step.ave_cpu = row[STEP_REQ_AVE_CPU];
1509		step.act_cpufreq = row[STEP_REQ_ACT_CPUFREQ];
1510		step.consumed_energy = row[STEP_REQ_CONSUMED_ENERGY];
1511		step.ave_pages = row[STEP_REQ_AVE_PAGES];
1512		step.ave_rss = row[STEP_REQ_AVE_RSS];
1513		step.ave_vsize = row[STEP_REQ_AVE_VSIZE];
1514		step.exit_code = row[STEP_REQ_EXIT_CODE];
1515		step.cpus = row[STEP_REQ_CPUS];
1516		step.id = row[STEP_REQ_ID];
1517		step.kill_requid = row[STEP_REQ_KILL_REQUID];
1518		step.max_pages = row[STEP_REQ_MAX_PAGES];
1519		step.max_pages_node = row[STEP_REQ_MAX_PAGES_NODE];
1520		step.max_pages_task = row[STEP_REQ_MAX_PAGES_TASK];
1521		step.max_rss = row[STEP_REQ_MAX_RSS];
1522		step.max_rss_node = row[STEP_REQ_MAX_RSS_NODE];
1523		step.max_rss_task = row[STEP_REQ_MAX_RSS_TASK];
1524		step.max_vsize = row[STEP_REQ_MAX_VSIZE];
1525		step.max_vsize_node = row[STEP_REQ_MAX_VSIZE_NODE];
1526		step.max_vsize_task = row[STEP_REQ_MAX_VSIZE_TASK];
1527		step.min_cpu = row[STEP_REQ_MIN_CPU];
1528		step.min_cpu_node = row[STEP_REQ_MIN_CPU_NODE];
1529		step.min_cpu_task = row[STEP_REQ_MIN_CPU_TASK];
1530		step.name = row[STEP_REQ_NAME];
1531		step.nodelist = row[STEP_REQ_NODELIST];
1532		step.nodes = row[STEP_REQ_NODES];
1533		step.node_inx = row[STEP_REQ_NODE_INX];
1534		step.period_end = row[STEP_REQ_END];
1535		step.period_start = row[STEP_REQ_START];
1536		step.period_suspended = row[STEP_REQ_SUSPENDED];
1537		step.state = row[STEP_REQ_STATE];
1538		step.stepid = row[STEP_REQ_STEPID];
1539		step.sys_sec = row[STEP_REQ_SYS_SEC];
1540		step.sys_usec = row[STEP_REQ_SYS_USEC];
1541		step.tasks = row[STEP_REQ_TASKS];
1542		step.task_dist = row[STEP_REQ_TASKDIST];
1543		step.user_sec = row[STEP_REQ_USER_SEC];
1544		step.user_usec = row[STEP_REQ_USER_USEC];
1545
1546		_pack_local_step(&step, SLURMDBD_VERSION, buffer);
1547	}
1548	mysql_free_result(result);
1549
1550//	END_TIMER2("step query");
1551//	info("event query took %s", TIME_STR);
1552
1553	error_code = archive_write_file(buffer, cluster_name,
1554					period_start, period_end,
1555					arch_dir, "step", archive_period);
1556	free_buf(buffer);
1557
1558	if (error_code != SLURM_SUCCESS)
1559		return error_code;
1560
1561	return cnt;
1562}
1563
1564/* returns sql statement from archived data or NULL on error */
1565static char *_load_steps(uint16_t rpc_version, Buf buffer,
1566			 char *cluster_name, uint32_t rec_cnt)
1567{
1568	char *insert = NULL, *format = NULL;
1569	local_step_t object;
1570	int i = 0;
1571
1572	xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
1573		   cluster_name, step_table, step_req_inx[0]);
1574	xstrcat(format, "('%s'");
1575	for(i=1; i<STEP_REQ_COUNT; i++) {
1576		xstrfmtcat(insert, ", %s", step_req_inx[i]);
1577		xstrcat(format, ", '%s'");
1578	}
1579	xstrcat(insert, ") values ");
1580	xstrcat(format, ")");
1581	for(i=0; i<rec_cnt; i++) {
1582		memset(&object, 0, sizeof(local_step_t));
1583		if (_unpack_local_step(&object, rpc_version, buffer)
1584		    != SLURM_SUCCESS) {
1585			error("issue unpacking");
1586			xfree(format);
1587			xfree(insert);
1588			break;
1589		}
1590		if (i)
1591			xstrcat(insert, ", ");
1592
1593		xstrfmtcat(insert, format,
1594			   object.ave_cpu,
1595			   object.act_cpufreq,
1596			   object.consumed_energy,
1597			   object.ave_pages,
1598			   object.ave_rss,
1599			   object.ave_vsize,
1600			   object.exit_code,
1601			   object.cpus,
1602			   object.id,
1603			   object.kill_requid,
1604			   object.max_pages,
1605			   object.max_pages_node,
1606			   object.max_pages_task,
1607			   object.max_rss,
1608			   object.max_rss_node,
1609			   object.max_rss_task,
1610			   object.max_vsize,
1611			   object.max_vsize_node,
1612			   object.max_vsize_task,
1613			   object.min_cpu,
1614			   object.min_cpu_node,
1615			   object.min_cpu_task,
1616			   object.name,
1617			   object.nodelist,
1618			   object.nodes,
1619			   object.node_inx,
1620			   object.period_end,
1621			   object.period_start,
1622			   object.period_suspended,
1623			   object.state,
1624			   object.stepid,
1625			   object.sys_sec,
1626			   object.sys_usec,
1627			   object.tasks,
1628			   object.task_dist,
1629			   object.user_sec,
1630			   object.user_usec);
1631
1632	}
1633//	END_TIMER2("step query");
1634//	info("step query took %s", TIME_STR);
1635	xfree(format);
1636
1637	return insert;
1638}
1639
1640/* returns count of events archived or SLURM_ERROR on error */
1641static uint32_t _archive_suspend(mysql_conn_t *mysql_conn, char *cluster_name,
1642				 time_t period_end, char *arch_dir,
1643				 uint32_t archive_period)
1644{
1645	MYSQL_RES *result = NULL;
1646	MYSQL_ROW row;
1647	char *tmp = NULL, *query = NULL;
1648	time_t period_start = 0;
1649	uint32_t cnt = 0;
1650	local_suspend_t suspend;
1651	Buf buffer;
1652	int error_code = 0, i = 0;
1653
1654	xfree(tmp);
1655	xstrfmtcat(tmp, "%s", suspend_req_inx[0]);
1656	for(i=1; i<SUSPEND_REQ_COUNT; i++) {
1657		xstrfmtcat(tmp, ", %s", suspend_req_inx[i]);
1658	}
1659
1660	/* get all the events started before this time listed */
1661	query = xstrdup_printf("select %s from \"%s_%s\" where "
1662			       "time_start <= %ld && time_end != 0 "
1663			       "order by time_start asc",
1664			       tmp, cluster_name, suspend_table, period_end);
1665	xfree(tmp);
1666
1667//	START_TIMER;
1668	debug3("%d(%s:%d) query\n%s",
1669	       mysql_conn->conn, THIS_FILE, __LINE__, query);
1670	if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
1671		xfree(query);
1672		return SLURM_ERROR;
1673	}
1674	xfree(query);
1675
1676	if (!(cnt = mysql_num_rows(result))) {
1677		mysql_free_result(result);
1678		return 0;
1679	}
1680
1681	buffer = init_buf(high_buffer_size);
1682	pack16(SLURMDBD_VERSION, buffer);
1683	pack_time(time(NULL), buffer);
1684	pack16(DBD_JOB_SUSPEND, buffer);
1685	packstr(cluster_name, buffer);
1686	pack32(cnt, buffer);
1687
1688	while ((row = mysql_fetch_row(result))) {
1689		if (!period_start)
1690			period_start = slurm_atoul(row[SUSPEND_REQ_START]);
1691
1692		memset(&suspend, 0, sizeof(local_suspend_t));
1693
1694		suspend.id = row[SUSPEND_REQ_ID];
1695		suspend.associd = row[SUSPEND_REQ_ASSOCID];
1696		suspend.period_start = row[SUSPEND_REQ_START];
1697		suspend.period_end = row[SUSPEND_REQ_END];
1698
1699		_pack_local_suspend(&suspend, SLURMDBD_VERSION, buffer);
1700	}
1701	mysql_free_result(result);
1702
1703//	END_TIMER2("step query");
1704//	info("event query took %s", TIME_STR);
1705
1706	error_code = archive_write_file(buffer, cluster_name,
1707					period_start, period_end,
1708					arch_dir, "suspend", archive_period);
1709	free_buf(buffer);
1710
1711	if (error_code != SLURM_SUCCESS)
1712		return error_code;
1713
1714	return cnt;
1715}
1716
1717/* returns sql statement from archived data or NULL on error */
1718static char *_load_suspend(uint16_t rpc_version, Buf buffer,
1719			   char *cluster_name, uint32_t rec_cnt)
1720{
1721	char *insert = NULL, *format = NULL;
1722	local_suspend_t object;
1723	int i = 0;
1724
1725	xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
1726		   cluster_name, suspend_table, suspend_req_inx[0]);
1727	xstrcat(format, "('%s'");
1728	for(i=1; i<SUSPEND_REQ_COUNT; i++) {
1729		xstrfmtcat(insert, ", %s", suspend_req_inx[i]);
1730		xstrcat(format, ", '%s'");
1731	}
1732	xstrcat(insert, ") values ");
1733	xstrcat(format, ")");
1734	for(i=0; i<rec_cnt; i++) {
1735		memset(&object, 0, sizeof(local_suspend_t));
1736		if (_unpack_local_suspend(&object, rpc_version, buffer)
1737		    != SLURM_SUCCESS) {
1738			error("issue unpacking");
1739			xfree(format);
1740			xfree(insert);
1741			break;
1742		}
1743		if (i)
1744			xstrcat(insert, ", ");
1745
1746		xstrfmtcat(insert, format,
1747			   object.associd,
1748			   object.id,
1749			   object.period_end,
1750			   object.period_start);
1751
1752	}
1753//	END_TIMER2("suspend query");
1754//	info("suspend query took %s", TIME_STR);
1755	xfree(format);
1756
1757	return insert;
1758}
1759
1760static int _execute_archive(mysql_conn_t *mysql_conn,
1761			    char *cluster_name,
1762			    slurmdb_archive_cond_t *arch_cond)
1763{
1764	int rc = SLURM_SUCCESS;
1765	char *query = NULL;
1766	time_t curr_end;
1767	time_t last_submit = time(NULL);
1768
1769	if (arch_cond->archive_script)
1770		return archive_run_script(arch_cond, cluster_name, last_submit);
1771	else if (!arch_cond->archive_dir) {
1772		error("No archive dir given, can't process");
1773		return SLURM_ERROR;
1774	}
1775
1776	if (arch_cond->purge_event != NO_VAL) {
1777		/* remove all data from event table that was older than
1778		 * period_start * arch_cond->purge_event.
1779		 */
1780		if (!(curr_end = archive_setup_end_time(
1781			      last_submit, arch_cond->purge_event))) {
1782			error("Parsing purge event");
1783			return SLURM_ERROR;
1784		}
1785
1786		debug4("Purging event entries before %ld for %s",
1787		       curr_end, cluster_name);
1788
1789		if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_event)) {
1790			rc = _archive_events(mysql_conn, cluster_name,
1791					     curr_end, arch_cond->archive_dir,
1792					     arch_cond->purge_event);
1793			if (!rc)
1794				goto exit_events;
1795			else i

Large files files are truncated, but you can click here to view the full file