/* * load_usage() - print an usage of the load-utility * return: void */ static void load_usage (const char *argv0) { #ifdef LDR_OLD_LOADDB fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_USAGE + 1)); #else const char *exec_name; exec_name = basename ((char *) argv0); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_USAGE), exec_name); #endif }
/* * otable_insert - This inserts a new entry in the instance array of a class * table. * return: NO_ERROR if successful, error code otherwise * table(out): class table * instance(in): instance OID * id(in): instance id number */ int otable_insert (CLASS_TABLE * table, OID * instance, int id) { int error = NO_ERROR; INST_INFO *inst; if (id >= table->count) { error = grow_instance_table (table, id); } if (error == NO_ERROR) { inst = &table->instances[id]; if (inst->flags & INST_FLAG_INSERTED) /* lame, should pass in a stream for this */ fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_REDEFINING_INSTANCE), id, db_get_class_name (table->class_)); inst->oid = *instance; inst->flags = INST_FLAG_INSERTED; } return error; }
/* * loaddb_report_num_of_commits - report number of commits * return: void * num_committed(in): number of commits * * Note: * registered as a callback function the loader will call this function * to report the number of insertion that have taken place if the '-vc', * verbose commit parameter was specified. */ static void loaddb_report_num_of_commits (int num_committed) { print_log_msg (Verbose_commit, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTED_INSTANCES), num_committed); }
/* * compact_usage() - print an usage of the compactdb-utility * return: void * exec_name(in): a name of this application */ static void compactdb_usage (const char *argv0) { const char *exec_name; exec_name = basename ((char *) argv0); printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, 60), exec_name); }
/* * disk_update_instance - This updates an object that had previously been * reserved with the actual contents. * return: NO_ERROR if successful, error code otherwise * classop(in): class object * obj(in): description of object * oid(in): destination oid */ int disk_update_instance (MOP classop, DESC_OBJ * obj, OID * oid) { int error = NO_ERROR; HFID *hfid; int newsize; bool has_indexes = false; Diskrec->length = 0; if (desc_obj_to_disk (obj, Diskrec, &has_indexes)) { /* make the record larger */ newsize = -Diskrec->length + DB_PAGESIZE; free_recdes (Diskrec); Diskrec = alloc_recdes (newsize); /* try one more time */ if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0) { error = ER_LDR_CANT_TRANSFORM; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0); } } if (!error) { hfid = get_class_heap (classop, obj->class_); if (hfid == NULL) { assert (er_errid () != NO_ERROR); error = er_errid (); } else { HEAP_OPERATION_CONTEXT update_context; heap_create_update_context (&update_context, hfid, oid, WS_OID (classop), Diskrec, NULL, UPDATE_INPLACE_NONE); if (heap_update_logical (NULL, &update_context) != NO_ERROR) { assert (er_errid () != NO_ERROR); error = er_errid (); } if (update_context.is_logical_old) { fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING)); } else if (has_indexes) { error = update_indexes (WS_OID (classop), oid, Diskrec); } } } return (error); }
/* * signal_handler - signal handler registered via util_arm_signal_handlers * return: void */ static void signal_handler (void) { LOADDB_DEBUG_PRINTF (("Signal caught : interrupt flag : %d\n", Interrupt_type)); /* Flag the loader that that an interrupt has occurred. */ ldr_interrupt_has_occurred (Interrupt_type); print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_SIG1)); }
/* * ldr_validate_object_file - check input file arguments * return: 0 if successful, 1 if error * outfp(out): error message destination */ static int ldr_validate_object_file (FILE * outfp, const char *argv0) { if (Volume == NULL) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_MISSING_DBNAME)); load_usage (argv0); return 1; } if (Input_file[0] == 0 && Object_file[0] == 0) { /* if schema/index file are specified, process them only */ if (Schema_file[0] == 0 && Index_file[0] == 0) { load_usage (argv0); return 1; } else return 0; } else if (Input_file[0] != 0 && Object_file[0] != 0 && strcmp (Input_file, Object_file) != 0) { fprintf (outfp, msgcat_message (MSGCAT_CATALOG_CUBRID, MSGCAT_SET_GENERAL, MSGCAT_GENERAL_ARG_DUPLICATE), "input-file"); return 1; } else { if (Object_file[0] == 0) Object_file = Input_file; return 0; } }
/* * disk_update_instance - This updates an object that had previously been * reserved with the acutal contents. * return: NO_ERROR if successful, error code otherwise * classop(in): class object * obj(in): description of object * oid(in): destination oid */ int disk_update_instance (MOP classop, DESC_OBJ * obj, OID * oid) { int error = NO_ERROR; HFID *hfid; int newsize; bool has_indexes = false, oldflag; Diskrec->length = 0; if (desc_obj_to_disk (obj, Diskrec, &has_indexes)) { /* make the record larger */ newsize = -Diskrec->length + DB_PAGESIZE; free_recdes (Diskrec); Diskrec = alloc_recdes (newsize); /* try one more time */ if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0) { error = ER_LDR_CANT_TRANSFORM; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0); } } if (!error) { hfid = get_class_heap (classop, obj->class_); if (hfid == NULL) { error = er_errid (); } else if (heap_update (NULL, hfid, oid, Diskrec, &oldflag, NULL) != oid) { error = er_errid (); } else { if (oldflag) { fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING)); } else if (has_indexes) { error = update_indexes (WS_OID (classop), oid, Diskrec); } } } return (error); }
/* * otable_reserve - This is used to reserve an element for this instance id. * return: NO_ERROR if successful, error code otherwise * table(out): class table * instance(in): instance OID * id(in): instance id * Note: * This is exactly the same as otable_insert except that the * instance element is flagged with INST_FLAG_RESERVED. */ int otable_reserve (CLASS_TABLE * table, OID * instance, int id) { int error = NO_ERROR; INST_INFO *inst; if (id >= table->count) { error = grow_instance_table (table, id); } if (error == NO_ERROR) { inst = &table->instances[id]; if (inst->flags) { /* should pass in an appropriate stream here */ if (inst->flags & INST_FLAG_INSERTED) fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INSTANCE_DEFINED), id, db_get_class_name (table->class_)); else fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INSTANCE_RESERVED), id, db_get_class_name (table->class_)); } else { inst->oid = *instance; inst->flags = INST_FLAG_RESERVED; } } return error; }
/* * get_class_mops - Get the list of mops of specified classes * return: error code * class_names(in): the names of the classes * num_class(in): the number of classes * class_list(out): pointer to returned list of mops * num_class_list(out): pointer to returned number of mops */ static int get_class_mops (char **class_names, int num_class, MOP ** class_list, int *num_class_list) { int i, status = NO_ERROR; char downcase_class_name[SM_MAX_IDENTIFIER_LENGTH]; DB_OBJECT *class_ = NULL; if (class_names == NULL || num_class <= 0 || class_list == NULL || num_class_list == NULL) { return ER_FAILED; } *num_class_list = 0; *class_list = (DB_OBJECT **) malloc (DB_SIZEOF (DB_OBJECT *) * (num_class)); if (*class_list == NULL) { return ER_FAILED; } for (i = 0; i < num_class; ++i) { (*class_list)[i] = NULL; } for (i = 0; i < num_class; i++) { if (class_names[i] == NULL || strlen (class_names[i]) == 0) { status = ER_FAILED; goto error; } sm_downcase_name (class_names[i], downcase_class_name, SM_MAX_IDENTIFIER_LENGTH); class_ = locator_find_class (downcase_class_name); if (class_ != NULL) { (*class_list)[(*num_class_list)] = class_; (*num_class_list)++; } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_CLASS), downcase_class_name); printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_INVALID_CLASS)); } } return status; error: if (*class_list) { free (*class_list); *class_list = NULL; } if (num_class_list) { *num_class_list = 0; } return status; }
/* * ldr_exec_query_from_file - execute queries from file * return: 0 if successful, non-zero otherwise * file_name(in): file path * file(in): FILE * * start_line(in): start line * commit_period(in): commit period */ static int ldr_exec_query_from_file (const char *file_name, FILE * input_stream, int *start_line, int commit_period) { DB_SESSION *session = NULL; DB_QUERY_RESULT *res = NULL; int error = 0; int stmt_cnt, stmt_id = 0, stmt_type; int executed_cnt = 0; int parser_start_line_no; int parser_end_line_no = 1; int check_line_no = true; if ((*start_line) > 1) { int line_count = *start_line - 1; do { int c = fgetc (input_stream); if (c == EOF) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UNREACHABLE_LINE), file_name, *start_line); error = ER_GENERIC_ERROR; goto end; } else if (c == '\n') { line_count--; } } while (line_count > 0); } check_line_no = false; session = db_make_session_for_one_statement_execution (input_stream); if (session == NULL) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); error = er_errid (); goto end; } util_arm_signal_handlers (&ldr_exec_query_interrupt_handler, &ldr_exec_query_interrupt_handler); while (1) { if (interrupt_query) { if (er_errid () != ER_INTERRUPTED) { er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_INTERRUPTED, 0); } error = er_errid (); db_close_session (session); goto end; } parser_start_line_no = parser_end_line_no; stmt_cnt = db_parse_one_statement (session); if (stmt_cnt > 0) { db_get_parser_line_col (session, &parser_end_line_no, NULL); stmt_id = db_compile_statement (session); } if (stmt_cnt <= 0 || stmt_id <= 0) { DB_SESSION_ERROR *session_error; int line, col; if ((session_error = db_get_errors (session)) != NULL) { do { session_error = db_get_next_error (session_error, &line, &col); if (line >= 0) { print_log_msg (1, "In %s line %d,\n", file_name, line + (*start_line)); print_log_msg (1, "ERROR: %s \n", db_error_string (3)); error = er_errid (); } } while (session_error); } db_close_session (session); break; } stmt_type = db_get_statement_type (session, stmt_id); res = (DB_QUERY_RESULT *) NULL; error = db_execute_statement (session, stmt_id, &res); if (error < 0) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); db_close_session (session); break; } executed_cnt++; error = db_query_end (res); if (error < 0) { print_log_msg (1, "ERROR: %s\n", db_error_string (3)); db_close_session (session); break; } if (stmt_type == CUBRID_STMT_COMMIT_WORK || (commit_period && (executed_cnt % commit_period == 0))) { db_commit_transaction (); print_log_msg (Verbose_commit, "%8d statements executed. Commit transaction at line %d\n", executed_cnt, parser_end_line_no); *start_line = parser_end_line_no + 1; } print_log_msg ((int) Verbose, "Total %8d statements executed.\r", executed_cnt); fflush (stdout); } end: if (error < 0) { db_abort_transaction (); } else { *start_line = parser_end_line_no + 1; print_log_msg (1, "Total %8d statements executed.\n", executed_cnt); fflush (stdout); db_commit_transaction (); } return error; }
/* * logwr_archive_active_log - * * return: * Note: */ static int logwr_archive_active_log (void) { char archive_name[PATH_MAX] = { '\0' }, archive_name_first[PATH_MAX]; LOG_PAGE *arvhdr_pgptr = NULL; struct log_arv_header *arvhdr; char log_pgbuf[IO_MAX_PAGE_SIZE * LOGPB_IO_NPAGES + MAX_ALIGNMENT]; char *aligned_log_pgbuf; LOG_PAGE *log_pgptr = NULL; LOG_PAGE *malloc_arv_hdr_pgptr = NULL; PAGEID pageid, ar_phy_pageid = NULL_PAGEID, phy_pageid = NULL_PAGEID; int vdes = NULL_VOLDES; int i, first_arv_num_to_delete, last_arv_num_to_delete; int error_code; int num_pages = 0; const char *info_reason, *catmsg; BACKGROUND_ARCHIVING_INFO *bg_arv_info; aligned_log_pgbuf = PTR_ALIGN (log_pgbuf, MAX_ALIGNMENT); if ((logwr_Gl.last_arv_num - logwr_Gl.last_deleted_arv_num) > PRM_LOG_MAX_ARCHIVES) { er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_LOG_MAX_ARCHIVES_HAS_BEEN_EXCEEDED, 1, PRM_LOG_MAX_ARCHIVES); /* Remove the log archives at this point */ first_arv_num_to_delete = logwr_Gl.last_deleted_arv_num + 1; last_arv_num_to_delete = logwr_Gl.last_arv_num - PRM_LOG_MAX_ARCHIVES; last_arv_num_to_delete--; for (i = first_arv_num_to_delete; i <= last_arv_num_to_delete; i++) { fileio_make_log_archive_name (archive_name, logwr_Gl.log_path, logwr_Gl.db_name, i); fileio_unformat (NULL, archive_name); logwr_Gl.last_deleted_arv_num = last_arv_num_to_delete; } info_reason = msgcat_message (MSGCAT_CATALOG_CUBRID, MSGCAT_SET_LOG, MSGCAT_LOG_MAX_ARCHIVES_HAS_BEEN_EXCEEDED); if (info_reason == NULL) { info_reason = "Number of active log archives has been exceeded" " the max desired number."; } catmsg = msgcat_message (MSGCAT_CATALOG_CUBRID, MSGCAT_SET_LOG, MSGCAT_LOG_LOGINFO_REMOVE_REASON); if (catmsg == NULL) { catmsg = "REMOVE: %d %s to \n%d %s.\nREASON: %s\n"; } if (first_arv_num_to_delete == last_arv_num_to_delete) { log_dump_log_info (logwr_Gl.loginf_path, false, catmsg, first_arv_num_to_delete, archive_name, last_arv_num_to_delete, archive_name, info_reason); } else { fileio_make_log_archive_name (archive_name_first, logwr_Gl.log_path, logwr_Gl.db_name, first_arv_num_to_delete); log_dump_log_info (logwr_Gl.loginf_path, false, catmsg, first_arv_num_to_delete, archive_name_first, last_arv_num_to_delete, archive_name, info_reason); } /* ignore error from log_dump_log_info() */ /* It will continue.... */ } /* Create the archive header page */ malloc_arv_hdr_pgptr = (LOG_PAGE *) malloc (LOG_PAGESIZE); if (malloc_arv_hdr_pgptr == NULL) { error_code = ER_OUT_OF_VIRTUAL_MEMORY; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, LOG_PAGESIZE); goto error; } malloc_arv_hdr_pgptr->hdr.logical_pageid = LOGPB_HEADER_PAGE_ID; malloc_arv_hdr_pgptr->hdr.offset = NULL_OFFSET; /* Construct the archive log header */ arvhdr = (struct log_arv_header *) malloc_arv_hdr_pgptr->area; strncpy (arvhdr->magic, CUBRID_MAGIC_LOG_ARCHIVE, CUBRID_MAGIC_MAX_LENGTH); arvhdr->db_creation = logwr_Gl.hdr.db_creation; arvhdr->next_trid = NULL_TRANID; arvhdr->fpageid = logwr_Gl.last_arv_fpageid; arvhdr->arv_num = logwr_Gl.last_arv_num; arvhdr->npages = logwr_Gl.last_arv_lpageid - arvhdr->fpageid + 1; /* * Now create the archive and start copying pages */ fileio_make_log_archive_name (archive_name, logwr_Gl.log_path, logwr_Gl.db_name, arvhdr->arv_num); bg_arv_info = &logwr_Gl.bg_archive_info; if (PRM_LOG_BACKGROUND_ARCHIVING && bg_arv_info->vdes != NULL_VOLDES) { vdes = bg_arv_info->vdes; } else { if (fileio_is_volume_exist (archive_name) == true) { vdes = fileio_mount (NULL, archive_name, archive_name, LOG_DBLOG_ARCHIVE_VOLID, true, false); if (vdes == NULL_VOLDES) { error_code = ER_IO_MOUNT_FAIL; goto error; } } else { vdes = fileio_format (NULL, logwr_Gl.db_name, archive_name, LOG_DBLOG_ARCHIVE_VOLID, arvhdr->npages + 1, false, false, false, LOG_PAGESIZE); if (vdes == NULL_VOLDES) { /* Unable to create archive log to archive */ error_code = ER_LOG_CREATE_LOGARCHIVE_FAIL; er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOG_CREATE_LOGARCHIVE_FAIL, 3, archive_name, arvhdr->fpageid, arvhdr->fpageid + arvhdr->npages - 1); goto error; } } } if (fileio_write (NULL, vdes, malloc_arv_hdr_pgptr, 0, LOG_PAGESIZE) == NULL) { /* Error archiving header page into archive */ error_code = ER_LOG_WRITE; er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOG_WRITE, 3, 0, 0, archive_name); goto error; } if (PRM_LOG_BACKGROUND_ARCHIVING && bg_arv_info->vdes != NULL_VOLDES && logwr_Gl.last_arv_fpageid == bg_arv_info->start_page_id) { pageid = bg_arv_info->current_page_id; ar_phy_pageid = (bg_arv_info->current_page_id - bg_arv_info->start_page_id + 1); } else { pageid = logwr_Gl.last_arv_fpageid; ar_phy_pageid = 1; } log_pgptr = (LOG_PAGE *) aligned_log_pgbuf; /* Now start dumping the current active pages to archive */ for (; pageid <= logwr_Gl.last_arv_lpageid; pageid += num_pages, ar_phy_pageid += num_pages) { /* * Page is contained in the active log. * Find the corresponding physical page and read the page form disk. */ num_pages = MIN (LOGPB_IO_NPAGES, logwr_Gl.last_arv_lpageid - pageid + 1); phy_pageid = logwr_to_physical_pageid (pageid); num_pages = MIN (num_pages, logwr_Gl.hdr.npages - phy_pageid + 1); if (fileio_read_pages (NULL, logwr_Gl.append_vdes, (char *) log_pgptr, phy_pageid, num_pages, LOG_PAGESIZE) == NULL) { error_code = ER_LOG_READ; er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOG_READ, 3, pageid, phy_pageid, logwr_Gl.active_name); goto error; } else { if (log_pgptr->hdr.logical_pageid != pageid) { /* Clean the buffer... since it may be corrupted */ error_code = ER_LOG_PAGE_CORRUPTED; er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOG_PAGE_CORRUPTED, 1, pageid); goto error; } } if (fileio_write_pages (NULL, vdes, (char *) log_pgptr, ar_phy_pageid, num_pages, LOG_PAGESIZE) == NULL) { error_code = ER_LOG_WRITE; er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOG_WRITE, 3, pageid, ar_phy_pageid, archive_name); goto error; } } fileio_dismount (NULL, vdes); vdes = NULL_VOLDES; if (PRM_LOG_BACKGROUND_ARCHIVING && bg_arv_info->vdes != NULL_VOLDES) { bg_arv_info->vdes = NULL_VOLDES; if (fileio_rename (NULL_VOLID, logwr_Gl.bg_archive_name, archive_name) == NULL) { goto error; } bg_arv_info->vdes = fileio_format (NULL, logwr_Gl.db_name, logwr_Gl.bg_archive_name, LOG_DBLOG_BG_ARCHIVE_VOLID, logwr_Gl.hdr.npages, false, false, false, LOG_PAGESIZE); if (bg_arv_info->vdes != NULL_VOLDES) { bg_arv_info->start_page_id = logwr_Gl.hdr.nxarv_pageid; bg_arv_info->current_page_id = logwr_Gl.hdr.nxarv_pageid; } else { bg_arv_info->start_page_id = NULL_PAGEID; bg_arv_info->current_page_id = NULL_PAGEID; er_log_debug (ARG_FILE_LINE, "Unable to create temporary archive log %s\n", logwr_Gl.bg_archive_name); } } /* Update archive info */ logwr_Gl.last_arv_num++; logwr_Gl.last_arv_fpageid = logwr_Gl.last_arv_lpageid + 1; /* Flush the log header to reflect the archive */ logwr_flush_header_page (); er_set (ER_NOTIFICATION_SEVERITY, ARG_FILE_LINE, ER_LOG_ARCHIVE_CREATED, 3, archive_name, arvhdr->fpageid, arvhdr->fpageid + arvhdr->npages - 1); catmsg = msgcat_message (MSGCAT_CATALOG_CUBRID, MSGCAT_SET_LOG, MSGCAT_LOG_LOGINFO_ARCHIVE); if (catmsg == NULL) { catmsg = "ARCHIVE: %d %s %d %d\n"; } error_code = log_dump_log_info (logwr_Gl.loginf_path, false, catmsg, arvhdr->arv_num, archive_name, arvhdr->fpageid, arvhdr->fpageid + arvhdr->npages - 1); er_log_debug (ARG_FILE_LINE, "logwr_archive_active_log, arv_num(%d), fpageid(%d) lpageid(%d)\n", arvhdr->arv_num, arvhdr->fpageid, arvhdr->fpageid + arvhdr->npages - 1); free_and_init (malloc_arv_hdr_pgptr); return NO_ERROR; error: if (malloc_arv_hdr_pgptr != NULL) { free_and_init (malloc_arv_hdr_pgptr); } if (vdes != NULL_VOLDES) { fileio_dismount (NULL, vdes); fileio_unformat (NULL, archive_name); } return error_code; }
/* * utility_get_generic_message() - get a string of the generic-utility from the catalog * return: message string * message_index(in): an index of the message string */ const char * utility_get_generic_message (int message_index) { return (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_GENERIC, message_index)); }
/* * compactdb_start - Compact classes * return: error code * verbose_flag(in): * delete_old_repr_flag(in): delete old class representations from catalog * input_filename(in): classes file name * input_class_names(in): classes list * input_class_length(in): classes list length * max_processed_space(in): maximum space to process for one iteration */ static int compactdb_start (bool verbose_flag, bool delete_old_repr_flag, char *input_filename, char **input_class_names, int input_class_length, int max_processed_space, int instance_lock_timeout, int class_lock_timeout, DB_TRAN_ISOLATION tran_isolation) { int status = NO_ERROR; OID **class_oids = NULL, *next_oid = NULL; int i, num_classes = 0; LIST_MOPS *class_table = NULL; OID last_processed_class_oid, last_processed_oid; int *total_objects = NULL, *iteration_total_objects = NULL; int *failed_objects = NULL, *iteration_failed_objects = NULL; int *modified_objects = NULL, *iteration_modified_objects = NULL; char *incomplete_processing = NULL; int *big_objects = NULL, *iteration_big_objects = NULL; int *initial_last_repr = NULL; MOP *class_mops = NULL; int last_completed_class_index, temp_index; int num_class_mops = 0; SM_CLASS *class_ptr = NULL; int num_classes_fully_compacted = 0; char *class_name = NULL; MOP *processed_class_mops = NULL; if (input_filename && input_class_names && input_class_length > 0) { return ER_FAILED; } status = compact_db_start (); if (status != NO_ERROR) { if (status == ER_COMPACTDB_ALREADY_STARTED) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_ALREADY_STARTED)); } return ER_FAILED; } tran_reset_wait_times ((float) class_lock_timeout); if (input_class_names && input_class_length > 0) { status = get_class_mops (input_class_names, input_class_length, &class_mops, &num_class_mops); if (status != NO_ERROR) { goto error; } } else if (input_filename) { status = get_class_mops_from_file (input_filename, &class_mops, &num_class_mops); if (status != NO_ERROR) { goto error; } } else { class_table = locator_get_all_mops (sm_Root_class_mop, DB_FETCH_QUERY_READ); if (!class_table) { status = ER_FAILED; goto error; } class_mops = class_table->mops; num_class_mops = class_table->num; } class_oids = (OID **) malloc (DB_SIZEOF (OID *) * (num_class_mops)); if (class_oids == NULL) { status = ER_FAILED; goto error; } for (i = 0; i < num_class_mops; i++) { class_oids[i] = NULL; } processed_class_mops = (DB_OBJECT **) malloc (DB_SIZEOF (DB_OBJECT *) * (num_class_mops)); if (processed_class_mops == NULL) { status = ER_FAILED; goto error; } for (i = 0; i < num_class_mops; i++) { processed_class_mops[i] = NULL; } num_classes = 0; for (i = 0; i < num_class_mops; i++) { ws_find (class_mops[i], (MOBJ *) & class_ptr); if (class_ptr == NULL) { continue; } if (class_ptr->class_type != SM_CLASS_CT) { continue; } class_oids[num_classes] = ws_oid (class_mops[i]); if (class_oids[num_classes] != NULL) { processed_class_mops[num_classes] = class_mops[i]; num_classes++; } } if (num_classes == 0) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_NOTHING_TO_PROCESS)); goto error; } total_objects = (int *) malloc (num_classes * sizeof (int)); if (total_objects == NULL) { status = ER_FAILED; goto error; } iteration_total_objects = (int *) malloc (num_classes * sizeof (int)); if (iteration_total_objects == NULL) { status = ER_FAILED; goto error; } failed_objects = (int *) malloc (num_classes * sizeof (int)); if (failed_objects == NULL) { status = ER_FAILED; goto error; } iteration_failed_objects = (int *) malloc (num_classes * sizeof (int)); if (iteration_failed_objects == NULL) { status = ER_FAILED; goto error; } modified_objects = (int *) malloc (num_classes * sizeof (int)); if (modified_objects == NULL) { status = ER_FAILED; goto error; } iteration_modified_objects = (int *) malloc (num_classes * sizeof (int)); if (iteration_modified_objects == NULL) { status = ER_FAILED; goto error; } big_objects = (int *) malloc (num_classes * sizeof (int)); if (big_objects == NULL) { status = ER_FAILED; goto error; } iteration_big_objects = (int *) malloc (num_classes * sizeof (int)); if (iteration_big_objects == NULL) { status = ER_FAILED; goto error; } initial_last_repr = (int *) malloc (num_classes * sizeof (int)); if (initial_last_repr == NULL) { status = ER_FAILED; goto error; } incomplete_processing = (char *) malloc (num_classes * sizeof (char)); if (incomplete_processing == NULL) { status = ER_FAILED; goto error; } for (i = 0; i < num_classes; i++) { total_objects[i] = 0; failed_objects[i] = 0; modified_objects[i] = 0; big_objects[i] = 0; incomplete_processing[i] = 0; initial_last_repr[i] = NULL_REPRID; } for (i = 0; i < num_class_mops; i++) { status = locator_flush_all_instances (class_mops[i], true); if (status != NO_ERROR) { goto error; } } status = db_commit_transaction (); if (status != NO_ERROR) { goto error; } COPY_OID (&last_processed_class_oid, class_oids[0]); OID_SET_NULL (&last_processed_oid); temp_index = -1; last_completed_class_index = -1; if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_PASS1)); } while (true) { status = db_set_isolation (tran_isolation); if (status != NO_ERROR) { if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_ISOLATION_LEVEL_FAILURE)); } status = ER_FAILED; goto error; } status = boot_compact_classes (class_oids, num_classes, max_processed_space, instance_lock_timeout * 1000, class_lock_timeout * 1000, delete_old_repr_flag, &last_processed_class_oid, &last_processed_oid, iteration_total_objects, iteration_failed_objects, iteration_modified_objects, iteration_big_objects, initial_last_repr); if (OID_ISNULL (&last_processed_class_oid)) { temp_index = num_classes; } else { temp_index = find_oid (&last_processed_class_oid, class_oids, num_classes); } switch (status) { case NO_ERROR: if (delete_old_repr_flag && temp_index - 1 > last_completed_class_index) { for (i = last_completed_class_index + 1; i < temp_index; i++) { if (initial_last_repr[i] == COMPACTDB_REPR_DELETED) { sm_destroy_representations (processed_class_mops[i]); } } } status = db_commit_transaction (); if (status != NO_ERROR) { goto error; } break; case ER_LK_UNILATERALLY_ABORTED: status = tran_abort_only_client (false); if (status != NO_ERROR) { goto error; } break; case ER_FAILED: status = db_abort_transaction (); if (status != NO_ERROR) { goto error; } break; default: db_abort_transaction (); status = ER_FAILED; goto error; } for (i = 0; i < num_classes; i++) { if (iteration_total_objects[i] >= 0) { total_objects[i] += iteration_total_objects[i]; failed_objects[i] += iteration_failed_objects[i]; modified_objects[i] += iteration_modified_objects[i]; big_objects[i] += iteration_big_objects[i]; } else { incomplete_processing[i] = iteration_total_objects[i]; } } if (temp_index - 1 > last_completed_class_index) { for (i = last_completed_class_index + 1; i < temp_index; i++) { status = db_set_isolation (tran_isolation); if (status != NO_ERROR) { if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_ISOLATION_LEVEL_FAILURE)); } status = ER_FAILED; goto error; } tran_reset_wait_times ((float) class_lock_timeout); show_statistics (class_oids[i], incomplete_processing[i] != COMPACTDB_LOCKED_CLASS, incomplete_processing[i] != COMPACTDB_INVALID_CLASS, incomplete_processing[i] != COMPACTDB_UNPROCESSED_CLASS, total_objects[i], failed_objects[i], modified_objects[i], big_objects[i], delete_old_repr_flag, initial_last_repr[i] == COMPACTDB_REPR_DELETED); db_commit_transaction (); } last_completed_class_index = temp_index - 1; } if (OID_ISNULL (&last_processed_class_oid)) { break; } } if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_PASS2)); } status = do_reclaim_addresses (class_oids, num_classes, &num_classes_fully_compacted, verbose_flag, (float) class_lock_timeout); if (status != NO_ERROR) { goto error; } if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_PASS3)); } for (i = 0; i < num_classes; i++) { status = db_set_isolation (tran_isolation); if (status != NO_ERROR) { if (verbose_flag) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_ISOLATION_LEVEL_FAILURE)); } status = ER_FAILED; goto error; } tran_reset_wait_times ((float) class_lock_timeout); status = boot_heap_compact (class_oids[i]); switch (status) { case NO_ERROR: status = db_commit_transaction (); if (status != NO_ERROR) { goto error; } break; case ER_LK_UNILATERALLY_ABORTED: status = tran_abort_only_client (false); if (status != NO_ERROR) { goto error; } break; default: status = db_abort_transaction (); if (status != NO_ERROR) { goto error; } break; } class_name = get_name_from_class_oid (class_oids[i]); if (class_name == NULL) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_UNKNOWN_CLASS_NAME)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_CLASS), class_name); } if (status != NO_ERROR) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_HEAP_COMPACT_FAILED)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_HEAP_COMPACT_SUCCEEDED)); } if (class_name) { free (class_name); class_name = NULL; } db_commit_transaction (); } error: if (class_oids) { free_and_init (class_oids); } if (processed_class_mops) { free_and_init (processed_class_mops); } if (total_objects) { free_and_init (total_objects); } if (iteration_total_objects) { free_and_init (iteration_total_objects); } if (failed_objects) { free_and_init (failed_objects); } if (iteration_failed_objects) { free_and_init (iteration_failed_objects); } if (modified_objects) { free_and_init (modified_objects); } if (iteration_modified_objects) { free_and_init (iteration_modified_objects); } if (big_objects) { free_and_init (big_objects); } if (iteration_big_objects) { free_and_init (iteration_big_objects); } if (initial_last_repr) { free_and_init (initial_last_repr); } if (incomplete_processing) { free_and_init (incomplete_processing); } if (class_table) { locator_free_list_mops (class_table); } else { if (class_mops) { for (i = 0; i < num_class_mops; i++) { class_mops[i] = NULL; } free_and_init (class_mops); } } compact_db_stop (); return status; }
/* * disk_update_instance_using_mobj - updates an object that had previously * been reserved with the acutal contents. * return: NO_ERROR if successful, error code otherwise * classop(in): class object * classobj(in): class memory object * obj(in): object memory. * oid(in): oid of the destination */ int disk_update_instance_using_mobj (MOP classop, MOBJ classobj, MOBJ obj, OID * oid) { int error = NO_ERROR; HFID *hfid; bool has_indexes = false; volatile int newsize = 0; bool oldflag; TF_STATUS tf_status = TF_SUCCESS; Diskrec->length = 0; /* * tf_mem_to_disk() is used to get an estimate of the disk space requirements * for the object. When dealing with collections the estimate returned is * not always a good one, hence we need to enclose this block in a loop * increasing the space by increments of DB_PAGESIZE until we hit the correct * space requirement. */ while ((tf_status = tf_mem_to_disk (classop, classobj, obj, Diskrec, &has_indexes)) == TF_OUT_OF_SPACE) { /* make the record larger */ if (newsize) { newsize += DB_PAGESIZE; } else { newsize = -Diskrec->length + DB_PAGESIZE; } free_recdes (Diskrec); Diskrec = alloc_recdes (newsize); if (Diskrec == NULL) { error = er_errid (); break; } } if (tf_status != TF_SUCCESS) { error = ER_LDR_CANT_TRANSFORM; er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0); } if (error == NO_ERROR && Diskrec != NULL) { hfid = get_class_heap (classop, (SM_CLASS *) classop->object); if (hfid == NULL) { error = er_errid (); } else if (heap_update (NULL, hfid, oid, Diskrec, &oldflag, NULL) != oid) { error = er_errid (); } else { if (oldflag) { fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING)); } else if (has_indexes) { error = update_indexes (WS_OID (classop), oid, Diskrec); } } } return (error); }
static int do_reclaim_addresses (const OID ** const class_oids, const int num_class_oids, int *const num_classes_fully_processed, const bool verbose, const float class_lock_timeout) { bool any_class_can_be_referenced = false; int i = 0; int error_code = NO_ERROR; assert (num_class_oids >= 0); assert (class_oids != NULL); assert (num_classes_fully_processed != NULL); *num_classes_fully_processed = 0; tran_reset_wait_times (class_lock_timeout); for (i = 0; i < num_class_oids; ++i) { char *class_name = NULL; int error_while_processing = NO_ERROR; bool correctly_processed = false; bool addresses_reclaimed = false; error_code = do_reclaim_class_addresses (*class_oids[i], &class_name, &any_class_can_be_referenced, &correctly_processed, &addresses_reclaimed, &error_while_processing); if (correctly_processed) { assert (error_code == NO_ERROR); assert (error_while_processing == NO_ERROR); (*num_classes_fully_processed)++; } if (verbose) { if (class_name == NULL || strlen (class_name) == 0) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_UNKNOWN_CLASS_NAME)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_CLASS), class_name); } if (correctly_processed) { if (addresses_reclaimed) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_RECLAIMED)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_RECLAIM_SKIPPED)); } } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_RECLAIM_ERROR)); } } if (class_name != NULL) { free_and_init (class_name); } if (error_code != NO_ERROR) { goto error_exit; } } return error_code; error_exit: return error_code; }
/* * compactdb - compactdb main routine * return: 0 if successful, error code otherwise * arg(in): a map of command line arguments */ int compactdb (UTIL_FUNCTION_ARG * arg) { UTIL_ARG_MAP *arg_map = arg->arg_map; const char *exec_name = arg->command_name; int error; int i, status = 0; const char *database_name; bool verbose_flag = 0, delete_old_repr_flag = 0; char *input_filename = NULL; DB_OBJECT **req_class_table = NULL; LIST_MOPS *all_class_table = NULL; int maximum_processed_space = 10 * DB_PAGESIZE, pages; int instance_lock_timeout, class_lock_timeout; char **tables = NULL; int table_size = 0; database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0); verbose_flag = utility_get_option_bool_value (arg_map, COMPACT_VERBOSE_S); input_filename = utility_get_option_string_value (arg_map, COMPACT_INPUT_CLASS_FILE_S, 0); pages = utility_get_option_int_value (arg_map, COMPACT_PAGES_COMMITED_ONCE_S); if (pages < COMPACT_MIN_PAGES || pages > COMPACT_MAX_PAGES) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_PAGES), COMPACT_MIN_PAGES, COMPACT_MAX_PAGES); return ER_GENERIC_ERROR; } if (database_name == NULL || database_name[0] == '\0' || utility_get_option_string_table_size (arg_map) < 1) { compactdb_usage (arg->argv0); return ER_GENERIC_ERROR; } table_size = utility_get_option_string_table_size (arg_map); if (table_size > 1 && input_filename != NULL) { compactdb_usage (arg->argv0); return ER_GENERIC_ERROR; } instance_lock_timeout = utility_get_option_int_value (arg_map, COMPACT_INSTANCE_LOCK_TIMEOUT_S); if (instance_lock_timeout < COMPACT_INSTANCE_MIN_LOCK_TIMEOUT || instance_lock_timeout > COMPACT_INSTANCE_MAX_LOCK_TIMEOUT) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_INSTANCE_LOCK_TIMEOUT), COMPACT_INSTANCE_MIN_LOCK_TIMEOUT, COMPACT_INSTANCE_MAX_LOCK_TIMEOUT); return ER_GENERIC_ERROR; } class_lock_timeout = utility_get_option_int_value (arg_map, COMPACT_CLASS_LOCK_TIMEOUT_S); if (class_lock_timeout < COMPACT_CLASS_MIN_LOCK_TIMEOUT || class_lock_timeout > COMPACT_CLASS_MAX_LOCK_TIMEOUT) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_OUT_OF_RANGE_CLASS_LOCK_TIMEOUT), COMPACT_CLASS_MIN_LOCK_TIMEOUT, COMPACT_CLASS_MAX_LOCK_TIMEOUT); return ER_GENERIC_ERROR; } delete_old_repr_flag = utility_get_option_bool_value (arg_map, COMPACT_DELETE_OLD_REPR_S); maximum_processed_space = pages * DB_PAGESIZE; if (table_size > 1) { tables = (char **) malloc (sizeof (char *) * table_size - 1); for (i = 1; i < table_size; i++) { tables[i - 1] = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, i); } } sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no"); AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); if ((error = db_login ("dba", NULL)) || (error = db_restart (arg->argv0, TRUE, database_name))) { fprintf (stderr, "%s: %s.\n\n", exec_name, db_error_string (3)); status = error; } else { status = db_set_isolation (TRAN_REP_CLASS_UNCOMMIT_INSTANCE); if (status == NO_ERROR) { status = compactdb_start (verbose_flag, delete_old_repr_flag, input_filename, tables, table_size - 1, maximum_processed_space, instance_lock_timeout, class_lock_timeout, TRAN_REP_CLASS_UNCOMMIT_INSTANCE); if (status == ER_FAILED) { fprintf (stderr, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILURE)); } } db_shutdown (); } if (tables) { free (tables); tables = NULL; } return status; }
/* * process_value () - process a value * * return : error status * value(in,out) - the processed value * */ static int process_value (DB_VALUE * value) { int return_value = 0; switch (DB_VALUE_TYPE (value)) { case DB_TYPE_OID: { OID *ref_oid; OID ref_class_oid; ref_oid = DB_GET_OID (value); if (OID_ISNULL (ref_oid)) { break; } if (!heap_get_class_oid (NULL, ref_oid, &ref_class_oid)) { OID_SET_NULL (ref_oid); return_value = 1; break; } if (is_class (ref_oid, &ref_class_oid)) { break; } #if defined(CUBRID_DEBUG) printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_REFOID), ref_oid->volid, ref_oid->pageid, ref_oid->slotid, ref_class_oid.volid, ref_class_oid.pageid, ref_class_oid.slotid); #endif if (!heap_does_exist (NULL, ref_oid, &ref_class_oid)) { OID_SET_NULL (ref_oid); return_value = 1; } break; } case DB_TYPE_POINTER: case DB_TYPE_MULTISET: case DB_TYPE_SEQUENCE: case DB_TYPE_SET: { return_value = process_set (DB_GET_SET (value)); break; } default: break; } return return_value; }
/* * loaddb_internal - internal main loaddb function * return: NO_ERROR if successful, error code otherwise * argc(in): argc of main * argv(in): argv of main * dba_mode(in): */ static int loaddb_internal (UTIL_FUNCTION_ARG * arg, int dba_mode) { UTIL_ARG_MAP *arg_map = arg->arg_map; int error = NO_ERROR; /* set to static to avoid copiler warning (clobbered by longjump) */ static FILE *schema_file = NULL; static FILE *index_file = NULL; static FILE *object_file = NULL; FILE *error_file = NULL; int status = 0; int errors, objects, defaults; #if !defined (LDR_OLD_LOADDB) int lastcommit = 0; #endif /* !LDR_OLD_LOADDB */ char *passwd; /* set to static to avoid copiler warning (clobbered by longjump) */ static int interrupted = false; int au_save = 0; extern bool obt_Enable_autoincrement; char log_file_name[PATH_MAX]; LOADDB_INIT_DEBUG (); obt_Enable_autoincrement = false; Volume = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0); Input_file = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1); User_name = utility_get_option_string_value (arg_map, LOAD_USER_S, 0); Password = utility_get_option_string_value (arg_map, LOAD_PASSWORD_S, 0); Syntax_check = utility_get_option_bool_value (arg_map, LOAD_CHECK_ONLY_S); Load_only = utility_get_option_bool_value (arg_map, LOAD_LOAD_ONLY_S); Estimated_size = utility_get_option_int_value (arg_map, LOAD_ESTIMATED_SIZE_S); Verbose = utility_get_option_bool_value (arg_map, LOAD_VERBOSE_S); Disable_statistics = utility_get_option_bool_value (arg_map, LOAD_NO_STATISTICS_S); Periodic_commit = utility_get_option_int_value (arg_map, LOAD_PERIODIC_COMMIT_S); Verbose_commit = Periodic_commit > 0 ? true : false; No_oid_hint = utility_get_option_bool_value (arg_map, LOAD_NO_OID_S); Schema_file = utility_get_option_string_value (arg_map, LOAD_SCHEMA_FILE_S, 0); Index_file = utility_get_option_string_value (arg_map, LOAD_INDEX_FILE_S, 0); Object_file = utility_get_option_string_value (arg_map, LOAD_DATA_FILE_S, 0); Error_file = utility_get_option_string_value (arg_map, LOAD_ERROR_CONTROL_FILE_S, 0); Ignore_logging = utility_get_option_bool_value (arg_map, LOAD_IGNORE_LOGGING_S); #if !defined (LDR_OLD_LOADDB) Ignore_class_file = utility_get_option_string_value (arg_map, LOAD_IGNORE_CLASS_S, 0); #endif Input_file = Input_file ? Input_file : ""; Schema_file = Schema_file ? Schema_file : ""; Index_file = Index_file ? Index_file : ""; Object_file = Object_file ? Object_file : ""; Error_file = Error_file ? Error_file : ""; if (ldr_validate_object_file (stderr, arg->argv0)) { goto error_return; } /* error message log file */ sprintf (log_file_name, "%s_%s.err", Volume, arg->command_name); er_init (log_file_name, ER_NEVER_EXIT); if (Index_file[0] != '\0' && PRM_SR_NBUFFERS < LOAD_INDEX_MIN_SORT_BUFFER_PAGES) { sysprm_set_force (PRM_NAME_SR_NBUFFERS, LOAD_INDEX_MIN_SORT_BUFFER_PAGES_STRING); } sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no"); /* login */ if (User_name != NULL || !dba_mode) { (void) db_login (User_name, Password); if ((error = db_restart (arg->command_name, true, Volume))) { if (error == ER_AU_INVALID_PASSWORD) { /* prompt for password and try again */ error = NO_ERROR; passwd = getpass (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_PASSWORD_PROMPT)); if (!strlen (passwd)) passwd = NULL; (void) db_login (User_name, passwd); error = db_restart (arg->command_name, true, Volume); } } } else { /* if we're in the protected dba mode, just login without authorization */ AU_DISABLE_PASSWORDS (); db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY); (void) db_login ("dba", NULL); error = db_restart (arg->command_name, true, Volume); } /* open loaddb log file */ sprintf (log_file_name, "%s_loaddb.log", Volume); loaddb_log_file = fopen (log_file_name, "w+"); if (loaddb_log_file == NULL) { printf ("Cannot open log file %s\n", log_file_name); status = 2; goto error_return; } #if 0 #if !defined (LDR_OLD_LOADDB) /* Execute old loaddb if no optimization flag is set true * or LOADDB_NOPT is set, we must pass the argv except * -no option and invoke execvp() for no optimized loaddb */ if (No_optimization || envvar_get ("LOADDB_NOPT")) { char **tmp; char *lastslash, path[PATH_MAX]; int i = 1, j = 1; tmp = (char **) malloc (sizeof (char *) * (argc + 1)); tmp[0] = (char *) "loaddb"; while (j < argc) { if (!strcmp (argv[j], "-no")) j++; else tmp[i++] = argv[j++]; }; tmp[i] = 0; strcpy (path, argv[0]); lastslash = strrchr (path, (int) '/'); #if defined(WINDOWS) { char *p, exec_path[1024], cmd_line[1024 * 8]; int cp_len = 0; db_shutdown (); p = envvar_root (); if (p == NULL) { printf ("The `CUBRID' environment variable is not set.\n"); } else { sprintf (exec_path, "%s/migdb_o.exe", p); for (i = 0; tmp[i]; i++) { cp_len += sprintf (cmd_line + cp_len, "\"%s\" ", tmp[i]); } if (envvar_get ("FRONT_DEBUG") != NULL) { printf ("Executing:%s %s\n", exec_path, cmd_line); } run_proc (exec_path, cmd_line); } exit (0); } #else /* !WINDOWS */ if (lastslash != NULL) strcpy (lastslash + 1, "migdb_o"); else strcpy (path, "migdb_o"); if (execvp (path, tmp) == -1) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_NOPT_ERR)); exit (0); }; #endif /* WINDOWS */ } #endif /* !LDR_OLD_LOADDB */ #endif /* check if schema/index/object files exist */ ldr_check_file_name_and_line_no (); if (Schema_file[0] != 0) { schema_file = fopen (Schema_file, "r"); if (schema_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Schema_file); status = 2; goto error_return; } } if (Index_file[0] != 0) { index_file = fopen (Index_file, "r"); if (index_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Index_file); status = 2; goto error_return; } } if (Object_file[0] != 0) { object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Object_file); status = 2; goto error_return; } } #if !defined (LDR_OLD_LOADDB) if (Ignore_class_file) { int retval; retval = get_ignore_class_list (Ignore_class_file); if (retval < 0) { status = 2; goto error_return; } } #endif /* Disallow syntax only and load only options together */ if (Load_only && Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_LOAD_ONLY_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } if (Error_file[0] != 0) { if (Syntax_check) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INCOMPATIBLE_ARGS), "--" LOAD_ERROR_CONTROL_FILE_L, "--" LOAD_CHECK_ONLY_L); status = 1; /* parsing error */ goto error_return; } error_file = fopen_ex (Error_file, "rt"); if (error_file == NULL) { print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_BAD_INFILE), Error_file); status = 2; goto error_return; } er_filter_fileset (error_file); fclose (error_file); } /* check if no log option can be applied */ if (error || (Ignore_logging != 0 && locator_log_force_nologging () != NO_ERROR)) { /* couldn't log in */ print_log_msg (1, "%s\n", db_error_string (3)); status = 3; db_shutdown (); goto error_return; } /* change "print_key_value_on_unique_error" parameter */ sysprm_change_server_parameters ("print_key_value_on_unique_error=1"); /* if schema file is specified, do schema loading */ if (schema_file != NULL) { print_log_msg (1, "\nStart schema loading.\n"); /* * CUBRID 8.2 should be compatible with earlier versions of CUBRID. * Therefore, we do not perform user authentication when the loader * is executing by DBA group user. */ if (au_is_dba_group_member (Au_user)) { AU_DISABLE (au_save); } if (ldr_exec_query_from_file (Schema_file, schema_file, &schema_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during schema loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_SCHEMA_FILE_S, Schema_file, schema_file_start_line); goto error_return; } if (au_is_dba_group_member (Au_user)) { AU_ENABLE (au_save); } print_log_msg (1, "Schema loading from %s finished.\n", Schema_file); /* update catalog statistics */ AU_DISABLE (au_save); sm_update_all_catalog_statistics (); AU_ENABLE (au_save); print_log_msg (1, "Statistics for Catalog classes have been updated.\n\n"); db_commit_transaction (); fclose (schema_file); schema_file = NULL; } /* if index file is specified, do index creation */ if (object_file != NULL) { #if defined (SA_MODE) locator_Dont_check_foreign_key = true; #endif print_log_msg (1, "\nStart object loading.\n"); ldr_init (Verbose); /* set the flag to indicate what type of interrupts to raise * If logging has been disabled set commit flag. * If logging is enabled set abort flag. */ if (Ignore_logging) Interrupt_type = LDR_STOP_AND_COMMIT_INTERRUPT; else Interrupt_type = LDR_STOP_AND_ABORT_INTERRUPT; if (Periodic_commit) { /* register the post commit function */ #if defined(LDR_OLD_LOADDB) ldr_register_post_commit_handler (&loaddb_report_num_of_commits); #else /* !LDR_OLD_LOADDB */ ldr_register_post_commit_handler (&loaddb_report_num_of_commits, NULL); #endif /* LDR_OLD_LOADDB */ } /* Check if we need to perform syntax checking. */ if (!Load_only) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CHECKING)); do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ } else errors = 0; if (errors) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); else if (!Syntax_check) { /* now do it for real if there were no errors and we aren't doing a simple syntax check */ ldr_start (Periodic_commit); fclose (object_file); object_file = fopen_ex (Object_file, "rb"); /* keep out ^Z */ if (object_file != NULL) { print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_INSERTING)); /* make sure signals are caught */ util_arm_signal_handlers (signal_handler, signal_handler); /* register function to call and jmp environment to longjmp to * after aborting or committing. */ ldr_register_post_interrupt_handler (&loaddb_get_num_of_inserted_objects, &loaddb_jmp_buf); if (setjmp (loaddb_jmp_buf) != 0) { /* We have had an interrupt, the transaction should have * been already been aborted or committed by the loader. * If Total_objects_loaded is -1 an error occurred during * rollback or commit. */ if (Total_objects_loaded != -1) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), Total_objects_loaded); #if !defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults, &lastcommit); if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* !LDR_OLD_LOADDB */ interrupted = true; } else { do_loader_parse (object_file); #if defined(LDR_OLD_LOADDB) ldr_stats (&errors, &objects, &defaults); #else /* !LDR_OLD_LOADDB */ ldr_stats (&errors, &objects, &defaults, &lastcommit); #endif /* LDR_OLD_LOADDB */ if (errors) { #if defined(LDR_OLD_LOADDB) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_ERROR_COUNT), errors); #else /* !LDR_OLD_LOADDB */ if (lastcommit > 0) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_LAST_COMMITTED_LINE), lastcommit); #endif /* LDR_OLD_LOADDB */ /* * don't allow the transaction to be committed at * this point, note that if we ever move to a scheme * where we write directly to the heap without the * transaction context, we will have to unwind the * changes made if errors are detected ! */ db_abort_transaction (); } else { if (objects) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_OBJECT_COUNT), objects); if (defaults) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_DEFAULT_COUNT), defaults); print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); /* commit the transaction and then update statistics */ if (!db_commit_transaction ()) { if (!Disable_statistics) { if (Verbose) print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATING_STATISTICS)); if (!ldr_update_statistics ()) { /* * would it be faster to update statistics * before the first commit and just have a * single commit ? */ print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_COMMITTING)); (void) db_commit_transaction (); } } } } } } } ldr_final (); if (object_file != NULL) { fclose (object_file); object_file = NULL; } } /* create index */ if (!interrupted && index_file != NULL) { print_log_msg (1, "\nStart index loading.\n"); if (ldr_exec_query_from_file (Index_file, index_file, &index_file_start_line, Periodic_commit) != 0) { print_log_msg (1, "\nError occurred during index loading." "\nAborting current transaction..."); status = 3; db_shutdown (); print_log_msg (1, " done.\n\nRestart loaddb with '-%c %s:%d' option\n", LOAD_INDEX_FILE_S, Index_file, index_file_start_line); goto error_return; } /* update catalog statistics */ AU_DISABLE (au_save); sm_update_catalog_statistics (CT_INDEX_NAME); sm_update_catalog_statistics (CT_INDEXKEY_NAME); AU_ENABLE (au_save); print_log_msg (1, "Index loading from %s finished.\n", Index_file); db_commit_transaction (); } print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_CLOSING)); (void) db_shutdown (); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return (status); error_return: if (schema_file != NULL) fclose (schema_file); if (object_file != NULL) fclose (object_file); if (index_file != NULL) fclose (index_file); #if !defined (LDR_OLD_LOADDB) free_ignoreclasslist (); #endif return status; }
/* * show_statistics - show the statistics for specified class oids * return: * class_oid(in) : class oid * unlocked_class(in) : true if the class was not locked * valid_class(in): true if the class was valid * processed_class(in): true if the class was processed * total_objects(in): total class objects * failed_objects(in): failed class objects * modified_objects(in): modified class objects * big_objects(in): big class objects * delete_old_repr_flag: delete old representation flag * old_repr_deleted(in): old class representations removed from catalog */ static void show_statistics (OID * class_oid, bool unlocked_class, bool valid_class, bool processed_class, int total_objects, int failed_objects, int modified_objects, int big_objects, bool delete_old_repr_flag, bool old_repr_deleted) { MOP class_mop = NULL; char *temp_class_name; class_mop = db_object (class_oid); if (class_mop == NULL) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_INVALID_CLASS)); return; } temp_class_name = (char *) db_get_class_name (class_mop); if (temp_class_name == NULL || strlen (temp_class_name) == 0) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_UNKNOWN_CLASS_NAME)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_CLASS), temp_class_name); } if (!valid_class) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_INVALID_CLASS)); return; } if (!processed_class) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_PROCESS_CLASS_ERROR)); } if (!unlocked_class) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_LOCKED_CLASS)); } printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_TOTAL_OBJECTS), total_objects); printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_FAILED_OBJECTS), failed_objects); printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_MODIFIED_OBJECTS), modified_objects); printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_BIG_OBJECTS), big_objects); if (delete_old_repr_flag) { if (old_repr_deleted) { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_REPR_DELETED)); } else { printf (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_COMPACTDB, COMPACTDB_MSG_REPR_CANT_DELETE)); } } }