PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/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

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://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_r

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