48 #define V9_1_LEVEL (9.1f) 49 #define V9_2_LEVEL (9.2f) 51 #define FOPEN_AND_CHECK(fp, filename, mode) \ 53 (fp) = fopen ((filename), (mode)); \ 56 printf ("file open error: %s, %d\n", (filename), errno); \ 61 #define FSEEK_AND_CHECK(fp, size, origin, filename) \ 63 if (fseek ((fp), (size), (origin)) < 0) \ 65 printf ("file seek error: %s, %d\n", (filename), errno); \ 71 #define FREAD_AND_CHECK(ptr, size, n, fp, filename) \ 73 fread ((ptr), (size), (n), (fp)); \ 74 if (ferror ((fp)) != 0) \ 76 printf ("file fread error: %s, %d\n", (filename), errno); \ 82 #define FWRITE_AND_CHECK(ptr, size, n, fp, filename) \ 84 fwrite ((ptr), (size), (n), (fp)); \ 85 if (ferror ((fp)) != 0) \ 87 printf ("file fwrite error: %s, %d\n", (filename), errno); \ 93 #define FFLUSH_AND_CHECK(fp, filename) \ 95 if (fflush ((fp)) != 0) \ 97 printf ("file fflush error: %s, %d\n", (filename), errno); \ 103 #define FCLOSE_AND_CHECK(fp, filename) \ 105 if (fclose ((fp)) != 0) \ 107 printf ("file fclose error: %s, %d\n", (filename), errno); \ 112 #define UNDO_LIST_SIZE (32) 169 char vol_info_path[PATH_MAX], vol_path[PATH_MAX];
170 FILE *vol_info_fp =
NULL;
172 char scan_format[32];
178 sprintf (scan_format,
"%%d %%%ds", (
int) (
sizeof (vol_path) - 1));
181 if (fscanf (vol_info_fp, scan_format, &volid, vol_path) != 2)
191 strcpy (logvol_path, vol_path);
203 char vol_path[PATH_MAX];
210 printf (
"Can't find log active volume path.\n");
214 hdr_page = (
LOG_PAGE *) log_io_page;
234 char vol_path[PATH_MAX];
241 printf (
"Can't found log active volume path.\n");
245 hdr_page = (
LOG_PAGE *) log_io_page;
253 printf (
"This database (%s) is already updated.\n", db_name);
259 printf (
"Cannot migrate this database: " "%s is not CUBRID 9.1 database.\n", db_name);
265 printf (
"This database (%s) was not normally terminated.\n" "Please start and shutdown with CUBRID 9.1 ," 266 "and retry migration.\n", db_name);
285 char vol_path[PATH_MAX];
292 printf (
"Can't found log active volume path.\n");
296 hdr_page = (
LOG_PAGE *) log_io_page;
320 printf (
"Can't found databases.txt.\n");
333 printf (
"Unknown database: %s\n", db_name);
351 if (sig_no == CTRL_C_EVENT)
364 #define QUERY_SIZE 1024 372 snprintf (query,
QUERY_SIZE,
"SELECT [charset] FROM [db_root]");
373 db_status =
db_execute (query, &query_result, &query_error);
407 char db_full_path[PATH_MAX];
408 int coll_need_manual_migr = 0;
414 bool db_started =
false;
418 printf (
"Usage: %s <database name>\n", argv[0]);
430 printf (
"CUBRID Migration: 9.1 to 9.2\n\n");
435 printf (
"CUBRID library version is invalid.\n" "Please upgrade to CUBRID 9.2 and retry migrate.\n");
456 goto error_undo_compat;
461 printf (
"Failed to initialize error manager.\n");
462 goto error_undo_compat;
467 goto error_undo_vol_header;
482 goto error_undo_vol_header;
488 if (db_collations !=
NULL)
491 db_collations =
NULL;
493 goto error_undo_vol_header;
496 for (i = 0; i < db_coll_cnt; i++)
501 ref_c = &(db_collations[
i]);
509 printf (
"Collation '%s' with id %d from database %s " "was not loaded by migration process\n",
511 goto error_undo_vol_header;
516 printf (
"Names of collation with id %d do not match : " "the collation loaded by migration process is '%s'; " 519 goto error_undo_vol_header;
524 printf (
"Codesets of collation '%s' with id %d do not match : " 525 "the collation loaded by migration process has codeset %d; " 528 goto error_undo_vol_header;
538 printf (
"Collation '%s' with id %d has changed : " "the collation loaded by migration process has checksum " 539 "'%s'; the collation from database %s has checksum '%s'\n", ref_c->
coll_name, ref_c->
coll_id,
541 goto error_undo_vol_header;
545 printf (
"Updating database system collations \n\n");
549 goto error_undo_vol_header;
557 printf (
"Could not update the statistics of the used pages of a volume: %s.\n",
db_error_string (3));
558 goto error_undo_vol_header;
571 goto error_undo_vol_header;
576 printf (
"\nCould not get the codeset from db_root: %s",
db_error_string (3));
577 goto error_undo_vol_header;
580 printf (
"\nMigration to CUBRID 9.2 has been successfully completed.\n");
586 error_undo_vol_header:
587 if (db_collations !=
NULL)
590 db_collations =
NULL;
599 printf (
"rollback volume header: %s\n", p->
filename);
604 printf (
"recovering volume header fails.\n");
614 printf (
"\nRecovering db_compatibility level fails.\n");
617 printf (
"\nMigration failed.\n");
625 char vol_info_path[PATH_MAX], vol_path[PATH_MAX];
626 FILE *vol_info_fp =
NULL;
628 char scan_format[32];
638 if (vol_undo_info ==
NULL)
640 fclose (vol_info_fp);
644 sprintf (scan_format,
"%%d %%%ds", (
int) (
sizeof (vol_path) - 1));
647 if (fscanf (vol_info_fp, scan_format, &volid, vol_path) != 2)
661 fclose (vol_info_fp);
675 DISK_VAR_HEADER *r92_header;
682 char *r91_aligned_buf, *r92_aligned_buf;
683 int var_field_length;
692 if (undo_page ==
NULL)
704 r92_header = (DISK_VAR_HEADER *) r92_iopage->
page;
709 r92_header->iopagesize = r91_header->
iopagesize;
710 r92_header->volid = r91_header->
volid;
711 r92_header->purpose = r91_header->
purpose;
712 r92_header->sect_npgs = r91_header->
sect_npgs;
714 r92_header->free_sects = r91_header->
free_sects;
717 r92_header->free_pages = r91_header->
free_pages;
735 memcpy (r92_header->var_fields, r91_header->
var_fields, var_field_length);
738 r92_header->used_data_npages = r92_header->used_index_npages = 0;
741 FWRITE_AND_CHECK (r92_aligned_buf,
sizeof (
char), r92_header->iopagesize, fp, vol_path);
745 printf (
"%s... done\n", vol_path);
755 char *undo_page, *undo_file_name;
760 if (new_undo_info ==
NULL)
766 free (vol_undo_info);
767 vol_undo_info = new_undo_info;
772 undo_page = (
char *) malloc (size *
sizeof (
char));
773 if (undo_page ==
NULL)
778 undo_file_name = (
char *) malloc (PATH_MAX);
779 if (undo_file_name ==
NULL)
786 strcpy (undo_file_name, vol_path);
829 free (vol_undo_info);
#define LANG_MAX_COLLATIONS
static int undo_fix_volume_header(const char *vol_path, char *undo_page, int size)
void db_set_client_type(int client_type)
#define FREAD_AND_CHECK(ptr, size, n, fp, filename)
float rel_disk_compatible(void)
int sysprm_set_force(const char *pname, const char *pvalue)
int db_login(const char *name, const char *password)
void LSA_COPY(log_lsa *plsa1, const log_lsa *plsa2)
int db_get_int(const DB_VALUE *value)
#define AU_DISABLE_PASSWORDS
static int get_codeset_from_db_root(void)
int catcls_get_db_collation(THREAD_ENTRY *thread_p, LANG_COLL_COMPAT **db_collations, int *coll_cnt)
int db_query_end(DB_QUERY_RESULT *result)
#define FCLOSE_AND_CHECK(fp, filename)
const VOLID LOG_DBLOG_ACTIVE_VOLID
static char * make_volume_header_undo_page(const char *vol_path, int size)
int check_database_name(const char *name)
int main(int argc, char *argv[])
#define PTR_ALIGN(addr, boundary)
static int check_and_fix_compat_level(const char *db_name, const char *vol_path)
int er_init(const char *msglog_filename, int exit_ask)
int db_restart(const char *program, int print_version, const char *volume)
LANG_COLLATION * lang_get_collation(const int coll_id)
static int get_db_path(const char *db_name, char *db_full_path)
#define CUBRID_MAGIC_MAX_LENGTH
const char * db_error_string(int level)
static VOLUME_UNDO_INFO * vol_undo_info
int db_abort_transaction(void)
int db_execute(const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
#define FOPEN_AND_CHECK(fp, filename, mode)
#define db_private_free(thrd, ptr)
void COMPOSE_FULL_NAME(char *buf, size_t buf_size, const char *path, const char *name)
int db_query_next_tuple(DB_QUERY_RESULT *result)
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
static int fix_volume_header(const char *vol_path)
#define FWRITE_AND_CHECK(ptr, size, n, fp, filename)
static int vol_undo_count
#define DB_CURSOR_SUCCESS
enum intl_codeset INTL_CODESET
static int undo_fix_compat_level(const char *db_path)
static int vol_undo_list_length
const char * prm_get_name(PARAM_ID prm_id)
static int fix_all_volume_header(const char *db_path)
#define FFLUSH_AND_CHECK(fp, filename)
char coll_name[COLL_NAME_SIZE]
static void free_volume_header_undo_list(void)
int db_query_get_tuple_value(DB_QUERY_RESULT *result, int index, DB_VALUE *value)
static int fix_codeset_in_active_log(const char *db_path, INTL_CODESET codeset)
void cfg_free_directory(DB_INFO *databases)
#define HFID_COPY(hfid_ptr1, hfid_ptr2)
void fileio_make_volume_info_name(char *vol_info_name_p, const char *db_full_name_p)
char coll_name[COLL_NAME_SIZE]
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)
static void intr_handler(int sig_no)
int db_commit_transaction(void)
DB_INFO * cfg_find_db_list(DB_INFO *db_info_list_p, const char *name)
static int get_active_log_vol_path(const char *db_path, char *logvol_path)