CUBRID Engine  latest
migrate.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * migrate.c :
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <signal.h>
32 #include <errno.h>
33 #include <assert.h>
34 
35 #include "dbi.h"
36 #include "porting.h"
37 #include "utility.h"
38 #include "databases_file.h"
39 #include "boot_sr.h"
40 #include "log_impl.h"
41 #include "btree.h"
42 #include "transform.h"
43 #include "message_catalog.h"
44 #include "error_manager.h"
45 #include "system_parameter.h"
46 #include "language_support.h"
47 
48 #define V9_1_LEVEL (9.1f)
49 #define V9_2_LEVEL (9.2f)
50 
51 #define FOPEN_AND_CHECK(fp, filename, mode) \
52 do { \
53  (fp) = fopen ((filename), (mode)); \
54  if ((fp) == NULL) \
55  { \
56  printf ("file open error: %s, %d\n", (filename), errno); \
57  return ER_FAILED; \
58  } \
59 } while (0)
60 
61 #define FSEEK_AND_CHECK(fp, size, origin, filename) \
62 do { \
63  if (fseek ((fp), (size), (origin)) < 0) \
64  { \
65  printf ("file seek error: %s, %d\n", (filename), errno); \
66  fclose ((fp)); \
67  return ER_FAILED; \
68  } \
69 } while (0)
70 
71 #define FREAD_AND_CHECK(ptr, size, n, fp, filename) \
72 do { \
73  fread ((ptr), (size), (n), (fp)); \
74  if (ferror ((fp)) != 0) \
75  { \
76  printf ("file fread error: %s, %d\n", (filename), errno); \
77  fclose ((fp)); \
78  return ER_FAILED; \
79  } \
80 } while (0)
81 
82 #define FWRITE_AND_CHECK(ptr, size, n, fp, filename) \
83 do { \
84  fwrite ((ptr), (size), (n), (fp)); \
85  if (ferror ((fp)) != 0) \
86  { \
87  printf ("file fwrite error: %s, %d\n", (filename), errno); \
88  fclose ((fp)); \
89  return ER_FAILED; \
90  } \
91 } while (0)
92 
93 #define FFLUSH_AND_CHECK(fp, filename) \
94 do { \
95  if (fflush ((fp)) != 0) \
96  { \
97  printf ("file fflush error: %s, %d\n", (filename), errno); \
98  fclose ((fp)); \
99  return ER_FAILED; \
100  } \
101 } while (0)
102 
103 #define FCLOSE_AND_CHECK(fp, filename) \
104 do { \
105  if (fclose ((fp)) != 0) \
106  { \
107  printf ("file fclose error: %s, %d\n", (filename), errno); \
108  return ER_FAILED; \
109  } \
110 } while (0)
111 
112 #define UNDO_LIST_SIZE (32)
113 
116 {
118  INT16 iopagesize;
119  INT16 volid;
121  INT32 sect_npgs;
122  INT32 total_sects;
123  INT32 free_sects;
125  INT32 total_pages;
126  INT32 free_pages;
132  INT64 db_creation;
133  INT32 max_npages;
134  INT32 dummy;
140  char var_fields[1];
141 };
142 
143 typedef struct
144 {
145  char *filename;
146  char *page;
149 
151 static int vol_undo_count;
153 
154 static int fix_all_volume_header (const char *db_path);
155 static int fix_volume_header (const char *vol_path);
156 static int undo_fix_volume_header (const char *vol_path, char *undo_page, int size);
157 static char *make_volume_header_undo_page (const char *vol_path, int size);
158 static void free_volume_header_undo_list (void);
159 
160 static int get_active_log_vol_path (const char *db_path, char *logvol_path);
161 static int check_and_fix_compat_level (const char *db_name, const char *vol_path);
162 static int get_db_path (const char *db_name, char *db_full_path);
163 static int fix_codeset_in_active_log (const char *db_path, INTL_CODESET codeset);
164 extern int catcls_get_db_collation (THREAD_ENTRY * thread_p, LANG_COLL_COMPAT ** db_collations, int *coll_cnt);
165 
166 static int
167 get_active_log_vol_path (const char *db_path, char *logvol_path)
168 {
169  char vol_info_path[PATH_MAX], vol_path[PATH_MAX];
170  FILE *vol_info_fp = NULL;
171  int volid = NULL_VOLID;
172  char scan_format[32];
173 
174  fileio_make_volume_info_name (vol_info_path, db_path);
175 
176  FOPEN_AND_CHECK (vol_info_fp, vol_info_path, "r");
177 
178  sprintf (scan_format, "%%d %%%ds", (int) (sizeof (vol_path) - 1));
179  while (true)
180  {
181  if (fscanf (vol_info_fp, scan_format, &volid, vol_path) != 2)
182  {
183  break;
184  }
185 
186  if (volid != LOG_DBLOG_ACTIVE_VOLID)
187  {
188  continue;
189  }
190 
191  strcpy (logvol_path, vol_path);
192  break;
193  }
194 
195  FCLOSE_AND_CHECK (vol_info_fp, vol_info_path);
196  return NO_ERROR;
197 }
198 
199 static int
200 fix_codeset_in_active_log (const char *db_path, INTL_CODESET codeset)
201 {
202  FILE *fp = NULL;
203  char vol_path[PATH_MAX];
204  LOG_HEADER *hdr;
205  LOG_PAGE *hdr_page;
206  char log_io_page[IO_MAX_PAGE_SIZE];
207 
208  if (get_active_log_vol_path (db_path, vol_path) != NO_ERROR)
209  {
210  printf ("Can't find log active volume path.\n");
211  return ER_FAILED;
212  }
213 
214  hdr_page = (LOG_PAGE *) log_io_page;
215  hdr = (LOG_HEADER *) hdr_page->area;
216 
217  FOPEN_AND_CHECK (fp, vol_path, "rb+");
218  FREAD_AND_CHECK (log_io_page, sizeof (char), LOG_PAGESIZE, fp, vol_path);
219 
220  hdr->db_charset = codeset;
221 
222  rewind (fp);
223  FWRITE_AND_CHECK (log_io_page, sizeof (char), LOG_PAGESIZE, fp, vol_path);
224  FFLUSH_AND_CHECK (fp, vol_path);
225  FCLOSE_AND_CHECK (fp, vol_path);
226 
227  return NO_ERROR;
228 }
229 
230 static int
231 check_and_fix_compat_level (const char *db_name, const char *db_path)
232 {
233  FILE *fp = NULL;
234  char vol_path[PATH_MAX];
235  LOG_HEADER *hdr;
236  LOG_PAGE *hdr_page;
237  char log_io_page[IO_MAX_PAGE_SIZE];
238 
239  if (get_active_log_vol_path (db_path, vol_path) != NO_ERROR)
240  {
241  printf ("Can't found log active volume path.\n");
242  return ER_FAILED;
243  }
244 
245  hdr_page = (LOG_PAGE *) log_io_page;
246  hdr = (LOG_HEADER *) hdr_page->area;
247 
248  FOPEN_AND_CHECK (fp, vol_path, "rb+");
249  FREAD_AND_CHECK (log_io_page, sizeof (char), LOG_PAGESIZE, fp, vol_path);
250 
251  if (hdr->db_compatibility == V9_2_LEVEL)
252  {
253  printf ("This database (%s) is already updated.\n", db_name);
254  return ER_FAILED;
255  }
256 
257  if (hdr->db_compatibility != V9_1_LEVEL)
258  {
259  printf ("Cannot migrate this database: " "%s is not CUBRID 9.1 database.\n", db_name);
260  return ER_FAILED;
261  }
262 
263  if (hdr->is_shutdown == false)
264  {
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);
267  return ER_FAILED;
268  }
269 
272 
273  rewind (fp);
274  FWRITE_AND_CHECK (log_io_page, sizeof (char), hdr->db_logpagesize, fp, vol_path);
275  FFLUSH_AND_CHECK (fp, vol_path);
276  FCLOSE_AND_CHECK (fp, vol_path);
277 
278  return NO_ERROR;
279 }
280 
281 static int
282 undo_fix_compat_level (const char *db_path)
283 {
284  FILE *fp = NULL;
285  char vol_path[PATH_MAX];
286  LOG_HEADER *hdr;
287  LOG_PAGE *hdr_page;
288  char log_io_page[IO_MAX_PAGE_SIZE];
289 
290  if (get_active_log_vol_path (db_path, vol_path) != NO_ERROR)
291  {
292  printf ("Can't found log active volume path.\n");
293  return ER_FAILED;
294  }
295 
296  hdr_page = (LOG_PAGE *) log_io_page;
297  hdr = (LOG_HEADER *) hdr_page->area;
298 
299  FOPEN_AND_CHECK (fp, vol_path, "rb+");
300  FREAD_AND_CHECK (log_io_page, sizeof (char), LOG_PAGESIZE, fp, vol_path);
301 
303 
304  rewind (fp);
305  FWRITE_AND_CHECK (log_io_page, sizeof (char), LOG_PAGESIZE, fp, vol_path);
306  FFLUSH_AND_CHECK (fp, vol_path);
307  FCLOSE_AND_CHECK (fp, vol_path);
308 
309  return NO_ERROR;
310 }
311 
312 static int
313 get_db_path (const char *db_name, char *db_full_path)
314 {
315  DB_INFO *dir = NULL;
316  DB_INFO *db = NULL;
317 
318  if (cfg_read_directory (&dir, false) != NO_ERROR)
319  {
320  printf ("Can't found databases.txt.\n");
321  return ER_FAILED;
322  }
323 
324  db = cfg_find_db_list (dir, db_name);
325 
326  if (db == NULL)
327  {
328  if (dir)
329  {
330  cfg_free_directory (dir);
331  }
332 
333  printf ("Unknown database: %s\n", db_name);
334  return ER_FAILED;
335  }
336 
337  COMPOSE_FULL_NAME (db_full_path, PATH_MAX, db->pathname, db_name);
338 
339  return NO_ERROR;
340 }
341 
342 #if defined(WINDOWS)
343 static BOOL WINAPI
344 #else
345 static void
346 #endif
347 intr_handler (int sig_no)
348 {
349  /* do nothing */
350 #if defined(WINDOWS)
351  if (sig_no == CTRL_C_EVENT)
352  {
353  /* ignore */
354  return TRUE;
355  }
356 
357  return FALSE;
358 #endif /* WINDOWS */
359 }
360 
361 static int
363 {
364 #define QUERY_SIZE 1024
365 
366  DB_QUERY_RESULT *query_result;
367  DB_QUERY_ERROR query_error;
368  int db_status;
369  char query[QUERY_SIZE];
370  DB_VALUE value;
371 
372  snprintf (query, QUERY_SIZE, "SELECT [charset] FROM [db_root]");
373  db_status = db_execute (query, &query_result, &query_error);
374  if (db_status < 0)
375  {
376  return db_status;
377  }
378 
379  db_status = db_query_next_tuple (query_result);
380  if (db_status == DB_CURSOR_SUCCESS)
381  {
382  db_status = db_query_get_tuple_value (query_result, 0, &value);
383  if (db_status != NO_ERROR)
384  {
385  db_query_end (query_result);
386  return db_status;
387  }
388  }
389  else if (db_status == DB_CURSOR_END)
390  {
391  return ER_FAILED;
392  }
393  else
394  {
395  return db_status;
396  }
397 
398  db_query_end (query_result);
399  return db_get_int (&value);
400 }
401 
402 
403 int
404 main (int argc, char *argv[])
405 {
406  const char *db_name;
407  char db_full_path[PATH_MAX];
408  int coll_need_manual_migr = 0;
409  INTL_CODESET codeset;
410  int i;
412  LANG_COLL_COMPAT *db_collations = NULL;
413  int db_coll_cnt;
414  bool db_started = false;
415 
416  if (argc != 2)
417  {
418  printf ("Usage: %s <database name>\n", argv[0]);
419  return EXIT_FAILURE;
420  }
421 
422 #if defined(WINDOWS)
423  SetConsoleCtrlHandler ((PHANDLER_ROUTINE) intr_handler, TRUE);
424 #else
425  os_set_signal_handler (SIGINT, intr_handler);
426 #endif
427 
428  db_name = argv[1];
429 
430  printf ("CUBRID Migration: 9.1 to 9.2\n\n");
431 
433  {
434  /* invalid cubrid library */
435  printf ("CUBRID library version is invalid.\n" "Please upgrade to CUBRID 9.2 and retry migrate.\n");
436  return EXIT_FAILURE;
437  }
438 
439  if (check_database_name (db_name))
440  {
441  return EXIT_FAILURE;
442  }
443 
444  if (get_db_path (db_name, db_full_path) != NO_ERROR)
445  {
446  return EXIT_FAILURE;
447  }
448 
449  if (check_and_fix_compat_level (db_name, db_full_path) != NO_ERROR)
450  {
451  return EXIT_FAILURE;
452  }
453 
454  if (utility_initialize () != NO_ERROR)
455  {
456  goto error_undo_compat;
457  }
458 
459  if (er_init ("./migrate_91_to_92.err", ER_NEVER_EXIT) != NO_ERROR)
460  {
461  printf ("Failed to initialize error manager.\n");
462  goto error_undo_compat;
463  }
464 
465  if (fix_all_volume_header (db_full_path) != NO_ERROR)
466  {
467  goto error_undo_vol_header;
468  }
469 
472 
474 
475  /* boot_set_skip_check_ct_classes (true); */
477  db_login ("DBA", NULL);
478 
479  if (db_restart (argv[0], TRUE, db_name) != NO_ERROR)
480  {
481  printf ("\n%s\n", db_error_string (3));
482  goto error_undo_vol_header;
483  }
484  db_started = true;
485 
486  if (catcls_get_db_collation (NULL, &db_collations, &db_coll_cnt) != NO_ERROR)
487  {
488  if (db_collations != NULL)
489  {
490  db_private_free (NULL, db_collations);
491  db_collations = NULL;
492  }
493  goto error_undo_vol_header;
494  }
495 
496  for (i = 0; i < db_coll_cnt; i++)
497  {
498  const LANG_COLL_COMPAT *ref_c;
499  LANG_COLLATION *lc;
500 
501  ref_c = &(db_collations[i]);
502 
503  assert (ref_c->coll_id >= 0 && ref_c->coll_id < LANG_MAX_COLLATIONS);
504  /* collation id is valid, check if same collation */
505  lc = lang_get_collation (ref_c->coll_id);
506 
507  if (lc->coll.coll_id != ref_c->coll_id)
508  {
509  printf ("Collation '%s' with id %d from database %s " "was not loaded by migration process\n",
510  ref_c->coll_name, ref_c->coll_id, db_name);
511  goto error_undo_vol_header;
512  }
513 
514  if (strcmp (lc->coll.coll_name, ref_c->coll_name))
515  {
516  printf ("Names of collation with id %d do not match : " "the collation loaded by migration process is '%s'; "
517  "the collation in database %s, is '%s'\n", ref_c->coll_id, lc->coll.coll_name, db_name,
518  ref_c->coll_name);
519  goto error_undo_vol_header;
520  }
521 
522  if (lc->codeset != ref_c->codeset)
523  {
524  printf ("Codesets of collation '%s' with id %d do not match : "
525  "the collation loaded by migration process has codeset %d; "
526  "the collation in database %s has codeset %d\n", ref_c->coll_name, ref_c->coll_id, lc->codeset,
527  db_name, ref_c->codeset);
528  goto error_undo_vol_header;
529  }
530 
531  /* The 'COLL_CONTRACTION' struct exported in locales lib was reorganized to optimize memory; as a side-effect,
532  * collations having contractions have altered checksum, but their properties are the same */
533 
534  /* collations with contractions are ignored, there is no acceptable solution to check them; we just assume that
535  * user does not change their properties */
536  if (lc->coll.count_contr == 0 && strcasecmp (lc->coll.checksum, ref_c->checksum))
537  {
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,
540  lc->coll.checksum, db_name, ref_c->checksum);
541  goto error_undo_vol_header;
542  }
543  }
544 
545  printf ("Updating database system collations \n\n");
546  if (synccoll_force () != EXIT_SUCCESS)
547  {
549  goto error_undo_vol_header;
550  }
552 
553  au_disable ();
554 
555  if (file_update_used_pages_of_vol_header (NULL) == DISK_ERROR)
556  {
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;
559  }
560 
561  /* read codeset from db_root */
562  codeset = get_codeset_from_db_root ();
563  db_shutdown ();
564  db_started = false;
565 
566  if (codeset >= INTL_CODESET_ISO88591 && codeset <= INTL_CODESET_LAST)
567  {
568  /* write codeset to the header of an active log */
569  if (fix_codeset_in_active_log (db_full_path, codeset) != NO_ERROR)
570  {
571  goto error_undo_vol_header;
572  }
573  }
574  else
575  {
576  printf ("\nCould not get the codeset from db_root: %s", db_error_string (3));
577  goto error_undo_vol_header;
578  }
579 
580  printf ("\nMigration to CUBRID 9.2 has been successfully completed.\n");
581 
583 
584  return NO_ERROR;
585 
586 error_undo_vol_header:
587  if (db_collations != NULL)
588  {
589  db_private_free (NULL, db_collations);
590  db_collations = NULL;
591  }
592  if (db_started)
593  {
594  db_shutdown ();
595  db_started = false;
596  }
597  for (p = vol_undo_info, i = 0; i < vol_undo_count; i++, p++)
598  {
599  printf ("rollback volume header: %s\n", p->filename);
600  fflush (stdout);
601 
603  {
604  printf ("recovering volume header fails.\n");
605  break;
606  }
607  }
608 
610 
611 error_undo_compat:
612  if (undo_fix_compat_level (db_full_path) != NO_ERROR)
613  {
614  printf ("\nRecovering db_compatibility level fails.\n");
615  }
616 
617  printf ("\nMigration failed.\n");
618  return EXIT_FAILURE;
619 }
620 
621 
622 static int
623 fix_all_volume_header (const char *db_path)
624 {
625  char vol_info_path[PATH_MAX], vol_path[PATH_MAX];
626  FILE *vol_info_fp = NULL;
627  int volid = NULL_VOLID;
628  char scan_format[32];
629 
630  fileio_make_volume_info_name (vol_info_path, db_path);
631 
632  FOPEN_AND_CHECK (vol_info_fp, vol_info_path, "r");
633 
634  vol_undo_count = 0;
636  vol_undo_info = (VOLUME_UNDO_INFO *) calloc (vol_undo_list_length, sizeof (VOLUME_UNDO_INFO));
637 
638  if (vol_undo_info == NULL)
639  {
640  fclose (vol_info_fp);
641  return ER_FAILED;
642  }
643 
644  sprintf (scan_format, "%%d %%%ds", (int) (sizeof (vol_path) - 1));
645  while (true)
646  {
647  if (fscanf (vol_info_fp, scan_format, &volid, vol_path) != 2)
648  {
649  break;
650  }
651 
652  if (volid == NULL_VOLID || volid < LOG_DBLOG_ACTIVE_VOLID)
653  {
654  continue;
655  }
656 
657  if (volid != LOG_DBLOG_ACTIVE_VOLID)
658  {
659  if (fix_volume_header (vol_path) != NO_ERROR)
660  {
661  fclose (vol_info_fp);
662  return ER_FAILED;
663  }
664  }
665  }
666 
667 
668  return NO_ERROR;
669 }
670 
671 static int
672 fix_volume_header (const char *vol_path)
673 {
674  FILE *fp = NULL;
675  DISK_VAR_HEADER *r92_header;
676  R91_DISK_VAR_HEADER *r91_header;
677  char *undo_page;
678 
679  FILEIO_PAGE *r91_iopage, *r92_iopage;
680  char r91_page[IO_MAX_PAGE_SIZE + MAX_ALIGNMENT];
681  char r92_page[IO_MAX_PAGE_SIZE + MAX_ALIGNMENT];
682  char *r91_aligned_buf, *r92_aligned_buf;
683  int var_field_length;
684 
685  r91_aligned_buf = PTR_ALIGN (r91_page, MAX_ALIGNMENT);
686  r92_aligned_buf = PTR_ALIGN (r92_page, MAX_ALIGNMENT);
687 
688  FOPEN_AND_CHECK (fp, vol_path, "rb+");
689  FREAD_AND_CHECK (r91_aligned_buf, sizeof (char), IO_PAGESIZE, fp, vol_path);
690 
691  undo_page = make_volume_header_undo_page (vol_path, IO_PAGESIZE);
692  if (undo_page == NULL)
693  {
694  FCLOSE_AND_CHECK (fp, vol_path);
695  return ER_FAILED;
696  }
697 
698  memcpy (undo_page, r91_aligned_buf, IO_PAGESIZE);
699 
700  r91_iopage = (FILEIO_PAGE *) r91_aligned_buf;
701  r91_header = (R91_DISK_VAR_HEADER *) r91_iopage->page;
702 
703  r92_iopage = (FILEIO_PAGE *) r92_aligned_buf;
704  r92_header = (DISK_VAR_HEADER *) r92_iopage->page;
705 
706  LSA_COPY (&r92_iopage->prv.lsa, &r91_iopage->prv.lsa);
707 
708  memcpy (r92_header->magic, r91_header->magic, CUBRID_MAGIC_MAX_LENGTH);
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;
713  r92_header->total_sects = r91_header->total_sects;
714  r92_header->free_sects = r91_header->free_sects;
715  r92_header->hint_allocsect = r91_header->hint_allocsect;
716  r92_header->total_pages = r91_header->total_pages;
717  r92_header->free_pages = r91_header->free_pages;
718  r92_header->sect_alloctb_npages = r91_header->sect_alloctb_npages;
719  r92_header->page_alloctb_npages = r91_header->page_alloctb_npages;
720  r92_header->sect_alloctb_page1 = r91_header->sect_alloctb_page1;
721  r92_header->page_alloctb_page1 = r91_header->page_alloctb_page1;
722  r92_header->sys_lastpage = r91_header->sys_lastpage;
723  r92_header->db_creation = r91_header->db_creation;
724  r92_header->max_npages = r91_header->total_pages;
725  LSA_COPY (&r92_header->chkpt_lsa, &r91_header->chkpt_lsa);
726  HFID_COPY (&r92_header->boot_hfid, &r91_header->boot_hfid);
727  r92_header->offset_to_vol_fullname = r91_header->offset_to_vol_fullname;
728  r92_header->offset_to_next_vol_fullname = r91_header->offset_to_next_vol_fullname;
729  r92_header->offset_to_vol_remarks = r91_header->offset_to_vol_remarks;
730 
731  var_field_length =
732  r91_header->offset_to_vol_remarks +
733  (int) strlen ((char *) (r91_header->var_fields + r91_header->offset_to_vol_remarks));
734 
735  memcpy (r92_header->var_fields, r91_header->var_fields, var_field_length);
736 
737  /* These new fields will be fixed later */
738  r92_header->used_data_npages = r92_header->used_index_npages = 0;
739 
740  rewind (fp);
741  FWRITE_AND_CHECK (r92_aligned_buf, sizeof (char), r92_header->iopagesize, fp, vol_path);
742  FFLUSH_AND_CHECK (fp, vol_path);
743  FCLOSE_AND_CHECK (fp, vol_path);
744 
745  printf ("%s... done\n", vol_path);
746  fflush (stdout);
747 
748  return NO_ERROR;
749 }
750 
751 static char *
752 make_volume_header_undo_page (const char *vol_path, int size)
753 {
754  VOLUME_UNDO_INFO *new_undo_info;
755  char *undo_page, *undo_file_name;
756 
758  {
759  new_undo_info = (VOLUME_UNDO_INFO *) calloc (2 * vol_undo_list_length, sizeof (VOLUME_UNDO_INFO));
760  if (new_undo_info == NULL)
761  {
762  return NULL;
763  }
764 
765  memcpy (new_undo_info, vol_undo_info, vol_undo_list_length * sizeof (VOLUME_UNDO_INFO));
766  free (vol_undo_info);
767  vol_undo_info = new_undo_info;
768 
770  }
771 
772  undo_page = (char *) malloc (size * sizeof (char));
773  if (undo_page == NULL)
774  {
775  return NULL;
776  }
777 
778  undo_file_name = (char *) malloc (PATH_MAX);
779  if (undo_file_name == NULL)
780  {
781  free (undo_page);
782  return NULL;
783  }
784 
785 
786  strcpy (undo_file_name, vol_path);
787  vol_undo_info[vol_undo_count].filename = undo_file_name;
788  vol_undo_info[vol_undo_count].page = undo_page;
789  vol_undo_info[vol_undo_count].page_size = size;
790  vol_undo_count++;
791 
792  return undo_page;
793 }
794 
795 static int
796 undo_fix_volume_header (const char *vol_path, char *undo_page, int size)
797 {
798  FILE *fp = NULL;
799 
800  FOPEN_AND_CHECK (fp, vol_path, "rb+");
801  FWRITE_AND_CHECK (undo_page, sizeof (char), size, fp, vol_path);
802  FFLUSH_AND_CHECK (fp, vol_path);
803  FCLOSE_AND_CHECK (fp, vol_path);
804 
805  return NO_ERROR;
806 }
807 
808 static void
810 {
811  int i;
813 
814  for (p = vol_undo_info, i = 0; i < vol_undo_count; i++, p++)
815  {
816  if (p->filename)
817  {
818  free (p->filename);
819  }
820 
821  if (p->page)
822  {
823  free (p->page);
824  }
825  }
826 
827  if (vol_undo_info)
828  {
829  free (vol_undo_info);
830  }
831 }
INT32 sect_alloctb_npages
Definition: migrate.c:127
#define LANG_MAX_COLLATIONS
#define NO_ERROR
Definition: error_code.h:46
#define TRUE
Definition: broker_admin.c:49
char var_fields[1]
Definition: migrate.c:140
static int undo_fix_volume_header(const char *vol_path, char *undo_page, int size)
Definition: migrate.c:796
float db_compatibility
void db_set_client_type(int client_type)
Definition: db_admin.c:495
#define IO_PAGESIZE
#define FREAD_AND_CHECK(ptr, size, n, fp, filename)
Definition: migrate.c:71
float rel_disk_compatible(void)
int sysprm_set_force(const char *pname, const char *pvalue)
int db_login(const char *name, const char *password)
Definition: db_admin.c:804
void LSA_COPY(log_lsa *plsa1, const log_lsa *plsa2)
Definition: log_lsa.hpp:139
int argc
Definition: dynamic_load.c:951
int db_get_int(const DB_VALUE *value)
#define DISK_VOLPURPOSE
#define ER_FAILED
Definition: error_code.h:47
#define AU_DISABLE_PASSWORDS
Definition: authenticate.h:140
static int get_codeset_from_db_root(void)
Definition: migrate.c:362
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)
Definition: db_query.c:3362
int db_shutdown(void)
Definition: db_admin.c:964
#define FCLOSE_AND_CHECK(fp, filename)
Definition: migrate.c:103
const VOLID LOG_DBLOG_ACTIVE_VOLID
Definition: log_volids.hpp:49
static char * make_volume_header_undo_page(const char *vol_path, int size)
Definition: migrate.c:752
int check_database_name(const char *name)
Definition: util_common.c:99
int main(int argc, char *argv[])
Definition: migrate.c:404
int au_disable(void)
char * filename
Definition: migrate.c:145
INT32 hint_allocsect
Definition: migrate.c:124
#define QUERY_SIZE
#define PTR_ALIGN(addr, boundary)
Definition: memory_alloc.h:77
static int check_and_fix_compat_level(const char *db_name, const char *vol_path)
Definition: migrate.c:231
int synccoll_force(void)
Definition: util_sa.c:3411
#define MAX_ALIGNMENT
Definition: memory_alloc.h:70
int er_init(const char *msglog_filename, int exit_ask)
INT16 offset_to_next_vol_fullname
Definition: migrate.c:138
void THREAD_ENTRY
int db_restart(const char *program, int print_version, const char *volume)
Definition: db_admin.c:868
INTL_CODESET codeset
LANG_COLLATION * lang_get_collation(const int coll_id)
INT16 offset_to_vol_fullname
Definition: migrate.c:137
#define assert(x)
PGLENGTH db_logpagesize
static int get_db_path(const char *db_name, char *db_full_path)
Definition: migrate.c:313
#define CUBRID_MAGIC_MAX_LENGTH
INT16 offset_to_vol_remarks
Definition: migrate.c:139
char area[1]
Definition: log_storage.hpp:85
const char * db_error_string(int level)
Definition: db_admin.c:2116
static VOLUME_UNDO_INFO * vol_undo_info
Definition: migrate.c:152
DISK_VOLPURPOSE purpose
Definition: migrate.c:120
int db_abort_transaction(void)
Definition: db_admin.c:1114
int utility_initialize()
Definition: util_common.c:69
#define NULL
Definition: freelistheap.h:34
char checksum[32+1]
int db_execute(const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
Definition: db_query.c:1836
#define FOPEN_AND_CHECK(fp, filename, mode)
Definition: migrate.c:51
#define V9_1_LEVEL
Definition: migrate.c:48
#define db_private_free(thrd, ptr)
Definition: memory_alloc.h:229
void COMPOSE_FULL_NAME(char *buf, size_t buf_size, const char *path, const char *name)
Definition: boot.h:161
char * db_name
int db_query_next_tuple(DB_QUERY_RESULT *result)
Definition: db_query.c:2088
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
static int fix_volume_header(const char *vol_path)
Definition: migrate.c:672
#define FWRITE_AND_CHECK(ptr, size, n, fp, filename)
Definition: migrate.c:82
const char ** argv
Definition: dynamic_load.c:952
#define strlen(s1)
Definition: intl_support.c:43
INTL_CODESET codeset
bool is_shutdown
static int vol_undo_count
Definition: migrate.c:151
#define DB_CURSOR_SUCCESS
Definition: dbtype_def.h:166
enum intl_codeset INTL_CODESET
Definition: intl_support.h:190
#define FALSE
Definition: broker_admin.c:50
static int undo_fix_compat_level(const char *db_path)
Definition: migrate.c:282
char magic[CUBRID_MAGIC_MAX_LENGTH]
Definition: migrate.c:117
int i
Definition: dynamic_load.c:954
INT32 sect_alloctb_page1
Definition: migrate.c:129
static int vol_undo_list_length
Definition: migrate.c:150
const char * prm_get_name(PARAM_ID prm_id)
static int fix_all_volume_header(const char *db_path)
Definition: migrate.c:623
#define NULL_VOLID
#define FFLUSH_AND_CHECK(fp, filename)
Definition: migrate.c:93
#define IO_MAX_PAGE_SIZE
char coll_name[COLL_NAME_SIZE]
#define LOG_PAGESIZE
static void free_volume_header_undo_list(void)
Definition: migrate.c:809
char page[1]
Definition: file_io.h:195
int db_query_get_tuple_value(DB_QUERY_RESULT *result, int index, DB_VALUE *value)
Definition: db_query.c:2873
static int fix_codeset_in_active_log(const char *db_path, INTL_CODESET codeset)
Definition: migrate.c:200
FILEIO_PAGE_RESERVED prv
Definition: file_io.h:194
#define DB_CURSOR_END
Definition: dbtype_def.h:167
LOG_LSA chkpt_lsa
Definition: migrate.c:135
#define V9_2_LEVEL
Definition: migrate.c:49
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)
Definition: file_io.c:5636
char coll_name[COLL_NAME_SIZE]
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)
Definition: porting.c:1333
INT32 page_alloctb_npages
Definition: migrate.c:128
const char ** p
Definition: dynamic_load.c:945
static void intr_handler(int sig_no)
Definition: migrate.c:347
int db_commit_transaction(void)
Definition: db_admin.c:1091
INT32 page_alloctb_page1
Definition: migrate.c:130
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)
Definition: migrate.c:167
#define UNDO_LIST_SIZE
Definition: migrate.c:112