/** * @brief * Save a queue to the database * * @param[in] pque - Pointer to the queue to save * @param[in] mode: * QUE_SAVE_FULL - Save full queue information (update) * QUE_SAVE_NEW - Save new queue information (insert) * * @return Error code * @retval 0 - Success * @retval 1 - Failure * */ int que_save_db(pbs_queue *pque, int mode) { pbs_db_que_info_t dbque; pbs_db_attr_info_t attr_info; pbs_db_obj_info_t obj; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; int flag=0; svr_to_db_que(pque, &dbque); obj.pbs_db_obj_type = PBS_DB_QUEUE; obj.pbs_db_un.pbs_db_que = &dbque; /* load que_qs */ if (pbs_db_begin_trx(conn, 0, 0) !=0) goto db_err; if (mode == QUE_SAVE_NEW) { if (pbs_db_insert_obj(conn, &obj) != 0) goto db_err; flag = 1; } else if (mode == QUE_SAVE_FULL) { /* * Delete the queue and write it afresh * Deleting the queue removes all attributes automatically * Thus when reinserting, we add only the set attributes */ pbs_db_delete_obj(conn, &obj); if (pbs_db_insert_obj(conn, &obj) != 0) goto db_err; flag = 1; } else { /* que_qs*/ if (pbs_db_update_obj(conn, &obj) != 0) goto db_err; } /* que_attrs */ attr_info.parent_obj_type = PARENT_TYPE_QUE_ALL; /* que attr */ attr_info.parent_id = dbque.qu_name; if (save_attr_db(conn, &attr_info, que_attr_def, pque->qu_attr, (int)QA_ATR_LAST, flag) !=0) goto db_err; if (pbs_db_end_trx(conn, PBS_DB_COMMIT) != 0) goto db_err; return (0); db_err: strcpy(log_buffer, "que_save failed "); if (conn->conn_db_err != NULL) strncat(log_buffer, conn->conn_db_err, LOG_BUF_SIZE - strlen(log_buffer) - 1); log_err(-1, __func__, log_buffer); (void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK); panic_stop_db(log_buffer); return (-1); }
/** * @brief * Save a queue to the database * * @param[in] pque - Pointer to the queue to save * @param[in] mode: * QUE_SAVE_FULL - Save full queue information (update) * QUE_SAVE_NEW - Save new queue information (insert) * * @return Error code * @retval 0 - Success * @retval 1 - Failure * */ int que_save_db(pbs_queue *pque, int mode) { pbs_db_que_info_t dbque; pbs_db_obj_info_t obj; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; int savetype = PBS_UPDATE_DB_FULL; if (svr_to_db_que(pque, &dbque, savetype) != 0) goto db_err; obj.pbs_db_obj_type = PBS_DB_QUEUE; obj.pbs_db_un.pbs_db_que = &dbque; if (mode == QUE_SAVE_NEW) savetype = PBS_INSERT_DB; if (pbs_db_save_obj(conn, &obj, savetype) != 0) goto db_err; pbs_db_reset_obj(&obj); return (0); db_err: /* free the attribute list allocated by encode_attrs */ free(dbque.attr_list.attributes); strcpy(log_buffer, "que_save failed "); if (conn->conn_db_err != NULL) strncat(log_buffer, conn->conn_db_err, LOG_BUF_SIZE - strlen(log_buffer) - 1); log_err(-1, __func__, log_buffer); panic_stop_db(log_buffer); return (-1); }