PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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