CUBRID Engine  latest
util_sa.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  * util_sa.c - Implementation for utilities that operate in standalone mode.
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 <sys/types.h>
31 #include <sys/stat.h>
32 #include <assert.h>
33 #if defined(WINDOWS)
34 #include <io.h>
35 #endif
36 
37 #include "porting.h"
38 #include "chartype.h"
39 #include "error_manager.h"
40 #include "message_catalog.h"
41 #include "databases_file.h"
42 #include "environment_variable.h"
43 #include "system_parameter.h"
44 #include "boot_sr.h"
45 #include "db.h"
46 #include "authenticate.h"
47 #include "schema_manager.h"
48 #include "heap_file.h"
49 #include "btree.h"
50 #include "extendible_hash.h"
51 #include "locator_sr.h"
52 #include "xserver_interface.h"
53 #include "utility.h"
54 #include "transform.h"
55 #include "csql.h"
56 #include "locator_cl.h"
57 #include "network_interface_cl.h"
58 #include "locale_support.h"
59 #include "tz_support.h"
60 #include "tz_compile.h"
61 #include "boot_cl.h"
62 #include "tsc_timer.h"
63 #if defined(WINDOWS)
64 #include "wintcp.h"
65 #else
66 #include <dlfcn.h>
67 #endif
68 
69 #include "dbtype.h"
70 #include "thread_manager.hpp"
71 #include "log_volids.hpp"
72 
73 #if defined (SUPPRESS_STRLEN_WARNING)
74 #define strlen(s1) ((int) strlen(s1))
75 #endif /* defined (SUPPRESS_STRLEN_WARNING) */
76 
77 #define MAX_LINE_LEN 4096
78 
79 #define COMMENT_CHAR '-'
80 #define COMMAND_USER "user"
81 #define COMMAND_GROUP "group"
82 #define COMMAND_MEMBERS "members"
83 #define COMMAND_GROUPS "groups"
84 
85 #if defined(WINDOWS)
86 typedef int pid_t;
87 #define strtok_r strtok_s
88 #endif
89 
90 #define BO_DB_FULLNAME (bo_Dbfullname)
91 
92 static char bo_Dbfullname[PATH_MAX];
93 
94 extern bool catcls_Enable;
96 
97 extern int catcls_compile_catalog_classes (THREAD_ENTRY * thread_p);
98 extern int catcls_get_db_collation (THREAD_ENTRY * thread_p, LANG_COLL_COMPAT ** db_collations, int *coll_cnt);
99 
100 static int parse_user_define_line (char *line, FILE * output_file);
101 static int parse_user_define_file (FILE * user_define_file, FILE * output_file);
102 static int parse_up_to_date (char *up_to_date, struct tm *time_date);
103 static int print_backup_info (char *database_name, BO_RESTART_ARG * restart_arg);
104 static int synccoll_check (const char *db_name, int *db_obs_coll_cnt, int *new_sys_coll_cnt);
105 
106 static int delete_all_ha_apply_info (void);
107 static int insert_ha_apply_info (char *database_name, char *master_host_name, INT64 database_creation, INT64 pageid,
108  int offset);
109 static int delete_all_slave_ha_apply_info (char *database_name, char *master_host_name);
110 
111 static bool check_ha_db_and_node_list (char *database_name, char *source_host_name);
112 
113 
114 /*
115  * util_admin_usage - display an usage of this utility
116  *
117  * return:
118  *
119  * NOTE:
120  */
121 void
122 util_admin_usage (const char *argv0)
123 {
124  const char *exec_name;
125 
126  exec_name = basename ((char *) argv0);
127  fprintf (stderr, utility_get_generic_message (MSGCAT_UTIL_GENERIC_ADMIN_USAGE), PRODUCT_STRING, exec_name, exec_name,
128  exec_name);
129 }
130 
131 /*
132  * util_admin_version - display a version of this utility
133  *
134  * return:
135  *
136  * NOTE:
137  */
138 void
139 util_admin_version (const char *argv0)
140 {
141  const char *exec_name;
142 
143  exec_name = basename ((char *) argv0);
144  fprintf (stderr, utility_get_generic_message (MSGCAT_UTIL_GENERIC_VERSION), exec_name, PRODUCT_STRING);
145 }
146 
147 
148 /*
149  * parse_user_define_line() - parse user information
150  * return: 0 if success
151  * line_buffer(in)
152  * output_file(in)
153  */
154 static int
155 parse_user_define_line (char *line_buffer, FILE * output_file)
156 {
157  const char *delim = " \t\n";
158  char *save_ptr, *token;
159  bool group_type;
160  int exists;
161  MOP database_object, user;
162 
163  /* A first word must be the "user" keyword. */
164  token = strtok_r (line_buffer, delim, &save_ptr);
165  if (token != NULL && strcasecmp (token, COMMAND_USER) == 0)
166  {
167  /* A second word must be an user's name. */
168  token = strtok_r (NULL, delim, &save_ptr);
169  if (token == NULL || (user = au_add_user (token, &exists)) == NULL)
170  {
171  fprintf (output_file,
173  return ER_GENERIC_ERROR;
174  }
175 
176  token = strtok_r (NULL, delim, &save_ptr);
177 
178  if (token == NULL)
179  {
180  /* GROUPS or MEMBERS keyword could be omitted */
181  return NO_ERROR;
182  }
183  else if (strcasecmp (token, COMMAND_GROUPS) == 0)
184  {
185  group_type = true;
186  }
187  else if (strcasecmp (token, COMMAND_MEMBERS) == 0)
188  {
189  group_type = false;
190  }
191  else
192  {
193  fprintf (output_file,
195  return ER_GENERIC_ERROR;
196  }
197 
198  /* loop for the list of user's name */
199  while ((token = strtok_r (NULL, delim, &save_ptr)) != NULL)
200  {
201  database_object = au_find_user (token);
202  if (database_object == NULL)
203  {
204  /* could not found the user */
205  fprintf (output_file,
207  token);
208  return ER_GENERIC_ERROR;
209  }
210  else
211  {
212  if (group_type)
213  {
214  au_add_member (database_object, user);
215  }
216  else
217  {
218  au_add_member (user, database_object);
219  }
220  }
221  }
222  }
223  else
224  {
225  if (token != NULL)
226  {
227  fprintf (output_file,
229  return ER_GENERIC_ERROR;
230  }
231  }
232  return NO_ERROR;
233 }
234 
235 /*
236  * parse_user_define_file() - read user information file and parse it
237  * return: 0 if success
238  * user_define_file(in)
239  * output_file(in)
240  *
241  * Note: user definition file format :
242  * USER name GROUPS group1 group2 . . .
243  * USER name MEMBERS user1 user2 . . .
244  */
245 static int
246 parse_user_define_file (FILE * user_define_file, FILE * output_file)
247 {
248  int status = NO_ERROR;
249  int line_number = 1;
250  char line_buffer[MAX_LINE_LEN];
251 
252  while (fgets (line_buffer, MAX_LINE_LEN, user_define_file) != NULL)
253  {
254  if (strlen (line_buffer) == 0 || line_buffer[0] == COMMENT_CHAR)
255  {
256  line_number++;
257  continue;
258  }
259  status = parse_user_define_line (line_buffer, output_file);
260  if (status != NO_ERROR)
261  {
262  fprintf (stderr, "parse error at line: %d\n", line_number);
263  return status;
264  }
265  line_number++;
266  }
267  return status;
268 }
269 
270 static void
272 {
273  int pow_size;
274 
275  if (*v < IO_MIN_PAGE_SIZE)
276  {
277  *v = IO_MIN_PAGE_SIZE;
278  return;
279  }
280 
281  if (*v > IO_MAX_PAGE_SIZE)
282  {
283  *v = IO_MAX_PAGE_SIZE;
284  return;
285  }
286 
287  pow_size = IO_MIN_PAGE_SIZE;
288  if ((*v & (*v - 1)) != 0)
289  {
290  while (pow_size < *v)
291  {
292  pow_size *= 2;
293  }
294  *v = pow_size;
295  }
296 }
297 
298 /*
299  * createdb() - createdb main routine
300  * return: EXIT_SUCCESS/EXIT_FAILURE
301  */
302 int
304 {
305  UTIL_ARG_MAP *arg_map = arg->arg_map;
306  char er_msg_file[PATH_MAX];
307  int status;
308  FILE *output_file = NULL;
309  FILE *user_define_file = NULL;
310 
311  const char *output_file_name;
312  const char *program_name;
313  const char *database_name;
314  const char *volume_path;
315  const char *log_path;
316  const char *lob_path;
317  const char *host_name;
318  bool overwrite;
319  bool verbose;
320  const char *comment;
321  const char *init_file_name;
322  const char *volume_spec_file_name;
323  const char *user_define_file_name;
324  const char *cubrid_charset;
325 
326  int db_volume_sect;
327  int db_volume_pages;
328  int db_page_size;
329  UINT64 db_volume_size;
330  int log_volume_pages;
331  int log_page_size;
332  UINT64 log_volume_size;
333  char *db_volume_str;
334  char *db_page_str;
335  char *log_volume_str;
336  char *log_page_str;
337  const TZ_DATA *tzd;
338 
339  char required_size[16];
340 
341  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
342  cubrid_charset = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1);
343 
344  if (database_name == 0 || database_name[0] == 0 || cubrid_charset == 0 || cubrid_charset[0] == 0
345  || utility_get_option_string_table_size (arg_map) != 2)
346  {
347  goto print_create_usage;
348  }
349 
350  /* initialize time zone data */
351  if (tz_load () != NO_ERROR)
352  {
353  goto error_exit;
354  }
355 
356  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
357  {
359  goto error_exit;
360  }
361 
362  output_file_name = utility_get_option_string_value (arg_map, CREATE_OUTPUT_FILE_S, 0);
363  program_name = arg->command_name;
364  volume_path = utility_get_option_string_value (arg_map, CREATE_FILE_PATH_S, 0);
365  log_path = utility_get_option_string_value (arg_map, CREATE_LOG_PATH_S, 0);
366  lob_path = utility_get_option_string_value (arg_map, CREATE_LOB_PATH_S, 0);
367  host_name = utility_get_option_string_value (arg_map, CREATE_SERVER_NAME_S, 0);
368  overwrite = utility_get_option_bool_value (arg_map, CREATE_REPLACE_S);
369  verbose = utility_get_option_bool_value (arg_map, CREATE_VERBOSE_S);
370  comment = utility_get_option_string_value (arg_map, CREATE_COMMENT_S, 0);
372  volume_spec_file_name = utility_get_option_string_value (arg_map, CREATE_MORE_VOLUME_FILE_S, 0);
373  user_define_file_name = utility_get_option_string_value (arg_map, CREATE_USER_DEFINITION_FILE_S, 0);
374 
375  db_page_size = utility_get_option_int_value (arg_map, CREATE_PAGE_SIZE_S);
376  if (db_page_size != -1)
377  {
379  }
380  else
381  {
382  db_page_size = IO_PAGESIZE;
383  }
384 
385  db_page_str = utility_get_option_string_value (arg_map, CREATE_DB_PAGE_SIZE_S, 0);
386  if (db_page_str != NULL)
387  {
388  UINT64 v;
389 
390  if (util_size_string_to_byte (&v, db_page_str) != NO_ERROR)
391  {
394  CREATE_DB_PAGE_SIZE_L, db_page_str);
395  goto error_exit;
396  }
397  db_page_size = (int) v;
398  }
399  make_valid_page_size (&db_page_size);
400 
401  db_volume_str = utility_get_option_string_value (arg_map, CREATE_DB_VOLUME_SIZE_S, 0);
402  if (db_volume_str == NULL)
403  {
404  db_volume_size = prm_get_bigint_value (PRM_ID_DB_VOLUME_SIZE);
405  }
406  else
407  {
408  if (util_size_string_to_byte (&db_volume_size, db_volume_str) != NO_ERROR)
409  {
412  CREATE_DB_VOLUME_SIZE_L, db_volume_str);
413  goto error_exit;
414  }
415  }
416 
417  db_volume_pages = utility_get_option_int_value (arg_map, CREATE_PAGES_S);
418  if (db_volume_pages != -1)
419  {
421  }
422  else
423  {
424  /* round up the number of pages */
425  db_volume_pages = (int) ceil ((double) db_volume_size / db_page_size);
426  }
427  /* determine volume number of sectors */
428  db_volume_sect = disk_sectors_to_extend_npages (db_volume_pages);
429  /* adjust the number of pages according to the number of sectors */
430  db_volume_pages = DISK_SECTOR_NPAGES * db_volume_sect;
431 
432  db_volume_size = (UINT64) db_volume_pages *(UINT64) db_page_size;
433 
434  log_page_str = utility_get_option_string_value (arg_map, CREATE_LOG_PAGE_SIZE_S, 0);
435  if (log_page_str == NULL)
436  {
437  log_page_size = db_page_size;
438  }
439  else
440  {
441  UINT64 v;
442 
443  if (util_size_string_to_byte (&v, log_page_str) != NO_ERROR)
444  {
447  CREATE_LOG_PAGE_SIZE_L, log_page_str);
448  goto error_exit;
449  }
450  log_page_size = (int) v;
451  }
452  make_valid_page_size (&log_page_size);
453 
454  log_volume_str = utility_get_option_string_value (arg_map, CREATE_LOG_VOLUME_SIZE_S, 0);
455  if (log_volume_str == NULL)
456  {
457  log_volume_size = prm_get_bigint_value (PRM_ID_LOG_VOLUME_SIZE);
458  }
459  else
460  {
461  if (util_size_string_to_byte (&log_volume_size, log_volume_str) != NO_ERROR)
462  {
465  CREATE_LOG_VOLUME_SIZE_L, log_volume_str);
466  goto error_exit;
467  }
468  }
469 
470  log_volume_pages = utility_get_option_int_value (arg_map, CREATE_LOG_PAGE_COUNT_S);
471  if (log_volume_pages != -1)
472  {
474  }
475  else
476  {
477  log_volume_pages = (int) (log_volume_size / log_page_size);
478  }
479 
480  if (check_new_database_name (database_name))
481  {
482  goto error_exit;
483  }
484 
485  if (output_file_name == 0 || output_file_name[0] == 0)
486  {
487  output_file = stdout;
488  }
489  else
490  {
491  output_file = fopen (output_file_name, "w");
492  }
493 
494  if (output_file == NULL)
495  {
497  output_file_name);
498  goto error_exit;
499  }
500 
502  {
503  UINT64 min, max;
504  char min_buf[64], max_buf[64], vol_buf[64];
505 
507  {
508  goto error_exit;
509  }
510  util_byte_to_size_string (min_buf, 64, min);
511  util_byte_to_size_string (max_buf, 64, max);
512  if (db_volume_str != NULL)
513  {
514  int len;
515  len = strlen (db_volume_str);
516  if (char_isdigit (db_volume_str[len - 1]))
517  {
518  snprintf (vol_buf, 64, "%sB", db_volume_str);
519  }
520  else
521  {
522  snprintf (vol_buf, 64, "%s", db_volume_str);
523  }
524  }
525  else
526  {
527  util_byte_to_size_string (vol_buf, 64, db_volume_size);
528  }
530 
532  prm_get_name (PRM_ID_DB_VOLUME_SIZE), vol_buf, min_buf, max_buf);
533  goto error_exit;
534  }
535  if (sysprm_check_range (prm_get_name (PRM_ID_LOG_VOLUME_SIZE), &log_volume_size) != NO_ERROR)
536  {
537  UINT64 min, max;
538  char min_buf[64], max_buf[64], vol_buf[64];
539 
541  {
542  goto error_exit;
543  }
544  util_byte_to_size_string (min_buf, 64, min);
545  util_byte_to_size_string (max_buf, 64, max);
546  if (log_volume_str != NULL)
547  {
548  int len;
549  len = strlen (log_volume_str);
550  if (char_isdigit (log_volume_str[len - 1]))
551  {
552  snprintf (vol_buf, 64, "%sB", log_volume_str);
553  }
554  else
555  {
556  snprintf (vol_buf, 64, "%s", log_volume_str);
557  }
558  }
559  else
560  {
561  util_byte_to_size_string (vol_buf, 64, log_volume_size);
562  }
565  prm_get_name (PRM_ID_LOG_VOLUME_SIZE), vol_buf, min_buf, max_buf);
566 
567  goto error_exit;
568  }
569 
570  if (user_define_file_name != 0)
571  {
572  user_define_file = fopen (user_define_file_name, "r");
573  if (user_define_file == NULL)
574  {
577  user_define_file_name);
578  goto error_exit;
579  }
580  }
581 
582  util_byte_to_size_string (er_msg_file, sizeof (er_msg_file), db_volume_size);
583  /* total amount of disk space of database is db volume size + log_volume_size + temp_log_volume_size */
584  util_byte_to_size_string (required_size, sizeof (required_size), db_volume_size + (UINT64) (log_volume_size * 2));
586  er_msg_file, cubrid_charset, required_size);
587 
588  /* error message log file */
589  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
590  er_init (er_msg_file, ER_NEVER_EXIT);
591 
592  /* tuning system parameters */
596 
599 
600  db_login ("DBA", NULL);
601  status = db_init (program_name, true, database_name, volume_path, NULL, log_path, lob_path, host_name, overwrite,
602  comment, volume_spec_file_name, db_volume_pages, db_page_size, log_volume_pages, log_page_size,
603  cubrid_charset);
604 
605  if (status != NO_ERROR)
606  {
609  goto error_exit;
610  }
611 
613 
614  (void) lang_db_put_charset ();
615 
616  tzd = tz_get_data ();
617  if (put_timezone_checksum ((char *) tzd->checksum) != NO_ERROR)
618  {
619  goto error_exit;
620  }
621 
622  if (verbose)
623  {
624  au_dump_to_file (output_file);
625  }
627  {
629  }
631  {
633  db_shutdown ();
634  goto error_exit;
635  }
636  if (catcls_Enable == true)
637  {
639  {
641  db_shutdown ();
642  goto error_exit;
643  }
644  }
646  {
648  db_shutdown ();
649  goto error_exit;
650  }
651 
653 
654  if (user_define_file != NULL)
655  {
656  if (parse_user_define_file (user_define_file, output_file) != NO_ERROR)
657  {
660  user_define_file_name);
661  db_shutdown ();
662  goto error_exit;
663  }
664  fclose (user_define_file);
665  }
667  db_shutdown ();
668 
669  if (output_file != stdout)
670  {
671  fclose (output_file);
672  }
673 
674  if (init_file_name != NULL)
675  {
676  CSQL_ARGUMENT csql_arg;
677  memset (&csql_arg, 0, sizeof (CSQL_ARGUMENT));
678  csql_arg.auto_commit = true;
679  csql_arg.db_name = database_name;
680  csql_arg.in_file_name = init_file_name;
681  csql (arg->command_name, &csql_arg);
682  }
683 
684  return EXIT_SUCCESS;
685 
686 print_create_usage:
688  basename (arg->argv0));
690 
691 error_exit:
692  if (output_file != stdout && output_file != NULL)
693  {
694  fclose (output_file);
695  }
696  if (user_define_file != NULL)
697  {
698  fclose (user_define_file);
699  }
700  return EXIT_FAILURE;
701 }
702 
703 /*
704  * deletedb() - deletedb main routine
705  * return: EXIT_SUCCESS/EXIT_FAILURE
706  */
707 int
709 {
710  UTIL_ARG_MAP *arg_map = arg->arg_map;
711  char er_msg_file[PATH_MAX];
712  FILE *output_file = NULL;
713  const char *output_file_name;
714  const char *database_name;
715  bool force_delete;
716 
717  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
718  if (database_name == NULL)
719  {
720  goto print_delete_usage;
721  }
722 
723  output_file_name = utility_get_option_string_value (arg_map, DELETE_OUTPUT_FILE_S, 0);
724  force_delete = utility_get_option_bool_value (arg_map, DELETE_DELETE_BACKUP_S);
725 
726  if (utility_get_option_string_table_size (arg_map) != 1)
727  {
728  goto print_delete_usage;
729  }
730 
731  /* error message log file */
732  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
733  er_init (er_msg_file, ER_NEVER_EXIT);
734 
735  if (check_database_name (database_name))
736  {
737  goto error_exit;
738  }
739 
740  if (output_file_name == NULL)
741  {
742  output_file = stdout;
743  }
744  else
745  {
746  output_file = fopen (output_file_name, "w");
747  }
748 
749  if (output_file == NULL)
750  {
753  output_file_name);
754 
755  goto error_exit;
756  }
757 
758  /* tuning system parameters */
761 
764  db_login ("DBA", NULL);
765  if (boot_delete (database_name, force_delete) != NO_ERROR)
766  {
768  goto error_exit;
769  }
770 
772  if (output_file != stdout)
773  {
774  fclose (output_file);
775  }
776  return EXIT_SUCCESS;
777 
778 print_delete_usage:
780  basename (arg->argv0));
782 
783 error_exit:
785  if (output_file != stdout && output_file != NULL)
786  {
787  fclose (output_file);
788  }
789  return EXIT_FAILURE;
790 }
791 
792 static int
793 parse_up_to_date (char *date_string, struct tm *time_data)
794 {
795  int status;
796  int date_index;
797  char *save_ptr, *token;
798  const char *delim = "-:";
799 
800  status = NO_ERROR;
801  date_index = 0;
802  token = strtok_r (date_string, delim, &save_ptr);
803  while (status == NO_ERROR && token != NULL)
804  {
805  switch (date_index)
806  {
807  case 0: /* month-day */
808  time_data->tm_mday = atoi (token);
809  if (time_data->tm_mday < 1 || time_data->tm_mday > 31)
810  {
811  status = ER_GENERIC_ERROR;
812  }
813  break;
814  case 1: /* month */
815  time_data->tm_mon = atoi (token) - 1;
816  if (time_data->tm_mon < 0 || time_data->tm_mon > 11)
817  {
818  status = ER_GENERIC_ERROR;
819  }
820  break;
821  case 2: /* year */
822  time_data->tm_year = atoi (token) - 1900;
823  if (time_data->tm_year < 0)
824  {
825  status = ER_GENERIC_ERROR;
826  }
827  break;
828  case 3: /* hour */
829  time_data->tm_hour = atoi (token);
830  if (time_data->tm_hour < 0 || time_data->tm_hour > 23)
831  {
832  status = ER_GENERIC_ERROR;
833  }
834  break;
835  case 4: /* minute */
836  time_data->tm_min = atoi (token);
837  if (time_data->tm_min < 0 || time_data->tm_min > 59)
838  {
839  status = ER_GENERIC_ERROR;
840  }
841  break;
842  case 5: /* second */
843  time_data->tm_sec = atoi (token);
844  if (time_data->tm_sec < 0 || time_data->tm_sec > 59)
845  {
846  status = ER_GENERIC_ERROR;
847  }
848  break;
849  default:
850  status = ER_GENERIC_ERROR;
851  break;
852  }
853  date_index++;
854  token = strtok_r (NULL, delim, &save_ptr);
855  }
856 
857  return date_index != 6 ? ER_GENERIC_ERROR : status;
858 }
859 
860 static int
862 {
863  char from_volbackup[PATH_MAX];
864  int error_code = NO_ERROR;
865  DB_INFO *dir = NULL, *db;
866 
867  error_code = cfg_read_directory (&dir, false);
868  if (error_code != NO_ERROR)
869  {
870  goto exit;
871  }
872 
873  db = cfg_find_db_list (dir, database_name);
874  if (db == NULL)
875  {
876  error_code = ER_BO_UNKNOWN_DATABASE;
877  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_code, 1, database_name);
878  goto exit;
879  }
880 
881  COMPOSE_FULL_NAME (BO_DB_FULLNAME, sizeof (BO_DB_FULLNAME), db->pathname, database_name);
882 
883  error_code =
884  fileio_get_backup_volume (NULL, BO_DB_FULLNAME, db->logpath, restart_arg->backuppath, restart_arg->level,
885  from_volbackup);
886  if (error_code != NO_ERROR)
887  {
888  goto exit;
889  }
890 
891  error_code =
892  fileio_list_restore (NULL, BO_DB_FULLNAME, from_volbackup, (FILEIO_BACKUP_LEVEL) restart_arg->level,
893  restart_arg->newvolpath);
894 exit:
895  if (dir != NULL)
896  {
897  cfg_free_directory (dir);
898  }
899 
900  return error_code;
901 }
902 
903 /*
904  * restoredb() - restoredb main routine
905  * return: EXIT_SUCCESS/EXIT_FAILURE
906  */
907 int
909 {
910  UTIL_ARG_MAP *arg_map = arg->arg_map;
911  char er_msg_file[PATH_MAX];
912  int status, error_code;
913  struct tm time_data;
914  char *up_to_date;
915  char *database_name;
916  bool partial_recovery;
917  const char *mk_path;
918  BO_RESTART_ARG restart_arg;
919 
920  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
921  up_to_date = utility_get_option_string_value (arg_map, RESTORE_UP_TO_DATE_S, 0);
922  partial_recovery = utility_get_option_bool_value (arg_map, RESTORE_PARTIAL_RECOVERY_S);
923  restart_arg.printtoc = utility_get_option_bool_value (arg_map, RESTORE_LIST_S);
924  restart_arg.stopat = -1;
926  restart_arg.level = utility_get_option_int_value (arg_map, RESTORE_LEVEL_S);
930  restart_arg.restore_upto_bktime = false;
931  restart_arg.restore_slave = false;
932  restart_arg.is_restore_from_backup = true;
933 
934  if (mk_path != NULL)
935  {
936  memcpy (restart_arg.keys_file_path, mk_path, PATH_MAX);
937  }
938  else
939  {
940  /* prepare the buffer to contain mk path from the backup volume */
941  restart_arg.keys_file_path[0] = '\0';
942  }
943 
944  if (utility_get_option_string_table_size (arg_map) != 1)
945  {
946  goto print_restore_usage;
947  }
948 
949  if (up_to_date != NULL && strlen (up_to_date) > 0)
950  {
951  if (strcasecmp (up_to_date, "backuptime") == 0)
952  {
953  restart_arg.restore_upto_bktime = true;
954  }
955  else
956  {
957  status = parse_up_to_date (up_to_date, &time_data);
958  restart_arg.stopat = mktime (&time_data);
959  if (status != NO_ERROR || restart_arg.stopat < 0)
960  {
963  goto error_exit;
964  }
965  }
966  }
967  else
968  {
969  restart_arg.stopat = time (NULL);
970  }
971 
972  /* error message log file */
973  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
974  er_init (er_msg_file, ER_NEVER_EXIT);
975 
976  if (restart_arg.printtoc)
977  {
978  error_code = print_backup_info (database_name, &restart_arg);
979  if (error_code != NO_ERROR)
980  {
983  goto error_exit;
984  }
985 
986  return EXIT_SUCCESS;
987  }
988 
990 
993  db_login ("DBA", NULL);
994  if (partial_recovery == true)
995  {
997  }
998  status = boot_restart_from_backup (true, database_name, &restart_arg);
999  if (status == NULL_TRAN_INDEX)
1000  {
1001  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1003  goto error_exit;
1004  }
1005  else
1006  {
1008  }
1009 
1010  return EXIT_SUCCESS;
1011 
1012 print_restore_usage:
1014  basename (arg->argv0));
1016 
1017 error_exit:
1018  return EXIT_FAILURE;
1019 }
1020 
1021 /*
1022  * renamedb() - renamedb main routine
1023  * return: EXIT_SUCCESS/EXIT_FAILURE
1024  */
1025 int
1027 {
1028  UTIL_ARG_MAP *arg_map = arg->arg_map;
1029  char er_msg_file[PATH_MAX];
1030  const char *src_db_name;
1031  const char *dest_db_name;
1032  const char *ext_path;
1033  const char *control_file_name;
1034  bool force_delete;
1035 
1036  src_db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1037  dest_db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1);
1038  if (src_db_name == NULL || dest_db_name == NULL)
1039  {
1040  goto print_rename_usage;
1041  }
1042 
1044  control_file_name = utility_get_option_string_value (arg_map, RENAME_CONTROL_FILE_S, 0);
1045  force_delete = utility_get_option_bool_value (arg_map, RENAME_DELETE_BACKUP_S);
1046 
1047  if (utility_get_option_string_table_size (arg_map) != 2)
1048  {
1049  goto print_rename_usage;
1050  }
1051 
1052  if (check_database_name (src_db_name) || check_new_database_name (dest_db_name))
1053  {
1054  goto error_exit;
1055  }
1056  else if (ext_path && access (ext_path, F_OK) == -1)
1057  {
1060  goto error_exit;
1061  }
1062  else if (control_file_name && access (control_file_name, F_OK) == -1)
1063  {
1066  goto error_exit;
1067  }
1068 
1069  /* error message log file */
1070  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", src_db_name, arg->command_name);
1071  er_init (er_msg_file, ER_NEVER_EXIT);
1072 
1073  /* tuning system parameters */
1076 
1079  db_login ("DBA", NULL);
1080  if (db_restart (arg->command_name, TRUE, src_db_name) != NO_ERROR)
1081  {
1082  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1083  goto error_exit;
1084  }
1085  else
1086  {
1087  if (boot_soft_rename
1088  (src_db_name, dest_db_name, NULL, NULL, NULL, ext_path, control_file_name, FALSE, TRUE,
1089  force_delete) != NO_ERROR)
1090  {
1091  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1092  db_shutdown ();
1093  goto error_exit;
1094  }
1095  else
1096  {
1098  db_shutdown ();
1099  }
1100  }
1101  return EXIT_SUCCESS;
1102 
1103 print_rename_usage:
1105  basename (arg->argv0));
1107 
1108 error_exit:
1109  return EXIT_FAILURE;
1110 }
1111 
1112 /*
1113  * installdb() - installb main routine
1114  * return: EXIT_SUCCESS/EXIT_FAILURE
1115  */
1116 int
1118 {
1119  UTIL_ARG_MAP *arg_map = arg->arg_map;
1120  char er_msg_file[PATH_MAX];
1121  char lob_path_buf[PATH_MAX];
1122  const char *server_name;
1123  const char *db_path;
1124  const char *log_path;
1125  const char *db_name;
1126  DB_INFO *dir = NULL, *db;
1127  bool cfg_added = false;
1128 
1129  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1130  if (db_name == NULL)
1131  {
1132  goto print_install_usage;
1133  }
1134 
1135  server_name = utility_get_option_string_value (arg_map, INSTALL_SERVER_NAME_S, 0);
1136  db_path = utility_get_option_string_value (arg_map, INSTALL_FILE_PATH_S, 0);
1137  log_path = utility_get_option_string_value (arg_map, INSTALL_LOG_PATH_S, 0);
1138 
1139  if (utility_get_option_string_table_size (arg_map) != 1)
1140  {
1141  goto print_install_usage;
1142  }
1143 
1144  if (check_database_name (db_name))
1145  {
1146  goto error_exit;
1147  }
1148 
1149  /* error message log file */
1150  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
1151  er_init (er_msg_file, ER_NEVER_EXIT);
1152 
1153  db = cfg_find_db (db_name);
1154  if (db != NULL)
1155  {
1157  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1158  cfg_free_directory (db);
1159  goto error_exit;
1160  }
1161 
1162  /* have to add it to the config before calling boot_restart */
1163  if (cfg_read_directory (&dir, 1) != NO_ERROR)
1164  {
1165  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1166  goto error_exit;
1167  }
1168 
1169  db = cfg_add_db (&dir, db_name, db_path, log_path, NULL, server_name);
1170  if (db == NULL)
1171  {
1172  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1173  goto error_exit;
1174  }
1175  if (db->lobpath == NULL)
1176  {
1177  /* assign the data volume directory */
1178  snprintf (lob_path_buf, sizeof (lob_path_buf), "%s%s%clob", LOB_PATH_DEFAULT_PREFIX, db->pathname,
1179  PATH_SEPARATOR);
1180  lob_path_buf[PATH_MAX - 1] = '\0';
1181  db->lobpath = strdup (lob_path_buf);
1182  }
1183 
1184  cfg_write_directory (dir);
1185 
1186  cfg_added = true;
1187 
1189 
1192  db_login ("DBA", NULL);
1193  if (db_restart (arg->command_name, TRUE, db_name) != NO_ERROR)
1194  {
1195  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1196  goto error_exit;
1197  }
1198 
1199  if (boot_soft_rename (NULL, db_name, db_path, log_path, server_name, NULL, NULL, FALSE, FALSE, TRUE) != NO_ERROR)
1200  {
1201  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1202  db_shutdown ();
1203  goto error_exit;
1204  }
1205 
1207  db_shutdown ();
1208 
1209  cfg_free_directory (dir);
1210  return EXIT_SUCCESS;
1211 
1212 print_install_usage:
1214  basename (arg->argv0));
1216 
1217 error_exit:
1218  if (cfg_added)
1219  {
1220  /* got an error, have to back out the addition to the directory */
1221  cfg_delete_db (&dir, db_name);
1222  cfg_write_directory (dir);
1223  }
1224  if (dir != NULL)
1225  {
1226  cfg_free_directory (dir);
1227  }
1228  return EXIT_FAILURE;
1229 }
1230 
1231 /*
1232  * copydb() - copydb main routine
1233  * return: EXIT_SUCCESS/EXIT_FAILURE
1234  */
1235 int
1237 {
1238  UTIL_ARG_MAP *arg_map = arg->arg_map;
1239  char er_msg_file[PATH_MAX];
1240  const char *src_db_name;
1241  const char *dest_db_name;
1242  const char *server_name;
1243  const char *db_path;
1244  const char *log_path;
1245  const char *lob_path;
1246  char lob_pathbuf[PATH_MAX];
1247  const char *ext_path;
1248  const char *control_file_name;
1249  bool overwrite, delete_src, copy_lob_path;
1250 
1251  src_db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1252  dest_db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1);
1253  if (src_db_name == NULL || dest_db_name == NULL)
1254  {
1255  goto print_copy_usage;
1256  }
1257 
1258  server_name = utility_get_option_string_value (arg_map, COPY_SERVER_NAME_S, 0);
1259  db_path = utility_get_option_string_value (arg_map, COPY_FILE_PATH_S, 0);
1260  log_path = utility_get_option_string_value (arg_map, COPY_LOG_PATH_S, 0);
1261  lob_path = utility_get_option_string_value (arg_map, COPY_LOB_PATH_S, 0);
1263  control_file_name = utility_get_option_string_value (arg_map, COPY_CONTROL_FILE_S, 0);
1264  overwrite = utility_get_option_bool_value (arg_map, COPY_REPLACE_S);
1265  delete_src = utility_get_option_bool_value (arg_map, COPY_DELETE_SOURCE_S);
1266  copy_lob_path = utility_get_option_bool_value (arg_map, COPY_COPY_LOB_PATH_S);
1267 
1268  if (utility_get_option_string_table_size (arg_map) != 2)
1269  {
1270  goto print_copy_usage;
1271  }
1272 
1273  if (lob_path != NULL && copy_lob_path == true)
1274  {
1275  goto print_copy_usage;
1276  }
1277  if (delete_src == true && lob_path == NULL)
1278  {
1279  copy_lob_path = true;
1280  }
1281 
1282  /* error message log file */
1283  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", src_db_name, arg->command_name);
1284  er_init (er_msg_file, ER_NEVER_EXIT);
1285 
1286  if (check_database_name (src_db_name) || check_new_database_name (dest_db_name))
1287  {
1288  goto error_exit;
1289  }
1290 
1291  if (strcmp (src_db_name, dest_db_name) == 0)
1292  {
1294  goto error_exit;
1295  }
1296 
1297  /* tuning system parameters */
1300 
1303  db_login ("DBA", NULL);
1304 
1305  if (db_restart (arg->command_name, TRUE, src_db_name) != NO_ERROR)
1306  {
1307  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1308  goto error_exit;
1309  }
1310 
1311  if (copy_lob_path)
1312  {
1313  const char *s = boot_get_lob_path ();
1314  if (*s != '\0')
1315  {
1316  lob_path = strcpy (lob_pathbuf, s);
1317  }
1318  }
1319  if (boot_copy (src_db_name, dest_db_name, db_path, log_path, lob_path, server_name, ext_path, control_file_name,
1320  overwrite) != NO_ERROR)
1321  {
1322  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1323  goto error_exit;
1324  }
1325  if (delete_src)
1326  {
1327  boot_delete (src_db_name, true);
1328  }
1330 
1331  return EXIT_SUCCESS;
1332 
1333 print_copy_usage:
1335  basename (arg->argv0));
1337 
1338 error_exit:
1340 
1341  return EXIT_FAILURE;
1342 }
1343 
1344 /*
1345  * optimizedb() - optimizedb main routine
1346  * return: EXIT_SUCCESS/EXIT_FAILURE
1347  */
1348 int
1350 {
1351  UTIL_ARG_MAP *arg_map = arg->arg_map;
1352  char er_msg_file[PATH_MAX];
1353  const char *db_name;
1354  const char *class_name;
1355  int status;
1356  DB_OBJECT *class_mop;
1357 
1358  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1359  if (db_name == NULL)
1360  {
1361  goto print_optimize_usage;
1362  }
1363 
1364  class_name = utility_get_option_string_value (arg_map, OPTIMIZE_CLASS_NAME_S, 0);
1365 
1366  if (utility_get_option_string_table_size (arg_map) != 1)
1367  {
1368  goto print_optimize_usage;
1369  }
1370 
1371  status = NO_ERROR;
1372 
1373  if (check_database_name (db_name))
1374  {
1375  goto error_exit;
1376  }
1377 
1378  /* error message log file */
1379  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
1380  er_init (er_msg_file, ER_NEVER_EXIT);
1381 
1383 
1386  db_login ("DBA", NULL);
1387  if (db_restart (arg->command_name, TRUE, db_name) != NO_ERROR)
1388  {
1389  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1390  goto error_exit;
1391  }
1392 
1393  if (class_name != NULL && class_name[0] != 0)
1394  {
1395  if ((class_mop = db_find_class (class_name)) == NULL
1397  {
1398  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1399  db_shutdown ();
1400  goto error_exit;
1401  }
1402  }
1403  else
1404  {
1406  {
1407  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1408  db_shutdown ();
1409  goto error_exit;
1410  }
1411  }
1413  db_shutdown ();
1414 
1415  return EXIT_SUCCESS;
1416 
1417 print_optimize_usage:
1419  basename (arg->argv0));
1421 
1422 error_exit:
1423  return EXIT_FAILURE;
1424 }
1425 
1426 typedef enum
1427 {
1439 } DIAGDUMP_TYPE;
1440 
1441 /*
1442  * diagdb() - diagdb main routine
1443  * return: EXIT_SUCCESS/EXIT_FAILURE
1444  */
1445 int
1447 {
1448  UTIL_ARG_MAP *arg_map = arg->arg_map;
1449  char er_msg_file[PATH_MAX];
1450  const char *db_name;
1451  const char *output_file = NULL;
1452  FILE *outfp = NULL;
1453  bool is_emergency = false;
1454  DIAGDUMP_TYPE diag;
1455  THREAD_ENTRY *thread_p;
1456 
1457  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1458  if (db_name == NULL)
1459  {
1460  goto print_diag_usage;
1461  }
1462 
1463  is_emergency = utility_get_option_bool_value (arg_map, DIAG_EMERGENCY_S);
1464  if (is_emergency)
1465  {
1468  }
1469 
1470  output_file = utility_get_option_string_value (arg_map, DIAG_OUTPUT_FILE_S, 0);
1471  if (output_file == NULL)
1472  {
1473  outfp = stdout;
1474  }
1475  else
1476  {
1477  outfp = fopen (output_file, "w");
1478  if (outfp == NULL)
1479  {
1481  output_file);
1482  goto error_exit;
1483  }
1484  }
1485 
1487 
1488  if (diag != DIAGDUMP_LOG && utility_get_option_string_table_size (arg_map) != 1)
1489  {
1490  goto print_diag_usage;
1491  }
1492 
1493  if (check_database_name (db_name))
1494  {
1495  goto error_exit;
1496  }
1497 
1498  /* error message log file */
1499  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
1500  er_init (er_msg_file, ER_NEVER_EXIT);
1501 
1503 
1506  db_login ("DBA", NULL);
1507  if (db_restart (arg->command_name, TRUE, db_name) != NO_ERROR)
1508  {
1509  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1510  goto error_exit;
1511  }
1512 
1513  if (diag < DIAGDUMP_ALL || diag >= DIAGDUMP_END_OF_OPTION)
1514  {
1515  goto print_diag_usage;
1516  }
1517 
1518  thread_p = thread_get_thread_entry_info ();
1519 
1520  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_FILE_TABLES)
1521  {
1522  /* this dumps the allocated file stats */
1523  fprintf (outfp, "\n*** DUMP OF FILE STATISTICS ***\n");
1524  (void) file_tracker_dump (thread_p, outfp);
1525  }
1526 
1527  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_FILE_CAPACITIES)
1528  {
1529  /* this dumps the allocated file stats */
1530  fprintf (outfp, "\n*** DUMP OF FILE DESCRIPTIONS ***\n");
1531  (void) file_tracker_dump_all_capacities (thread_p, outfp);
1532  }
1533 
1534  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_HEAP_CAPACITIES)
1535  {
1536  /* this dumps lower level info about capacity of all heaps */
1537  fprintf (outfp, "\n*** DUMP CAPACITY OF ALL HEAPS ***\n");
1538  (void) file_tracker_dump_all_heap_capacities (thread_p, outfp);
1539  }
1540 
1541  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_INDEX_CAPACITIES)
1542  {
1543  /* this dumps lower level info about capacity of all indices */
1544  fprintf (outfp, "\n*** DUMP CAPACITY OF ALL INDICES ***\n");
1545  (void) file_tracker_dump_all_btree_capacities (thread_p, outfp);
1546  }
1547 
1548  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_CLASSNAMES)
1549  {
1550  /* this dumps the known classnames */
1551  fprintf (outfp, "\n*** DUMP CLASSNAMES ***\n");
1552  locator_dump_class_names (thread_p, outfp);
1553  }
1554 
1555  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_DISK_BITMAPS)
1556  {
1557  /* this dumps lower level info about the disk */
1558  fprintf (outfp, "\n*** DUMP OF DISK STATISTICS ***\n");
1559  disk_dump_all (thread_p, outfp);
1560  }
1561 
1562  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_CATALOG)
1563  {
1564  /* this dumps the content of catalog */
1565  fprintf (outfp, "\n*** DUMP OF CATALOG ***\n");
1566  catalog_dump (thread_p, outfp, 1);
1567  }
1568 
1569  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_LOG)
1570  {
1571  /* this dumps the content of log */
1572  int isforward, dump_npages, desired_tranid;
1573  LOG_PAGEID start_logpageid;
1574  long long int s;
1575 
1576  if (diag == DIAGDUMP_ALL || utility_get_option_string_table_size (arg_map) == 1)
1577  {
1578  char yn[2];
1579  do
1580  {
1581  printf ("\n");
1582  printf ("isforward (1 or 0) ? ");
1583  scanf ("%d", &isforward);
1584  printf ("start_logpageid (-1 for the first/last page) ? ");
1585  scanf ("%lld", &s);
1586  start_logpageid = s;
1587  printf ("dump_npages (-1 for all pages) ? ");
1588  scanf ("%d", &dump_npages);
1589  printf ("desired_tranid (-1 for all transactions) ? ");
1590  scanf ("%d", &desired_tranid);
1591  printf ("log_dump(%d, %lld, %d, %d) (y/n) ? ", isforward, (long long int) start_logpageid, dump_npages,
1592  desired_tranid);
1593  scanf ("%1s", yn);
1594  }
1595  while (yn[0] != 'y');
1596  }
1597  else if (utility_get_option_string_table_size (arg_map) == 5)
1598  {
1599  const char *cp;
1600  start_logpageid = isforward = dump_npages = desired_tranid = 0;
1601 
1603  if (cp != NULL)
1604  {
1605  isforward = atoi (cp);
1606  }
1607 
1609  if (cp != NULL)
1610  {
1611  start_logpageid = atoll (cp);
1612  }
1613 
1615  if (cp != NULL)
1616  {
1617  dump_npages = atoi (cp);
1618  }
1619 
1621  if (cp != NULL)
1622  {
1623  desired_tranid = atoi (cp);
1624  }
1625  }
1626  else
1627  {
1628  goto print_diag_usage;
1629  }
1630  fprintf (outfp, "\n*** DUMP OF LOG ***\n");
1631  xlog_dump (thread_p, outfp, isforward, start_logpageid, dump_npages, desired_tranid);
1632  }
1633 
1634  if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_HEAP)
1635  {
1636  bool dump_records;
1637  /* this dumps the contents of all heaps */
1638  dump_records = utility_get_option_bool_value (arg_map, DIAG_DUMP_RECORDS_S);
1639  fprintf (outfp, "\n*** DUMP OF ALL HEAPS ***\n");
1640  (void) file_tracker_dump_all_heap (thread_p, outfp, dump_records);
1641  }
1642 
1643  db_shutdown ();
1644 
1645  fflush (outfp);
1646  if (output_file != NULL && outfp != NULL && outfp != stdout)
1647  {
1648  fclose (outfp);
1649  }
1650 
1651  return EXIT_SUCCESS;
1652 
1653 print_diag_usage:
1655  basename (arg->argv0));
1657 
1658 error_exit:
1659  if (output_file != NULL && outfp != NULL && outfp != stdout)
1660  {
1661  fclose (outfp);
1662  }
1663 
1664  return EXIT_FAILURE;
1665 }
1666 
1667 /*
1668  * patchdb() - patchdb main routine
1669  * return: EXIT_SUCCESS/EXIT_FAILURE
1670  */
1671 int
1673 {
1674  char er_msg_file[PATH_MAX];
1675  UTIL_ARG_MAP *arg_map = arg->arg_map;
1676  const char *db_name;
1677  const char *db_locale = NULL;
1678  bool recreate_log;
1679 
1680  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1681  if (db_name == NULL)
1682  {
1683  goto print_patch_usage;
1684  }
1685 
1686  recreate_log = utility_get_option_bool_value (arg_map, PATCH_RECREATE_LOG_S);
1687 
1688  if (recreate_log == true)
1689  {
1690  db_locale = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1);
1691  if (db_locale == NULL)
1692  {
1693  goto print_patch_usage;
1694  }
1695  }
1696 
1697  if (utility_get_option_string_table_size (arg_map) != (recreate_log ? 2 : 1))
1698  {
1699  goto print_patch_usage;
1700  }
1701 
1702  if (check_database_name (db_name))
1703  {
1704  goto error_exit;
1705  }
1706 
1707  /* error message log file */
1708  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
1709  er_init (er_msg_file, ER_NEVER_EXIT);
1710 
1711  if (boot_emergency_patch (db_name, recreate_log, 0, db_locale, NULL) != NO_ERROR)
1712  {
1713  fprintf (stderr, "emergency patch fail:%s\n", db_error_string (3));
1715  goto error_exit;
1716  }
1717 
1718  return EXIT_SUCCESS;
1719 
1720 print_patch_usage:
1722  basename (arg->argv0));
1723 error_exit:
1724  return EXIT_FAILURE;
1725 }
1726 
1727 #if defined(ENABLE_UNUSED_FUNCTION )
1728 /*
1729  * estimatedb_data() - estimatedb_data main routine
1730  * return: EXIT_SUCCES/EXIT_FAILURE
1731  */
1732 int
1734 {
1735  /* todo: remove me */
1736 }
1737 #endif /* ENABLE_UNUSED_FUNCTION */
1738 
1739 #if defined(ENABLE_UNUSED_FUNCTION )
1740 /*
1741  * estimatedb_index() - restoredb main routine
1742  * return: 0 : success
1743  * non-zero : error
1744  */
1745 int
1747 {
1748  UTIL_ARG_MAP *arg_map = arg->arg_map;
1749  int num_instance;
1750  int num_diffkeys;
1751  int avg_key_size;
1752  const char *key_type;
1753 
1754  int status = -1;
1755  int npages = 0;
1756  int blt_npages = 0;
1757  int blt_wrs_npages = 0;
1758  PR_TYPE *type;
1759  DB_DOMAIN *domain = (DB_DOMAIN *) 0;
1760 
1761  if (utility_get_option_string_table_size (arg_map) != 4)
1762  {
1763  goto print_estimate_index_usage;
1764  }
1765 
1766  num_instance = atoi (utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0));
1767  num_diffkeys = atoi (utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1));
1768  avg_key_size = atoi (utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 2));
1769  key_type = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 3);
1770 
1773  if (num_instance <= num_diffkeys)
1774  {
1775  num_instance = num_diffkeys;
1776  }
1777  /* Initialize domain area */
1778  tp_init ();
1779 
1780  /* Initialize tsc-timer */
1781  tsc_init ();
1782 
1783  if (key_type != NULL)
1784  {
1785  domain = pt_string_to_db_domain (key_type, (const char *) NULL);
1786  if (domain)
1787  {
1788  type = domain->type;
1789  if (type != NULL)
1790  {
1791  if (tp_valid_indextype (type->id))
1792  {
1793 
1794 
1795  switch (type->id)
1796  {
1797  case DB_TYPE_BIT:
1798  case DB_TYPE_VARBIT:
1799  case DB_TYPE_CHAR:
1800  case DB_TYPE_VARCHAR:
1801  case DB_TYPE_NCHAR:
1802  case DB_TYPE_VARNCHAR:
1803  /* Do not override any information in Avg_key_size with precision information. Just make sure the
1804  * input makes sense for these cases. */
1805  if (avg_key_size > domain->precision)
1806  {
1807  /* Does not make sense to have avg_key_size bigger than precision - inform user of error.
1808  * This is illegal input since the char precision defaults to 1. estimatedb_index 100000 1000
1809  * 5 char */
1810  status = -2;
1811  }
1812  break;
1813  default:
1814  break;
1815  }
1816 
1817  if (status != -2)
1818  {
1819  /*
1820  * This will call pr_estimate_size which uses the
1821  * Avg_key_size and TP_DOMAIN_TYPE(domain) to really
1822  * compute the correct average key size that we
1823  * need to estimate the total number of pages.
1824  */
1825  npages =
1826  btree_estimate_total_numpages (NULL, num_diffkeys, avg_key_size, num_instance, &blt_npages,
1827  &blt_wrs_npages);
1828 
1829  fprintf (stdout,
1832  fprintf (stdout,
1834  ESTIMATEDB_INDEX_MSG_INSTANCES), num_instance);
1835  fprintf (stdout,
1837  ESTIMATEDB_INDEX_MSG_NUMBER_KEYS), num_diffkeys);
1838  fprintf (stdout,
1840  ESTIMATEDB_INDEX_MSG_AVG_KEYSIZE), avg_key_size);
1841  fprintf (stdout,
1843  ESTIMATEDB_INDEX_MSG_KEYTYPE), key_type);
1844  fflush (stdout);
1845  status = 0;
1846  }
1847  }
1848  }
1849  }
1850  }
1851 
1852  /* Remove domain area */
1853  tp_final ();
1854  switch (status)
1855  {
1856  case -1:
1857  fprintf (stderr,
1859  key_type);
1860  break;
1861  case -2:
1862  fprintf (stderr,
1864  avg_key_size, domain->precision);
1865  break;
1866  case 1:
1867  fprintf (stderr,
1869  break;
1870  default:
1871  fprintf (stdout,
1873  npages);
1874  fprintf (stdout,
1876  blt_npages);
1877  fprintf (stdout,
1879  ESTIMATEDB_INDEX_MSG_BLT_WRS_NPAGES), blt_wrs_npages);
1880  break;
1881  }
1882  return status;
1883 
1884 print_estimate_index_usage:
1886  basename (arg->argv0));
1887  return EXIT_FAILURE;
1888 }
1889 #endif /* ENABLE_UNUSED_FUNCTION */
1890 
1891 /*
1892  * alterdbhost() - restoredb main routine
1893  * return: EXIT_SUCCESS/EXIT_FAILURE
1894  */
1895 int
1897 {
1898  UTIL_ARG_MAP *arg_map = arg->arg_map;
1899  const char *db_name;
1900  const char *host_name;
1901  int dbtxt_vdes = NULL_VOLDES;
1902  int log_vdes = NULL_VOLDES;
1903  char dbtxt_label[PATH_MAX];
1904  char host_name_buf[CUB_MAXHOSTNAMELEN + 1];
1905  DB_INFO *db = NULL;
1906  DB_INFO *dir = NULL;
1907  const char *log_prefix;
1908  int num_hosts;
1909 
1910  if (utility_get_option_string_table_size (arg_map) != 1)
1911  {
1912  goto print_alterdbhost_usage;
1913  }
1914 
1915  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1916  if (db_name == NULL)
1917  {
1918  goto print_alterdbhost_usage;
1919  }
1920 
1921  host_name = utility_get_option_string_value (arg_map, ALTERDBHOST_HOST_S, 0);
1922  if (check_database_name (db_name))
1923  {
1924  goto error_exit;
1925  }
1926 
1927  /* If a host was not given, assume the current host */
1928  if (host_name == NULL)
1929  {
1930 #if 0 /* use Unix-domain socket for localhost */
1931  if (GETHOSTNAME (host_name_buf, CUB_MAXHOSTNAMELEN) != 0)
1932  {
1934  goto error;
1935  }
1936 #else
1937  strcpy (host_name_buf, "localhost");
1938 #endif
1939  host_name = host_name_buf;
1940  }
1941 
1943 
1944  /* get the database directory information in write mode */
1945  if (cfg_maycreate_get_directory_filename (dbtxt_label) == NULL
1946 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
1947 /* Temporary fix for NT file locking problem */
1948  || (dbtxt_vdes = fileio_mount (NULL, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) == NULL_VOLDES
1949 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
1950  )
1951  {
1952  goto error;
1953  }
1954 
1955  if (dbtxt_vdes != NULL_VOLDES)
1956  {
1957  if (cfg_read_directory_ex (dbtxt_vdes, &dir, true) != NO_ERROR)
1958  {
1959  goto error;
1960  }
1961  }
1962  else
1963  {
1964  if (cfg_read_directory (&dir, true) != NO_ERROR)
1965  {
1966  goto error;
1967  }
1968  }
1969  db = cfg_find_db_list (dir, db_name);
1970  if (db == NULL)
1971  {
1973  goto error;
1974  }
1975 
1976  /* Compose the full name of the database and find location of logs */
1977  log_prefix = fileio_get_base_file_name (db_name);
1978  COMPOSE_FULL_NAME (BO_DB_FULLNAME, sizeof (BO_DB_FULLNAME), db->pathname, db_name);
1979 
1980  /* System is not restarted. Read the header from disk */
1982 
1983  /* Avoid setting errors at this moment related to existance of files. */
1984  if (fileio_is_volume_exist (log_Name_active) == false)
1985  {
1986  goto error;
1987  }
1988 
1989  if ((log_vdes =
1991  {
1992  goto error;
1993  }
1994 
1995  if (db->hosts != NULL)
1996  {
1997  cfg_free_hosts (db->hosts);
1998  }
1999  db->hosts = cfg_get_hosts (host_name, &num_hosts, false);
2000 
2001  /* Dismount lgat */
2002  fileio_dismount (NULL, log_vdes);
2003 
2004 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
2005  /* must unlock this before we can open it again for writing */
2006  if (dbtxt_vdes != NULL_VOLDES)
2007  {
2008  fileio_dismount (NULL, dbtxt_vdes);
2009  dbtxt_vdes = NULL_VOLDES;
2010  }
2011 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
2012  if (dbtxt_vdes != NULL_VOLDES)
2013  {
2014  cfg_write_directory_ex (dbtxt_vdes, dir);
2015  }
2016  else
2017  {
2018  cfg_write_directory (dir);
2019  }
2020 
2021  cfg_free_directory (dir);
2022  if (dbtxt_vdes != NULL_VOLDES)
2023  {
2024  fileio_dismount (NULL, dbtxt_vdes);
2025  }
2026 
2027  return EXIT_SUCCESS;
2028 
2029 error:
2030  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2031 
2032  /* Deallocate any allocated structures */
2033  if (dir != NULL)
2034  {
2035  cfg_free_directory (dir);
2036  }
2037 
2038  if (dbtxt_vdes != NULL_VOLDES)
2039  {
2040  fileio_dismount (NULL, dbtxt_vdes);
2041  }
2042 
2043  return EXIT_FAILURE;
2044 
2045 print_alterdbhost_usage:
2047  basename (arg->argv0));
2049 
2050 error_exit:
2051  return EXIT_FAILURE;
2052 }
2053 
2054 /*
2055  * genlocale() - generate locales binary files
2056  * return: EXIT_SUCCESS/EXIT_FAILURE
2057  */
2058 int
2060 {
2061  char *locale_str = NULL;
2062  char *input_path = NULL;
2063  bool is_scan_locales = false;
2064  bool is_verbose = false;
2065  LOCALE_FILE *lf = NULL;
2066  LOCALE_FILE *curr_lf = NULL;
2067  int count_loc = 0, i;
2068  int start_lf_pos = -1;
2069  int end_lf_pos = -1;
2070  char er_msg_file[PATH_MAX];
2071  int str_count = 0;
2072  UTIL_ARG_MAP *arg_map = NULL;
2073  LOCALE_DATA **ld = NULL;
2074 
2075  int err_status = EXIT_SUCCESS;
2076 
2077  assert (arg != NULL);
2078 
2079  arg_map = arg->arg_map;
2080 
2081  if (!arg->valid_arg)
2082  {
2083  goto print_genlocale_usage;
2084  }
2085 
2086  str_count = utility_get_option_string_table_size (arg_map);
2087  if (str_count == 0)
2088  {
2089  is_scan_locales = true;
2090  locale_str = NULL;
2091  }
2092  else if (str_count == 1)
2093  {
2094  locale_str = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2095  if (locale_str == NULL)
2096  {
2097  goto print_genlocale_usage;
2098  }
2099  }
2100  else
2101  {
2102  goto print_genlocale_usage;
2103  }
2104 
2105  is_verbose = utility_get_option_bool_value (arg_map, GENLOCALE_VERBOSE_S);
2106 
2107  input_path = utility_get_option_string_value (arg_map, GENLOCALE_INPUT_PATH_S, 0);
2108  if (input_path != NULL && is_scan_locales)
2109  {
2110  goto print_genlocale_usage;
2111  }
2112 
2113  /* initialization of language module for built-in locales and collations, we don't care about environment here */
2114  lang_init_builtin ();
2115 
2116  /* error message log file */
2117  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s.err", arg->command_name);
2118  er_init (er_msg_file, ER_NEVER_EXIT);
2119 
2120  if (locale_get_cfg_locales (&lf, &count_loc, false) != NO_ERROR)
2121  {
2122  err_status = EXIT_FAILURE;
2123  goto exit;
2124  }
2125 
2126  if (is_scan_locales)
2127  {
2128  if (is_verbose)
2129  {
2130  printf ("\n\nFound %d locale files\n\n", count_loc);
2131  }
2132  start_lf_pos = 0;
2133  end_lf_pos = count_loc;
2134  }
2135  else
2136  {
2137  assert (locale_str != NULL);
2138 
2139  for (i = 0; i < count_loc; i++)
2140  {
2141  if (strcmp (locale_str, lf[i].locale_name) == 0)
2142  {
2143  curr_lf = &(lf[i]);
2144  start_lf_pos = i;
2145  end_lf_pos = i + 1;
2146  break;
2147  }
2148  }
2149 
2150  if (curr_lf == NULL)
2151  {
2154  true);
2155  err_status = EXIT_FAILURE;
2156  goto exit;
2157  }
2158 
2159  if (input_path != NULL)
2160  {
2161  if (curr_lf->ldml_file != NULL)
2162  {
2163  free (curr_lf->ldml_file);
2164  }
2165 
2166  curr_lf->ldml_file = strdup (input_path);
2167  if (curr_lf->ldml_file == NULL)
2168  {
2170  err_status = EXIT_FAILURE;
2171  goto exit;
2172  }
2173  }
2174  }
2175 
2176  ld = (LOCALE_DATA **) malloc (count_loc * sizeof (LOCALE_DATA *));
2177  if (ld == NULL)
2178  {
2180  err_status = EXIT_FAILURE;
2181  goto exit;
2182  }
2183  memset (ld, 0, count_loc * sizeof (LOCALE_DATA *));
2184 
2185 
2186  for (i = start_lf_pos; i < end_lf_pos; i++)
2187  {
2188  ld[i] = (LOCALE_DATA *) malloc (sizeof (LOCALE_DATA));
2189  if (ld[i] == NULL)
2190  {
2192  err_status = EXIT_FAILURE;
2193  goto exit;
2194  }
2195  memset (ld[i], 0, sizeof (LOCALE_DATA));
2196  }
2197 
2198  for (i = start_lf_pos; i < end_lf_pos; i++)
2199  {
2200  if (locale_check_and_set_default_files (&(lf[i]), false) != NO_ERROR)
2201  {
2202  err_status = EXIT_FAILURE;
2203  goto exit;
2204  }
2205 
2206  if (is_verbose)
2207  {
2208  printf ("*********************************\n");
2209  printf ("Compile locale:\n");
2210  printf ("Locale string: %s\n", lf[i].locale_name);
2211  printf ("Input LDML: %s\n", lf[i].ldml_file);
2212  printf ("Output Library: %s\n", lf[i].lib_file);
2213  }
2214 
2215  if (locale_compile_locale (&(lf[i]), ld[i], is_verbose) != NO_ERROR)
2216  {
2217  err_status = EXIT_FAILURE;
2218  goto exit;
2219  }
2220 
2221  if (!is_scan_locales)
2222  {
2223  break;
2224  }
2225  }
2226 
2227  locale_mark_duplicate_collations (ld, start_lf_pos, end_lf_pos, is_verbose);
2228 
2229  if (locale_prepare_C_file () != NO_ERROR || locale_save_all_to_C_file (ld, start_lf_pos, end_lf_pos, lf) != NO_ERROR)
2230  {
2231  err_status = EXIT_FAILURE;
2232  goto exit;
2233  }
2234 
2235 exit:
2236 
2237  /* Deallocate any allocated structures */
2238  for (i = 0; i < count_loc; i++)
2239  {
2240  if (lf[i].locale_name != NULL)
2241  {
2242  free_and_init (lf[i].locale_name);
2243  }
2244  if (lf[i].ldml_file != NULL)
2245  {
2246  free_and_init (lf[i].ldml_file);
2247  }
2248  if (lf[i].lib_file != NULL)
2249  {
2250  free_and_init (lf[i].lib_file);
2251  }
2252  if (ld != NULL && ld[i] != NULL)
2253  {
2254  locale_destroy_data (ld[i]);
2255  free (ld[i]);
2256  }
2257  }
2258 
2259  if (ld != NULL)
2260  {
2261  free (ld);
2262  }
2263 
2265 
2266  assert (lf != NULL);
2267  free_and_init (lf);
2268 
2269  if (err_status != EXIT_SUCCESS && er_errid () != NO_ERROR)
2270  {
2271  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2272  }
2273 
2274  return err_status;
2275 
2276 print_genlocale_usage:
2278  basename (arg->argv0));
2280 
2281  return EXIT_FAILURE;
2282 }
2283 
2284 /*
2285  * dumplocale() - generate locales binary files
2286  * return: error status
2287  */
2288 int
2290 {
2291  char *locale_str = NULL;
2292  char *input_path = NULL;
2293  char *alphabet_type = NULL;
2294  LANG_LOCALE_DATA lld;
2295  void *loclib_handle = NULL;
2296  LOCALE_FILE *lf = NULL;
2297  LOCALE_FILE lf_one;
2298  int dl_settings = 0;
2299  int str_count, i, count_loc, loc_index;
2300  int start_value = 0;
2301  int end_value = 0;
2302  UTIL_ARG_MAP *arg_map = NULL;
2303  int err_status = NO_ERROR;
2304 
2305  assert (arg != NULL);
2306  arg_map = arg->arg_map;
2307 
2308  if (!arg->valid_arg)
2309  {
2311  goto print_dumplocale_usage;
2312  }
2313 
2314  str_count = utility_get_option_string_table_size (arg_map);
2315 
2316  locale_str = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2317 
2318  input_path = utility_get_option_string_value (arg_map, DUMPLOCALE_INPUT_PATH_S, 0);
2319 
2321  {
2322  dl_settings |= DUMPLOCALE_IS_CALENDAR;
2323  }
2324 
2326  {
2327  dl_settings |= DUMPLOCALE_IS_NUMBERING;
2328  }
2329 
2330  alphabet_type = utility_get_option_string_value (arg_map, DUMPLOCALE_ALPHABET_S, 0);
2331  if (alphabet_type != NULL)
2332  {
2333  if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_LOWER_S) == 0
2334  || strcmp (alphabet_type, DUMPLOCALE_ALPHABET_LOWER_L) == 0)
2335  {
2336  dl_settings |= DUMPLOCALE_IS_ALPHABET;
2337  dl_settings |= DUMPLOCALE_IS_ALPHABET_LOWER;
2338  dl_settings &= ~DUMPLOCALE_IS_ALPHABET_UPPER;
2339  }
2340  else if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_UPPER_S) == 0
2341  || strcmp (alphabet_type, DUMPLOCALE_ALPHABET_UPPER_L) == 0)
2342  {
2343  dl_settings |= DUMPLOCALE_IS_ALPHABET;
2344  dl_settings &= ~DUMPLOCALE_IS_ALPHABET_LOWER;
2345  dl_settings |= DUMPLOCALE_IS_ALPHABET_UPPER;
2346  }
2347  else if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_ALL_CASING) == 0)
2348  {
2349  dl_settings |= DUMPLOCALE_IS_ALPHABET;
2350  dl_settings |= DUMPLOCALE_IS_ALPHABET_LOWER;
2351  dl_settings |= DUMPLOCALE_IS_ALPHABET_UPPER;
2352  }
2353  }
2354 
2355  alphabet_type = NULL;
2356  /* check if --identifier-alphabet is set. */
2358  if (alphabet_type != NULL)
2359  {
2360  if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_LOWER_S) == 0
2361  || strcmp (alphabet_type, DUMPLOCALE_ALPHABET_LOWER_L) == 0)
2362  {
2363  dl_settings |= DUMPLOCALE_IS_IDENTIFIER_ALPHABET;
2366  }
2367  else if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_UPPER_S) == 0
2368  || strcmp (alphabet_type, DUMPLOCALE_ALPHABET_UPPER_L) == 0)
2369  {
2370  dl_settings |= DUMPLOCALE_IS_IDENTIFIER_ALPHABET;
2373  }
2374  else if (strcmp (alphabet_type, DUMPLOCALE_ALPHABET_ALL_CASING) == 0)
2375  {
2376  dl_settings |= DUMPLOCALE_IS_IDENTIFIER_ALPHABET;
2379  }
2380  }
2381 
2383  {
2384  dl_settings |= DUMPLOCALE_IS_COLLATION_CP_ORDER;
2385  }
2386 
2388  {
2389  dl_settings |= DUMPLOCALE_IS_COLLATION_WEIGHT_ORDER;
2390  }
2391  start_value = utility_get_option_int_value (arg_map, DUMPLOCALE_START_VALUE_S);
2393 
2395  {
2396  dl_settings |= DUMPLOCALE_IS_NORMALIZATION;
2397  }
2398 
2400  {
2401  dl_settings |= DUMPLOCALE_IS_TEXT_CONV;
2402  }
2403 
2404  /* Check command line arguments for incompatibilities. */
2405  if (locale_str != NULL && input_path != NULL)
2406  {
2407  err_status = ER_LOC_GEN;
2410  ER_LOC_GEN, true);
2411  goto print_dumplocale_usage;
2412  }
2413  if (start_value > end_value)
2414  {
2415  err_status = ER_LOC_GEN;
2418  true);
2419  goto print_dumplocale_usage;
2420  }
2421 
2422  /* Start the dumping process. */
2423  /* Prepare the locale file(s) to be dumped. */
2424  memset (&lf_one, 0, sizeof (LOCALE_FILE));
2425  memset (&lld, 0, sizeof (LANG_LOCALE_DATA));
2426 
2427  if (locale_str != NULL)
2428  {
2429  /* Find binary file corresponding to the selected locale. */
2430  count_loc = 1;
2431  lf = &lf_one;
2432  if (locale_str == NULL || strlen (locale_str) > LOC_LOCALE_STR_SIZE)
2433  {
2434  err_status = ER_LOC_INIT;
2437  err_status, true);
2438  goto error;
2439  }
2440  lf->locale_name = (char *) malloc (strlen (locale_str) + 1);
2441  if (lf->locale_name == NULL)
2442  {
2443  err_status = ER_LOC_INIT;
2444  LOG_LOCALE_ERROR ("memory allocation failed", err_status, true);
2445  goto error;
2446  }
2447  strcpy (lf->locale_name, locale_str);
2448  err_status = locale_check_and_set_default_files (lf, true);
2449  }
2450  else
2451  {
2452  /* Parse cubrid_locales.txt and select all locale files. */
2453  err_status = locale_get_cfg_locales (&lf, &count_loc, false);
2454  }
2455 
2456  if (err_status != NO_ERROR)
2457  {
2458  goto error;
2459  }
2460 
2461  if (input_path != NULL)
2462  {
2463  /* set lib file in all locales */
2464  for (i = 0; i < count_loc; i++)
2465  {
2466  if (lf[i].lib_file != NULL)
2467  {
2468  free_and_init (lf[i].lib_file);
2469  }
2470 
2471  lf[i].lib_file = strdup (input_path);
2472  if (lf[i].lib_file == NULL)
2473  {
2474  err_status = ER_LOC_INIT;
2475  LOG_LOCALE_ERROR ("memory allocation failed", err_status, true);
2476  goto error;
2477  }
2478  }
2479  }
2480 
2481  /* Do the actual dumping. */
2482  for (loc_index = 0; loc_index < count_loc; loc_index++)
2483  {
2484  err_status = locale_check_and_set_default_files (&(lf[loc_index]), true);
2485  if (err_status != NO_ERROR)
2486  {
2487  goto error;
2488  }
2489 
2490  memset (&lld, 0, sizeof (LANG_LOCALE_DATA));
2491 
2492  err_status = lang_load_library (lf[loc_index].lib_file, &loclib_handle);
2493 
2494  if (err_status != NO_ERROR)
2495  {
2496  goto error;
2497  }
2498 
2499  err_status = lang_locale_data_load_from_lib (&lld, loclib_handle, &(lf[loc_index]), true);
2500  if (err_status != NO_ERROR)
2501  {
2502  goto error;
2503  }
2504  err_status = locale_dump (&lld, &(lf[loc_index]), dl_settings, start_value, end_value);
2505  if (err_status != NO_ERROR)
2506  {
2507  goto error;
2508  }
2509 
2510  if (((dl_settings & DUMPLOCALE_IS_COLLATION_CP_ORDER) != 0)
2511  || ((dl_settings & DUMPLOCALE_IS_COLLATION_WEIGHT_ORDER) != 0))
2512  {
2513  err_status =
2514  locale_dump_lib_collations (loclib_handle, &(lf[loc_index]), dl_settings, start_value, end_value);
2515 
2516  if (err_status != NO_ERROR)
2517  {
2518  goto error;
2519  }
2520  }
2521 
2522  if (lld.txt_conv != NULL && lld.txt_conv->init_conv_func == NULL)
2523  {
2524  free (lld.txt_conv);
2525  lld.txt_conv = NULL;
2526  }
2527 
2528 #if defined(WINDOWS)
2529  FreeLibrary ((HMODULE) loclib_handle);
2530 #else
2531  dlclose (loclib_handle);
2532 #endif
2533  }
2534 
2535 error:
2536  for (i = 0; i < count_loc; i++)
2537  {
2538  if (lf[i].lib_file != NULL)
2539  {
2540  free (lf[i].lib_file);
2541  }
2542  if (lf[i].ldml_file != NULL)
2543  {
2544  free (lf[i].ldml_file);
2545  }
2546  if (lf[i].locale_name != NULL)
2547  {
2548  free (lf[i].locale_name);
2549  }
2550  }
2551 
2552  if (lf != &lf_one)
2553  {
2554  free (lf);
2555  lf = NULL;
2556  }
2557 
2558  /*
2559  * Text conversions having init_conv_func not NULL are built-in.
2560  * They can't be deallocates, as they are static constants.
2561  */
2562  if (lld.txt_conv != NULL && lld.txt_conv->init_conv_func == NULL)
2563  {
2564  free (lld.txt_conv);
2565  lld.txt_conv = NULL;
2566  }
2567 
2568  return err_status;
2569 
2570 print_dumplocale_usage:
2572  basename (arg->argv0));
2573 
2574  return EXIT_FAILURE;
2575 }
2576 
2577 /*
2578  * synccolldb() - sync_collations main routine
2579  * return: EXIT_SUCCESS/EXIT_FAILURE
2580  */
2581 int
2583 {
2584  UTIL_ARG_MAP *arg_map = arg->arg_map;
2585  char er_msg_file[PATH_MAX];
2586  const char *db_name;
2587  int status = EXIT_SUCCESS;
2588  bool is_check, is_force, is_sync = true;
2589  int db_obs_coll_cnt = 0;
2590  int new_sys_coll_cnt = 0;
2591 
2592  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2593  if (db_name == NULL)
2594  {
2595  goto print_sync_collations_usage;
2596  }
2597 
2598  if (utility_get_option_string_table_size (arg_map) != 1)
2599  {
2600  goto print_sync_collations_usage;
2601  }
2602 
2603  is_check = utility_get_option_bool_value (arg_map, SYNCCOLL_CHECK_S);
2605 
2606  if (is_check && is_force)
2607  {
2608  goto print_sync_collations_usage;
2609  }
2610 
2611  if (is_check || is_force)
2612  {
2613  is_sync = false;
2614  }
2615 
2616  if (check_database_name (db_name))
2617  {
2618  goto error_exit;
2619  }
2620 
2621  /* error message log file */
2622  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
2623  er_init (er_msg_file, ER_NEVER_EXIT);
2624 
2626 
2629  db_login ("DBA", NULL);
2630  if (db_restart (arg->command_name, TRUE, db_name) != NO_ERROR)
2631  {
2632  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2633  goto error_exit;
2634  }
2635 
2636  if (is_check || is_sync)
2637  {
2638  status = synccoll_check (db_name, &db_obs_coll_cnt, &new_sys_coll_cnt);
2639  if (status != EXIT_SUCCESS)
2640  {
2641  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2642  goto exit;
2643  }
2644 
2645  if (!is_sync && (db_obs_coll_cnt != 0 || new_sys_coll_cnt != 0))
2646  {
2647  /* return error if synchronization is required */
2648  status = EXIT_FAILURE;
2649  goto exit;
2650  }
2651  }
2652 
2653  if (is_sync || is_force)
2654  {
2655  char yn[2];
2656 
2657  if (!is_force && db_obs_coll_cnt == 0 && new_sys_coll_cnt == 0)
2658  {
2659  /* message SYNCCOLLDB_MSG_SYNC_NOT_NEEDED displayed in 'synccoll_check' */
2660  goto exit;
2661  }
2662 
2663  if (!is_force)
2664  {
2665  fprintf (stdout,
2667  scanf ("%1s", yn);
2668  if (yn[0] != 'y')
2669  {
2672  goto exit;
2673  }
2674  }
2675 
2676  status = synccoll_force ();
2677  if (status != EXIT_SUCCESS)
2678  {
2679  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2681  fprintf (stdout,
2683  goto exit;
2684  }
2685  else
2686  {
2690  }
2691  }
2692 
2693 exit:
2694  db_shutdown ();
2695 
2696  return status;
2697 
2698 print_sync_collations_usage:
2700  basename (arg->argv0));
2702 
2703 error_exit:
2704  return EXIT_FAILURE;
2705 }
2706 
2707 /*
2708  * synccoll_check() - sync_collations check
2709  * return: EXIT_SUCCESS/EXIT_FAILURE
2710  */
2711 static int
2712 synccoll_check (const char *db_name, int *db_obs_coll_cnt, int *new_sys_coll_cnt)
2713 {
2714 #define FILE_STMT_NAME "cubrid_synccolldb_"
2715 #define QUERY_SIZE 1024
2716 
2717  LANG_COLL_COMPAT *db_collations = NULL;
2718  DB_QUERY_RESULT *query_result = NULL;
2719  const LANG_COLL_COMPAT *db_coll;
2720  LANG_COLLATION *lc;
2721  FILE *f_stmt = NULL;
2722  char f_stmt_name[PATH_MAX];
2723  int sys_coll_found[LANG_MAX_COLLATIONS] = { 0 };
2724  int sys_coll_found_cnt = 0;
2725  int i, db_coll_cnt;
2726  int status = EXIT_SUCCESS;
2727  int db_status;
2728  char *vclass_names = NULL;
2729  int vclass_names_used = 0;
2730  int vclass_names_alloced = 0;
2731  char *part_tables = NULL;
2732  int part_tables_used = 0;
2733  int part_tables_alloced = 0;
2734  bool need_manual_sync = false;
2735  THREAD_ENTRY *thread_p;
2736 
2737  assert (db_name != NULL);
2738  assert (db_obs_coll_cnt != NULL);
2739  assert (new_sys_coll_cnt != NULL);
2740 
2741  *db_obs_coll_cnt = 0;
2742  *new_sys_coll_cnt = 0;
2743 
2744  thread_p = thread_get_thread_entry_info ();
2745 
2746  /* read all collations from DB : id, name, checksum */
2747  db_status = catcls_get_db_collation (thread_p, &db_collations, &db_coll_cnt);
2748  if (db_status != NO_ERROR)
2749  {
2750  if (db_collations != NULL)
2751  {
2752  db_private_free (thread_p, db_collations);
2753  }
2754  status = EXIT_FAILURE;
2755  goto exit;
2756  }
2757 
2758  assert (db_collations != NULL);
2759 
2760  strcpy (f_stmt_name, FILE_STMT_NAME);
2761  strcat (f_stmt_name, db_name);
2762  strcat (f_stmt_name, ".sql");
2763 
2764  f_stmt = fopen (f_stmt_name, "wt");
2765  if (f_stmt == NULL)
2766  {
2767  fprintf (stderr,
2769  f_stmt_name);
2770  goto exit;
2771  }
2772 
2773  for (i = 0; i < db_coll_cnt; i++)
2774  {
2775  DB_QUERY_ERROR query_error;
2776  char query[QUERY_SIZE];
2777  int j;
2778  bool is_obs_coll = false;
2779  bool check_atts = false;
2780  bool check_views = false;
2781  bool check_triggers = false;
2782  bool check_func_index = false;
2783  bool check_tables = false;
2784 
2785  db_coll = &(db_collations[i]);
2786 
2787  assert (db_coll->coll_id >= 0 && db_coll->coll_id < LANG_MAX_COLLATIONS);
2788 
2789  for (j = 0; j < LANG_MAX_COLLATIONS; j++)
2790  {
2791  lc = lang_get_collation (j);
2792  if (strcmp (db_coll->coll_name, lc->coll.coll_name) == 0)
2793  {
2794  sys_coll_found[j] = 1;
2795  sys_coll_found_cnt++;
2796  break;
2797  }
2798  }
2799 
2800  /* check if same collation */
2801  lc = lang_get_collation (db_coll->coll_id);
2802  assert (lc != NULL);
2803 
2804  if (lc->coll.coll_id != db_coll->coll_id || lc->codeset != db_coll->codeset
2805  || strcasecmp (lc->coll.checksum, db_coll->checksum) != 0)
2806  {
2807  check_tables = true;
2808  check_views = true;
2809  check_atts = true;
2810  check_triggers = true;
2811  check_func_index = true;
2812  is_obs_coll = true;
2813  }
2814  else if (strcmp (lc->coll.coll_name, db_coll->coll_name))
2815  {
2816  check_tables = true;
2817  check_views = true;
2818  check_triggers = true;
2819  is_obs_coll = true;
2820  check_func_index = true;
2821  }
2822 
2823  if (is_obs_coll)
2824  {
2825  (*db_obs_coll_cnt)++;
2826  fprintf (stdout, "----------------------------------------\n");
2827  fprintf (stdout, "----------------------------------------\n");
2829  db_coll->coll_name, db_coll->coll_id);
2830  }
2831 
2832  if (check_tables)
2833  {
2834  /* get table names having collation; do not include partition sub-classes */
2835  sprintf (query,
2836  "SELECT C.class_name, C.class_type " "FROM _db_class C " "WHERE C.collation_id = %d "
2837  "AND NOT (C.class_name IN " "(SELECT P.class_of.class_name " "FROM _db_partition P WHERE "
2838  "P.class_of.class_name " " = C.class_name AND P.pname IS NOT NULL))", db_coll->coll_id);
2839 
2840  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
2841 
2842  if (db_status < 0)
2843  {
2844  status = EXIT_FAILURE;
2845  goto exit;
2846  }
2847  else if (db_status > 0)
2848  {
2849  DB_VALUE class_name;
2850  DB_VALUE ct;
2851 
2852  fprintf (stdout, "----------------------------------------\n");
2853  fprintf (stdout,
2855  db_coll->coll_name);
2856 
2857  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
2858  {
2859  if (db_query_get_tuple_value (query_result, 0, &class_name) != NO_ERROR
2860  || db_query_get_tuple_value (query_result, 1, &ct) != NO_ERROR)
2861  {
2862  status = EXIT_FAILURE;
2863  goto exit;
2864  }
2865 
2866  assert (DB_VALUE_TYPE (&class_name) == DB_TYPE_STRING);
2868 
2869  if (db_get_int (&ct) != 0)
2870  {
2871  continue;
2872  }
2873  fprintf (stdout, "%s\n", db_get_string (&class_name));
2874 
2875  /* output query to fix schema */
2876  snprintf (query, sizeof (query) - 1, "ALTER TABLE [%s] " "COLLATE utf8_bin;",
2877  db_get_string (&class_name));
2878  fprintf (f_stmt, "%s\n", query);
2879  need_manual_sync = true;
2880  }
2881  }
2882 
2883  if (query_result != NULL)
2884  {
2885  db_query_end (query_result);
2886  query_result = NULL;
2887  }
2888  }
2889 
2890  if (check_atts)
2891  {
2892  /* first drop foreign keys on attributes using collation; do not include partition sub-classes */
2893  /* CLASS_NAME, INDEX_NAME */
2894 
2895  sprintf (query,
2896  "SELECT A.class_of.class_name, I.index_name " "from _db_attribute A, _db_index I, "
2897  "_db_index_key IK, _db_domain D " "where D.object_of = A AND D.collation_id = %d AND "
2898  "NOT (A.class_of.class_name IN (SELECT " "P.class_of.class_name " "FROM _db_partition P WHERE "
2899  "P.class_of.class_name = " "A.class_of.class_name AND P.pname IS NOT NULL))"
2900  "AND A.attr_name = IK.key_attr_name AND IK in I.key_attrs "
2901  "AND I.is_foreign_key = 1 AND I.class_of = A.class_of", db_coll->coll_id);
2902 
2903  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
2904 
2905  if (db_status < 0)
2906  {
2907  status = EXIT_FAILURE;
2908  goto exit;
2909  }
2910  else if (db_status > 0)
2911  {
2912  DB_VALUE class_name;
2913  DB_VALUE index_name;
2914 
2915  fprintf (stdout, "----------------------------------------\n");
2916  fprintf (stdout,
2918  db_coll->coll_name);
2919 
2920  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
2921  {
2922  if (db_query_get_tuple_value (query_result, 0, &class_name) != NO_ERROR
2923  || db_query_get_tuple_value (query_result, 1, &index_name) != NO_ERROR)
2924  {
2925  status = EXIT_FAILURE;
2926  goto exit;
2927  }
2928  assert (DB_VALUE_TYPE (&class_name) == DB_TYPE_STRING);
2929  assert (DB_VALUE_TYPE (&index_name) == DB_TYPE_STRING);
2930  fprintf (stdout, "%s | %s\n", db_get_string (&class_name), db_get_string (&index_name));
2931  snprintf (query, sizeof (query) - 1, "ALTER TABLE [%s] DROP FOREIGN KEY [%s];",
2932  db_get_string (&class_name), db_get_string (&index_name));
2933  fprintf (f_stmt, "%s\n", query);
2934  need_manual_sync = true;
2935  }
2936  }
2937 
2938  if (query_result != NULL)
2939  {
2940  db_query_end (query_result);
2941  query_result = NULL;
2942  }
2943 
2944 
2945  /* attributes having collation; do not include partition sub-classes */
2946  /* CLASS_NAME, CLASS_TYPE, ATTR_NAME, ATTR_FULL_TYPE */
2947  /* ATTR_FULL_TYPE = CHAR(20) */
2948  /* or ENUM ('a', 'b') */
2949 
2950  sprintf (query,
2951  "SELECT A.class_of.class_name, " "A.class_of.class_type, A.attr_name, " "IF (D.data_type = 35,"
2952  "CONCAT ('ENUM (', " "(SELECT GROUP_CONCAT(concat('''',EV.a,'''')) "
2953  "FROM TABLE(D.enumeration) as EV(a)) , ')'), " "CONCAT (CASE D.data_type WHEN 4 THEN 'VARCHAR' "
2954  "WHEN 25 THEN 'CHAR' WHEN 27 THEN 'NCHAR VARYING' " "WHEN 26 THEN 'NCHAR' WHEN 35 THEN 'ENUM' END, "
2955  "IF (D.prec < 0 AND " "(D.data_type = 4 OR D.data_type = 27) ," "'', CONCAT ('(', D.prec,')')))), "
2956  "CASE WHEN A.class_of.sub_classes IS NULL THEN 0 " "ELSE NVL((SELECT 1 FROM _db_partition p "
2957  "WHERE p.class_of = A.class_of AND p.pname IS NULL AND "
2958  "LOCATE(A.attr_name, TRIM(SUBSTRING(p.pexpr FROM 8 FOR "
2959  "(POSITION(' FROM ' IN p.pexpr)-8)))) > 0 ), 0) " "END " "FROM _db_domain D,_db_attribute A "
2960  "WHERE D.object_of = A AND D.collation_id = %d " "AND NOT (A.class_of.class_name IN "
2961  "(SELECT P.class_of.class_name " "FROM _db_partition P WHERE " "P.class_of.class_name "
2962  " = A.class_of.class_name AND P.pname IS NOT NULL)) " "ORDER BY A.class_of.class_name",
2963  db_coll->coll_id);
2964 
2965  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
2966 
2967  if (db_status < 0)
2968  {
2969  status = EXIT_FAILURE;
2970  goto exit;
2971  }
2972  else if (db_status > 0)
2973  {
2974  DB_VALUE class_name;
2975  DB_VALUE attr;
2976  DB_VALUE ct;
2977  DB_VALUE attr_data_type;
2978  DB_VALUE has_part;
2979 
2980  fprintf (stdout, "----------------------------------------\n");
2981  fprintf (stdout,
2983  db_coll->coll_name);
2984 
2985  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
2986  {
2987  bool add_to_part_tables = false;
2988 
2989  if (db_query_get_tuple_value (query_result, 0, &class_name) != NO_ERROR
2990  || db_query_get_tuple_value (query_result, 1, &ct) != NO_ERROR
2991  || db_query_get_tuple_value (query_result, 2, &attr) != NO_ERROR
2992  || db_query_get_tuple_value (query_result, 3, &attr_data_type) != NO_ERROR
2993  || db_query_get_tuple_value (query_result, 4, &has_part) != NO_ERROR)
2994  {
2995  status = EXIT_FAILURE;
2996  goto exit;
2997  }
2998 
2999  assert (DB_VALUE_TYPE (&class_name) == DB_TYPE_STRING);
3000  assert (DB_VALUE_TYPE (&attr) == DB_TYPE_STRING);
3002  assert (DB_VALUE_TYPE (&attr_data_type) == DB_TYPE_STRING);
3003  assert (DB_VALUE_TYPE (&has_part) == DB_TYPE_INTEGER);
3004 
3005  fprintf (stdout, "%s | %s %s\n", db_get_string (&class_name), db_get_string (&attr),
3006  db_get_string (&attr_data_type));
3007 
3008  /* output query to fix schema */
3009  if (db_get_int (&ct) == 0)
3010  {
3011  if (db_get_int (&has_part) == 1)
3012  {
3013  /* class is partitioned, remove partition; we cannot change the collation of an attribute
3014  * having partitions */
3015  fprintf (f_stmt, "ALTER TABLE [%s] REMOVE PARTITIONING;\n", db_get_string (&class_name));
3016  add_to_part_tables = true;
3017  }
3018 
3019  snprintf (query, sizeof (query) - 1, "ALTER TABLE [%s] " "MODIFY [%s] %s COLLATE utf8_bin;",
3020  db_get_string (&class_name), db_get_string (&attr), db_get_string (&attr_data_type));
3021  }
3022  else
3023  {
3024  snprintf (query, sizeof (query) - 1, "DROP VIEW [%s];", db_get_string (&class_name));
3025 
3026  if (vclass_names == NULL || vclass_names_alloced <= vclass_names_used)
3027  {
3028  if (vclass_names_alloced == 0)
3029  {
3030  vclass_names_alloced = 1 + DB_MAX_IDENTIFIER_LENGTH;
3031  }
3032  vclass_names = (char *) db_private_realloc (thread_p, vclass_names, 2 * vclass_names_alloced);
3033 
3034  if (vclass_names == NULL)
3035  {
3036  status = EXIT_FAILURE;
3037  goto exit;
3038  }
3039  vclass_names_alloced *= 2;
3040  }
3041 
3042  memcpy (vclass_names + vclass_names_used, db_get_string (&class_name),
3043  db_get_string_size (&class_name));
3044  vclass_names_used += db_get_string_size (&class_name);
3045  memcpy (vclass_names + vclass_names_used, "\0", 1);
3046  vclass_names_used += 1;
3047  }
3048  fprintf (f_stmt, "%s\n", query);
3049  need_manual_sync = true;
3050 
3051  if (add_to_part_tables)
3052  {
3053  if (part_tables == NULL || part_tables_alloced <= part_tables_used)
3054  {
3055  if (part_tables_alloced == 0)
3056  {
3057  part_tables_alloced = 1 + DB_MAX_IDENTIFIER_LENGTH;
3058  }
3059  part_tables = (char *) db_private_realloc (thread_p, part_tables, 2 * part_tables_alloced);
3060 
3061  if (part_tables == NULL)
3062  {
3063  status = EXIT_FAILURE;
3064  goto exit;
3065  }
3066  part_tables_alloced *= 2;
3067  }
3068 
3069  memcpy (part_tables + part_tables_used, db_get_string (&class_name),
3070  db_get_string_size (&class_name));
3071  part_tables_used += db_get_string_size (&class_name);
3072  memcpy (part_tables + part_tables_used, "\0", 1);
3073  part_tables_used += 1;
3074  }
3075  }
3076  if (part_tables != NULL)
3077  {
3078  char *curr_tbl = part_tables;
3079  int tbl_size = strlen (curr_tbl);
3080 
3081  fprintf (stdout, "----------------------------------------\n");
3082  fprintf (stdout,
3085 
3086  while (tbl_size > 0)
3087  {
3088  printf ("%s\n", curr_tbl);
3089  curr_tbl += tbl_size + 1;
3090  if (curr_tbl >= part_tables + part_tables_used)
3091  {
3092  break;
3093  }
3094  tbl_size = strlen (curr_tbl);
3095  }
3096  }
3097  }
3098 
3099  if (query_result != NULL)
3100  {
3101  db_query_end (query_result);
3102  query_result = NULL;
3103  }
3104  }
3105 
3106  if (check_views)
3107  {
3108  sprintf (query,
3109  "SELECT class_of.class_name, spec " "FROM _db_query_spec " "WHERE LOCATE ('collate %s', spec) > 0",
3110  db_coll->coll_name);
3111 
3112  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
3113 
3114  if (db_status < 0)
3115  {
3116  status = EXIT_FAILURE;
3117  goto exit;
3118  }
3119  else if (db_status > 0)
3120  {
3121  DB_VALUE view;
3122  DB_VALUE query_spec;
3123 
3124  fprintf (stdout, "----------------------------------------\n");
3125  fprintf (stdout,
3127  db_coll->coll_name);
3128 
3129  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
3130  {
3131  bool already_dropped = false;
3132 
3133  if (db_query_get_tuple_value (query_result, 0, &view) != NO_ERROR
3134  || db_query_get_tuple_value (query_result, 1, &query_spec) != NO_ERROR)
3135  {
3136  status = EXIT_FAILURE;
3137  goto exit;
3138  }
3139 
3140  assert (DB_VALUE_TYPE (&view) == DB_TYPE_STRING);
3141  assert (DB_VALUE_TYPE (&query_spec) == DB_TYPE_STRING);
3142 
3143  fprintf (stdout, "%s | %s\n", db_get_string (&view), db_get_string (&query_spec));
3144 
3145  /* output query to fix schema */
3146  if (vclass_names != NULL)
3147  {
3148  char *search = vclass_names;
3149  int view_name_size = db_get_string_size (&view);
3150 
3151  /* search if the view was already put in .SQL file */
3152  while (search + view_name_size < vclass_names + vclass_names_used)
3153  {
3154  if (memcmp (search, db_get_string (&view), view_name_size) == 0
3155  && *(search + view_name_size) == '\0')
3156  {
3157  already_dropped = true;
3158  break;
3159  }
3160 
3161  while (*search++ != '\0')
3162  {
3163  ;
3164  }
3165  }
3166  }
3167 
3168  if (!already_dropped)
3169  {
3170  snprintf (query, sizeof (query) - 1, "DROP VIEW [%s];", db_get_string (&view));
3171  fprintf (f_stmt, "%s\n", query);
3172  }
3173  need_manual_sync = true;
3174  }
3175  }
3176 
3177  if (query_result != NULL)
3178  {
3179  db_query_end (query_result);
3180  query_result = NULL;
3181  }
3182  }
3183 
3184  if (check_triggers)
3185  {
3186  sprintf (query, "SELECT name, condition FROM db_trigger " "WHERE LOCATE ('collate %s', condition) > 0",
3187  db_coll->coll_name);
3188 
3189  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
3190 
3191  if (db_status < 0)
3192  {
3193  status = EXIT_FAILURE;
3194  goto exit;
3195  }
3196  else if (db_status > 0)
3197  {
3198  DB_VALUE trig_name;
3199  DB_VALUE trig_cond;
3200 
3201  fprintf (stdout, "----------------------------------------\n");
3202  fprintf (stdout,
3204  db_coll->coll_name);
3205 
3206 
3207  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
3208  {
3209  if (db_query_get_tuple_value (query_result, 0, &trig_name) != NO_ERROR
3210  || db_query_get_tuple_value (query_result, 1, &trig_cond) != NO_ERROR)
3211  {
3212  status = EXIT_FAILURE;
3213  goto exit;
3214  }
3215 
3216  assert (DB_VALUE_TYPE (&trig_name) == DB_TYPE_STRING);
3217  assert (DB_VALUE_TYPE (&trig_cond) == DB_TYPE_STRING);
3218 
3219  fprintf (stdout, "%s | %s\n", db_get_string (&trig_name), db_get_string (&trig_cond));
3220 
3221  /* output query to fix schema */
3222  snprintf (query, sizeof (query) - 1, "DROP TRIGGER [%s];", db_get_string (&trig_name));
3223  fprintf (f_stmt, "%s\n", query);
3224  need_manual_sync = true;
3225  }
3226  }
3227 
3228  if (query_result != NULL)
3229  {
3230  db_query_end (query_result);
3231  query_result = NULL;
3232  }
3233  }
3234 
3235  if (check_func_index)
3236  {
3237  /* Function indexes using collation; do not include partition sub-classes */
3238  /* INDEX_NAME, FUNCTION_EXPRESSION, CLASS_NAME */
3239  sprintf (query,
3240  "SELECT index_of.index_name, func, " "index_of.class_of.class_name FROM "
3241  "_db_index_key WHERE LOCATE ('%s', func) > 0 " "AND NOT (index_of.class_of.class_name IN "
3242  "(SELECT P.class_of.class_name " "FROM _db_partition P WHERE " "P.class_of.class_name "
3243  " = index_of.class_of.class_name " "AND P.pname IS NOT NULL)) ", db_coll->coll_name);
3244 
3245  db_status = db_compile_and_execute_local (query, &query_result, &query_error);
3246 
3247  if (db_status < 0)
3248  {
3249  status = EXIT_FAILURE;
3250  goto exit;
3251  }
3252  else if (db_status > 0)
3253  {
3254  DB_VALUE index_name;
3255  DB_VALUE func_expr;
3256  DB_VALUE class_name;
3257 
3258  fprintf (stdout, "----------------------------------------\n");
3259  fprintf (stdout,
3261  db_coll->coll_name);
3262 
3263 
3264  while (db_query_next_tuple (query_result) == DB_CURSOR_SUCCESS)
3265  {
3266  if (db_query_get_tuple_value (query_result, 0, &index_name) != NO_ERROR
3267  || db_query_get_tuple_value (query_result, 1, &func_expr) != NO_ERROR
3268  || db_query_get_tuple_value (query_result, 2, &class_name) != NO_ERROR)
3269  {
3270  status = EXIT_FAILURE;
3271  goto exit;
3272  }
3273 
3274  assert (DB_VALUE_TYPE (&index_name) == DB_TYPE_STRING);
3275  assert (DB_VALUE_TYPE (&func_expr) == DB_TYPE_STRING);
3276  assert (DB_VALUE_TYPE (&class_name) == DB_TYPE_STRING);
3277 
3278  fprintf (stdout, "%s | %s | %s\n", db_get_string (&class_name), db_get_string (&index_name),
3279  db_get_string (&func_expr));
3280 
3281  /* output query to fix schema */
3282  snprintf (query, sizeof (query) - 1, "ALTER TABLE [%s] " "DROP INDEX [%s];",
3283  db_get_string (&class_name), db_get_string (&index_name));
3284  fprintf (f_stmt, "%s\n", query);
3285  need_manual_sync = true;
3286  }
3287  }
3288 
3289  if (query_result != NULL)
3290  {
3291  db_query_end (query_result);
3292  query_result = NULL;
3293  }
3294  }
3295  }
3296 
3297  fprintf (stdout, "----------------------------------------\n");
3298  fprintf (stdout, "----------------------------------------\n");
3299  if (*db_obs_coll_cnt == 0)
3300  {
3301  fprintf (stdout,
3303  db_name);
3304  }
3305  else
3306  {
3307  fprintf (stdout,
3309  *db_obs_coll_cnt);
3310  if (need_manual_sync)
3311  {
3312  fprintf (stdout,
3314  f_stmt_name);
3315  }
3316  }
3317 
3318  if (!need_manual_sync)
3319  {
3320  if (f_stmt != NULL)
3321  {
3322  fclose (f_stmt);
3323  f_stmt = NULL;
3324  }
3325  remove (f_stmt_name);
3326  }
3327 
3328  if (lang_collation_count () != sys_coll_found_cnt)
3329  {
3330  fprintf (stdout,
3332  lang_collation_count () - sys_coll_found_cnt);
3333 
3334  for (i = 0; i < LANG_MAX_COLLATIONS; i++)
3335  {
3336  if (sys_coll_found[i] == 1)
3337  {
3338  continue;
3339  }
3340 
3341  lc = lang_get_collation (i);
3342  if (lc->coll.coll_id == LANG_COLL_DEFAULT)
3343  {
3344  assert (i != 0);
3345  continue;
3346  }
3347 
3348  assert (sys_coll_found[i] == 0);
3349  /* system collation was not found in DB */
3350  fprintf (stdout, "%s\n", lc->coll.coll_name);
3351  (*new_sys_coll_cnt)++;
3352  }
3353  fprintf (stdout, "\n");
3354  }
3355 
3356  if (*db_obs_coll_cnt == 0 && *new_sys_coll_cnt == 0)
3357  {
3358  fprintf (stdout,
3360  }
3361  else
3362  {
3363  fprintf (stdout,
3365  db_name);
3366  }
3367 
3368  fprintf (stdout, "----------------------------------------\n");
3369  fprintf (stdout, "----------------------------------------\n");
3370 
3371 exit:
3372  if (vclass_names != NULL)
3373  {
3374  db_private_free (thread_p, vclass_names);
3375  vclass_names = NULL;
3376  }
3377 
3378  if (part_tables != NULL)
3379  {
3380  db_private_free (thread_p, part_tables);
3381  part_tables = NULL;
3382  }
3383 
3384  if (f_stmt != NULL)
3385  {
3386  fclose (f_stmt);
3387  f_stmt = NULL;
3388  }
3389 
3390  if (query_result != NULL)
3391  {
3392  db_query_end (query_result);
3393  query_result = NULL;
3394  }
3395  if (db_collations != NULL)
3396  {
3397  db_private_free (thread_p, db_collations);
3398  }
3399 
3400  return status;
3401 
3402 #undef FILE_STMT_NAME
3403 #undef QUERY_SIZE
3404 }
3405 
3406 /*
3407  * synccoll_force() - sync_collations force new collation into DB
3408  * return: EXIT_SUCCESS/EXIT_FAILURE
3409  */
3410 int
3412 {
3413  DB_OBJECT *class_mop;
3414  int status = EXIT_SUCCESS;
3415  int au_save;
3416 
3417  class_mop = db_find_class (CT_COLLATION_NAME);
3418  if (class_mop == NULL)
3419  {
3420  status = EXIT_FAILURE;
3421  return status;
3422  }
3423 
3424  AU_DISABLE (au_save);
3425  if (db_truncate_class (class_mop) != NO_ERROR)
3426  {
3427  AU_ENABLE (au_save);
3428  status = EXIT_FAILURE;
3429  return status;
3430  }
3431 
3432  if (boot_add_collations (class_mop) != NO_ERROR)
3433  {
3434  status = EXIT_FAILURE;
3435  }
3436 
3437  AU_ENABLE (au_save);
3438  return status;
3439 }
3440 
3441 /*
3442  * delete_all_ha_apply_info () - delete ha apply info
3443  * return:
3444  */
3445 static int
3447 {
3448 #define QUERY_BUF_SIZE 2048
3449 
3450  int res, au_save;
3451  DB_QUERY_RESULT *result;
3452  DB_QUERY_ERROR query_error;
3453  char query_buf[QUERY_BUF_SIZE];
3454 
3455  snprintf (query_buf, sizeof (query_buf), "DELETE FROM %s ;", CT_HA_APPLY_INFO_NAME);
3456 
3457  AU_DISABLE (au_save);
3458 
3459  res = db_execute (query_buf, &result, &query_error);
3460  if (res >= 0)
3461  {
3462  int error;
3463 
3464  error = db_query_end (result);
3465  if (error != NO_ERROR)
3466  {
3467  res = error;
3468  }
3469  }
3470 
3471  AU_ENABLE (au_save);
3472 
3473  return res;
3474 #undef QUERY_BUF_SIZE
3475 }
3476 
3477 /*
3478  * insert_ha_apply_info () - insert ha apply info
3479  * return:
3480  */
3481 static int
3482 insert_ha_apply_info (char *database_name, char *master_host_name, INT64 database_creation, INT64 pageid, int offset)
3483 {
3484 #define APPLY_INFO_VALUES 15
3485 #define QUERY_BUF_SIZE 2048
3486 
3487  int i, res, au_save;
3488  int in_value_idx;
3489  char *copy_log_base;
3490  char copy_log_base_buf[PATH_MAX];
3491  char log_path[PATH_MAX];
3492  char query_buf[QUERY_BUF_SIZE];
3493  DB_VALUE in_value[APPLY_INFO_VALUES];
3494  DB_DATETIME db_creation;
3495  DB_QUERY_RESULT *result;
3496  DB_QUERY_ERROR query_error;
3497 
3498  db_localdatetime (&database_creation, &db_creation);
3500  if (copy_log_base == NULL || *copy_log_base == '\0')
3501  {
3502  copy_log_base = (char *) envvar_get ("DATABASES");
3503  if (copy_log_base == NULL)
3504  {
3505  return ER_FAILED;
3506  }
3507  }
3508 
3509  copy_log_base = realpath (copy_log_base, copy_log_base_buf);
3510  snprintf (log_path, PATH_MAX, "%s/%s_%s", copy_log_base, database_name, master_host_name);
3511 
3512  snprintf (query_buf, sizeof (query_buf), "INSERT INTO %s " /* INSERT */
3513  "( db_name, " /* 1 */
3514  " db_creation_time, " /* 2 */
3515  " copied_log_path, " /* 3 */
3516  " committed_lsa_pageid, " /* 4 */
3517  " committed_lsa_offset, " /* 5 */
3518  " committed_rep_pageid, " /* 6 */
3519  " committed_rep_offset, " /* 7 */
3520  " append_lsa_pageid, " /* 8 */
3521  " append_lsa_offset, " /* 9 */
3522  " eof_lsa_pageid, " /* 10 */
3523  " eof_lsa_offset, " /* 11 */
3524  " final_lsa_pageid, " /* 12 */
3525  " final_lsa_offset, " /* 13 */
3526  " required_lsa_pageid, " /* 14 */
3527  " required_lsa_offset, " /* 15 */
3528  " log_record_time, " /* 16 */
3529  " log_commit_time, " /* 17 */
3530  " last_access_time, " /* 18 */
3531  " status, " /* 19 */
3532  " insert_counter, " /* 20 */
3533  " update_counter, " /* 21 */
3534  " delete_counter, " /* 22 */
3535  " schema_counter, " /* 23 */
3536  " commit_counter, " /* 24 */
3537  " fail_counter, " /* 25 */
3538  " start_time ) " /* 26 */
3539  " VALUES ( ?, " /* 1. db_name */
3540  " ?, " /* 2. db_creation_time */
3541  " ?, " /* 3. copied_log_path */
3542  " ?, " /* 4. committed_lsa_pageid */
3543  " ?, " /* 5. committed_lsa_offset */
3544  " ?, " /* 6. committed_rep_pageid */
3545  " ?, " /* 7. committed_rep_offset */
3546  " ?, " /* 8. append_lsa_pageid */
3547  " ?, " /* 9. append_lsa_offset */
3548  " ?, " /* 10. eof_lsa_pageid */
3549  " ?, " /* 11. eof_lsa_offset */
3550  " ?, " /* 12. final_lsa_pageid */
3551  " ?, " /* 13. final_lsa_offset */
3552  " ?, " /* 14. required_lsa_pageid */
3553  " ?, " /* 15. required_lsa_offset */
3554  " NULL, " /* 16. log_record_time */
3555  " NULL, " /* 17. log_commit_time */
3556  " NULL, " /* 18. last_access_time */
3557  " 0, " /* 19. status */
3558  " 0, " /* 20. insert_counter */
3559  " 0, " /* 21. update_counter */
3560  " 0, " /* 22. delete_counter */
3561  " 0, " /* 23. schema_counter */
3562  " 0, " /* 24. commit_counter */
3563  " 0, " /* 25. fail_counter */
3564  " NULL " /* 26. start_time */
3565  " ) ;", CT_HA_APPLY_INFO_NAME);
3566 
3567  in_value_idx = 0;
3568 
3569  /* 1. db_name */
3570  db_make_varchar (&in_value[in_value_idx++], 255, database_name, strlen (database_name), LANG_SYS_CODESET,
3572 
3573  /* 2. db_creation time */
3574  db_make_datetime (&in_value[in_value_idx++], &db_creation);
3575 
3576  /* 3. copied_log_path */
3577  db_make_varchar (&in_value[in_value_idx++], 4096, log_path, strlen (log_path), LANG_SYS_CODESET, LANG_SYS_COLLATION);
3578 
3579  /* 4 ~ 15. lsa */
3580  for (i = 0; i < 6; i++)
3581  {
3582  db_make_bigint (&in_value[in_value_idx++], pageid);
3583  db_make_int (&in_value[in_value_idx++], offset);
3584  }
3585 
3586  assert_release (in_value_idx == APPLY_INFO_VALUES);
3587 
3588  AU_DISABLE (au_save);
3589 
3590  res = db_execute_with_values (query_buf, &result, &query_error, in_value_idx, &in_value[0]);
3591  if (res >= 0)
3592  {
3593  int error;
3594 
3595  error = db_query_end (result);
3596  if (error != NO_ERROR)
3597  {
3598  res = error;
3599  }
3600  }
3601 
3602  AU_ENABLE (au_save);
3603 
3604  for (i = 0; i < in_value_idx; i++)
3605  {
3606  db_value_clear (&in_value[i]);
3607  }
3608 
3609  return res;
3610 
3611 #undef APPLY_INFO_VALUES
3612 #undef QUERY_BUF_SIZE
3613 }
3614 
3615 /*
3616  * delete_all_slave_ha_apply_info () - delete slave ha apply info
3617  * return:
3618  */
3619 static int
3620 delete_all_slave_ha_apply_info (char *database_name, char *master_host_name)
3621 {
3622 #define APPLY_INFO_VALUES 2
3623 #define QUERY_BUF_SIZE 2048
3624 
3625  int res, au_save;
3626  int in_value_idx;
3627  char *copy_log_base;
3628  char copy_log_base_buf[PATH_MAX];
3629  char log_path[PATH_MAX];
3630  DB_VALUE in_value[APPLY_INFO_VALUES];
3631  DB_QUERY_RESULT *result;
3632  DB_QUERY_ERROR query_error;
3633  char query_buf[QUERY_BUF_SIZE];
3634 
3636  if (copy_log_base == NULL || *copy_log_base == '\0')
3637  {
3638  copy_log_base = (char *) envvar_get ("DATABASES");
3639  if (copy_log_base == NULL)
3640  {
3641  return ER_FAILED;
3642  }
3643  }
3644 
3645  copy_log_base = realpath (copy_log_base, copy_log_base_buf);
3646  snprintf (log_path, PATH_MAX, "%s/%s_%s", copy_log_base, database_name, master_host_name);
3647 
3648  snprintf (query_buf, sizeof (query_buf), "DELETE FROM %s " "WHERE db_name = ? and copied_log_path <> ?",
3650 
3651  in_value_idx = 0;
3652  /* 1. db_name */
3653  db_make_varchar (&in_value[in_value_idx++], 255, database_name, strlen (database_name), LANG_SYS_CODESET,
3655 
3656  /* 2. copied_log_path */
3657  db_make_varchar (&in_value[in_value_idx++], 4096, log_path, strlen (log_path), LANG_SYS_CODESET, LANG_SYS_COLLATION);
3658 
3659  AU_DISABLE (au_save);
3660 
3661  res = db_execute_with_values (query_buf, &result, &query_error, in_value_idx, &in_value[0]);
3662  if (res >= 0)
3663  {
3664  int error;
3665 
3666  error = db_query_end (result);
3667  if (error != NO_ERROR)
3668  {
3669  res = error;
3670  }
3671  }
3672 
3673  AU_ENABLE (au_save);
3674 
3675  return res;
3676 #undef APPLY_INFO_VALUES
3677 #undef QUERY_BUF_SIZE
3678 }
3679 
3680 /*
3681  * check_ha_db_and_node_list () - check ha db list and ha node list
3682  * return:
3683  */
3684 static bool
3685 check_ha_db_and_node_list (char *database_name, char *source_host_name)
3686 {
3687  int i, j, status, num_nodes;
3688  char **dbs;
3689  HA_CONF ha_conf;
3690  HA_NODE_CONF *nc;
3691 
3692  memset ((void *) &ha_conf, 0, sizeof (HA_CONF));
3693  status = util_make_ha_conf (&ha_conf);
3694  if (status != NO_ERROR)
3695  {
3696  return false;
3697  }
3698 
3699  num_nodes = ha_conf.num_node_conf;
3700  dbs = ha_conf.db_names;
3701  nc = ha_conf.node_conf;
3702 
3703  for (i = 0; dbs[i] != NULL; i++)
3704  {
3705  if (strcmp (dbs[i], database_name) != 0)
3706  {
3707  continue;
3708  }
3709 
3710  for (j = 0; j < num_nodes; j++)
3711  {
3712  if (strcmp (nc[j].node_name, source_host_name) != 0)
3713  {
3714  continue;
3715  }
3716 
3717  if (util_is_localhost (nc[j].node_name))
3718  {
3719  continue;
3720  }
3721 
3722  util_free_ha_conf (&ha_conf);
3723  return true;
3724  }
3725  }
3726 
3727  util_free_ha_conf (&ha_conf);
3728  return false;
3729 }
3730 
3731 /*
3732  * restoreslave() - restoreslave main routine
3733  * return: EXIT_SUCCESS/EXIT_FAILURE
3734  */
3735 int
3737 {
3738  UTIL_ARG_MAP *arg_map = arg->arg_map;
3739  DB_DATETIME datetime;
3740  bool init_ha_catalog;
3741  int status, error_code;
3742  char er_msg_file[PATH_MAX];
3743  char db_creation_time[LINE_MAX];
3744  char *database_name;
3745  char *source_state;
3746  char *master_host_name;
3747  const char *mk_path;
3748  BO_RESTART_ARG restart_arg;
3749 
3751  {
3753  goto error_exit;
3754  }
3755 
3756  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
3757  master_host_name = utility_get_option_string_value (arg_map, RESTORESLAVE_MASTER_HOST_NAME_S, 0);
3758  source_state = utility_get_option_string_value (arg_map, RESTORESLAVE_SOURCE_STATE_S, 0);
3759 
3760  if (master_host_name == NULL || source_state == NULL)
3761  {
3762  goto print_restoreslave_usage;
3763  }
3764 
3765  if (strcasecmp (source_state, "master") == 0)
3766  {
3767  init_ha_catalog = true;
3768  }
3769  else if (strcasecmp (source_state, "slave") == 0 || strcasecmp (source_state, "replica") == 0)
3770  {
3771  init_ha_catalog = false;
3772  }
3773  else
3774  {
3775  fprintf (stderr,
3777  source_state);
3778  goto error_exit;
3779  }
3780 
3781  restart_arg.restore_slave = true;
3784  restart_arg.level = 0;
3788  restart_arg.restore_upto_bktime = false;
3789  restart_arg.stopat = time (NULL);
3790  restart_arg.is_restore_from_backup = false;
3791 
3792  if (mk_path != NULL)
3793  {
3794  memcpy (restart_arg.keys_file_path, mk_path, PATH_MAX);
3795  }
3796  else
3797  {
3798  restart_arg.keys_file_path[0] = '\0';
3799  }
3800 
3801  if (utility_get_option_string_table_size (arg_map) != 1)
3802  {
3803  goto print_restoreslave_usage;
3804  }
3805 
3806  if (check_ha_db_and_node_list (database_name, master_host_name) == false)
3807  {
3808  fprintf (stderr,
3810  goto error_exit;
3811  }
3812 
3813  /* error message log file */
3814  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
3815  er_init (er_msg_file, ER_NEVER_EXIT);
3816 
3817  if (restart_arg.printtoc)
3818  {
3819  error_code = print_backup_info (database_name, &restart_arg);
3820  if (error_code != NO_ERROR)
3821  {
3822  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3823  fprintf (stderr,
3825  goto error_exit;
3826  }
3827 
3828  return EXIT_SUCCESS;
3829  }
3830 
3832 
3835  db_login ("DBA", NULL);
3836 
3837  status = boot_restart_from_backup (true, database_name, &restart_arg);
3838  if (status == NULL_TRAN_INDEX)
3839  {
3840  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3842  goto error_exit;
3843  }
3844  else
3845  {
3847  }
3848 
3849  db_localdatetime (&restart_arg.db_creation, &datetime);
3850  db_datetime_to_string (db_creation_time, LINE_MAX, &datetime);
3851 
3852  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
3853  {
3854  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3855  fprintf (stderr,
3857  db_creation_time, restart_arg.restart_repl_lsa.pageid, restart_arg.restart_repl_lsa.offset);
3858  return EXIT_FAILURE;
3859  }
3860 
3861  if (init_ha_catalog)
3862  {
3863  error_code = delete_all_ha_apply_info ();
3864  if (error_code < 0)
3865  {
3866  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3867  fprintf (stderr,
3869  RESTORESLAVE_MSG_HA_CATALOG_FAIL), db_creation_time,
3870  restart_arg.restart_repl_lsa.pageid, restart_arg.restart_repl_lsa.offset);
3871  db_shutdown ();
3872  return EXIT_FAILURE;
3873  }
3874 
3875  error_code =
3876  insert_ha_apply_info (database_name, master_host_name, restart_arg.db_creation,
3877  restart_arg.restart_repl_lsa.pageid, (int) restart_arg.restart_repl_lsa.offset);
3878  if (error_code < 0)
3879  {
3880  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3881  fprintf (stderr,
3883  RESTORESLAVE_MSG_HA_CATALOG_FAIL), db_creation_time,
3884  restart_arg.restart_repl_lsa.pageid, restart_arg.restart_repl_lsa.offset);
3885  db_shutdown ();
3886  return EXIT_FAILURE;
3887  }
3888  }
3889  else
3890  {
3891  error_code = delete_all_slave_ha_apply_info (database_name, master_host_name);
3892  if (error_code < 0)
3893  {
3894  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3895  fprintf (stderr,
3897  RESTORESLAVE_MSG_HA_CATALOG_FAIL), db_creation_time,
3898  restart_arg.restart_repl_lsa.pageid, restart_arg.restart_repl_lsa.offset);
3899  db_shutdown ();
3900  return EXIT_FAILURE;
3901  }
3902 
3903  }
3905  db_shutdown ();
3906 
3907  return EXIT_SUCCESS;
3908 
3909 print_restoreslave_usage:
3911  basename (arg->argv0));
3913 
3914 error_exit:
3915  return EXIT_FAILURE;
3916 }
3917 
3918 /*
3919  * gen_tz() - generate time zone data as a C source file, to be compiled into
3920  * a shared library (DLL/so) using included makefile/build script
3921  * return: EXIT_SUCCESS/EXIT_FAILURE
3922  */
3923 int
3925 {
3926  UTIL_ARG_MAP *arg_map = NULL;
3927  char *input_path = NULL;
3928  char inputpath_local[PATH_MAX] = { 0 };
3929  char *tz_gen_mode = NULL;
3930  TZ_GEN_TYPE tz_gen_type = TZ_GEN_TYPE_NEW;
3931  int exit_status = EXIT_SUCCESS;
3932  char checksum[TZ_CHECKSUM_SIZE + 1];
3933  bool need_db_shutdown = false;
3934  bool er_inited = false;
3935  DB_INFO *dir = NULL;
3936  DB_INFO *db_info_p = NULL;
3937  char *db_name = NULL;
3938  char er_msg_file[PATH_MAX];
3939 
3940  assert (arg != NULL);
3941  arg_map = arg->arg_map;
3942 
3943  tz_gen_mode = utility_get_option_string_value (arg_map, GEN_TZ_MODE_S, 0);
3944  if (tz_gen_mode == NULL)
3945  {
3947  basename (arg->argv0), basename (arg->argv0));
3948  goto exit;
3949  }
3950 
3951  if (strcasecmp (tz_gen_mode, "new") == 0)
3952  {
3953  tz_gen_type = TZ_GEN_TYPE_NEW;
3954  }
3955  else if (strcasecmp (tz_gen_mode, "extend") == 0)
3956  {
3957  tz_gen_type = TZ_GEN_TYPE_EXTEND;
3958 
3959  db_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
3960 
3961 #if !defined (WINDOWS)
3962  /* workaround for Linux: gen_tz process should be restarted after each database migration, since globals variables
3963  * from shared libcubrid.so are not properly reset at db_shutdown */
3964  if (db_name == NULL)
3965  {
3966  goto print_gen_tz_usage;
3967  }
3968 #endif /* !WINDOWS */
3969 
3970  if (db_name != NULL && check_database_name (db_name) != NO_ERROR)
3971  {
3972  exit_status = EXIT_FAILURE;
3973  goto exit;
3974  }
3975  }
3976  else if (strcasecmp (tz_gen_mode, "update") == 0)
3977  {
3978  tz_gen_type = TZ_GEN_TYPE_UPDATE;
3979 
3980  /* This is a temporary fix to show usages until we have the update option.
3981  * Please remove the following when you are going to implement it.
3982  */
3984  goto print_gen_tz_usage;
3985  }
3986  else
3987  {
3989  goto print_gen_tz_usage;
3990  }
3991 
3992  input_path = utility_get_option_string_value (arg_map, GEN_TZ_INPUT_FOLDER_S, 0);
3993 
3994  if (input_path == NULL || strlen (input_path) == 0)
3995  {
3996  envvar_tzdata_dir_file (inputpath_local, sizeof (inputpath_local), "");
3997  input_path = inputpath_local;
3998  }
3999 
4000  /* error message log file */
4001  if (db_name != NULL)
4002  {
4003  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", db_name, arg->command_name);
4004  }
4005  else
4006  {
4007  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s.err", arg->command_name);
4008  }
4009  er_init (er_msg_file, ER_NEVER_EXIT);
4010  er_inited = true;
4011 
4012  memset (checksum, 0, sizeof (checksum));
4013  if (timezone_compile_data (input_path, tz_gen_type, db_name, NULL, checksum) != NO_ERROR)
4014  {
4015  exit_status = EXIT_FAILURE;
4016  goto exit;
4017  }
4018 
4019  if (tz_gen_type == TZ_GEN_TYPE_EXTEND && checksum[0] != '\0')
4020  {
4023  db_login ("DBA", NULL);
4024 
4025  if (db_name != NULL)
4026  {
4027  dir = (DB_INFO *) calloc (1, sizeof (DB_INFO));
4028  if (dir == NULL)
4029  {
4031  exit_status = EXIT_FAILURE;
4032  goto exit;
4033  }
4034  dir->name = (char *) calloc (strlen (db_name) + 1, sizeof (char));
4035  if (dir->name == NULL)
4036  {
4038  exit_status = EXIT_FAILURE;
4039  goto exit;
4040  }
4041  strcpy (dir->name, db_name);
4042  dir->next = NULL;
4043  }
4044  else if (cfg_read_directory (&dir, false) != NO_ERROR)
4045  {
4046  exit_status = EXIT_FAILURE;
4047  goto exit;
4048  }
4049 
4050  for (db_info_p = dir; db_info_p != NULL; db_info_p = db_info_p->next)
4051  {
4052  if (db_restart (arg->command_name, TRUE, db_info_p->name) != NO_ERROR)
4053  {
4054  need_db_shutdown = true;
4055  exit_status = EXIT_FAILURE;
4056  goto exit;
4057  }
4058  if (put_timezone_checksum (checksum) != NO_ERROR)
4059  {
4060  need_db_shutdown = true;
4061  exit_status = EXIT_FAILURE;
4063  goto exit;
4064  }
4065  else
4066  {
4067  /* write the new checksum in the database */
4069  }
4070  db_shutdown ();
4071  }
4072  }
4073 
4074 exit:
4075  if (dir != NULL)
4076  {
4077  cfg_free_directory (dir);
4078  }
4079 
4080  if (exit_status != EXIT_SUCCESS)
4081  {
4082  if (er_inited == true)
4083  {
4084  fprintf (stderr, "%s\n", db_error_string (3));
4085  }
4086 
4087  if (need_db_shutdown == true)
4088  {
4089  db_shutdown ();
4090  er_inited = false;
4091  }
4092  }
4093 
4094  if (er_inited == true)
4095  {
4097  }
4098 
4099  return exit_status;
4100 
4101 print_gen_tz_usage:
4103  basename (arg->argv0), basename (arg->argv0));
4104  return EXIT_FAILURE;
4105 }
4106 
4107 /*
4108  * dump_tz() - display time zone data from CUBRID's timezone shared library
4109  * or from the generated and embedded timezone_list.c file
4110  * return: EXIT_SUCCESS/EXIT_FAILURE
4111  */
4112 int
4114 {
4115  long int zone_id = -1;
4116  UTIL_ARG_MAP *arg_map = NULL;
4117  int err_status = EXIT_SUCCESS;
4118  char *zone = NULL;
4119  char *str_next = NULL;
4120  bool is_dump_countries = false;
4121  bool is_dump_zone_list = false;
4122  bool is_dump_zone = false;
4123  bool is_dump_leap_sec = false;
4124  bool is_dump_summary = false;
4125  const TZ_DATA *tzd;
4126 
4127  assert (arg != NULL);
4128  arg_map = arg->arg_map;
4129 
4130  /* read and check arguments */
4131  is_dump_countries = utility_get_option_bool_value (arg_map, DUMP_TZ_COUNTRIES_S);
4132  is_dump_zone_list = utility_get_option_bool_value (arg_map, DUMP_TZ_ZONES_S);
4133  is_dump_leap_sec = utility_get_option_bool_value (arg_map, DUMP_TZ_LEAP_SEC_S);
4134  is_dump_summary = utility_get_option_bool_value (arg_map, DUMP_TZ_DUMP_SUM_S);
4136 
4137  if ((zone == NULL) && (!is_dump_countries) && (!is_dump_zone_list) && (!is_dump_leap_sec) && (!is_dump_summary))
4138  {
4139  goto print_dump_tz_usage;
4140  }
4141 
4142  if (zone != NULL && *zone != '\0')
4143  {
4144  /* check if either a single zone or all zones should be dumped */
4145  if (strcasecmp (zone, "all") == 0)
4146  {
4147  zone_id = -1;
4148  }
4149  else
4150  {
4151  zone_id = strtol (zone, &str_next, 10);
4152  /* check zone_id, str_next, and errno */
4153  if (zone_id == 0 && *str_next != '\0')
4154  {
4155  goto print_dump_tz_usage;
4156  }
4157  if (errno == ERANGE)
4158  {
4160  fprintf (stderr,
4162  err_status = EXIT_FAILURE;
4163  goto exit;
4164  }
4165  }
4166  is_dump_zone = true;
4167  }
4168 
4169  if (tz_load () != NO_ERROR)
4170  {
4171  err_status = EXIT_FAILURE;
4172  goto exit;
4173  }
4174  tzd = tz_get_data ();
4175  assert (tzd != NULL);
4176  /* check if zone_id is valid for the loaded timezone library */
4177  if (is_dump_zone && zone_id < -1 && zone_id >= tzd->timezone_count)
4178  {
4181  err_status = EXIT_FAILURE;
4182  goto exit;
4183  }
4184 
4185  printf ("\nDump timezone data");
4186 
4187  if (!is_dump_countries && !is_dump_zone && !is_dump_zone_list && !is_dump_leap_sec)
4188  {
4189  tzc_dump_summary (tzd);
4190  goto exit;
4191  }
4192 
4193  if (is_dump_countries)
4194  {
4195  printf ("\n\nDumping countries...\n");
4196  tzc_dump_countries (tzd);
4197  }
4198  if (is_dump_zone_list)
4199  {
4200  printf ("\n\nDumping timezones...\n");
4201  tzc_dump_timezones (tzd);
4202  }
4203  if (is_dump_zone)
4204  {
4205  if (zone_id != -1)
4206  {
4207  tzc_dump_one_timezone (tzd, zone_id);
4208  }
4209  else
4210  {
4211  for (zone_id = 0; zone_id < tzd->timezone_count; zone_id++)
4212  {
4213  printf ("\n\n");
4214  tzc_dump_one_timezone (tzd, zone_id);
4215  }
4216  }
4217  }
4218 
4219  if (is_dump_leap_sec)
4220  {
4221  printf ("\n\nDumping leap seconds...\n");
4222  tzc_dump_leap_sec (tzd);
4223  }
4224 
4225 exit:
4226  tz_unload ();
4227 
4228  return err_status;
4229 
4230 print_dump_tz_usage:
4232  basename (arg->argv0));
4233  return err_status;
4234 }
#define CREATE_FILE_PATH_S
Definition: utility.h:966
#define DUMPLOCALE_ALPHABET_LOWER_L
Definition: utility.h:1512
DB_OBJECT * db_find_class(const char *name)
Definition: db_info.c:133
#define CREATE_LOG_VOLUME_SIZE_S
Definition: utility.h:998
bool util_is_localhost(char *host)
Definition: util_common.c:418
#define OPTIMIZE_CLASS_NAME_S
Definition: utility.h:1133
#define LANG_MAX_COLLATIONS
void util_admin_usage(const char *argv0)
Definition: util_sa.c:122
char * cfg_maycreate_get_directory_filename(char *buffer)
bool auto_commit
Definition: csql.h:268
#define RESTORE_KEYS_FILE_PATH_S
Definition: utility.h:1077
int db_make_datetime(DB_VALUE *value, const DB_DATETIME *datetime)
#define COMMAND_GROUPS
Definition: util_sa.c:83
LOG_LSA restart_repl_lsa
Definition: boot_sr.h:106
cubthread::entry * thread_get_thread_entry_info(void)
#define NO_ERROR
Definition: error_code.h:46
int logpb_initialize_log_names(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
#define CREATE_USER_DEFINITION_FILE_S
Definition: utility.h:978
#define AU_DISABLE(save)
Definition: authenticate.h:106
DB_INFO * cfg_find_db(const char *db_name)
#define TRUE
Definition: broker_admin.c:49
#define LANG_SYS_COLLATION
const char * verbose_file
Definition: boot_sr.h:98
int lang_db_put_charset(void)
int lang_locale_data_load_from_lib(LANG_LOCALE_DATA *lld, void *lib_handle, const LOCALE_FILE *lf, bool is_load_for_dump)
#define ER_LOC_GEN
Definition: error_code.h:1371
void db_set_client_type(int client_type)
Definition: db_admin.c:495
bool restore_slave
Definition: boot_sr.h:103
#define IO_PAGESIZE
#define COPY_CONTROL_FILE_S
Definition: utility.h:1018
int synccolldb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:2582
#define DUMPLOCALE_IDENTIFIER_ALPHABET_S
Definition: utility.h:1516
int restoreslave(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:3736
int locale_dump_lib_collations(void *lib_handle, const LOCALE_FILE *lf, int dl_settings, int start_value, int end_value)
static char bo_Dbfullname[PATH_MAX]
Definition: util_sa.c:92
#define PRINT_AND_LOG_ERR_MSG(...)
Definition: util_func.h:49
void tzc_dump_countries(const TZ_DATA *tzd)
Definition: tz_compile.c:4637
int sysprm_set_force(const char *pname, const char *pvalue)
char ** cfg_get_hosts(const char *prim_host, int *count, bool include_local_host)
void au_dump_to_file(FILE *fp)
int util_size_string_to_byte(UINT64 *size_num, const char *size_str)
Definition: util_common.c:1027
#define DUMPLOCALE_ALPHABET_UPPER_L
Definition: utility.h:1514
int db_login(const char *name, const char *password)
Definition: db_admin.c:804
#define CREATE_LOG_VOLUME_SIZE_L
Definition: utility.h:999
#define DUMP_TZ_COUNTRIES_S
Definition: utility.h:1544
INT64 db_creation
Definition: boot_sr.h:105
META_CLASS tf_Metaclass_class
Definition: transform.c:221
#define CREATE_PAGE_SIZE_S
Definition: utility.h:990
int boot_copy(const char *from_dbname, const char *new_db_name, const char *new_db_path, const char *new_log_path, const char *new_lob_path, const char *new_db_server_host, const char *new_volext_path, const char *fileof_vols_and_copypaths, bool new_db_overwrite)
void tzc_dump_leap_sec(const TZ_DATA *tzd)
Definition: tz_compile.c:4788
int tp_init(void)
const char * backuppath
Definition: boot_sr.h:96
char * locale_name
static int delete_all_ha_apply_info(void)
Definition: util_sa.c:3446
void tzc_dump_one_timezone(const TZ_DATA *tzd, const int zone_id)
Definition: tz_compile.c:4674
#define CREATE_COMMENT_S
Definition: utility.h:964
void(* init_conv_func)(void)
int db_make_bigint(DB_VALUE *value, const DB_BIGINT num)
int db_get_int(const DB_VALUE *value)
#define DUMP_TZ_ZONE_ID_S
Definition: utility.h:1548
int copydb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1236
int sm_update_all_statistics(bool with_fullscan)
void cfg_free_hosts(char **host_array)
#define RESTORESLAVE_LIST_S
Definition: utility.h:1563
const char * boot_get_lob_path(void)
Definition: boot_sr.c:479
#define COPY_REPLACE_S
Definition: utility.h:1020
#define COPY_LOB_PATH_S
Definition: utility.h:1024
int locale_compile_locale(LOCALE_FILE *lf, LOCALE_DATA *ld, bool is_verbose)
#define CREATE_OUTPUT_FILE_S
Definition: utility.h:982
#define ER_FAILED
Definition: error_code.h:47
const TZ_DATA * tz_get_data(void)
Definition: tz_support.c:687
int db_make_varchar(DB_VALUE *value, const int max_char_length, DB_CONST_C_CHAR str, const int char_str_byte_size, const int codeset, const int collation_id)
#define AU_DISABLE_PASSWORDS
Definition: authenticate.h:140
static int parse_user_define_file(FILE *user_define_file, FILE *output_file)
Definition: util_sa.c:246
int au_force_write_new_auth(void)
#define RESTORE_PARTIAL_RECOVERY_S
Definition: utility.h:1071
void locale_free_shared_data(void)
bool boot_shutdown_server(ER_FINAL_CODE iserfinal)
int boot_soft_rename(const char *old_db_name, const char *new_db_name, const char *new_db_path, const char *new_log_path, const char *new_db_server_host, const char *new_volext_path, const char *fileof_vols_and_renamepaths, bool new_db_overwrite, bool extern_rename, bool force_delete)
#define GEN_TZ_MODE_S
Definition: utility.h:1540
int diagdb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1446
time_t stopat
Definition: boot_sr.h:95
int lang_load_library(const char *lib_file, void **handle)
#define CREATE_LOG_PAGE_SIZE_S
Definition: utility.h:992
int disk_dump_all(THREAD_ENTRY *thread_p, FILE *fp)
#define PATCH_RECREATE_LOG_S
Definition: utility.h:1155
int db_query_end(DB_QUERY_RESULT *result)
Definition: db_query.c:3362
#define COPY_SERVER_NAME_S
Definition: utility.h:1010
#define assert_release(e)
Definition: error_manager.h:96
int db_shutdown(void)
Definition: db_admin.c:964
int util_byte_to_size_string(char *buf, size_t len, UINT64 size_num)
Definition: util_common.c:955
int db_truncate_class(DB_OBJECT *class_)
Definition: db_class.c:1859
#define DUMPLOCALE_COLLATION_S
Definition: utility.h:1518
#define DUMPLOCALE_CONSOLE_CONV_S
Definition: utility.h:1528
#define CREATE_LOG_PAGE_COUNT_S
Definition: utility.h:988
char log_Name_active[PATH_MAX]
Definition: log_global.c:90
const VOLID LOG_DBLOG_ACTIVE_VOLID
Definition: log_volids.hpp:49
void xlog_dump(THREAD_ENTRY *thread_p, FILE *out_fp, int isforward, LOG_PAGEID start_logpageid, DKNPAGES dump_npages, TRANID desired_tranid)
Definition: log_manager.c:6759
#define CREATE_PAGES_S
Definition: utility.h:962
int locale_save_all_to_C_file(LOCALE_DATA **ld, int start_index, int end_index, LOCALE_FILE *lf)
int check_database_name(const char *name)
Definition: util_common.c:99
#define QUERY_SIZE
#define CREATE_LOG_PAGE_SIZE_L
Definition: utility.h:993
#define COMMAND_USER
Definition: util_sa.c:80
int tz_load(void)
Definition: tz_support.c:337
bool fileio_is_volume_exist(const char *vol_label_p)
Definition: file_io.c:5094
#define CREATE_LOB_PATH_S
Definition: utility.h:970
int renamedb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1026
#define RENAME_CONTROL_FILE_S
Definition: utility.h:1004
#define DUMPLOCALE_IS_COLLATION_WEIGHT_ORDER
static void make_valid_page_size(int *v)
Definition: util_sa.c:271
FILE * output_file
Definition: unloaddb.c:48
int er_errid(void)
const VOLID LOG_DBTXT_VOLID
Definition: log_volids.hpp:37
int synccoll_force(void)
Definition: util_sa.c:3411
#define CREATE_DB_VOLUME_SIZE_S
Definition: utility.h:996
int util_log_write_errid(int message_id,...)
Definition: util_func.c:468
#define NULL_VOLDES
Definition: file_io.h:44
#define CREATE_DB_VOLUME_SIZE_L
Definition: utility.h:997
#define CREATE_VERBOSE_S
Definition: utility.h:984
int er_init(const char *msglog_filename, int exit_ask)
void tzc_dump_summary(const TZ_DATA *tzd)
Definition: tz_compile.c:4617
#define GEN_TZ_INPUT_FOLDER_S
Definition: utility.h:1538
#define GENLOCALE_VERBOSE_S
Definition: utility.h:1499
#define DUMPLOCALE_ALPHABET_S
Definition: utility.h:1509
int fileio_mount(THREAD_ENTRY *thread_p, const char *db_full_name_p, const char *vol_label_p, VOLID vol_id, int lock_wait, bool is_do_sync)
Definition: file_io.c:2957
#define COMMAND_MEMBERS
Definition: util_sa.c:82
int optimizedb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1349
#define COPY_LOG_PATH_S
Definition: utility.h:1014
int utility_get_option_int_value(UTIL_ARG_MAP *arg_map, int arg_ch)
Definition: util_common.c:227
#define RESTORE_OUTPUT_FILE_S
Definition: utility.h:1073
#define CREATE_LOG_PAGE_COUNT_L
Definition: utility.h:989
void THREAD_ENTRY
#define TZ_CHECKSUM_SIZE
const char * db_name
Definition: csql.h:256
int deletedb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:708
void util_print_deprecated(const char *option)
Definition: util_common.c:1205
#define MAX_LINE_LEN
Definition: util_sa.c:77
void lang_init_builtin(void)
static char * node_name
Definition: cas_runner.c:174
#define DUMPLOCALE_NUMBERING_S
Definition: utility.h:1507
char * ldml_file
#define COPY_FILE_PATH_S
Definition: utility.h:1012
UINT64 prm_get_bigint_value(PARAM_ID prm_id)
void locator_dump_class_names(THREAD_ENTRY *thread_p, FILE *out_fp)
Definition: locator_sr.c:1786
int createdb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:303
#define ER_BO_UNKNOWN_DATABASE
Definition: error_code.h:177
#define CT_HA_APPLY_INFO_NAME
Definition: transform.h:136
#define GENLOCALE_INPUT_PATH_S
Definition: utility.h:1497
int db_restart(const char *program, int print_version, const char *volume)
Definition: db_admin.c:868
void catalog_dump(THREAD_ENTRY *thread_p, FILE *fp, int dump_flag)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
#define CREATE_PAGES_L
Definition: utility.h:963
#define RESTORESLAVE_OUTPUT_FILE_S
Definition: utility.h:1567
INTL_CODESET codeset
#define RESTORESLAVE_SOURCE_STATE_S
Definition: utility.h:1559
LANG_COLLATION * lang_get_collation(const int coll_id)
#define DUMPLOCALE_IS_CALENDAR
int db_init(const char *program, int print_version, const char *dbname, const char *db_path, const char *vol_path, const char *log_path, const char *lob_path, const char *host_name, const bool overwrite, const char *comments, const char *addmore_vols_file, int npages, int desired_pagesize, int log_npages, int desired_log_page_size, const char *lang_charset)
Definition: db_admin.c:164
#define DIAG_OUTPUT_FILE_S
Definition: utility.h:1149
bool utility_get_option_bool_value(UTIL_ARG_MAP *arg_map, int arg_ch)
Definition: util_common.c:245
const char * fileio_get_base_file_name(const char *full_name_p)
Definition: file_io.c:5533
#define assert(x)
void er_final(ER_FINAL_CODE do_global_final)
char checksum[TZ_CHECKSUM_SIZE+1]
#define DUMPLOCALE_IS_IDENTIFIER_ALPHABET_LOWER
void util_admin_version(const char *argv0)
Definition: util_sa.c:139
#define CREATE_REPLACE_S
Definition: utility.h:974
#define DUMPLOCALE_ALPHABET_LOWER_S
Definition: utility.h:1511
#define DUMPLOCALE_INPUT_PATH_S
Definition: utility.h:1503
#define RESTORESLAVE_BACKUP_FILE_PATH_S
Definition: utility.h:1565
#define COPY_COPY_LOB_PATH_S
Definition: utility.h:1026
MOP au_add_user(const char *name, int *exists)
#define ER_GENERIC_ERROR
Definition: error_code.h:49
static int synccoll_check(const char *db_name, int *db_obs_coll_cnt, int *new_sys_coll_cnt)
Definition: util_sa.c:2712
static int delete_all_slave_ha_apply_info(char *database_name, char *master_host_name)
Definition: util_sa.c:3620
int file_tracker_dump_all_btree_capacities(THREAD_ENTRY *thread_p, FILE *fp)
#define DUMPLOCALE_IS_NORMALIZATION
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
static int print_backup_info(char *database_name, BO_RESTART_ARG *restart_arg)
Definition: util_sa.c:861
#define RESTORE_LIST_S
Definition: utility.h:1065
int estimatedb_data(UTIL_FUNCTION_ARG *arg_map)
#define DIAG_DUMP_TYPE_S
Definition: utility.h:1145
int sysprm_load_and_init(const char *db_name, const char *conf_file, const int load_flags)
int sm_update_statistics(MOP classop, bool with_fullscan)
#define RESTORE_USE_DATABASE_LOCATION_PATH_S
Definition: utility.h:1075
#define INSTALL_FILE_PATH_S
Definition: utility.h:1139
#define DB_MAX_IDENTIFIER_LENGTH
Definition: dbtype_def.h:495
void tp_final(void)
#define INSTALL_LOG_PATH_S
Definition: utility.h:1141
int sysprm_check_range(const char *pname, void *value)
#define DUMPLOCALE_WEIGHT_ORDER_S
Definition: utility.h:1520
int file_tracker_dump_all_capacities(THREAD_ENTRY *thread_p, FILE *fp)
bool is_restore_from_backup
Definition: boot_sr.h:104
int catcls_get_db_collation(THREAD_ENTRY *thread_p, LANG_COLL_COMPAT **db_collations, int *coll_cnt)
void db_localdatetime(time_t *epoch_time, DB_DATETIME *datetime)
Definition: db_date.c:1030
const char * db_error_string(int level)
Definition: db_admin.c:2116
PGLENGTH db_page_size(void)
char keys_file_path[PATH_MAX]
Definition: boot_sr.h:107
#define DUMPLOCALE_IS_IDENTIFIER_ALPHABET_UPPER
#define min(a, b)
#define IO_MIN_PAGE_SIZE
#define DIAG_EMERGENCY_S
Definition: utility.h:1151
int check_new_database_name(const char *name)
Definition: util_common.c:110
int locale_dump(void *data, LOCALE_FILE *lf, int dl_settings, int start_value, int end_value)
int locale_get_cfg_locales(LOCALE_FILE **p_locale_files, int *p_num_locales, bool is_lang_init)
int lang_collation_count(void)
#define CREATE_MORE_VOLUME_FILE_S
Definition: utility.h:976
void fileio_dismount(THREAD_ENTRY *thread_p, int vol_fd)
Definition: file_io.c:3134
int db_abort_transaction(void)
Definition: db_admin.c:1114
#define DUMPLOCALE_IS_ALPHABET
std::int64_t pageid
Definition: log_lsa.hpp:36
int estimatedb_index(UTIL_FUNCTION_ARG *arg_map)
INT64 LOG_PAGEID
int char_isdigit(int c)
Definition: chartype.c:73
int genlocale(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:2059
int au_add_member(MOP group, MOP member)
void util_free_ha_conf(HA_CONF *ha_conf)
Definition: util_common.c:651
#define DUMPLOCALE_IS_NUMBERING
#define NULL
Definition: freelistheap.h:34
#define DUMPLOCALE_END_VALUE_S
Definition: utility.h:1524
char checksum[32+1]
int tp_valid_indextype(DB_TYPE type)
int db_execute(const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error)
Definition: db_query.c:1836
MOP au_find_user(const char *user_name)
struct pr_type * type
Definition: object_domain.h:76
#define APPLY_INFO_VALUES
int patchdb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1672
int sm_force_write_all_classes(void)
#define ER_LOC_INIT
Definition: error_code.h:1370
static int parse_user_define_line(char *line, FILE *output_file)
Definition: util_sa.c:155
#define INSTALL_SERVER_NAME_S
Definition: utility.h:1137
#define RESTORESLAVE_USE_DATABASE_LOCATION_PATH_S
Definition: utility.h:1569
#define DIAG_DUMP_RECORDS_S
Definition: utility.h:1147
int disk_sectors_to_extend_npages(const int num_pages)
bool cfg_delete_db(DB_INFO **dir_info_p, const char *name)
#define RESTORE_BACKUP_FILE_PATH_S
Definition: utility.h:1067
int log_default_input_for_archive_log_location
static int insert_ha_apply_info(char *database_name, char *master_host_name, INT64 database_creation, INT64 pageid, int offset)
Definition: util_sa.c:3482
#define db_private_free(thrd, ptr)
Definition: memory_alloc.h:229
#define SYNCCOLL_CHECK_S
Definition: utility.h:1532
void COMPOSE_FULL_NAME(char *buf, size_t buf_size, const char *path, const char *name)
Definition: boot.h:161
int cfg_read_directory_ex(int vdes, DB_INFO **info_p, bool write_flag)
int csql(const char *argv0, CSQL_ARGUMENT *csql_arg)
Definition: csql.c:2703
int catcls_compile_catalog_classes(THREAD_ENTRY *thread_p)
char * db_name
#define QUERY_BUF_SIZE
#define DUMP_TZ_ZONES_S
Definition: utility.h:1546
#define CT_COLLATION_NAME
Definition: transform.h:137
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
DB_DOMAIN * pt_string_to_db_domain(const char *s, const char *class_name)
Definition: parse_dbi.c:1332
#define IO_DEFAULT_PAGE_SIZE
DB_INFO * cfg_add_db(DB_INFO **dir, const char *name, const char *path, const char *logpath, const char *lobpath, const char *host)
int utility_get_option_string_table_size(UTIL_ARG_MAP *arg_map)
Definition: util_common.c:305
#define DUMPLOCALE_ALPHABET_ALL_CASING
Definition: utility.h:1515
#define DUMPLOCALE_CALENDAR_S
Definition: utility.h:1505
#define DELETE_DELETE_BACKUP_S
Definition: utility.h:1032
const char * utility_get_generic_message(int message_index)
Definition: util_common.c:88
int db_datetime_to_string(char *buf, int bufsize, DB_DATETIME *datetime)
Definition: db_date.c:4225
#define max(a, b)
#define ER_BO_UNABLE_TO_FIND_HOSTNAME
Definition: error_code.h:180
void tf_compile_meta_classes()
Definition: transform.c:550
#define SYNCCOLL_FORCESYNC_S
Definition: utility.h:1534
const char * envvar_get(const char *name)
#define NULL_TRAN_INDEX
#define DUMPLOCALE_IS_TEXT_CONV
static void error(const char *msg)
Definition: gencat.c:331
DIAGDUMP_TYPE
Definition: util_sa.c:1426
#define CREATE_PAGE_SIZE_L
Definition: utility.h:991
void locale_destroy_data(LOCALE_DATA *ld)
#define DUMPLOCALE_ALPHABET_UPPER_S
Definition: utility.h:1513
#define RENAME_EXTENTED_VOLUME_PATH_S
Definition: utility.h:1002
int db_query_next_tuple(DB_QUERY_RESULT *result)
Definition: db_query.c:2088
int file_tracker_dump(THREAD_ENTRY *thread_p, FILE *fp)
int db_execute_with_values(const char *CSQL_query, DB_QUERY_RESULT **result, DB_QUERY_ERROR *query_error, int arg_count, DB_VALUE *vals)
Definition: db_query.c:1511
bool restore_upto_bktime
Definition: boot_sr.h:101
#define ARG_FILE_LINE
Definition: error_manager.h:44
static bool check_ha_db_and_node_list(char *database_name, char *source_host_name)
Definition: util_sa.c:3685
static char database_name[MAX_HA_DBINFO_LENGTH]
Definition: cas_execute.c:387
void tsc_init(void)
Definition: tsc_timer.c:67
char ** db_names
Definition: utility.h:807
#define RESTORE_UP_TO_DATE_S
Definition: utility.h:1063
UTIL_ARG_MAP * arg_map
Definition: utility.h:1698
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
int fileio_list_restore(THREAD_ENTRY *thread_p, const char *db_full_name_p, char *backup_source_p, FILEIO_BACKUP_LEVEL level, bool is_new_vol_path)
Definition: file_io.c:9703
#define AU_ENABLE(save)
Definition: authenticate.h:113
TEXT_CONVERSION * txt_conv
void locale_mark_duplicate_collations(LOCALE_DATA **ld, int start_index, int end_index, bool is_verbose)
int fileio_get_backup_volume(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *user_backuppath, int try_level, char *from_volbackup)
Definition: file_io.c:9846
int sm_update_all_catalog_statistics(bool with_fullscan)
#define DUMPLOCALE_START_VALUE_S
Definition: utility.h:1522
#define ER_ARG_OUT_OF_RANGE
Definition: error_code.h:1412
#define LOC_LOCALE_STR_SIZE
#define free_and_init(ptr)
Definition: memory_alloc.h:147
#define strlen(s1)
Definition: intl_support.c:43
char * prm_get_string_value(PARAM_ID prm_id)
int sysprm_get_range(const char *pname, void *min, void *max)
INTL_CODESET codeset
#define STATS_WITH_FULLSCAN
Definition: statistics.h:34
#define DB_CURSOR_SUCCESS
Definition: dbtype_def.h:166
int dumplocale(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:2289
#define DUMP_TZ_DUMP_SUM_S
Definition: utility.h:1552
#define CREATE_LOG_PATH_S
Definition: utility.h:968
HA_NODE_CONF * node_conf
Definition: utility.h:810
#define FALSE
Definition: broker_admin.c:50
int db_get_string_size(const DB_VALUE *value)
int util_log_write_errstr(const char *format,...)
Definition: util_func.c:493
char * basename(const char *path)
Definition: porting.c:1132
#define COMMENT_CHAR
Definition: util_sa.c:79
#define FILE_STMT_NAME
#define ALTERDBHOST_HOST_S
Definition: util_admin.c:376
bool catcls_Enable
#define DB_VALUE_TYPE(value)
Definition: dbtype.h:72
#define COPY_DELETE_SOURCE_S
Definition: utility.h:1022
#define CREATE_CSQL_INITIALIZATION_FILE_S
Definition: utility.h:980
int i
Definition: dynamic_load.c:954
char * envvar_tzdata_dir_file(char *path, size_t size, const char *filename)
char * msgcat_message(int cat_id, int set_id, int msg_id)
const char * prm_get_name(PARAM_ID prm_id)
DB_TYPE id
#define LOG_LOCALE_ERROR(msg, er_status, do_print)
int boot_add_collations(MOP class_mop)
Definition: boot_cl.c:3661
#define CREATE_DB_PAGE_SIZE_L
Definition: utility.h:995
#define DUMPLOCALE_IS_IDENTIFIER_ALPHABET
char * strdup(const char *str)
Definition: porting.c:901
int boot_emergency_patch(const char *db_name, bool recreate_log, DKNPAGES log_npages, const char *db_locale, FILE *out_fp)
#define IO_MAX_PAGE_SIZE
char coll_name[COLL_NAME_SIZE]
#define DUMPLOCALE_IS_COLLATION_CP_ORDER
#define DUMPLOCALE_NORMALIZATION_S
Definition: utility.h:1526
int db_value_clear(DB_VALUE *value)
Definition: db_macro.c:1588
int db_make_int(DB_VALUE *value, const int num)
int db_query_get_tuple_value(DB_QUERY_RESULT *result, int index, DB_VALUE *value)
Definition: db_query.c:2873
#define OPTION_STRING_TABLE
Definition: utility.h:813
#define DUMP_TZ_LEAP_SEC_S
Definition: utility.h:1550
DB_INFO * next
int mc_n_variable
Definition: transform.h:53
#define STATS_WITH_SAMPLING
Definition: statistics.h:35
int put_timezone_checksum(char *checksum)
Definition: tz_support.c:5017
void cfg_write_directory_ex(int vdes, const DB_INFO *databases)
#define LANG_SYS_CODESET
#define RESTORE_LEVEL_S
Definition: utility.h:1069
#define RENAME_DELETE_BACKUP_S
Definition: utility.h:1006
#define RESTORESLAVE_MASTER_HOST_NAME_S
Definition: utility.h:1561
#define ER_BO_DATABASE_EXISTS
Definition: error_code.h:176
int locale_prepare_C_file(void)
const char * program_name
Definition: cas.c:147
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
void sm_mark_system_classes(void)
#define COPY_EXTENTED_VOLUME_PATH_S
Definition: utility.h:1016
#define LOB_PATH_DEFAULT_PREFIX
Definition: boot.h:156
void tzc_dump_timezones(const TZ_DATA *tzd)
Definition: tz_compile.c:4655
int util_make_ha_conf(HA_CONF *ha_conf)
Definition: util_common.c:694
#define db_private_realloc(thrd, ptr, size)
Definition: memory_alloc.h:231
int db_compile_and_execute_local(const char *CSQL_query, void *result, DB_QUERY_ERROR *query_error)
Definition: db_vdb.c:3068
static int parse_up_to_date(char *up_to_date, struct tm *time_date)
Definition: util_sa.c:793
FILEIO_BACKUP_LEVEL
Definition: file_io.h:96
int file_tracker_dump_all_heap(THREAD_ENTRY *thread_p, FILE *fp, bool dump_records)
bool printtoc
Definition: boot_sr.h:94
const char * in_file_name
Definition: csql.h:259
void cfg_free_directory(DB_INFO *databases)
int dump_tz(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:4113
#define PATH_SEPARATOR
Definition: porting.h:347
void tz_unload(void)
Definition: tz_support.c:381
char coll_name[COLL_NAME_SIZE]
#define DELETE_OUTPUT_FILE_S
Definition: utility.h:1030
int restoredb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:908
std::int64_t offset
Definition: log_lsa.hpp:37
const char * command_name
Definition: utility.h:1699
int boot_delete(const char *db_name, bool force_delete)
#define GETHOSTNAME(p, l)
Definition: porting.h:381
int locale_check_and_set_default_files(LOCALE_FILE *lf, bool is_lang_init)
char * utility_get_option_string_value(UTIL_ARG_MAP *arg_map, int arg_ch, int index)
Definition: util_common.c:266
int num_node_conf
Definition: utility.h:809
DB_CONST_C_CHAR db_get_string(const DB_VALUE *value)
bool newvolpath
Definition: boot_sr.h:99
int alterdbhost(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1896
int db_set_page_size(PGLENGTH io_page_size, PGLENGTH log_page_size)
#define BO_DB_FULLNAME
Definition: util_sa.c:90
int file_tracker_dump_all_heap_capacities(THREAD_ENTRY *thread_p, FILE *fp)
int installdb(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:1117
#define DISK_SECTOR_NPAGES
int db_commit_transaction(void)
Definition: db_admin.c:1091
#define CREATE_DB_PAGE_SIZE_S
Definition: utility.h:994
int search(int &result, const cub_regex_object &reg, const std::string &src, const INTL_CODESET codeset)
DB_INFO * cfg_find_db_list(DB_INFO *db_info_list_p, const char *name)
#define CREATE_SERVER_NAME_S
Definition: utility.h:972
#define DUMPLOCALE_IS_ALPHABET_LOWER
void cfg_write_directory(const DB_INFO *databases)
int gen_tz(UTIL_FUNCTION_ARG *arg)
Definition: util_sa.c:3924
#define DUMPLOCALE_IS_ALPHABET_UPPER
#define MSGCAT_CATALOG_UTILS