PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/FredHutch/slurm
C | 2568 lines | 2236 code | 188 blank | 144 comment | 434 complexity | a838cace37fab81c7e896cb3e8045d50 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  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://slurm.schedmd.com/>.
  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. #include <fcntl.h>
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42. #include <unistd.h>
  43. #include "as_mysql_archive.h"
  44. #include "src/common/slurmdbd_defs.h"
  45. #include "src/common/env.h"
  46. #define SLURMDBD_2_5_VERSION 11 /* slurm version 2.5 */
  47. typedef struct {
  48. char *cluster_nodes;
  49. char *cpu_count;
  50. char *node_name;
  51. char *period_end;
  52. char *period_start;
  53. char *reason;
  54. char *reason_uid;
  55. char *state;
  56. } local_event_t;
  57. typedef struct {
  58. char *account;
  59. char *alloc_cpus;
  60. char *alloc_nodes;
  61. char *associd;
  62. char *array_jobid;
  63. char *array_taskid;
  64. char *blockid;
  65. char *derived_ec;
  66. char *derived_es;
  67. char *exit_code;
  68. char *eligible;
  69. char *end;
  70. char *gid;
  71. char *id;
  72. char *jobid;
  73. char *kill_requid;
  74. char *name;
  75. char *nodelist;
  76. char *node_inx;
  77. char *partition;
  78. char *priority;
  79. char *qos;
  80. char *req_cpus;
  81. char *req_mem;
  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. typedef struct {
  94. char *assocs;
  95. char *cpus;
  96. char *flags;
  97. char *id;
  98. char *name;
  99. char *nodes;
  100. char *node_inx;
  101. char *time_end;
  102. char *time_start;
  103. } local_resv_t;
  104. typedef struct {
  105. char *act_cpufreq;
  106. char *ave_cpu;
  107. char *ave_disk_read;
  108. char *ave_disk_write;
  109. char *ave_pages;
  110. char *ave_rss;
  111. char *ave_vsize;
  112. char *exit_code;
  113. char *consumed_energy;
  114. char *cpus;
  115. char *id;
  116. char *kill_requid;
  117. char *max_disk_read;
  118. char *max_disk_read_node;
  119. char *max_disk_read_task;
  120. char *max_disk_write;
  121. char *max_disk_write_node;
  122. char *max_disk_write_task;
  123. char *max_pages;
  124. char *max_pages_node;
  125. char *max_pages_task;
  126. char *max_rss;
  127. char *max_rss_node;
  128. char *max_rss_task;
  129. char *max_vsize;
  130. char *max_vsize_node;
  131. char *max_vsize_task;
  132. char *min_cpu;
  133. char *min_cpu_node;
  134. char *min_cpu_task;
  135. char *name;
  136. char *nodelist;
  137. char *nodes;
  138. char *node_inx;
  139. char *period_end;
  140. char *period_start;
  141. char *period_suspended;
  142. char *req_cpufreq;
  143. char *state;
  144. char *stepid;
  145. char *sys_sec;
  146. char *sys_usec;
  147. char *tasks;
  148. char *task_dist;
  149. char *user_sec;
  150. char *user_usec;
  151. } local_step_t;
  152. typedef struct {
  153. char *associd;
  154. char *id;
  155. char *period_end;
  156. char *period_start;
  157. } local_suspend_t;
  158. /* if this changes you will need to edit the corresponding
  159. * enum below */
  160. char *event_req_inx[] = {
  161. "time_start",
  162. "time_end",
  163. "node_name",
  164. "cluster_nodes",
  165. "cpu_count",
  166. "reason",
  167. "reason_uid",
  168. "state",
  169. };
  170. enum {
  171. EVENT_REQ_START,
  172. EVENT_REQ_END,
  173. EVENT_REQ_NODE,
  174. EVENT_REQ_CNODES,
  175. EVENT_REQ_CPU,
  176. EVENT_REQ_REASON,
  177. EVENT_REQ_REASON_UID,
  178. EVENT_REQ_STATE,
  179. EVENT_REQ_COUNT
  180. };
  181. /* if this changes you will need to edit the corresponding
  182. * enum below */
  183. static char *job_req_inx[] = {
  184. "account",
  185. "cpus_alloc",
  186. "nodes_alloc",
  187. "id_assoc",
  188. "id_array_job",
  189. "id_array_task",
  190. "id_block",
  191. "derived_ec",
  192. "derived_es",
  193. "exit_code",
  194. "timelimit",
  195. "time_eligible",
  196. "time_end",
  197. "id_group",
  198. "job_db_inx",
  199. "id_job",
  200. "kill_requid",
  201. "job_name",
  202. "nodelist",
  203. "node_inx",
  204. "`partition`",
  205. "priority",
  206. "id_qos",
  207. "cpus_req",
  208. "mem_req",
  209. "id_resv",
  210. "time_start",
  211. "state",
  212. "time_submit",
  213. "time_suspended",
  214. "track_steps",
  215. "id_user",
  216. "wckey",
  217. "id_wckey"
  218. };
  219. enum {
  220. JOB_REQ_ACCOUNT,
  221. JOB_REQ_ALLOC_CPUS,
  222. JOB_REQ_ALLOC_NODES,
  223. JOB_REQ_ASSOCID,
  224. JOB_REQ_ARRAYJOBID,
  225. JOB_REQ_ARRAYTASKID,
  226. JOB_REQ_BLOCKID,
  227. JOB_REQ_DERIVED_EC,
  228. JOB_REQ_DERIVED_ES,
  229. JOB_REQ_EXIT_CODE,
  230. JOB_REQ_TIMELIMIT,
  231. JOB_REQ_ELIGIBLE,
  232. JOB_REQ_END,
  233. JOB_REQ_GID,
  234. JOB_REQ_ID,
  235. JOB_REQ_JOBID,
  236. JOB_REQ_KILL_REQUID,
  237. JOB_REQ_NAME,
  238. JOB_REQ_NODELIST,
  239. JOB_REQ_NODE_INX,
  240. JOB_REQ_RESVID,
  241. JOB_REQ_PARTITION,
  242. JOB_REQ_PRIORITY,
  243. JOB_REQ_QOS,
  244. JOB_REQ_REQ_CPUS,
  245. JOB_REQ_REQ_MEM,
  246. JOB_REQ_START,
  247. JOB_REQ_STATE,
  248. JOB_REQ_SUBMIT,
  249. JOB_REQ_SUSPENDED,
  250. JOB_REQ_TRACKSTEPS,
  251. JOB_REQ_UID,
  252. JOB_REQ_WCKEY,
  253. JOB_REQ_WCKEYID,
  254. JOB_REQ_COUNT
  255. };
  256. /* if this changes you will need to edit the corresponding enum */
  257. char *resv_req_inx[] = {
  258. "id_resv",
  259. "assoclist",
  260. "cpus",
  261. "flags",
  262. "nodelist",
  263. "node_inx",
  264. "resv_name",
  265. "time_start",
  266. "time_end",
  267. };
  268. enum {
  269. RESV_REQ_ID,
  270. RESV_REQ_ASSOCS,
  271. RESV_REQ_CPUS,
  272. RESV_REQ_FLAGS,
  273. RESV_REQ_NODES,
  274. RESV_REQ_NODE_INX,
  275. RESV_REQ_NAME,
  276. RESV_REQ_START,
  277. RESV_REQ_END,
  278. RESV_REQ_COUNT
  279. };
  280. /* if this changes you will need to edit the corresponding
  281. * enum below */
  282. static char *step_req_inx[] = {
  283. "job_db_inx",
  284. "id_step",
  285. "time_start",
  286. "time_end",
  287. "time_suspended",
  288. "step_name",
  289. "nodelist",
  290. "node_inx",
  291. "state",
  292. "kill_requid",
  293. "exit_code",
  294. "nodes_alloc",
  295. "cpus_alloc",
  296. "task_cnt",
  297. "task_dist",
  298. "user_sec",
  299. "user_usec",
  300. "sys_sec",
  301. "sys_usec",
  302. "max_vsize",
  303. "max_vsize_task",
  304. "max_vsize_node",
  305. "ave_vsize",
  306. "max_rss",
  307. "max_rss_task",
  308. "max_rss_node",
  309. "ave_rss",
  310. "max_pages",
  311. "max_pages_task",
  312. "max_pages_node",
  313. "ave_pages",
  314. "min_cpu",
  315. "min_cpu_task",
  316. "min_cpu_node",
  317. "ave_cpu",
  318. "act_cpufreq",
  319. "consumed_energy",
  320. "req_cpufreq",
  321. "max_disk_read",
  322. "max_disk_read_task",
  323. "max_disk_read_node",
  324. "ave_disk_read",
  325. "max_disk_write",
  326. "max_disk_write_task",
  327. "max_disk_write_node",
  328. "ave_disk_write"
  329. };
  330. enum {
  331. STEP_REQ_ID,
  332. STEP_REQ_STEPID,
  333. STEP_REQ_START,
  334. STEP_REQ_END,
  335. STEP_REQ_SUSPENDED,
  336. STEP_REQ_NAME,
  337. STEP_REQ_NODELIST,
  338. STEP_REQ_NODE_INX,
  339. STEP_REQ_STATE,
  340. STEP_REQ_KILL_REQUID,
  341. STEP_REQ_EXIT_CODE,
  342. STEP_REQ_NODES,
  343. STEP_REQ_CPUS,
  344. STEP_REQ_TASKS,
  345. STEP_REQ_TASKDIST,
  346. STEP_REQ_USER_SEC,
  347. STEP_REQ_USER_USEC,
  348. STEP_REQ_SYS_SEC,
  349. STEP_REQ_SYS_USEC,
  350. STEP_REQ_MAX_VSIZE,
  351. STEP_REQ_MAX_VSIZE_TASK,
  352. STEP_REQ_MAX_VSIZE_NODE,
  353. STEP_REQ_AVE_VSIZE,
  354. STEP_REQ_MAX_RSS,
  355. STEP_REQ_MAX_RSS_TASK,
  356. STEP_REQ_MAX_RSS_NODE,
  357. STEP_REQ_AVE_RSS,
  358. STEP_REQ_MAX_PAGES,
  359. STEP_REQ_MAX_PAGES_TASK,
  360. STEP_REQ_MAX_PAGES_NODE,
  361. STEP_REQ_AVE_PAGES,
  362. STEP_REQ_MIN_CPU,
  363. STEP_REQ_MIN_CPU_TASK,
  364. STEP_REQ_MIN_CPU_NODE,
  365. STEP_REQ_AVE_CPU,
  366. STEP_REQ_ACT_CPUFREQ,
  367. STEP_REQ_CONSUMED_ENERGY,
  368. STEP_REQ_REQ_CPUFREQ,
  369. STEP_REQ_MAX_DISK_READ,
  370. STEP_REQ_MAX_DISK_READ_TASK,
  371. STEP_REQ_MAX_DISK_READ_NODE,
  372. STEP_REQ_AVE_DISK_READ,
  373. STEP_REQ_MAX_DISK_WRITE,
  374. STEP_REQ_MAX_DISK_WRITE_TASK,
  375. STEP_REQ_MAX_DISK_WRITE_NODE,
  376. STEP_REQ_AVE_DISK_WRITE,
  377. STEP_REQ_COUNT,
  378. };
  379. /* if this changes you will need to edit the corresponding
  380. * enum below */
  381. static char *suspend_req_inx[] = {
  382. "job_db_inx",
  383. "id_assoc",
  384. "time_start",
  385. "time_end",
  386. };
  387. enum {
  388. SUSPEND_REQ_ID,
  389. SUSPEND_REQ_ASSOCID,
  390. SUSPEND_REQ_START,
  391. SUSPEND_REQ_END,
  392. SUSPEND_REQ_COUNT
  393. };
  394. static int high_buffer_size = (1024 * 1024);
  395. static void _pack_local_event(local_event_t *object,
  396. uint16_t rpc_version, Buf buffer)
  397. {
  398. packstr(object->cluster_nodes, buffer);
  399. packstr(object->cpu_count, buffer);
  400. packstr(object->node_name, buffer);
  401. packstr(object->period_end, buffer);
  402. packstr(object->period_start, buffer);
  403. packstr(object->reason, buffer);
  404. packstr(object->reason_uid, buffer);
  405. packstr(object->state, buffer);
  406. }
  407. /* this needs to be allocated before calling, and since we aren't
  408. * doing any copying it needs to be used before destroying buffer */
  409. static int _unpack_local_event(local_event_t *object,
  410. uint16_t rpc_version, Buf buffer)
  411. {
  412. uint32_t tmp32;
  413. unpackstr_ptr(&object->cluster_nodes, &tmp32, buffer);
  414. unpackstr_ptr(&object->cpu_count, &tmp32, buffer);
  415. unpackstr_ptr(&object->node_name, &tmp32, buffer);
  416. unpackstr_ptr(&object->period_end, &tmp32, buffer);
  417. unpackstr_ptr(&object->period_start, &tmp32, buffer);
  418. unpackstr_ptr(&object->reason, &tmp32, buffer);
  419. unpackstr_ptr(&object->reason_uid, &tmp32, buffer);
  420. unpackstr_ptr(&object->state, &tmp32, buffer);
  421. return SLURM_SUCCESS;
  422. }
  423. static void _pack_local_job(local_job_t *object,
  424. uint16_t rpc_version, Buf buffer)
  425. {
  426. packstr(object->account, buffer);
  427. packstr(object->alloc_cpus, buffer);
  428. packstr(object->alloc_nodes, buffer);
  429. packstr(object->associd, buffer);
  430. packstr(object->array_jobid, buffer);
  431. packstr(object->array_taskid, buffer);
  432. packstr(object->blockid, buffer);
  433. packstr(object->derived_ec, buffer);
  434. packstr(object->derived_es, buffer);
  435. packstr(object->exit_code, buffer);
  436. packstr(object->timelimit, buffer);
  437. packstr(object->eligible, buffer);
  438. packstr(object->end, buffer);
  439. packstr(object->gid, buffer);
  440. packstr(object->id, buffer);
  441. packstr(object->jobid, buffer);
  442. packstr(object->kill_requid, buffer);
  443. packstr(object->name, buffer);
  444. packstr(object->nodelist, buffer);
  445. packstr(object->node_inx, buffer);
  446. packstr(object->partition, buffer);
  447. packstr(object->priority, buffer);
  448. packstr(object->qos, buffer);
  449. packstr(object->req_cpus, buffer);
  450. packstr(object->req_mem, buffer);
  451. packstr(object->resvid, buffer);
  452. packstr(object->start, buffer);
  453. packstr(object->state, buffer);
  454. packstr(object->submit, buffer);
  455. packstr(object->suspended, buffer);
  456. packstr(object->track_steps, buffer);
  457. packstr(object->uid, buffer);
  458. packstr(object->wckey, buffer);
  459. packstr(object->wckey_id, buffer);
  460. }
  461. /* this needs to be allocated before calling, and since we aren't
  462. * doing any copying it needs to be used before destroying buffer */
  463. static int _unpack_local_job(local_job_t *object,
  464. uint16_t rpc_version, Buf buffer)
  465. {
  466. uint32_t tmp32;
  467. if (rpc_version >= SLURM_14_11_PROTOCOL_VERSION) {
  468. unpackstr_ptr(&object->account, &tmp32, buffer);
  469. unpackstr_ptr(&object->alloc_cpus, &tmp32, buffer);
  470. unpackstr_ptr(&object->alloc_nodes, &tmp32, buffer);
  471. unpackstr_ptr(&object->associd, &tmp32, buffer);
  472. unpackstr_ptr(&object->array_jobid, &tmp32, buffer);
  473. unpackstr_ptr(&object->array_taskid, &tmp32, buffer);
  474. unpackstr_ptr(&object->blockid, &tmp32, buffer);
  475. unpackstr_ptr(&object->derived_ec, &tmp32, buffer);
  476. unpackstr_ptr(&object->derived_es, &tmp32, buffer);
  477. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  478. unpackstr_ptr(&object->timelimit, &tmp32, buffer);
  479. unpackstr_ptr(&object->eligible, &tmp32, buffer);
  480. unpackstr_ptr(&object->end, &tmp32, buffer);
  481. unpackstr_ptr(&object->gid, &tmp32, buffer);
  482. unpackstr_ptr(&object->id, &tmp32, buffer);
  483. unpackstr_ptr(&object->jobid, &tmp32, buffer);
  484. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  485. unpackstr_ptr(&object->name, &tmp32, buffer);
  486. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  487. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  488. unpackstr_ptr(&object->partition, &tmp32, buffer);
  489. unpackstr_ptr(&object->priority, &tmp32, buffer);
  490. unpackstr_ptr(&object->qos, &tmp32, buffer);
  491. unpackstr_ptr(&object->req_cpus, &tmp32, buffer);
  492. unpackstr_ptr(&object->req_mem, &tmp32, buffer);
  493. unpackstr_ptr(&object->resvid, &tmp32, buffer);
  494. unpackstr_ptr(&object->start, &tmp32, buffer);
  495. unpackstr_ptr(&object->state, &tmp32, buffer);
  496. unpackstr_ptr(&object->submit, &tmp32, buffer);
  497. unpackstr_ptr(&object->suspended, &tmp32, buffer);
  498. unpackstr_ptr(&object->track_steps, &tmp32, buffer);
  499. unpackstr_ptr(&object->uid, &tmp32, buffer);
  500. unpackstr_ptr(&object->wckey, &tmp32, buffer);
  501. unpackstr_ptr(&object->wckey_id, &tmp32, buffer);
  502. } else if (rpc_version >= SLURMDBD_2_6_VERSION) {
  503. unpackstr_ptr(&object->account, &tmp32, buffer);
  504. unpackstr_ptr(&object->alloc_cpus, &tmp32, buffer);
  505. unpackstr_ptr(&object->alloc_nodes, &tmp32, buffer);
  506. unpackstr_ptr(&object->associd, &tmp32, buffer);
  507. unpackstr_ptr(&object->blockid, &tmp32, buffer);
  508. unpackstr_ptr(&object->derived_ec, &tmp32, buffer);
  509. unpackstr_ptr(&object->derived_es, &tmp32, buffer);
  510. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  511. unpackstr_ptr(&object->timelimit, &tmp32, buffer);
  512. unpackstr_ptr(&object->eligible, &tmp32, buffer);
  513. unpackstr_ptr(&object->end, &tmp32, buffer);
  514. unpackstr_ptr(&object->gid, &tmp32, buffer);
  515. unpackstr_ptr(&object->id, &tmp32, buffer);
  516. unpackstr_ptr(&object->jobid, &tmp32, buffer);
  517. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  518. unpackstr_ptr(&object->name, &tmp32, buffer);
  519. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  520. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  521. unpackstr_ptr(&object->partition, &tmp32, buffer);
  522. unpackstr_ptr(&object->priority, &tmp32, buffer);
  523. unpackstr_ptr(&object->qos, &tmp32, buffer);
  524. unpackstr_ptr(&object->req_cpus, &tmp32, buffer);
  525. unpackstr_ptr(&object->req_mem, &tmp32, buffer);
  526. unpackstr_ptr(&object->resvid, &tmp32, buffer);
  527. unpackstr_ptr(&object->start, &tmp32, buffer);
  528. unpackstr_ptr(&object->state, &tmp32, buffer);
  529. unpackstr_ptr(&object->submit, &tmp32, buffer);
  530. unpackstr_ptr(&object->suspended, &tmp32, buffer);
  531. unpackstr_ptr(&object->track_steps, &tmp32, buffer);
  532. unpackstr_ptr(&object->uid, &tmp32, buffer);
  533. unpackstr_ptr(&object->wckey, &tmp32, buffer);
  534. unpackstr_ptr(&object->wckey_id, &tmp32, buffer);
  535. } else {
  536. unpackstr_ptr(&object->account, &tmp32, buffer);
  537. unpackstr_ptr(&object->alloc_cpus, &tmp32, buffer);
  538. unpackstr_ptr(&object->alloc_nodes, &tmp32, buffer);
  539. unpackstr_ptr(&object->associd, &tmp32, buffer);
  540. unpackstr_ptr(&object->blockid, &tmp32, buffer);
  541. unpackstr_ptr(&object->derived_ec, &tmp32, buffer);
  542. unpackstr_ptr(&object->derived_es, &tmp32, buffer);
  543. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  544. unpackstr_ptr(&object->timelimit, &tmp32, buffer);
  545. unpackstr_ptr(&object->eligible, &tmp32, buffer);
  546. unpackstr_ptr(&object->end, &tmp32, buffer);
  547. unpackstr_ptr(&object->gid, &tmp32, buffer);
  548. unpackstr_ptr(&object->id, &tmp32, buffer);
  549. unpackstr_ptr(&object->jobid, &tmp32, buffer);
  550. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  551. unpackstr_ptr(&object->name, &tmp32, buffer);
  552. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  553. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  554. unpackstr_ptr(&object->partition, &tmp32, buffer);
  555. unpackstr_ptr(&object->priority, &tmp32, buffer);
  556. unpackstr_ptr(&object->qos, &tmp32, buffer);
  557. unpackstr_ptr(&object->req_cpus, &tmp32, buffer);
  558. unpackstr_ptr(&object->resvid, &tmp32, buffer);
  559. unpackstr_ptr(&object->start, &tmp32, buffer);
  560. unpackstr_ptr(&object->state, &tmp32, buffer);
  561. unpackstr_ptr(&object->submit, &tmp32, buffer);
  562. unpackstr_ptr(&object->suspended, &tmp32, buffer);
  563. unpackstr_ptr(&object->track_steps, &tmp32, buffer);
  564. unpackstr_ptr(&object->uid, &tmp32, buffer);
  565. unpackstr_ptr(&object->wckey, &tmp32, buffer);
  566. unpackstr_ptr(&object->wckey_id, &tmp32, buffer);
  567. }
  568. return SLURM_SUCCESS;
  569. }
  570. static void _pack_local_resv(local_resv_t *object,
  571. uint16_t rpc_version, Buf buffer)
  572. {
  573. packstr(object->assocs, buffer);
  574. packstr(object->cpus, buffer);
  575. packstr(object->flags, buffer);
  576. packstr(object->id, buffer);
  577. packstr(object->name, buffer);
  578. packstr(object->nodes, buffer);
  579. packstr(object->node_inx, buffer);
  580. packstr(object->time_end, buffer);
  581. packstr(object->time_start, buffer);
  582. }
  583. /* this needs to be allocated before calling, and since we aren't
  584. * doing any copying it needs to be used before destroying buffer */
  585. static int _unpack_local_resv(local_resv_t *object,
  586. uint16_t rpc_version, Buf buffer)
  587. {
  588. uint32_t tmp32;
  589. unpackstr_ptr(&object->assocs, &tmp32, buffer);
  590. unpackstr_ptr(&object->cpus, &tmp32, buffer);
  591. unpackstr_ptr(&object->flags, &tmp32, buffer);
  592. unpackstr_ptr(&object->id, &tmp32, buffer);
  593. unpackstr_ptr(&object->name, &tmp32, buffer);
  594. unpackstr_ptr(&object->nodes, &tmp32, buffer);
  595. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  596. unpackstr_ptr(&object->time_end, &tmp32, buffer);
  597. unpackstr_ptr(&object->time_start, &tmp32, buffer);
  598. return SLURM_SUCCESS;
  599. }
  600. static void _pack_local_step(local_step_t *object,
  601. uint16_t rpc_version, Buf buffer)
  602. {
  603. if (rpc_version >= SLURMDBD_2_6_VERSION) {
  604. packstr(object->act_cpufreq, buffer);
  605. packstr(object->ave_cpu, buffer);
  606. packstr(object->ave_disk_read, buffer);
  607. packstr(object->ave_disk_write, buffer);
  608. packstr(object->ave_pages, buffer);
  609. packstr(object->ave_rss, buffer);
  610. packstr(object->ave_vsize, buffer);
  611. packstr(object->exit_code, buffer);
  612. packstr(object->consumed_energy, buffer);
  613. packstr(object->cpus, buffer);
  614. packstr(object->id, buffer);
  615. packstr(object->kill_requid, buffer);
  616. packstr(object->max_disk_read, buffer);
  617. packstr(object->max_disk_read_node, buffer);
  618. packstr(object->max_disk_read_task, buffer);
  619. packstr(object->max_disk_write, buffer);
  620. packstr(object->max_disk_write_node, buffer);
  621. packstr(object->max_disk_write_task, buffer);
  622. packstr(object->max_pages, buffer);
  623. packstr(object->max_pages_node, buffer);
  624. packstr(object->max_pages_task, buffer);
  625. packstr(object->max_rss, buffer);
  626. packstr(object->max_rss_node, buffer);
  627. packstr(object->max_rss_task, buffer);
  628. packstr(object->max_vsize, buffer);
  629. packstr(object->max_vsize_node, buffer);
  630. packstr(object->max_vsize_task, buffer);
  631. packstr(object->min_cpu, buffer);
  632. packstr(object->min_cpu_node, buffer);
  633. packstr(object->min_cpu_task, buffer);
  634. packstr(object->name, buffer);
  635. packstr(object->nodelist, buffer);
  636. packstr(object->nodes, buffer);
  637. packstr(object->node_inx, buffer);
  638. packstr(object->period_end, buffer);
  639. packstr(object->period_start, buffer);
  640. packstr(object->period_suspended, buffer);
  641. packstr(object->req_cpufreq, buffer);
  642. packstr(object->state, buffer);
  643. packstr(object->stepid, buffer);
  644. packstr(object->sys_sec, buffer);
  645. packstr(object->sys_usec, buffer);
  646. packstr(object->tasks, buffer);
  647. packstr(object->task_dist, buffer);
  648. packstr(object->user_sec, buffer);
  649. packstr(object->user_usec, buffer);
  650. } else if (rpc_version >= SLURMDBD_2_5_VERSION) {
  651. packstr(object->act_cpufreq, buffer);
  652. packstr(object->ave_cpu, buffer);
  653. packstr(object->ave_pages, buffer);
  654. packstr(object->ave_rss, buffer);
  655. packstr(object->ave_vsize, buffer);
  656. packstr(object->exit_code, buffer);
  657. packstr(object->consumed_energy, buffer);
  658. packstr(object->cpus, buffer);
  659. packstr(object->id, buffer);
  660. packstr(object->kill_requid, buffer);
  661. packstr(object->max_pages, buffer);
  662. packstr(object->max_pages_node, buffer);
  663. packstr(object->max_pages_task, buffer);
  664. packstr(object->max_rss, buffer);
  665. packstr(object->max_rss_node, buffer);
  666. packstr(object->max_rss_task, buffer);
  667. packstr(object->max_vsize, buffer);
  668. packstr(object->max_vsize_node, buffer);
  669. packstr(object->max_vsize_task, buffer);
  670. packstr(object->min_cpu, buffer);
  671. packstr(object->min_cpu_node, buffer);
  672. packstr(object->min_cpu_task, buffer);
  673. packstr(object->name, buffer);
  674. packstr(object->nodelist, buffer);
  675. packstr(object->nodes, buffer);
  676. packstr(object->node_inx, buffer);
  677. packstr(object->period_end, buffer);
  678. packstr(object->period_start, buffer);
  679. packstr(object->period_suspended, buffer);
  680. packstr(object->state, buffer);
  681. packstr(object->stepid, buffer);
  682. packstr(object->sys_sec, buffer);
  683. packstr(object->sys_usec, buffer);
  684. packstr(object->tasks, buffer);
  685. packstr(object->task_dist, buffer);
  686. packstr(object->user_sec, buffer);
  687. packstr(object->user_usec, buffer);
  688. } else {
  689. packstr(object->ave_cpu, buffer);
  690. packstr(object->ave_pages, buffer);
  691. packstr(object->ave_rss, buffer);
  692. packstr(object->ave_vsize, buffer);
  693. packstr(object->exit_code, buffer);
  694. packstr(object->cpus, buffer);
  695. packstr(object->id, buffer);
  696. packstr(object->kill_requid, buffer);
  697. packstr(object->max_pages, buffer);
  698. packstr(object->max_pages_node, buffer);
  699. packstr(object->max_pages_task, buffer);
  700. packstr(object->max_rss, buffer);
  701. packstr(object->max_rss_node, buffer);
  702. packstr(object->max_rss_task, buffer);
  703. packstr(object->max_vsize, buffer);
  704. packstr(object->max_vsize_node, buffer);
  705. packstr(object->max_vsize_task, buffer);
  706. packstr(object->min_cpu, buffer);
  707. packstr(object->min_cpu_node, buffer);
  708. packstr(object->min_cpu_task, buffer);
  709. packstr(object->name, buffer);
  710. packstr(object->nodelist, buffer);
  711. packstr(object->nodes, buffer);
  712. packstr(object->node_inx, buffer);
  713. packstr(object->period_end, buffer);
  714. packstr(object->period_start, buffer);
  715. packstr(object->period_suspended, buffer);
  716. packstr(object->state, buffer);
  717. packstr(object->stepid, buffer);
  718. packstr(object->sys_sec, buffer);
  719. packstr(object->sys_usec, buffer);
  720. packstr(object->tasks, buffer);
  721. packstr(object->task_dist, buffer);
  722. packstr(object->user_sec, buffer);
  723. packstr(object->user_usec, buffer);
  724. }
  725. }
  726. /* this needs to be allocated before calling, and since we aren't
  727. * doing any copying it needs to be used before destroying buffer */
  728. static int _unpack_local_step(local_step_t *object,
  729. uint16_t rpc_version, Buf buffer)
  730. {
  731. uint32_t tmp32;
  732. if (rpc_version >= SLURMDBD_2_6_VERSION) {
  733. unpackstr_ptr(&object->act_cpufreq, &tmp32, buffer);
  734. unpackstr_ptr(&object->ave_cpu, &tmp32, buffer);
  735. unpackstr_ptr(&object->ave_disk_read, &tmp32, buffer);
  736. unpackstr_ptr(&object->ave_disk_write, &tmp32, buffer);
  737. unpackstr_ptr(&object->ave_pages, &tmp32, buffer);
  738. unpackstr_ptr(&object->ave_rss, &tmp32, buffer);
  739. unpackstr_ptr(&object->ave_vsize, &tmp32, buffer);
  740. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  741. unpackstr_ptr(&object->consumed_energy, &tmp32, buffer);
  742. unpackstr_ptr(&object->cpus, &tmp32, buffer);
  743. unpackstr_ptr(&object->id, &tmp32, buffer);
  744. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  745. unpackstr_ptr(&object->max_disk_read, &tmp32, buffer);
  746. unpackstr_ptr(&object->max_disk_read_node, &tmp32, buffer);
  747. unpackstr_ptr(&object->max_disk_read_task, &tmp32, buffer);
  748. unpackstr_ptr(&object->max_disk_write, &tmp32, buffer);
  749. unpackstr_ptr(&object->max_disk_write_node, &tmp32, buffer);
  750. unpackstr_ptr(&object->max_disk_write_task, &tmp32, buffer);
  751. unpackstr_ptr(&object->max_pages, &tmp32, buffer);
  752. unpackstr_ptr(&object->max_pages_node, &tmp32, buffer);
  753. unpackstr_ptr(&object->max_pages_task, &tmp32, buffer);
  754. unpackstr_ptr(&object->max_rss, &tmp32, buffer);
  755. unpackstr_ptr(&object->max_rss_node, &tmp32, buffer);
  756. unpackstr_ptr(&object->max_rss_task, &tmp32, buffer);
  757. unpackstr_ptr(&object->max_vsize, &tmp32, buffer);
  758. unpackstr_ptr(&object->max_vsize_node, &tmp32, buffer);
  759. unpackstr_ptr(&object->max_vsize_task, &tmp32, buffer);
  760. unpackstr_ptr(&object->min_cpu, &tmp32, buffer);
  761. unpackstr_ptr(&object->min_cpu_node, &tmp32, buffer);
  762. unpackstr_ptr(&object->min_cpu_task, &tmp32, buffer);
  763. unpackstr_ptr(&object->name, &tmp32, buffer);
  764. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  765. unpackstr_ptr(&object->nodes, &tmp32, buffer);
  766. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  767. unpackstr_ptr(&object->period_end, &tmp32, buffer);
  768. unpackstr_ptr(&object->period_start, &tmp32, buffer);
  769. unpackstr_ptr(&object->period_suspended, &tmp32, buffer);
  770. unpackstr_ptr(&object->req_cpufreq, &tmp32, buffer);
  771. unpackstr_ptr(&object->state, &tmp32, buffer);
  772. unpackstr_ptr(&object->stepid, &tmp32, buffer);
  773. unpackstr_ptr(&object->sys_sec, &tmp32, buffer);
  774. unpackstr_ptr(&object->sys_usec, &tmp32, buffer);
  775. unpackstr_ptr(&object->tasks, &tmp32, buffer);
  776. unpackstr_ptr(&object->task_dist, &tmp32, buffer);
  777. unpackstr_ptr(&object->user_sec, &tmp32, buffer);
  778. unpackstr_ptr(&object->user_usec, &tmp32, buffer);
  779. } else if (rpc_version >= SLURMDBD_2_5_VERSION) {
  780. unpackstr_ptr(&object->act_cpufreq, &tmp32, buffer);
  781. unpackstr_ptr(&object->ave_cpu, &tmp32, buffer);
  782. unpackstr_ptr(&object->ave_pages, &tmp32, buffer);
  783. unpackstr_ptr(&object->ave_rss, &tmp32, buffer);
  784. unpackstr_ptr(&object->ave_vsize, &tmp32, buffer);
  785. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  786. unpackstr_ptr(&object->consumed_energy, &tmp32, buffer);
  787. unpackstr_ptr(&object->cpus, &tmp32, buffer);
  788. unpackstr_ptr(&object->id, &tmp32, buffer);
  789. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  790. unpackstr_ptr(&object->max_pages, &tmp32, buffer);
  791. unpackstr_ptr(&object->max_pages_node, &tmp32, buffer);
  792. unpackstr_ptr(&object->max_pages_task, &tmp32, buffer);
  793. unpackstr_ptr(&object->max_rss, &tmp32, buffer);
  794. unpackstr_ptr(&object->max_rss_node, &tmp32, buffer);
  795. unpackstr_ptr(&object->max_rss_task, &tmp32, buffer);
  796. unpackstr_ptr(&object->max_vsize, &tmp32, buffer);
  797. unpackstr_ptr(&object->max_vsize_node, &tmp32, buffer);
  798. unpackstr_ptr(&object->max_vsize_task, &tmp32, buffer);
  799. unpackstr_ptr(&object->min_cpu, &tmp32, buffer);
  800. unpackstr_ptr(&object->min_cpu_node, &tmp32, buffer);
  801. unpackstr_ptr(&object->min_cpu_task, &tmp32, buffer);
  802. unpackstr_ptr(&object->name, &tmp32, buffer);
  803. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  804. unpackstr_ptr(&object->nodes, &tmp32, buffer);
  805. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  806. unpackstr_ptr(&object->period_end, &tmp32, buffer);
  807. unpackstr_ptr(&object->period_start, &tmp32, buffer);
  808. unpackstr_ptr(&object->period_suspended, &tmp32, buffer);
  809. unpackstr_ptr(&object->state, &tmp32, buffer);
  810. unpackstr_ptr(&object->stepid, &tmp32, buffer);
  811. unpackstr_ptr(&object->sys_sec, &tmp32, buffer);
  812. unpackstr_ptr(&object->sys_usec, &tmp32, buffer);
  813. unpackstr_ptr(&object->tasks, &tmp32, buffer);
  814. unpackstr_ptr(&object->task_dist, &tmp32, buffer);
  815. unpackstr_ptr(&object->user_sec, &tmp32, buffer);
  816. unpackstr_ptr(&object->user_usec, &tmp32, buffer);
  817. } else {
  818. unpackstr_ptr(&object->ave_cpu, &tmp32, buffer);
  819. unpackstr_ptr(&object->ave_pages, &tmp32, buffer);
  820. unpackstr_ptr(&object->ave_rss, &tmp32, buffer);
  821. unpackstr_ptr(&object->ave_vsize, &tmp32, buffer);
  822. unpackstr_ptr(&object->exit_code, &tmp32, buffer);
  823. unpackstr_ptr(&object->cpus, &tmp32, buffer);
  824. unpackstr_ptr(&object->id, &tmp32, buffer);
  825. unpackstr_ptr(&object->kill_requid, &tmp32, buffer);
  826. unpackstr_ptr(&object->max_pages, &tmp32, buffer);
  827. unpackstr_ptr(&object->max_pages_node, &tmp32, buffer);
  828. unpackstr_ptr(&object->max_pages_task, &tmp32, buffer);
  829. unpackstr_ptr(&object->max_rss, &tmp32, buffer);
  830. unpackstr_ptr(&object->max_rss_node, &tmp32, buffer);
  831. unpackstr_ptr(&object->max_rss_task, &tmp32, buffer);
  832. unpackstr_ptr(&object->max_vsize, &tmp32, buffer);
  833. unpackstr_ptr(&object->max_vsize_node, &tmp32, buffer);
  834. unpackstr_ptr(&object->max_vsize_task, &tmp32, buffer);
  835. unpackstr_ptr(&object->min_cpu, &tmp32, buffer);
  836. unpackstr_ptr(&object->min_cpu_node, &tmp32, buffer);
  837. unpackstr_ptr(&object->min_cpu_task, &tmp32, buffer);
  838. unpackstr_ptr(&object->name, &tmp32, buffer);
  839. unpackstr_ptr(&object->nodelist, &tmp32, buffer);
  840. unpackstr_ptr(&object->nodes, &tmp32, buffer);
  841. unpackstr_ptr(&object->node_inx, &tmp32, buffer);
  842. unpackstr_ptr(&object->period_end, &tmp32, buffer);
  843. unpackstr_ptr(&object->period_start, &tmp32, buffer);
  844. unpackstr_ptr(&object->period_suspended, &tmp32, buffer);
  845. unpackstr_ptr(&object->state, &tmp32, buffer);
  846. unpackstr_ptr(&object->stepid, &tmp32, buffer);
  847. unpackstr_ptr(&object->sys_sec, &tmp32, buffer);
  848. unpackstr_ptr(&object->sys_usec, &tmp32, buffer);
  849. unpackstr_ptr(&object->tasks, &tmp32, buffer);
  850. unpackstr_ptr(&object->task_dist, &tmp32, buffer);
  851. unpackstr_ptr(&object->user_sec, &tmp32, buffer);
  852. unpackstr_ptr(&object->user_usec, &tmp32, buffer);
  853. }
  854. return SLURM_SUCCESS;
  855. }
  856. static void _pack_local_suspend(local_suspend_t *object,
  857. uint16_t rpc_version, Buf buffer)
  858. {
  859. packstr(object->associd, buffer);
  860. packstr(object->id, buffer);
  861. packstr(object->period_end, buffer);
  862. packstr(object->period_start, buffer);
  863. }
  864. /* this needs to be allocated before calling, and since we aren't
  865. * doing any copying it needs to be used before destroying buffer */
  866. static int _unpack_local_suspend(local_suspend_t *object,
  867. uint16_t rpc_version, Buf buffer)
  868. {
  869. uint32_t tmp32;
  870. unpackstr_ptr(&object->associd, &tmp32, buffer);
  871. unpackstr_ptr(&object->id, &tmp32, buffer);
  872. unpackstr_ptr(&object->period_end, &tmp32, buffer);
  873. unpackstr_ptr(&object->period_start, &tmp32, buffer);
  874. return SLURM_SUCCESS;
  875. }
  876. static int _process_old_sql_line(const char *data_in, char **data_full_out)
  877. {
  878. int start = 0, i = 0;
  879. char *beginning = NULL;
  880. char *ending = NULL;
  881. char *data_out = *data_full_out;
  882. char *table = NULL;
  883. char *fields = NULL;
  884. char *new_vals = NULL;
  885. char *vals = NULL;
  886. char *new_cluster_name = NULL;
  887. char *cluster_name = NULL;
  888. int rc = SLURM_SUCCESS;
  889. int cnt = 0, cluster_inx = -1, ending_start = 0, ending_end = 0;
  890. bool delete = 0;
  891. bool new_cluster = 0;
  892. while (data_in[i]) {
  893. if (!strncmp("insert into ", data_in+i, 12)) {
  894. beginning = xstrndup(data_in+i, 11);
  895. i+=12;
  896. break;
  897. } else if (!strncmp("delete from ", data_in+i, 12)) {
  898. beginning = xstrndup(data_in+i, 11);
  899. i+=12;
  900. delete = 1;
  901. break;
  902. } else if (!strncmp("drop table ", data_in+i, 11)) {
  903. start = i;
  904. i+=11;
  905. while (data_in[i] && data_in[i-1] != ';')
  906. i++;
  907. xstrncat(data_out, data_in+start, i-start);
  908. goto end_it;
  909. } else if (!strncmp("truncate table ", data_in+i, 15)) {
  910. start = i;
  911. i+=15;
  912. while (data_in[i] && data_in[i-1] != ';')
  913. i++;
  914. xstrncat(data_out, data_in+start, i-start);
  915. goto end_it;
  916. }
  917. i++;
  918. }
  919. if (!data_in[i])
  920. goto end_it;
  921. //info("processing %s", data_in);
  922. /* get table name */
  923. if (!strncmp("cluster_event_table", data_in+i, 19)) {
  924. i+=19;
  925. table = event_table;
  926. } else if (!strncmp("job_table", data_in+i, 9)) {
  927. i+=9;
  928. table = job_table;
  929. } else if (!strncmp("step_table", data_in+i, 10)) {
  930. i+=10;
  931. table = step_table;
  932. } else if (!strncmp("suspend_table", data_in+i, 13)) {
  933. i+=13;
  934. table = suspend_table;
  935. } else if (!strncmp("cluster_day_usage_table", data_in+i, 23)) {
  936. i+=23;
  937. table = cluster_day_table;
  938. } else if (!strncmp("cluster_hour_usage_table", data_in+i, 24)) {
  939. i+=24;
  940. table = cluster_hour_table;
  941. } else if (!strncmp("cluster_month_usage_table", data_in+i, 25)) {
  942. i+=25;
  943. table = cluster_month_table;
  944. } else if (!strncmp("assoc_day_usage_table", data_in+i, 21)) {
  945. i+=21;
  946. table = assoc_day_table;
  947. } else if (!strncmp("assoc_hour_usage_table", data_in+i, 22)) {
  948. i+=22;
  949. table = assoc_hour_table;
  950. } else if (!strncmp("assoc_month_usage_table", data_in+i, 23)) {
  951. i+=23;
  952. table = assoc_month_table;
  953. } else {
  954. error("unknown table in sql '%s'", data_in);
  955. rc = SLURM_ERROR;
  956. goto end_it;
  957. }
  958. /* get to the columns */
  959. if (!delete)
  960. while (data_in[i] && data_in[i-1] != '(' && data_in[i-1] != ';')
  961. i++;
  962. else
  963. while (data_in[i] && data_in[i-1] != ' ')
  964. i++;
  965. //info("table is %s '%s'", table, data_in+i);
  966. while (data_in[i] && data_in[i] != ')') {
  967. if (delete && !strncmp("where ", data_in+i, 6)) {
  968. i+=6;
  969. continue;
  970. } else if (!strncmp("period_start", data_in+i, 12)) {
  971. xstrcat(fields, "time_start");
  972. i+=12;
  973. } else if (!strncmp("period_end", data_in+i, 10)) {
  974. xstrcat(fields, "time_end");
  975. i+=10;
  976. } else if (!strncmp("jobid", data_in+i, 5)) {
  977. xstrcat(fields, "id_job");
  978. i+=5;
  979. } else if (!strncmp("stepid", data_in+i, 6)) {
  980. xstrcat(fields, "id_step");
  981. i+=6;
  982. } else if (!strncmp("associd", data_in+i, 7)) {
  983. xstrcat(fields, "id_assoc");
  984. i+=7;
  985. } else if (!strncmp("blockid", data_in+i, 7)) {
  986. xstrcat(fields, "id_block");
  987. i+=7;
  988. } else if (!strncmp("wckeyid", data_in+i, 7)) {
  989. xstrcat(fields, "id_wckey");
  990. i+=7;
  991. } else if (!strncmp("qos", data_in+i, 3)) {
  992. xstrcat(fields, "id_qos");
  993. i+=3;
  994. } else if (!strncmp("uid", data_in+i, 3)) {
  995. xstrcat(fields, "id_user");
  996. i+=3;
  997. } else if (!strncmp("gid", data_in+i, 3)) {
  998. xstrcat(fields, "id_group");
  999. i+=3;
  1000. } else if (!strncmp("submit", data_in+i, 6)) {
  1001. xstrcat(fields, "time_submit");
  1002. i+=6;
  1003. } else if (!strncmp("eligible", data_in+i, 8)) {
  1004. xstrcat(fields, "time_eligible");
  1005. i+=8;
  1006. } else if (!strncmp("start", data_in+i, 5)) {
  1007. xstrcat(fields, "time_start");
  1008. i+=5;
  1009. } else if (!strncmp("suspended", data_in+i, 9)) {
  1010. xstrcat(fields, "time_suspended");
  1011. i+=9;
  1012. } else if (!strncmp("end", data_in+i, 3)) {
  1013. xstrcat(fields, "time_end");
  1014. i+=3;
  1015. } else if (!strncmp("comp_code", data_in+i, 9)) {
  1016. xstrcat(fields, "exit_code");
  1017. i+=9;
  1018. } else if (!strncmp("alloc_cpus", data_in+i, 10)) {
  1019. xstrcat(fields, "cpus_alloc");
  1020. i+=10;
  1021. } else if (!strncmp("req_cpus", data_in+i, 8)) {
  1022. xstrcat(fields, "cpus_req");
  1023. i+=8;
  1024. } else if (!strncmp("alloc_nodes", data_in+i, 11)) {
  1025. xstrcat(fields, "nodes_alloc");
  1026. i+=11;
  1027. } else if (!strncmp("name", data_in+i, 4)) {
  1028. if (table == job_table)
  1029. xstrcat(fields, "job_name");
  1030. else if (table == step_table)
  1031. xstrcat(fields, "step_name");
  1032. i+=4;
  1033. } else if (!strncmp("id", data_in+i, 2)) {
  1034. i+=2;
  1035. if ((table == assoc_day_table)
  1036. || (table == assoc_hour_table)
  1037. || (table == assoc_month_table)) {
  1038. char *id_assoc = NULL;
  1039. while (data_in[i] && data_in[i-1] != '=') {
  1040. i++;
  1041. }
  1042. start = i;
  1043. while (data_in[i]
  1044. && data_in[i] != ' '
  1045. && data_in[i] != ';') {
  1046. i++;
  1047. }
  1048. if (!data_in[i]) {
  1049. error("returning at id_assoc");
  1050. rc = SLURM_ERROR;
  1051. goto end_it;
  1052. }
  1053. if (data_in[i] == ' ') {
  1054. while (data_in[i] && data_in[i] == ' ')
  1055. i++;
  1056. while (data_in[i] && data_in[i] == '|')
  1057. i++;
  1058. while (data_in[i] && data_in[i] == ' ')
  1059. i++;
  1060. }
  1061. xstrncat(id_assoc, data_in+start, (i-start));
  1062. if (!fields)
  1063. xstrcat(fields, "where ");
  1064. xstrfmtcat(fields, "id_assoc=%s", id_assoc);
  1065. xfree(id_assoc);
  1066. } else
  1067. xstrcat(fields, "job_db_inx");
  1068. } else if (!strncmp("cluster_nodes", data_in+i, 13)) {
  1069. /* this is here just to make it easier to
  1070. handle the cluster field. */
  1071. xstrcat(fields, "cluster_nodes");
  1072. i+=13;
  1073. } else if (!strncmp("cluster", data_in+i, 7)) {
  1074. i+=7;
  1075. if (!delete) {
  1076. cluster_inx = cnt;
  1077. if (cnt)
  1078. fields[strlen(fields)-2] = '\0';
  1079. } else {
  1080. while (data_in[i] && data_in[i-1] != '\'')
  1081. i++;
  1082. start = i;
  1083. while (data_in[i] && data_in[i] != '\'')
  1084. i++;
  1085. if (!data_in[i]) {
  1086. error("returning here cluster");
  1087. rc = SLURM_ERROR;
  1088. goto end_it;
  1089. }
  1090. cluster_name = xstrndup(data_in+start,
  1091. (i-start));
  1092. i++;
  1093. }
  1094. } else {
  1095. start = i;
  1096. while (data_in[i]
  1097. && data_in[i] != ',' && data_in[i] != ')') {
  1098. i++;
  1099. }
  1100. if (!data_in[i]) {
  1101. error("returning here end");
  1102. rc = SLURM_ERROR;
  1103. goto end_it;
  1104. }
  1105. xstrncat(fields, data_in+start, (i-start));
  1106. }
  1107. if (data_in[i]) {
  1108. if (!delete || ((table != assoc_day_table)
  1109. && (table != assoc_hour_table)
  1110. && (table != assoc_month_table))) {
  1111. if (data_in[i] == ',')
  1112. xstrcat(fields, ", ");
  1113. else if (data_in[i] == ')'
  1114. || data_in[i] == ';') {
  1115. break;
  1116. } else {
  1117. error("unknown char '%s'", data_in+i);
  1118. rc = SLURM_ERROR;
  1119. goto end_it;
  1120. }
  1121. i++;
  1122. } else {
  1123. if (data_in[i] == ';')
  1124. break;
  1125. }
  1126. while (data_in[i] && data_in[i] == ' ')
  1127. i++;
  1128. }
  1129. cnt++;
  1130. }
  1131. if (data_in[i] && data_in[i] == ')') {
  1132. ending_end = i;
  1133. ending_start = 0;
  1134. while (data_in[ending_end] && data_in[ending_end-1] != ';') {
  1135. if (!strncmp(data_in+ending_end,
  1136. "on duplicate key", 16)) {
  1137. ending_start = ending_end;
  1138. }
  1139. if (ending_start) {
  1140. if (!strncmp("period_start",
  1141. data_in+ending_end, 12)) {
  1142. xstrcat(ending, "time_start");
  1143. ending_end+=12;
  1144. } else if (!strncmp("period_end",
  1145. data_in+ending_end, 10)) {
  1146. xstrcat(ending, "time_end");
  1147. ending_end+=10;
  1148. } else if (!strncmp("jobid",
  1149. data_in+ending_end, 5)) {
  1150. xstrcat(ending, "id_job");
  1151. ending_end+=5;
  1152. } else if (!strncmp("stepid",
  1153. data_in+ending_end, 6)) {
  1154. xstrcat(ending, "id_step");
  1155. ending_end+=6;
  1156. } else if (!strncmp("associd",
  1157. data_in+ending_end, 7)) {
  1158. xstrcat(ending, "id_assoc");
  1159. ending_end+=7;
  1160. } else if (!strncmp("blockid",
  1161. data_in+ending_end, 7)) {
  1162. xstrcat(ending, "id_block");
  1163. ending_end+=7;
  1164. } else if (!strncmp("wckeyid",
  1165. data_in+ending_end, 7)) {
  1166. xstrcat(ending, "id_wckey");
  1167. ending_end+=7;
  1168. } else if (!strncmp("uid",
  1169. data_in+ending_end, 3)) {
  1170. xstrcat(ending, "id_user");
  1171. ending_end+=3;
  1172. } else if (!strncmp("gid",
  1173. data_in+ending_end, 3)) {
  1174. xstrcat(ending, "id_group");
  1175. ending_end+=3;
  1176. } else if (!strncmp("submit",
  1177. data_in+ending_end, 6)) {
  1178. xstrcat(ending, "time_submit");
  1179. ending_end+=6;
  1180. } else if (!strncmp("eligible",
  1181. data_in+ending_end, 8)) {
  1182. xstrcat(ending, "time_eligible");
  1183. ending_end+=8;
  1184. } else if (!strncmp("start",
  1185. data_in+ending_end, 5)) {
  1186. xstrcat(ending, "time_start");
  1187. ending_end+=5;
  1188. } else if (!strncmp("suspended",
  1189. data_in+ending_end, 9)) {
  1190. xstrcat(ending, "time_suspended");
  1191. ending_end+=9;
  1192. } else if (!strncmp("end",
  1193. data_in+ending_end, 3)) {
  1194. xstrcat(ending, "time_end");
  1195. ending_end+=3;
  1196. } else if (!strncmp("comp_code",
  1197. data_in+ending_end, 9)) {
  1198. xstrcat(ending, "exit_code");
  1199. ending_end+=9;
  1200. } else if (!strncmp("alloc_cpus",
  1201. data_in+ending_end, 10)) {
  1202. xstrcat(ending, "cpus_alloc");
  1203. ending_end+=10;
  1204. } else if (!strncmp("req_cpus",
  1205. data_in+ending_end, 8)) {
  1206. xstrcat(ending, "cpus_req");
  1207. ending_end+=8;
  1208. } else if (!strncmp("alloc_nodes",
  1209. data_in+ending_end, 11)) {
  1210. xstrcat(ending, "nodes_alloc");
  1211. ending_end+=11;
  1212. } else if (!strncmp("name",
  1213. data_in+ending_end, 4)) {
  1214. if (table == job_table)
  1215. xstrcat(ending, "job_name");
  1216. else if (table == step_table)
  1217. xstrcat(ending, "step_name");
  1218. ending_end+=4;
  1219. } else if (!strncmp("id",
  1220. data_in+ending_end, 2)) {
  1221. if ((table == assoc_day_table)
  1222. || (table == assoc_hour_table)
  1223. || (table == assoc_month_table))
  1224. xstrcat(ending, "id_assoc");
  1225. else
  1226. xstrcat(ending, "job_db_inx");
  1227. ending_end+=2;
  1228. }
  1229. if (data_in[ending_end])
  1230. xstrcatchar(ending,
  1231. data_in[ending_end]);
  1232. }
  1233. ending_end++;
  1234. }
  1235. /* get values */
  1236. while ((i < ending_start) && i < ending_start) {
  1237. /* get to the start of the values */
  1238. while ((i < ending_start) && data_in[i-1] != '(')
  1239. i++;
  1240. /* find the values */
  1241. cnt = 0;
  1242. while ((i < ending_start) && data_in[i] != ')') {
  1243. start = i;
  1244. while ((i < ending_start)
  1245. && data_in[i] != ','
  1246. && data_in[i] != ')') {
  1247. i++;
  1248. }
  1249. if (!data_in[i]) {
  1250. rc = SLURM_ERROR;
  1251. goto end_it;
  1252. }
  1253. if (cnt == cluster_inx) {
  1254. /* get the cluster name and remove the
  1255. ticks */
  1256. xstrncat(new_cluster_name,
  1257. data_in+start+1, (i-start-2));
  1258. if (cluster_name) {
  1259. if (strcmp(cluster_name,
  1260. new_cluster_name))
  1261. new_cluster = 1;
  1262. else
  1263. xfree(new_cluster_name);
  1264. } else {
  1265. cluster_name = new_cluster_name;
  1266. new_cluster_name = NULL;
  1267. }
  1268. } else {
  1269. xstrncat(new_vals, data_in+start,
  1270. (i-start));
  1271. if (data_in[i]) {
  1272. if (data_in[i] == ',')
  1273. xstrcat(new_vals, ", ");
  1274. else if (data_in[i] == ')'
  1275. || data_in[i] == ';') {
  1276. i++;
  1277. break;
  1278. } else {
  1279. error("unknown char "
  1280. "'%s'",
  1281. data_in+i);
  1282. rc = SLURM_ERROR;
  1283. goto end_it;
  1284. }
  1285. }
  1286. }
  1287. i++;
  1288. while ((i < ending_start) && data_in[i] == ' ')
  1289. i++;
  1290. cnt++;
  1291. }
  1292. if (new_cluster) {
  1293. /* info("new cluster, adding insert\n%s " */
  1294. /* "\"%s_%s\" (%s) values %s %s", */
  1295. /* beginning, cluster_name, table, */
  1296. /* fields, vals, ending); */
  1297. xstrfmtcat(data_out,
  1298. "%s \"%s_%s\" (%s) values %s %s",
  1299. beginning, cluster_name,
  1300. table, fields, vals, ending);
  1301. new_cluster = 0;
  1302. xfree(vals);
  1303. xfree(cluster_name);
  1304. cluster_name = new_cluster_name;
  1305. new_cluster_name = NULL;
  1306. }
  1307. if (new_vals) {
  1308. if (vals)
  1309. xstrfmtcat(vals, ", (%s)", new_vals);
  1310. else
  1311. xstrfmtcat(vals, "(%s)", new_vals);
  1312. xfree(new_vals);
  1313. }
  1314. }
  1315. i = ending_end;
  1316. }
  1317. if (!cluster_name) {
  1318. error("No cluster given for %s", table);
  1319. goto end_it;
  1320. }
  1321. if (!delete) {
  1322. /* info("adding insert\n%s \"%s_%s\" (%s) values %s %s",
  1323. beginning, cluster_name, table, fields, vals, ending); */
  1324. xstrfmtcat(data_out, "%s \"%s_%s\" (%s) values %s %s",
  1325. beginning, cluster_name, table, fields,
  1326. vals, ending);
  1327. } else {
  1328. if (fields) {
  1329. /* info("adding delete\n%s \"%s_%s\" %s", */
  1330. /* beginning, cluster_name, table, fields); */
  1331. xstrfmtcat(data_out, "%s \"%s_%s\" %s",
  1332. beginning, cluster_name, table, fields);
  1333. } else {
  1334. /* info("adding drop\ndrop table \"%s_%s\";", */
  1335. /* cluster_name, table); */
  1336. xstrfmtcat(data_out, "drop table \"%s_%s\";",
  1337. cluster_name, table);
  1338. }
  1339. }
  1340. end_it:
  1341. xfree(cluster_name);
  1342. xfree(beginning);
  1343. xfree(ending);
  1344. xfree(fields);
  1345. xfree(vals);
  1346. *data_full_out = data_out;
  1347. //info("returning\n%s", data_out);
  1348. if (rc == SLURM_ERROR)
  1349. return -1;
  1350. return i;
  1351. }
  1352. static int _process_old_sql(char **data)
  1353. {
  1354. int i = 0;
  1355. char *data_in = *data;
  1356. char *data_out = NULL;
  1357. int rc = SLURM_SUCCESS;
  1358. while (data_in[i]) {
  1359. if ((rc = _process_old_sql_line(data_in+i, &data_out)) == -1)
  1360. break;
  1361. i += rc;
  1362. }
  1363. //rc = -1;
  1364. xfree(data_in);
  1365. if (rc == -1)
  1366. xfree(data_out);
  1367. //info("returning\n%s", data_out);
  1368. *data = data_out;
  1369. return rc;
  1370. }
  1371. /* returns count of events archived or SLURM_ERROR on error */
  1372. static uint32_t _archive_events(mysql_conn_t *mysql_conn, char *cluster_name,
  1373. time_t period_end, char *arch_dir,
  1374. uint32_t archive_period)
  1375. {
  1376. MYSQL_RES *result = NULL;
  1377. MYSQL_ROW row;
  1378. char *tmp = NULL, *query = NULL;
  1379. time_t period_start = 0;
  1380. uint32_t cnt = 0;
  1381. local_event_t event;
  1382. Buf buffer;
  1383. int error_code = 0, i = 0;
  1384. xfree(tmp);
  1385. xstrfmtcat(tmp, "%s", event_req_inx[0]);
  1386. for(i=1; i<EVENT_REQ_COUNT; i++) {
  1387. xstrfmtcat(tmp, ", %s", event_req_inx[i]);
  1388. }
  1389. /* get all the events started before this time listed */
  1390. query = xstrdup_printf("select %s from \"%s_%s\" where "
  1391. "time_start <= %ld "
  1392. "&& time_end != 0 order by time_start asc",
  1393. tmp, cluster_name, event_table, period_end);
  1394. xfree(tmp);
  1395. // START_TIMER;
  1396. debug3("%d(%s:%d) query\n%s",
  1397. mysql_conn->conn, THIS_FILE, __LINE__, query);
  1398. if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
  1399. xfree(query);
  1400. return SLURM_ERROR;
  1401. }
  1402. xfree(query);
  1403. if (!(cnt = mysql_num_rows(result))) {
  1404. mysql_free_result(result);
  1405. return 0;
  1406. }
  1407. buffer = init_buf(high_buffer_size);
  1408. pack16(SLURM_PROTOCOL_VERSION, buffer);
  1409. pack_time(time(NULL), buffer);
  1410. pack16(DBD_GOT_EVENTS, buffer);
  1411. packstr(cluster_name, buffer);
  1412. pack32(cnt, buffer);
  1413. while ((row = mysql_fetch_row(result))) {
  1414. if (!period_start)
  1415. period_start = slurm_atoul(row[EVENT_REQ_START]);
  1416. memset(&event, 0, sizeof(local_event_t));
  1417. event.cluster_nodes = row[EVENT_REQ_CNODES];
  1418. event.cpu_count = row[EVENT_REQ_CPU];
  1419. event.node_name = row[EVENT_REQ_NODE];
  1420. event.period_end = row[EVENT_REQ_END];
  1421. event.period_start = row[EVENT_REQ_START];
  1422. event.reason = row[EVENT_REQ_REASON];
  1423. event.reason_uid = row[EVENT_REQ_REASON_UID];
  1424. event.state = row[EVENT_REQ_STATE];
  1425. _pack_local_event(&event, SLURM_PROTOCOL_VERSION, buffer);
  1426. }
  1427. mysql_free_result(result);
  1428. // END_TIMER2("step query");
  1429. // info("event query took %s", TIME_STR);
  1430. error_code = archive_write_file(buffer, cluster_name,
  1431. period_start, period_end,
  1432. arch_dir, "event", archive_period);
  1433. free_buf(buffer);
  1434. if (error_code != SLURM_SUCCESS)
  1435. return error_code;
  1436. return cnt;
  1437. }
  1438. /* returns sql statement from archived data or NULL on error */
  1439. static char *
  1440. _load_events(uint16_t rpc_version, Buf buffer, char *cluster_name,
  1441. uint32_t rec_cnt)
  1442. {
  1443. char *insert = NULL, *format = NULL;
  1444. local_event_t object;
  1445. int i = 0;
  1446. xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
  1447. cluster_name, event_table, event_req_inx[0]);
  1448. xstrcat(format, "('%s'");
  1449. for(i=1; i<EVENT_REQ_COUNT; i++) {
  1450. xstrfmtcat(insert, ", %s", event_req_inx[i]);
  1451. xstrcat(format, ", '%s'");
  1452. }
  1453. xstrcat(insert, ") values ");
  1454. xstrcat(format, ")");
  1455. for(i=0; i<rec_cnt; i++) {
  1456. memset(&object, 0, sizeof(local_event_t));
  1457. if (_unpack_local_event(&object, rpc_version, buffer)
  1458. != SLURM_SUCCESS) {
  1459. error("issue unpacking");
  1460. xfree(format);
  1461. xfree(insert);
  1462. break;
  1463. }
  1464. if (i)
  1465. xstrcat(insert, ", ");
  1466. xstrfmtcat(insert, format,
  1467. object.cluster_nodes,
  1468. object.cpu_count,
  1469. object.node_name,
  1470. object.period_end,
  1471. object.period_start,
  1472. object.reason,
  1473. object.reason_uid,
  1474. object.state);
  1475. }
  1476. // END_TIMER2("step query");
  1477. // info("event query took %s", TIME_STR);
  1478. xfree(format);
  1479. return insert;
  1480. }
  1481. /* returns count of jobs archived or SLURM_ERROR on error */
  1482. static uint32_t _archive_jobs(mysql_conn_t *mysql_conn, char *cluster_name,
  1483. time_t period_end, char *arch_dir,
  1484. uint32_t archive_period)
  1485. {
  1486. MYSQL_RES *result = NULL;
  1487. MYSQL_ROW row;
  1488. char *tmp = NULL, *query = NULL;
  1489. time_t period_start = 0;
  1490. uint32_t cnt = 0;
  1491. local_job_t job;
  1492. Buf buffer;
  1493. int error_code = 0, i = 0;
  1494. xfree(tmp);
  1495. xstrfmtcat(tmp, "%s", job_req_inx[0]);
  1496. for(i=1; i<JOB_REQ_COUNT; i++) {
  1497. xstrfmtcat(tmp, ", %s", job_req_inx[i]);
  1498. }
  1499. /* get all the events started before this time listed */
  1500. query = xstrdup_printf("select %s from \"%s_%s\" where "
  1501. "time_submit < %ld && time_end != 0 && !deleted "
  1502. "order by time_submit asc",
  1503. tmp, cluster_name, job_table, period_end);
  1504. xfree(tmp);
  1505. // START_TIMER;
  1506. debug3("%d(%s:%d) query\n%s",
  1507. mysql_conn->conn, THIS_FILE, __LINE__, query);
  1508. if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
  1509. xfree(query);
  1510. return SLURM_ERROR;
  1511. }
  1512. xfree(query);
  1513. if (!(cnt = mysql_num_rows(result))) {
  1514. mysql_free_result(result);
  1515. return 0;
  1516. }
  1517. buffer = init_buf(high_buffer_size);
  1518. pack16(SLURM_PROTOCOL_VERSION, buffer);
  1519. pack_time(time(NULL), buffer);
  1520. pack16(DBD_GOT_JOBS, buffer);
  1521. packstr(cluster_name, buffer);
  1522. pack32(cnt, buffer);
  1523. while ((row = mysql_fetch_row(result))) {
  1524. if (!period_start)
  1525. period_start = slurm_atoul(row[JOB_REQ_SUBMIT]);
  1526. memset(&job, 0, sizeof(local_job_t));
  1527. job.account = row[JOB_REQ_ACCOUNT];
  1528. job.alloc_cpus = row[JOB_REQ_ALLOC_CPUS];
  1529. job.alloc_nodes = row[JOB_REQ_ALLOC_NODES];
  1530. job.associd = row[JOB_REQ_ASSOCID];
  1531. job.array_jobid = row[JOB_REQ_ARRAYJOBID];
  1532. job.array_taskid = row[JOB_REQ_ARRAYTASKID];
  1533. job.blockid = row[JOB_REQ_BLOCKID];
  1534. job.derived_ec = row[JOB_REQ_DERIVED_EC];
  1535. job.derived_es = row[JOB_REQ_DERIVED_ES];
  1536. job.exit_code = row[JOB_REQ_EXIT_CODE];
  1537. job.timelimit = row[JOB_REQ_TIMELIMIT];
  1538. job.eligible = row[JOB_REQ_ELIGIBLE];
  1539. job.end = row[JOB_REQ_END];
  1540. job.gid = row[JOB_REQ_GID];
  1541. job.id = row[JOB_REQ_ID];
  1542. job.jobid = row[JOB_REQ_JOBID];
  1543. job.kill_requid = row[JOB_REQ_KILL_REQUID];
  1544. job.name = row[JOB_REQ_NAME];
  1545. job.nodelist = row[JOB_REQ_NODELIST];
  1546. job.node_inx = row[JOB_REQ_NODE_INX];
  1547. job.partition = row[JOB_REQ_PARTITION];
  1548. job.priority = row[JOB_REQ_PRIORITY];
  1549. job.qos = row[JOB_REQ_QOS];
  1550. job.req_cpus = row[JOB_REQ_REQ_CPUS];
  1551. job.req_mem = row[JOB_REQ_REQ_MEM];
  1552. job.resvid = row[JOB_REQ_RESVID];
  1553. job.start = row[JOB_REQ_START];
  1554. job.state = row[JOB_REQ_STATE];
  1555. job.submit = row[JOB_REQ_SUBMIT];
  1556. job.suspended = row[JOB_REQ_SUSPENDED];
  1557. job.track_steps = row[JOB_REQ_TRACKSTEPS];
  1558. job.uid = row[JOB_REQ_UID];
  1559. job.wckey = row[JOB_REQ_WCKEY];
  1560. job.wckey_id = row[JOB_REQ_WCKEYID];
  1561. _pack_local_job(&job, SLURM_PROTOCOL_VERSION, buffer);
  1562. }
  1563. mysql_free_result(result);
  1564. // END_TIMER2("step query");
  1565. // info("event query took %s", TIME_STR);
  1566. error_code = archive_write_file(buffer, cluster_name,
  1567. period_start, period_end,
  1568. arch_dir, "job", archive_period);
  1569. free_buf(buffer);
  1570. if (error_code != SLURM_SUCCESS)
  1571. return error_code;
  1572. return cnt;
  1573. }
  1574. /* returns sql statement from archived data or NULL on error */
  1575. static char *_load_jobs(uint16_t rpc_version, Buf buffer,
  1576. char *cluster_name, uint32_t rec_cnt)
  1577. {
  1578. char *insert = NULL, *format = NULL;
  1579. local_job_t object;
  1580. int i = 0;
  1581. xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
  1582. cluster_name, job_table, job_req_inx[0]);
  1583. xstrcat(format, "('%s'");
  1584. for(i=1; i<JOB_REQ_COUNT; i++) {
  1585. xstrfmtcat(insert, ", %s", job_req_inx[i]);
  1586. xstrcat(format, ", '%s'");
  1587. }
  1588. xstrcat(insert, ") values ");
  1589. xstrcat(format, ")");
  1590. for(i=0; i<rec_cnt; i++) {
  1591. memset(&object, 0, sizeof(local_job_t));
  1592. if (_unpack_local_job(&object, rpc_version, buffer)
  1593. != SLURM_SUCCESS) {
  1594. error("issue unpacking");
  1595. xfree(format);
  1596. xfree(insert);
  1597. break;
  1598. }
  1599. if (i)
  1600. xstrcat(insert, ", ");
  1601. xstrfmtcat(insert, format,
  1602. object.account,
  1603. object.alloc_cpus,
  1604. object.alloc_nodes,
  1605. object.associd,
  1606. object.array_jobid,
  1607. object.array_taskid,
  1608. object.blockid,
  1609. object.derived_ec,
  1610. object.derived_es,
  1611. object.exit_code,
  1612. object.timelimit,
  1613. object.eligible,
  1614. object.end,
  1615. object.gid,
  1616. object.id,
  1617. object.jobid,
  1618. object.kill_requid,
  1619. object.name,
  1620. object.nodelist,
  1621. object.node_inx,
  1622. object.partition,
  1623. object.priority,
  1624. object.qos,
  1625. object.req_cpus,
  1626. object.req_mem,
  1627. object.resvid,
  1628. object.start,
  1629. object.state,
  1630. object.submit,
  1631. object.suspended,
  1632. object.track_steps,
  1633. object.uid,
  1634. object.wckey,
  1635. object.wckey_id);
  1636. }
  1637. // END_TIMER2("step query");
  1638. // info("job query took %s", TIME_STR);
  1639. xfree(format);
  1640. return insert;
  1641. }
  1642. /* returns count of resvations archived or SLURM_ERROR on error */
  1643. static uint32_t _archive_resvs(mysql_conn_t *mysql_conn, char *cluster_name,
  1644. time_t period_end, char *arch_dir,
  1645. uint32_t archive_period)
  1646. {
  1647. MYSQL_RES *result = NULL;
  1648. MYSQL_ROW row;
  1649. char *tmp = NULL, *query = NULL;
  1650. time_t period_start = 0;
  1651. uint32_t cnt = 0;
  1652. local_resv_t resv;
  1653. Buf buffer;
  1654. int error_code = 0, i = 0;
  1655. xfree(tmp);
  1656. xstrfmtcat(tmp, "%s", resv_req_inx[0]);
  1657. for(i=1; i<RESV_REQ_COUNT; i++) {
  1658. xstrfmtcat(tmp, ", %s", resv_req_inx[i]);
  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 "
  1663. "&& time_end != 0 order by time_start asc",
  1664. tmp, cluster_name, resv_table, period_end);
  1665. xfree(tmp);
  1666. // START_TIMER;
  1667. debug3("%d(%s:%d) query\n%s",
  1668. mysql_conn->conn, THIS_FILE, __LINE__, query);
  1669. if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
  1670. xfree(query);
  1671. return SLURM_ERROR;
  1672. }
  1673. xfree(query);
  1674. if (!(cnt = mysql_num_rows(result))) {
  1675. mysql_free_result(result);
  1676. return 0;
  1677. }
  1678. buffer = init_buf(high_buffer_size);
  1679. pack16(SLURM_PROTOCOL_VERSION, buffer);
  1680. pack_time(time(NULL), buffer);
  1681. pack16(DBD_GOT_RESVS, buffer);
  1682. packstr(cluster_name, buffer);
  1683. pack32(cnt, buffer);
  1684. while ((row = mysql_fetch_row(result))) {
  1685. if (!period_start)
  1686. period_start = slurm_atoul(row[RESV_REQ_START]);
  1687. memset(&resv, 0, sizeof(local_resv_t));
  1688. resv.assocs = row[RESV_REQ_ASSOCS];
  1689. resv.cpus = row[RESV_REQ_CPUS];
  1690. resv.flags = row[RESV_REQ_FLAGS];
  1691. resv.id = row[RESV_REQ_ID];
  1692. resv.name = row[RESV_REQ_NAME];
  1693. resv.nodes = row[RESV_REQ_NODES];
  1694. resv.node_inx = row[RESV_REQ_NODE_INX];
  1695. resv.time_end = row[RESV_REQ_END];
  1696. resv.time_start = row[RESV_REQ_START];
  1697. _pack_local_resv(&resv, SLURM_PROTOCOL_VERSION, buffer);
  1698. }
  1699. mysql_free_result(result);
  1700. // END_TIMER2("step query");
  1701. // info("event query took %s", TIME_STR);
  1702. error_code = archive_write_file(buffer, cluster_name,
  1703. period_start, period_end,
  1704. arch_dir, "resv", archive_period);
  1705. free_buf(buffer);
  1706. if (error_code != SLURM_SUCCESS)
  1707. return error_code;
  1708. return cnt;
  1709. }
  1710. /* returns sql statement from archived data or NULL on error */
  1711. static char *_load_resvs(uint16_t rpc_version, Buf buffer,
  1712. char *cluster_name, uint32_t rec_cnt)
  1713. {
  1714. char *insert = NULL, *format = NULL;
  1715. local_resv_t object;
  1716. int i = 0;
  1717. xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
  1718. cluster_name, resv_table, resv_req_inx[0]);
  1719. xstrcat(format, "('%s'");
  1720. for(i=1; i<RESV_REQ_COUNT; i++) {
  1721. xstrfmtcat(insert, ", %s", resv_req_inx[i]);
  1722. xstrcat(format, ", '%s'");
  1723. }
  1724. xstrcat(insert, ") values ");
  1725. xstrcat(format, ")");
  1726. for(i=0; i<rec_cnt; i++) {
  1727. memset(&object, 0, sizeof(local_resv_t));
  1728. if (_unpack_local_resv(&object, rpc_version, buffer)
  1729. != SLURM_SUCCESS) {
  1730. error("issue unpacking");
  1731. xfree(format);
  1732. xfree(insert);
  1733. break;
  1734. }
  1735. if (i)
  1736. xstrcat(insert, ", ");
  1737. xstrfmtcat(insert, format,
  1738. object.assocs,
  1739. object.cpus,
  1740. object.flags,
  1741. object.id,
  1742. object.name,
  1743. object.nodes,
  1744. object.node_inx,
  1745. object.time_end,
  1746. object.time_start);
  1747. }
  1748. // END_TIMER2("step query");
  1749. // info("resv query took %s", TIME_STR);
  1750. xfree(format);
  1751. return insert;
  1752. }
  1753. /* returns count of steps archived or SLURM_ERROR on error */
  1754. static uint32_t _archive_steps(mysql_conn_t *mysql_conn, char *cluster_name,
  1755. time_t period_end, char *arch_dir,
  1756. uint32_t archive_period)
  1757. {
  1758. MYSQL_RES *result = NULL;
  1759. MYSQL_ROW row;
  1760. char *tmp = NULL, *query = NULL;
  1761. time_t period_start = 0;
  1762. uint32_t cnt = 0;
  1763. local_step_t step;
  1764. Buf buffer;
  1765. int error_code = 0, i = 0;
  1766. xfree(tmp);
  1767. xstrfmtcat(tmp, "%s", step_req_inx[0]);
  1768. for(i=1; i<STEP_REQ_COUNT; i++) {
  1769. xstrfmtcat(tmp, ", %s", step_req_inx[i]);
  1770. }
  1771. /* get all the events started before this time listed */
  1772. query = xstrdup_printf("select %s from \"%s_%s\" where "
  1773. "time_start <= %ld && time_end != 0 "
  1774. "&& !deleted order by time_start asc",
  1775. tmp, cluster_name, step_table, period_end);
  1776. xfree(tmp);
  1777. // START_TIMER;
  1778. debug3("%d(%s:%d) query\n%s",
  1779. mysql_conn->conn, THIS_FILE, __LINE__, query);
  1780. if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
  1781. xfree(query);
  1782. return SLURM_ERROR;
  1783. }
  1784. xfree(query);
  1785. if (!(cnt = mysql_num_rows(result))) {
  1786. mysql_free_result(result);
  1787. return 0;
  1788. }
  1789. buffer = init_buf(high_buffer_size);
  1790. pack16(SLURM_PROTOCOL_VERSION, buffer);
  1791. pack_time(time(NULL), buffer);
  1792. pack16(DBD_STEP_START, buffer);
  1793. packstr(cluster_name, buffer);
  1794. pack32(cnt, buffer);
  1795. while ((row = mysql_fetch_row(result))) {
  1796. if (!period_start)
  1797. period_start = slurm_atoul(row[STEP_REQ_START]);
  1798. memset(&step, 0, sizeof(local_step_t));
  1799. step.ave_cpu = row[STEP_REQ_AVE_CPU];
  1800. step.act_cpufreq = row[STEP_REQ_ACT_CPUFREQ];
  1801. step.consumed_energy = row[STEP_REQ_CONSUMED_ENERGY];
  1802. step.ave_disk_read = row[STEP_REQ_AVE_DISK_READ];
  1803. step.ave_disk_write = row[STEP_REQ_AVE_DISK_WRITE];
  1804. step.ave_pages = row[STEP_REQ_AVE_PAGES];
  1805. step.ave_rss = row[STEP_REQ_AVE_RSS];
  1806. step.ave_vsize = row[STEP_REQ_AVE_VSIZE];
  1807. step.exit_code = row[STEP_REQ_EXIT_CODE];
  1808. step.cpus = row[STEP_REQ_CPUS];
  1809. step.id = row[STEP_REQ_ID];
  1810. step.kill_requid = row[STEP_REQ_KILL_REQUID];
  1811. step.max_disk_read = row[STEP_REQ_MAX_DISK_READ];
  1812. step.max_disk_read_node = row[STEP_REQ_MAX_DISK_READ_NODE];
  1813. step.max_disk_read_task = row[STEP_REQ_MAX_DISK_READ_TASK];
  1814. step.max_disk_write = row[STEP_REQ_MAX_DISK_WRITE];
  1815. step.max_disk_write_node = row[STEP_REQ_MAX_DISK_WRITE_NODE];
  1816. step.max_disk_write_task = row[STEP_REQ_MAX_DISK_WRITE_TASK];
  1817. step.max_pages = row[STEP_REQ_MAX_PAGES];
  1818. step.max_pages_node = row[STEP_REQ_MAX_PAGES_NODE];
  1819. step.max_pages_task = row[STEP_REQ_MAX_PAGES_TASK];
  1820. step.max_rss = row[STEP_REQ_MAX_RSS];
  1821. step.max_rss_node = row[STEP_REQ_MAX_RSS_NODE];
  1822. step.max_rss_task = row[STEP_REQ_MAX_RSS_TASK];
  1823. step.max_vsize = row[STEP_REQ_MAX_VSIZE];
  1824. step.max_vsize_node = row[STEP_REQ_MAX_VSIZE_NODE];
  1825. step.max_vsize_task = row[STEP_REQ_MAX_VSIZE_TASK];
  1826. step.min_cpu = row[STEP_REQ_MIN_CPU];
  1827. step.min_cpu_node = row[STEP_REQ_MIN_CPU_NODE];
  1828. step.min_cpu_task = row[STEP_REQ_MIN_CPU_TASK];
  1829. step.name = row[STEP_REQ_NAME];
  1830. step.nodelist = row[STEP_REQ_NODELIST];
  1831. step.nodes = row[STEP_REQ_NODES];
  1832. step.node_inx = row[STEP_REQ_NODE_INX];
  1833. step.period_end = row[STEP_REQ_END];
  1834. step.period_start = row[STEP_REQ_START];
  1835. step.period_suspended = row[STEP_REQ_SUSPENDED];
  1836. step.req_cpufreq = row[STEP_REQ_REQ_CPUFREQ];
  1837. step.state = row[STEP_REQ_STATE];
  1838. step.stepid = row[STEP_REQ_STEPID];
  1839. step.sys_sec = row[STEP_REQ_SYS_SEC];
  1840. step.sys_usec = row[STEP_REQ_SYS_USEC];
  1841. step.tasks = row[STEP_REQ_TASKS];
  1842. step.task_dist = row[STEP_REQ_TASKDIST];
  1843. step.user_sec = row[STEP_REQ_USER_SEC];
  1844. step.user_usec = row[STEP_REQ_USER_USEC];
  1845. _pack_local_step(&step, SLURM_PROTOCOL_VERSION, buffer);
  1846. }
  1847. mysql_free_result(result);
  1848. // END_TIMER2("step query");
  1849. // info("event query took %s", TIME_STR);
  1850. error_code = archive_write_file(buffer, cluster_name,
  1851. period_start, period_end,
  1852. arch_dir, "step", archive_period);
  1853. free_buf(buffer);
  1854. if (error_code != SLURM_SUCCESS)
  1855. return error_code;
  1856. return cnt;
  1857. }
  1858. /* returns sql statement from archived data or NULL on error */
  1859. static char *_load_steps(uint16_t rpc_version, Buf buffer,
  1860. char *cluster_name, uint32_t rec_cnt)
  1861. {
  1862. char *insert = NULL, *format = NULL;
  1863. local_step_t object;
  1864. int i = 0;
  1865. xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
  1866. cluster_name, step_table, step_req_inx[0]);
  1867. xstrcat(format, "('%s'");
  1868. for(i=1; i<STEP_REQ_COUNT; i++) {
  1869. xstrfmtcat(insert, ", %s", step_req_inx[i]);
  1870. xstrcat(format, ", '%s'");
  1871. }
  1872. xstrcat(insert, ") values ");
  1873. xstrcat(format, ")");
  1874. for(i=0; i<rec_cnt; i++) {
  1875. memset(&object, 0, sizeof(local_step_t));
  1876. if (_unpack_local_step(&object, rpc_version, buffer)
  1877. != SLURM_SUCCESS) {
  1878. error("issue unpacking");
  1879. xfree(format);
  1880. xfree(insert);
  1881. break;
  1882. }
  1883. if (i)
  1884. xstrcat(insert, ", ");
  1885. xstrfmtcat(insert, format,
  1886. object.ave_cpu,
  1887. object.act_cpufreq,
  1888. object.consumed_energy,
  1889. object.ave_disk_read,
  1890. object.ave_disk_write,
  1891. object.ave_pages,
  1892. object.ave_rss,
  1893. object.ave_vsize,
  1894. object.exit_code,
  1895. object.cpus,
  1896. object.id,
  1897. object.kill_requid,
  1898. object.max_disk_read,
  1899. object.max_disk_read_node,
  1900. object.max_disk_read_task,
  1901. object.max_disk_write,
  1902. object.max_disk_write_node,
  1903. object.max_disk_write_task,
  1904. object.max_pages,
  1905. object.max_pages_node,
  1906. object.max_pages_task,
  1907. object.max_rss,
  1908. object.max_rss_node,
  1909. object.max_rss_task,
  1910. object.max_vsize,
  1911. object.max_vsize_node,
  1912. object.max_vsize_task,
  1913. object.min_cpu,
  1914. object.min_cpu_node,
  1915. object.min_cpu_task,
  1916. object.name,
  1917. object.nodelist,
  1918. object.nodes,
  1919. object.node_inx,
  1920. object.period_end,
  1921. object.period_start,
  1922. object.period_suspended,
  1923. object.req_cpufreq,
  1924. object.state,
  1925. object.stepid,
  1926. object.sys_sec,
  1927. object.sys_usec,
  1928. object.tasks,
  1929. object.task_dist,
  1930. object.user_sec,
  1931. object.user_usec);
  1932. }
  1933. // END_TIMER2("step query");
  1934. // info("step query took %s", TIME_STR);
  1935. xfree(format);
  1936. return insert;
  1937. }
  1938. /* returns count of events archived or SLURM_ERROR on error */
  1939. static uint32_t _archive_suspend(mysql_conn_t *mysql_conn, char *cluster_name,
  1940. time_t period_end, char *arch_dir,
  1941. uint32_t archive_period)
  1942. {
  1943. MYSQL_RES *result = NULL;
  1944. MYSQL_ROW row;
  1945. char *tmp = NULL, *query = NULL;
  1946. time_t period_start = 0;
  1947. uint32_t cnt = 0;
  1948. local_suspend_t suspend;
  1949. Buf buffer;
  1950. int error_code = 0, i = 0;
  1951. xfree(tmp);
  1952. xstrfmtcat(tmp, "%s", suspend_req_inx[0]);
  1953. for(i=1; i<SUSPEND_REQ_COUNT; i++) {
  1954. xstrfmtcat(tmp, ", %s", suspend_req_inx[i]);
  1955. }
  1956. /* get all the events started before this time listed */
  1957. query = xstrdup_printf("select %s from \"%s_%s\" where "
  1958. "time_start <= %ld && time_end != 0 "
  1959. "order by time_start asc",
  1960. tmp, cluster_name, suspend_table, period_end);
  1961. xfree(tmp);
  1962. // START_TIMER;
  1963. debug3("%d(%s:%d) query\n%s",
  1964. mysql_conn->conn, THIS_FILE, __LINE__, query);
  1965. if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
  1966. xfree(query);
  1967. return SLURM_ERROR;
  1968. }
  1969. xfree(query);
  1970. if (!(cnt = mysql_num_rows(result))) {
  1971. mysql_free_result(result);
  1972. return 0;
  1973. }
  1974. buffer = init_buf(high_buffer_size);
  1975. pack16(SLURM_PROTOCOL_VERSION, buffer);
  1976. pack_time(time(NULL), buffer);
  1977. pack16(DBD_JOB_SUSPEND, buffer);
  1978. packstr(cluster_name, buffer);
  1979. pack32(cnt, buffer);
  1980. while ((row = mysql_fetch_row(result))) {
  1981. if (!period_start)
  1982. period_start = slurm_atoul(row[SUSPEND_REQ_START]);
  1983. memset(&suspend, 0, sizeof(local_suspend_t));
  1984. suspend.id = row[SUSPEND_REQ_ID];
  1985. suspend.associd = row[SUSPEND_REQ_ASSOCID];
  1986. suspend.period_start = row[SUSPEND_REQ_START];
  1987. suspend.period_end = row[SUSPEND_REQ_END];
  1988. _pack_local_suspend(&suspend, SLURM_PROTOCOL_VERSION, buffer);
  1989. }
  1990. mysql_free_result(result);
  1991. // END_TIMER2("step query");
  1992. // info("event query took %s", TIME_STR);
  1993. error_code = archive_write_file(buffer, cluster_name,
  1994. period_start, period_end,
  1995. arch_dir, "suspend", archive_period);
  1996. free_buf(buffer);
  1997. if (error_code != SLURM_SUCCESS)
  1998. return error_code;
  1999. return cnt;
  2000. }
  2001. /* returns sql statement from archived data or NULL on error */
  2002. static char *_load_suspend(uint16_t rpc_version, Buf buffer,
  2003. char *cluster_name, uint32_t rec_cnt)
  2004. {
  2005. char *insert = NULL, *format = NULL;
  2006. local_suspend_t object;
  2007. int i = 0;
  2008. xstrfmtcat(insert, "insert into \"%s_%s\" (%s",
  2009. cluster_name, suspend_table, suspend_req_inx[0]);
  2010. xstrcat(format, "('%s'");
  2011. for(i=1; i<SUSPEND_REQ_COUNT; i++) {
  2012. xstrfmtcat(insert, ", %s", suspend_req_inx[i]);
  2013. xstrcat(format, ", '%s'");
  2014. }
  2015. xstrcat(insert, ") values ");
  2016. xstrcat(format, ")");
  2017. for(i=0; i<rec_cnt; i++) {
  2018. memset(&object, 0, sizeof(local_suspend_t));
  2019. if (_unpack_local_suspend(&object, rpc_version, buffer)
  2020. != SLURM_SUCCESS) {
  2021. error("issue unpacking");
  2022. xfree(format);
  2023. xfree(insert);
  2024. break;
  2025. }
  2026. if (i)
  2027. xstrcat(insert, ", ");
  2028. xstrfmtcat(insert, format,
  2029. object.associd,
  2030. object.id,
  2031. object.period_end,
  2032. object.period_start);
  2033. }
  2034. // END_TIMER2("suspend query");
  2035. // info("suspend query took %s", TIME_STR);
  2036. xfree(format);
  2037. return insert;
  2038. }
  2039. static int _execute_archive(mysql_conn_t *mysql_conn,
  2040. char *cluster_name,
  2041. slurmdb_archive_cond_t *arch_cond)
  2042. {
  2043. int rc = SLURM_SUCCESS;
  2044. char *query = NULL;
  2045. time_t curr_end;
  2046. time_t last_submit = time(NULL);
  2047. if (arch_cond->archive_script)
  2048. return archive_run_script(arch_cond, cluster_name, last_submit);
  2049. else if (!arch_cond->archive_dir) {
  2050. error("No archive dir given, can't process");
  2051. return SLURM_ERROR;
  2052. }
  2053. if (arch_cond->purge_event != NO_VAL) {
  2054. /* remove all data from event table that was older than
  2055. * period_start * arch_cond->purge_event.
  2056. */
  2057. if (!(curr_end = archive_setup_end_time(
  2058. last_submit, arch_cond->purge_event))) {
  2059. error("Parsing purge event");
  2060. return SLURM_ERROR;
  2061. }
  2062. debug4("Purging event entries before %ld for %s",
  2063. curr_end, cluster_name);
  2064. if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_event)) {
  2065. rc = _archive_events(mysql_conn, cluster_name,
  2066. curr_end, arch_cond->archive_dir,
  2067. arch_cond->purge_event);
  2068. if (!rc)
  2069. goto exit_events;
  2070. else if (rc == SLURM_ERROR)
  2071. return rc;
  2072. }
  2073. query = xstrdup_printf("delete from \"%s_%s\" where "
  2074. "time_start <= %ld && time_end != 0",
  2075. cluster_name, event_table, curr_end);
  2076. debug3("%d(%s:%d) query\n%s",
  2077. mysql_conn->conn, THIS_FILE, __LINE__, query);
  2078. rc = mysql_db_query(mysql_conn, query);
  2079. xfree(query);
  2080. if (rc != SLURM_SUCCESS) {
  2081. error("Couldn't remove old event data");
  2082. return SLURM_ERROR;
  2083. }
  2084. }
  2085. exit_events:
  2086. if (arch_cond->purge_suspend != NO_VAL) {
  2087. /* remove all data from suspend table that was older than
  2088. * period_start * arch_cond->purge_suspend.
  2089. */
  2090. if (!(curr_end = archive_setup_end_time(
  2091. last_submit, arch_cond->purge_suspend))) {
  2092. error("Parsing purge suspend");
  2093. return SLURM_ERROR;
  2094. }
  2095. debug4("Purging suspend entries before %ld for %s",
  2096. curr_end, cluster_name);
  2097. if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_suspend)) {
  2098. rc = _archive_suspend(mysql_conn, cluster_name,
  2099. curr_end, arch_cond->archive_dir,
  2100. arch_cond->purge_suspend);
  2101. if (!rc)
  2102. goto exit_suspend;
  2103. else if (rc == SLURM_ERROR)
  2104. return rc;
  2105. }
  2106. query = xstrdup_printf("delete from \"%s_%s\" where "
  2107. "time_start <= %ld && time_end != 0",
  2108. cluster_name, suspend_table, curr_end);
  2109. debug3("%d(%s:%d) query\n%s",
  2110. mysql_conn->conn, THIS_FILE, __LINE__, query);
  2111. rc = mysql_db_query(mysql_conn, query);
  2112. xfree(query);
  2113. if (rc != SLURM_SUCCESS) {
  2114. error("Couldn't remove old suspend data");
  2115. return SLURM_ERROR;
  2116. }
  2117. }
  2118. exit_suspend:
  2119. if (arch_cond->purge_step != NO_VAL) {
  2120. /* remove all data from step table that was older than
  2121. * start * arch_cond->purge_step.
  2122. */
  2123. if (!(curr_end = archive_setup_end_time(
  2124. last_submit, arch_cond->purge_step))) {
  2125. error("Parsing purge step");
  2126. return SLURM_ERROR;
  2127. }
  2128. debug4("Purging step entries before %ld for %s",
  2129. curr_end, cluster_name);
  2130. if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_step)) {
  2131. rc = _archive_steps(mysql_conn, cluster_name,
  2132. curr_end, arch_cond->archive_dir,
  2133. arch_cond->purge_step);
  2134. if (!rc)
  2135. goto exit_steps;
  2136. else if (rc == SLURM_ERROR)
  2137. return rc;
  2138. }
  2139. query = xstrdup_printf("delete from \"%s_%s\" where "
  2140. "time_start <= %ld && time_end != 0",
  2141. cluster_name, step_table, curr_end);
  2142. debug3("%d(%s:%d) query\n%s",
  2143. mysql_conn->conn, THIS_FILE, __LINE__, query);
  2144. rc = mysql_db_query(mysql_conn, query);
  2145. xfree(query);
  2146. if (rc != SLURM_SUCCESS) {
  2147. error("Couldn't remove old step data");
  2148. return SLURM_ERROR;
  2149. }
  2150. }
  2151. exit_steps:
  2152. if (arch_cond->purge_job != NO_VAL) {
  2153. /* remove all data from job table that was older than
  2154. * last_submit * arch_cond->purge_job.
  2155. */
  2156. if (!(curr_end = archive_setup_end_time(
  2157. last_submit, arch_cond->purge_job))) {
  2158. error("Parsing purge job");
  2159. return SLURM_ERROR;
  2160. }
  2161. debug4("Purging job entires before %ld for %s",
  2162. curr_end, cluster_name);
  2163. if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_job)) {
  2164. rc = _archive_jobs(mysql_conn, cluster_name,
  2165. curr_end, arch_cond->archive_dir,
  2166. arch_cond->purge_job);
  2167. if (!rc)
  2168. goto exit_jobs;
  2169. else if (rc == SLURM_ERROR)
  2170. return rc;
  2171. }
  2172. query = xstrdup_printf("delete from \"%s_%s\" "
  2173. "where time_submit <= %ld "
  2174. "&& time_end != 0",
  2175. cluster_name, job_table, curr_end);
  2176. debug3("%d(%s:%d) query\n%s",
  2177. mysql_conn->conn, THIS_FILE, __LINE__, query);
  2178. rc = mysql_db_query(mysql_conn, query);
  2179. xfree(query);
  2180. if (rc != SLURM_SUCCESS) {
  2181. error("Couldn't remove old job data");
  2182. return SLURM_ERROR;
  2183. }
  2184. }
  2185. exit_jobs:
  2186. if (arch_cond->purge_resv != NO_VAL) {
  2187. /* remove all data from resv table that was older than
  2188. * last_submit * arch_cond->purge_resv.
  2189. */
  2190. if (!(curr_end = archive_setup_end_time(
  2191. last_submit, arch_cond->purge_resv))) {
  2192. error("Parsing purge resv");
  2193. return SLURM_ERROR;
  2194. }
  2195. debug4("Purging resv entires before %ld for %s",
  2196. curr_end, cluster_name);
  2197. if (SLURMDB_PURGE_ARCHIVE_SET(arch_cond->purge_resv)) {
  2198. rc = _archive_resvs(mysql_conn, cluster_name,
  2199. curr_end, arch_cond->archive_dir,
  2200. arch_cond->purge_resv);
  2201. if (!rc)
  2202. goto exit_resvs;
  2203. else if (rc == SLURM_ERROR)
  2204. return rc;
  2205. }
  2206. query = xstrdup_printf("delete from \"%s_%s\" "
  2207. "where time_start <= %ld "
  2208. "&& time_end != 0",
  2209. cluster_name, resv_table, curr_end);
  2210. debug3("%d(%s:%d) query\n%s",
  2211. mysql_conn->conn, THIS_FILE, __LINE__, query);
  2212. rc = mysql_db_query(mysql_conn, query);
  2213. xfree(query);
  2214. if (rc != SLURM_SUCCESS) {
  2215. error("Couldn't remove old resv data");
  2216. return SLURM_ERROR;
  2217. }
  2218. }
  2219. exit_resvs:
  2220. return SLURM_SUCCESS;
  2221. }
  2222. extern int as_mysql_jobacct_process_archive(mysql_conn_t *mysql_conn,
  2223. slurmdb_archive_cond_t *arch_cond)
  2224. {
  2225. int rc = SLURM_SUCCESS;
  2226. char *cluster_name = NULL;
  2227. List use_cluster_list = as_mysql_cluster_list;
  2228. ListIterator itr = NULL;
  2229. // DEF_TIMERS;
  2230. if (!arch_cond) {
  2231. error("No arch_cond was given to archive from. returning");
  2232. return SLURM_ERROR;
  2233. }
  2234. if (arch_cond->job_cond && arch_cond->job_cond->cluster_list
  2235. && list_count(arch_cond->job_cond->cluster_list))
  2236. use_cluster_list = arch_cond->job_cond->cluster_list;
  2237. else
  2238. slurm_mutex_lock(&as_mysql_cluster_list_lock);
  2239. itr = list_iterator_create(use_cluster_list);
  2240. while ((cluster_name = list_next(itr))) {
  2241. if ((rc = _execute_archive(mysql_conn, cluster_name, arch_cond))
  2242. != SLURM_SUCCESS)
  2243. break;
  2244. }
  2245. list_iterator_destroy(itr);
  2246. if (use_cluster_list == as_mysql_cluster_list)
  2247. slurm_mutex_unlock(&as_mysql_cluster_list_lock);
  2248. return rc;
  2249. }
  2250. extern int as_mysql_jobacct_process_archive_load(
  2251. mysql_conn_t *mysql_conn, slurmdb_archive_rec_t *arch_rec)
  2252. {
  2253. char *data = NULL, *cluster_name = NULL;
  2254. int error_code = SLURM_SUCCESS;
  2255. Buf buffer;
  2256. time_t buf_time;
  2257. uint16_t type = 0, ver = 0;
  2258. uint32_t data_size = 0, rec_cnt = 0, tmp32 = 0;
  2259. if (!arch_rec) {
  2260. error("We need a slurmdb_archive_rec to load anything.");
  2261. return SLURM_ERROR;
  2262. }
  2263. if (arch_rec->insert) {
  2264. data = xstrdup(arch_rec->insert);
  2265. } else if (arch_rec->archive_file) {
  2266. int data_allocated, data_read = 0;
  2267. int state_fd = open(arch_rec->archive_file, O_RDONLY);
  2268. if (state_fd < 0) {
  2269. info("No archive file (%s) to recover",
  2270. arch_rec->archive_file);
  2271. error_code = ENOENT;
  2272. } else {
  2273. data_allocated = BUF_SIZE;
  2274. data = xmalloc(data_allocated);
  2275. while (1) {
  2276. data_read = read(state_fd, &data[data_size],
  2277. BUF_SIZE);
  2278. if (data_read < 0) {
  2279. if (errno == EINTR)
  2280. continue;
  2281. else {
  2282. error("Read error on %s: %m",
  2283. arch_rec->archive_file);
  2284. break;
  2285. }
  2286. } else if (data_read == 0) /* eof */
  2287. break;
  2288. data_size += data_read;
  2289. data_allocated += data_read;
  2290. xrealloc(data, data_allocated);
  2291. }
  2292. close(state_fd);
  2293. }
  2294. if (error_code != SLURM_SUCCESS) {
  2295. xfree(data);
  2296. return error_code;
  2297. }
  2298. } else {
  2299. error("Nothing was set in your "
  2300. "slurmdb_archive_rec so I am unable to process.");
  2301. return SLURM_ERROR;
  2302. }
  2303. if (!data) {
  2304. error("It doesn't appear we have anything to load.");
  2305. return SLURM_ERROR;
  2306. }
  2307. /* this is the old version of an archive file where the file
  2308. was straight sql. */
  2309. if ((strlen(data) >= 12)
  2310. && (!strncmp("insert into ", data, 12)
  2311. || !strncmp("delete from ", data, 12)
  2312. || !strncmp("drop table ", data, 11)
  2313. || !strncmp("truncate table ", data, 15))) {
  2314. _process_old_sql(&data);
  2315. goto got_sql;
  2316. }
  2317. buffer = create_buf(data, data_size);
  2318. safe_unpack16(&ver, buffer);
  2319. debug3("Version in assoc_mgr_state header is %u", ver);
  2320. /* Don't verify the lower limit as we should be keeping all
  2321. older versions around here just to support super old
  2322. archive files since they don't get regenerated all the
  2323. time.
  2324. */
  2325. if (ver > SLURM_PROTOCOL_VERSION) {
  2326. error("***********************************************");
  2327. error("Can not recover archive file, incompatible version, "
  2328. "got %u need <= %u", ver,
  2329. SLURM_PROTOCOL_VERSION);
  2330. error("***********************************************");
  2331. free_buf(buffer);
  2332. return EFAULT;
  2333. }
  2334. safe_unpack_time(&buf_time, buffer);
  2335. safe_unpack16(&type, buffer);
  2336. unpackstr_ptr(&cluster_name, &tmp32, buffer);
  2337. safe_unpack32(&rec_cnt, buffer);
  2338. if (!rec_cnt) {
  2339. error("we didn't get any records from this file of type '%s'",
  2340. slurmdbd_msg_type_2_str(type, 0));
  2341. free_buf(buffer);
  2342. goto got_sql;
  2343. }
  2344. switch(type) {
  2345. case DBD_GOT_EVENTS:
  2346. data = _load_events(ver, buffer, cluster_name, rec_cnt);
  2347. break;
  2348. case DBD_GOT_JOBS:
  2349. data = _load_jobs(ver, buffer, cluster_name, rec_cnt);
  2350. break;
  2351. case DBD_GOT_RESVS:
  2352. data = _load_resvs(ver, buffer, cluster_name, rec_cnt);
  2353. break;
  2354. case DBD_STEP_START:
  2355. data = _load_steps(ver, buffer, cluster_name, rec_cnt);
  2356. break;
  2357. case DBD_JOB_SUSPEND:
  2358. data = _load_suspend(ver, buffer, cluster_name, rec_cnt);
  2359. break;
  2360. default:
  2361. error("Unknown type '%u' to load from archive", type);
  2362. break;
  2363. }
  2364. free_buf(buffer);
  2365. got_sql:
  2366. if (!data) {
  2367. error("No data to load");
  2368. return SLURM_ERROR;
  2369. }
  2370. debug3("%d(%s:%d) query\n%s",
  2371. mysql_conn->conn, THIS_FILE, __LINE__, data);
  2372. error_code = mysql_db_query_check_after(mysql_conn, data);
  2373. xfree(data);
  2374. if (error_code != SLURM_SUCCESS) {
  2375. unpack_error:
  2376. error("Couldn't load old data");
  2377. return SLURM_ERROR;
  2378. }
  2379. return SLURM_SUCCESS;
  2380. }