CUBRID Engine  latest
util_cs.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_cs.c : Implementations of utilities that operate in both
21  * client/server and standalone modes.
22  */
23 
24 #ident "$Id$"
25 
26 #include "config.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <signal.h>
33 #include <errno.h>
34 #include <assert.h>
35 
36 #include "utility.h"
37 #include "error_manager.h"
38 #include "message_catalog.h"
39 #include "system_parameter.h"
40 #include "environment_variable.h"
41 #include "databases_file.h"
42 #include "boot_cl.h"
43 #include "boot_sr.h"
44 #include "db.h"
45 #include "authenticate.h"
46 #include "server_interface.h"
47 #include "object_representation.h"
48 #include "transaction_cl.h"
49 #include "porting.h"
50 #include "network_interface_cl.h"
51 #include "connection_defs.h"
52 #include "log_writer.h"
53 #include "log_applier.h"
54 #include "log_lsa.hpp"
55 #include "schema_manager.h"
56 #include "locator_cl.h"
57 #include "dynamic_array.h"
58 #include "util_func.h"
59 #include "xasl.h"
60 #include "log_volids.hpp"
61 #include "tde.h"
62 #if !defined(WINDOWS)
63 #include "heartbeat.h"
64 #endif
65 
66 #define PASSBUF_SIZE 12
67 #define SPACEDB_NUM_VOL_PURPOSE 2
68 #define MAX_KILLTRAN_INDEX_LIST_NUM 64
69 #define MAX_DELVOL_ID_LIST_NUM 64
70 
71 #define VOL_PURPOSE_STRING(VOL_PURPOSE) \
72  ((VOL_PURPOSE == DB_PERMANENT_DATA_PURPOSE) ? "PERMANENT DATA" \
73  : (VOL_PURPOSE == DB_TEMPORARY_DATA_PURPOSE) ? "TEMPORARY DATA" \
74  : "UNKNOWN")
75 
76 typedef enum
77 {
84 
85 typedef enum
86 {
91 
92 typedef enum
93 {
98 
99 static int tranlist_Sort_column = 0;
100 static bool tranlist_Sort_desc = false;
101 
102 static bool is_Sigint_caught = false;
103 #if defined(WINDOWS)
104 static BOOL WINAPI intr_handler (int sig_no);
105 #else
106 static void intr_handler (int sig_no);
107 #endif
108 
109 static void backupdb_sig_interrupt_handler (int sig_no);
110 STATIC_INLINE char *spacedb_get_size_str (char *buf, UINT64 num_pages, T_SPACEDB_SIZE_UNIT size_unit);
111 static void print_timestamp (FILE * outfp);
112 static int print_tran_entry (const ONE_TRAN_INFO * tran_info, TRANDUMP_LEVEL dump_level, bool full_sqltext);
113 static int tranlist_cmp_f (const void *p1, const void *p2);
114 static OID *util_get_class_oids_and_index_btid (dynamic_array * darray, const char *index_name, BTID * index_btid);
115 
116 /*
117  * backupdb() - backupdb main routine
118  * return: EXIT_SUCCESS/EXIT_FAILURE
119  */
120 int
122 {
123  UTIL_ARG_MAP *arg_map = arg->arg_map;
124  char er_msg_file[PATH_MAX];
125  const char *database_name;
126  const char *backup_path = NULL;
127  bool remove_log_archives = false;
128  int backup_level = FILEIO_BACKUP_FULL_LEVEL;
129  const char *backup_verbose_file = NULL;
130  bool no_check = false;
131  bool check = true;
132  int backup_num_threads;
133  bool compress_flag;
134  bool sa_mode;
135  bool separate_keys;
136  FILEIO_ZIP_METHOD backup_zip_method = FILEIO_ZIP_NONE_METHOD;
137  FILEIO_ZIP_LEVEL backup_zip_level = FILEIO_ZIP_NONE_LEVEL;
138  bool skip_activelog = false;
139  int sleep_msecs;
140  struct stat st_buf;
141  char real_pathbuf[PATH_MAX];
142  char verbose_file_realpath[PATH_MAX];
143 
144  if (utility_get_option_string_table_size (arg_map) != 1)
145  {
146  goto print_backup_usage;
147  }
148 
149  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
150  if (database_name == NULL)
151  {
152  goto print_backup_usage;
153  }
154 
156  remove_log_archives = utility_get_option_bool_value (arg_map, BACKUP_REMOVE_ARCHIVE_S);
157  backup_level = utility_get_option_int_value (arg_map, BACKUP_LEVEL_S);
158  backup_verbose_file = utility_get_option_string_value (arg_map, BACKUP_OUTPUT_FILE_S, 0);
159  no_check = utility_get_option_bool_value (arg_map, BACKUP_NO_CHECK_S);
160  check = !no_check;
161  backup_num_threads = utility_get_option_int_value (arg_map, BACKUP_THREAD_COUNT_S);
162  compress_flag = utility_get_option_bool_value (arg_map, BACKUP_COMPRESS_S);
163 
164  // BACKUP_EXCEPT_ACTIVE_LOG_S is obsoleted. This means backup will always include active log.
165  skip_activelog = false;
166 
167  sleep_msecs = utility_get_option_int_value (arg_map, BACKUP_SLEEP_MSECS_S);
168  sa_mode = utility_get_option_bool_value (arg_map, BACKUP_SA_MODE_S);
169  separate_keys = utility_get_option_bool_value (arg_map, BACKUP_SEPARATE_KEYS_S);
170 
171  /* Range checking of input */
172  if (backup_level < 0 || backup_level >= FILEIO_BACKUP_UNDEFINED_LEVEL)
173  {
174  goto print_backup_usage;
175  }
176 
177  if (sa_mode && backup_num_threads > 1)
178  {
181  }
182 
183  if (backup_num_threads < FILEIO_BACKUP_NUM_THREADS_AUTO)
184  {
185  goto print_backup_usage;
186  }
187 
188  if (sleep_msecs < FILEIO_BACKUP_SLEEP_MSECS_AUTO)
189  {
190  goto print_backup_usage;
191  }
192 
193  if (compress_flag)
194  {
195  backup_zip_method = FILEIO_ZIP_LZ4_METHOD;
196  backup_zip_level = FILEIO_ZIP_LZ4_DEFAULT_LEVEL;
197  }
198 
199  /* extra validation */
200  if (check_database_name (database_name))
201  {
202  goto error_exit;
203  }
204 
205  if (backup_path != NULL)
206  {
207  memset (real_pathbuf, 0, sizeof (real_pathbuf));
208  if (realpath (backup_path, real_pathbuf) != NULL)
209  {
210  backup_path = real_pathbuf;
211  }
212 
213  // accept directory and FIFO (named pipe) file as backup destination.
214  if (stat (backup_path, &st_buf) != 0)
215  {
218  goto error_exit;
219  }
220  else if (!S_ISDIR (st_buf.st_mode))
221  {
222 #if !defined (WINDOWS)
223  // Unfortunately, Windows does not support FIFO file.
224  if (!S_ISFIFO (st_buf.st_mode))
225 #endif /* !WINDOWS */
226  {
229  goto error_exit;
230  }
231 #if !defined (WINDOWS)
232  else if (separate_keys) /* FIFO file and --separate_keys is exclusive */
233  {
237  goto error_exit;
238  }
239 #endif /* !WINDOWS */
240  }
241  }
242 
243  if (separate_keys)
244  {
247  }
248  else
249  {
252  }
253 
254  /* error message log file */
255  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
256  er_init (er_msg_file, ER_NEVER_EXIT);
257 
259 
260  AU_DISABLE_PASSWORDS (); /* disable authorization for this operation */
262  db_login ("DBA", NULL);
263 
264  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
265  {
267  goto error_exit;
268  }
269 
270  if (check)
271  {
272  int check_flag = 0;
273 
274  check_flag |= CHECKDB_FILE_TRACKER_CHECK;
275  check_flag |= CHECKDB_HEAP_CHECK_ALLHEAPS;
276  check_flag |= CHECKDB_CT_CHECK_CAT_CONSISTENCY;
277  check_flag |= CHECKDB_BTREE_CHECK_ALL_BTREES;
278  check_flag |= CHECKDB_LC_CHECK_CLASSNAMES;
279 
281  || boot_check_db_consistency (check_flag, 0, 0, NULL) != NO_ERROR)
282  {
283  const char *tmpname;
284 
285  tmpname = er_get_msglog_filename ();
286  if (tmpname == NULL)
287  {
288  tmpname = "/dev/null";
289  }
291  CHECKDB_MSG_INCONSISTENT), tmpname);
292  db_shutdown ();
293  goto error_exit;
294  }
295  }
296 
297  /* some other utilities may need interrupt handler too */
298  if (os_set_signal_handler (SIGINT, backupdb_sig_interrupt_handler) == SIG_ERR)
299  {
302  db_shutdown ();
303  goto error_exit;
304  }
305 
306  if (backup_verbose_file && *backup_verbose_file && *backup_verbose_file != '/')
307  {
308  char dirname[PATH_MAX];
309 
310  /* resolve relative path */
311  if (getcwd (dirname, PATH_MAX) != NULL)
312  {
313  if (snprintf (verbose_file_realpath, PATH_MAX - 1, "%s/%s", dirname, backup_verbose_file) < 0)
314  {
315  assert (false);
316  db_shutdown ();
317  goto error_exit;
318  }
319  backup_verbose_file = verbose_file_realpath;
320  }
321  }
322 
323  if (boot_backup (backup_path, (FILEIO_BACKUP_LEVEL) backup_level, remove_log_archives, backup_verbose_file,
324  backup_num_threads, backup_zip_method, backup_zip_level, skip_activelog, sleep_msecs,
325  separate_keys) != NO_ERROR)
326  {
328  db_shutdown ();
329  goto error_exit;
330  }
331 
333  {
335  }
336 
337  db_shutdown ();
338 
339  return EXIT_SUCCESS;
340 
341 print_backup_usage:
343  basename (arg->argv0));
345 
346 error_exit:
347  return EXIT_FAILURE;
348 }
349 
350 /*
351  * addvoldb() - addvoldb main routine
352  * return: EXIT_SUCCESS/EXIT_FAILURE
353  */
354 int
356 {
357  UTIL_ARG_MAP *arg_map = arg->arg_map;
358  char er_msg_file[PATH_MAX];
359  const char *database_name;
360  UINT64 volext_size;
361  UINT64 volext_max_writesize;
362  const char *volext_string_purpose = NULL;
363  const char *volext_npages_string = NULL;
364  const char *volext_size_str = NULL;
365  const char *volext_max_writesize_in_sec_str = NULL;
366  char real_volext_path_buf[PATH_MAX];
367  bool sa_mode;
368  DBDEF_VOL_EXT_INFO ext_info;
369 
370  ext_info.overwrite = false;
371  ext_info.max_npages = 0;
372  if (utility_get_option_string_table_size (arg_map) < 1)
373  {
374  goto print_addvol_usage;
375  }
376 
377  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
378  if (database_name == NULL)
379  {
380  goto print_addvol_usage;
381  }
382 
383  volext_npages_string = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 1);
384  if (volext_npages_string)
385  {
386  util_print_deprecated ("number-of-pages");
387  ext_info.max_npages = atoi (volext_npages_string);
388  }
389 
390  volext_size = 0;
391  volext_size_str = utility_get_option_string_value (arg_map, ADDVOL_VOLUME_SIZE_S, 0);
392  if (volext_size_str)
393  {
394  if (util_size_string_to_byte (&volext_size, volext_size_str) != NO_ERROR)
395  {
396  goto print_addvol_usage;
397  }
398  }
399 
400  volext_max_writesize_in_sec_str = utility_get_option_string_value (arg_map, ADDVOL_MAX_WRITESIZE_IN_SEC_S, 0);
401  if (volext_max_writesize_in_sec_str)
402  {
403  if (util_size_string_to_byte (&volext_max_writesize, volext_max_writesize_in_sec_str) != NO_ERROR)
404  {
405  goto print_addvol_usage;
406  }
407  ext_info.max_writesize_in_sec = (int) volext_max_writesize / ONE_K;
408  }
409  else
410  {
411  ext_info.max_writesize_in_sec = 0;
412  }
413 
416  if (ext_info.path != NULL)
417  {
418  memset (real_volext_path_buf, 0, sizeof (real_volext_path_buf));
419  if (realpath (ext_info.path, real_volext_path_buf) != NULL)
420  {
421  ext_info.path = real_volext_path_buf;
422  }
423  }
425  volext_string_purpose = utility_get_option_string_value (arg_map, ADDVOL_PURPOSE_S, 0);
426  if (volext_string_purpose == NULL)
427  {
428  volext_string_purpose = "generic";
429  }
430 
432 
433  if (strcasecmp (volext_string_purpose, "data") == 0)
434  {
436  }
437  else if (strcasecmp (volext_string_purpose, "index") == 0)
438  {
440  }
441  else if (strcasecmp (volext_string_purpose, "temp") == 0)
442  {
444  }
445  else if (strcasecmp (volext_string_purpose, "generic") == 0)
446  {
448  }
449  else
450  {
452  volext_string_purpose);
453 
454  goto error_exit;
455  }
456 
457  sa_mode = utility_get_option_bool_value (arg_map, ADDVOL_SA_MODE_S);
458  if (sa_mode && ext_info.max_writesize_in_sec > 0)
459  {
460  ext_info.max_writesize_in_sec = 0;
461  fprintf (stderr,
463  }
464 
465  /* extra validation */
466  if (check_database_name (database_name) || check_volume_name (ext_info.name))
467  {
468  goto error_exit;
469  }
470 
471  /* error message log file */
472  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
473  er_init (er_msg_file, ER_NEVER_EXIT);
474 
475  /* tuning system parameters */
478 
481  db_login ("DBA", NULL);
482  if (db_restart (arg->command_name, TRUE, database_name) == NO_ERROR)
483  {
484  if (volext_size == 0)
485  {
487  }
488 
489  if (ext_info.max_npages == 0)
490  {
491  ext_info.max_npages = (int) (volext_size / IO_PAGESIZE);
492  }
493 
494  if (ext_info.max_npages <= 0)
495  {
498  db_shutdown ();
499  goto error_exit;
500  }
501 
502  if (db_add_volume_ex (&ext_info) == NO_ERROR)
503  {
505  }
506  else
507  {
509  db_shutdown ();
510  goto error_exit;
511  }
512  db_shutdown ();
513  }
514  else
515  {
517  goto error_exit;
518  }
519 
520  return EXIT_SUCCESS;
521 
522 print_addvol_usage:
524  basename (arg->argv0));
526 error_exit:
527  return EXIT_FAILURE;
528 }
529 
530 /*
531  * util_get_class_oids_and_index_btid() -
532  * return: OID array/NULL
533  * index_name(in)
534  * index_btid(out)
535  */
536 static OID *
537 util_get_class_oids_and_index_btid (dynamic_array * darray, const char *index_name, BTID * index_btid)
538 {
539  MOP cls_mop;
540  OID *oids;
541  OID *cls_oid;
542  SM_CLASS *cls_sm;
543  SM_CLASS_CONSTRAINT *constraint;
544  char table[SM_MAX_IDENTIFIER_LENGTH];
545  char name[SM_MAX_IDENTIFIER_LENGTH];
546  int i;
547  int num_tables = da_size (darray);
548  MOBJ *obj;
549 
550  oids = (OID *) malloc (sizeof (OID) * num_tables);
551  if (oids == NULL)
552  {
553  perror ("malloc");
555  return NULL;
556  }
557 
558  for (i = 0; i < num_tables; i++)
559  {
560  if (da_get (darray, i, table) != NO_ERROR)
561  {
562  free (oids);
563  return NULL;
564  }
565 
566  OID_SET_NULL (&oids[i]);
567  if (table == NULL || table[0] == '\0')
568  {
569  continue;
570  }
571 
573  cls_mop = locator_find_class (name);
574 
575  obj = (MOBJ *) & cls_sm;
576  ws_find (cls_mop, obj);
577  if (cls_sm == NULL || cls_sm->class_type != SM_CLASS_CT)
578  {
580  CHECKDB_MSG_NO_SUCH_CLASS), table);
581  continue;
582  }
583 
584  cls_oid = ws_oid (cls_mop);
585  if (cls_oid)
586  {
587  oids[i] = *cls_oid;
588  }
589  else
590  {
592  CHECKDB_MSG_NO_SUCH_CLASS), table);
593  continue;
594  }
595 
596  if (index_name != NULL)
597  {
598  constraint = classobj_find_class_index (cls_sm, index_name);
599  if (constraint == NULL)
600  {
602  CHECKDB_MSG_NO_SUCH_INDEX), index_name, name);
603  free_and_init (oids);
604  return NULL;
605  }
606 
607  db_constraint_index (constraint, index_btid);
608 
609  assert (i == 0);
610  }
611  }
612 
613  return oids;
614 }
615 
616 /*
617  * checkdb() - checkdb main routine
618  * return: EXIT_SUCCESS/EXIT_FAILURE
619  */
620 int
622 {
623  UTIL_ARG_MAP *arg_map = arg->arg_map;
624  char er_msg_file[PATH_MAX];
625  const char *database_name;
626  char *fname;
627  char *index_name = NULL;
628  bool repair = false;
629  bool repair_plink = false;
630  int flag = 0;
631  int i, num_tables;
632  OID *oids = NULL;
633  BTID index_btid;
634  dynamic_array *darray = NULL;
635 
636  if (utility_get_option_string_table_size (arg_map) < 1)
637  {
638  goto print_check_usage;
639  }
640 
641  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
642  if (database_name == NULL)
643  {
644  goto print_check_usage;
645  }
646 
647  /* extra validation */
648  if (check_database_name (database_name))
649  {
650  goto error_exit;
651  }
652 
654  {
656  }
657 
659  {
661  }
662 
664  {
666  }
667 
669  {
671  }
672 
674  {
676  }
677 
679  {
681  }
682 
684  if (repair_plink)
685  {
686  flag |= CHECKDB_REPAIR_PREV_LINK;
687  }
689  {
690  flag |= CHECKDB_CHECK_PREV_LINK;
691  }
692 
693  if (flag == 0)
694  {
696  }
697 
698  repair = utility_get_option_bool_value (arg_map, CHECK_REPAIR_S);
699  if (repair)
700  {
701  flag |= CHECKDB_REPAIR;
702  }
703 
705  index_name = utility_get_option_string_value (arg_map, CHECK_INDEXNAME_S, 0);
706  num_tables = utility_get_option_string_table_size (arg_map);
707  num_tables -= 1;
708 
709  if (index_name != NULL && num_tables != 1)
710  {
711  PRINT_AND_LOG_ERR_MSG ("Only one table is supported to check specific index.\n");
712  goto error_exit;
713  }
714 
715  darray = da_create (num_tables, SM_MAX_IDENTIFIER_LENGTH);
716  if (darray == NULL)
717  {
718  perror ("calloc");
720  goto error_exit;
721  }
722 
723  if (num_tables > 0)
724  {
725  char n[SM_MAX_IDENTIFIER_LENGTH];
726  char *p;
727 
728  for (i = 0; i < num_tables; i++)
729  {
731  if (p == NULL)
732  {
733  continue;
734  }
735  strncpy_bufsize (n, p);
736  if (da_add (darray, n) != NO_ERROR)
737  {
739  perror ("calloc");
740  goto error_exit;
741  }
742  }
743  }
744 
745  if (fname != NULL)
746  {
747  if (util_get_table_list_from_file (fname, darray) != NO_ERROR)
748  {
749  goto error_exit;
750  }
751  }
752 
753  num_tables = da_size (darray);
754 
755  /* error message log file */
756  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
757  er_init (er_msg_file, ER_NEVER_EXIT);
758 
760 
763  db_login ("DBA", NULL);
764  if (db_restart (arg->command_name, TRUE, database_name) == NO_ERROR)
765  {
766  if (num_tables > 0)
767  {
768  BTID_SET_NULL (&index_btid);
769  oids = util_get_class_oids_and_index_btid (darray, index_name, &index_btid);
770  if (oids == NULL)
771  {
772  db_shutdown ();
773  goto error_exit;
774  }
775  }
776 
778  || boot_check_db_consistency (flag, oids, num_tables, &index_btid) != NO_ERROR)
779  {
780  const char *tmpname;
781 
782  if ((tmpname = er_get_msglog_filename ()) == NULL)
783  {
784  tmpname = "/dev/null";
785  }
787  CHECKDB_MSG_INCONSISTENT), tmpname);
788 
789  if (repair_plink || repair)
790  {
792  }
794  db_shutdown ();
795  goto error_exit;
796  }
797  if (repair_plink || repair)
798  {
800  }
801  db_shutdown ();
802  }
803  else
804  {
806  goto error_exit;
807  }
808 
809  if (darray != NULL)
810  {
811  da_destroy (darray);
812  }
813  if (oids != NULL)
814  {
815  free (oids);
816  }
817 
818  return EXIT_SUCCESS;
819 
820 print_check_usage:
822  basename (arg->argv0));
824 
825 error_exit:
826  if (darray != NULL)
827  {
828  da_destroy (darray);
829  }
830  if (oids != NULL)
831  {
832  free (oids);
833  }
834 
835  return EXIT_FAILURE;
836 }
837 
838 
839 /*
840  * spacedb() - spacedb main routine
841  * return: EXIT_SUCCESS/EXIT_FAILURE
842  */
843 int
845 {
846 #define SPACEDB_TO_SIZE_ARG(no, npage) spacedb_get_size_str (size_str_##no, npage, size_unit_type)
847 
848  UTIL_ARG_MAP *arg_map = arg->arg_map;
849  char er_msg_file[PATH_MAX];
850  const char *database_name;
851  const char *output_file = NULL;
852  int i;
853  const char *size_unit;
854  T_SPACEDB_SIZE_UNIT size_unit_type;
855 
856  bool summarize, purpose;
857  FILE *outfp = NULL;
858  char io_size_str[64], log_size_str[64];
859 
861  SPACEDB_ONEVOL *vols = NULL;
862  SPACEDB_ONEVOL **volsp = NULL;
864  SPACEDB_FILES *filesp = NULL;
865 
866  char size_str_1[64];
867  char size_str_2[64];
868  char size_str_3[64];
869  char size_str_4[64];
870 
871  const char *file_type_strings[] = {
872  "INDEX", "HEAP", "SYSTEM", "TEMP", "-"
873  };
874 
875  /* todo: there is a lot of work to do here */
876 
877  if (utility_get_option_string_table_size (arg_map) != 1)
878  {
879  goto print_space_usage;
880  }
881 
882  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
883  if (database_name == NULL)
884  {
885  goto print_space_usage;
886  }
887 
888  output_file = utility_get_option_string_value (arg_map, SPACE_OUTPUT_FILE_S, 0);
889  size_unit = utility_get_option_string_value (arg_map, SPACE_SIZE_UNIT_S, 0);
890  summarize = utility_get_option_bool_value (arg_map, SPACE_SUMMARIZE_S);
891  purpose = utility_get_option_bool_value (arg_map, SPACE_PURPOSE_S);
892 
893  size_unit_type = SPACEDB_SIZE_UNIT_HUMAN_READABLE;
894 
895  if (size_unit != NULL)
896  {
897  if (strcasecmp (size_unit, "page") == 0)
898  {
899  size_unit_type = SPACEDB_SIZE_UNIT_PAGE;
900  }
901  else if (strcasecmp (size_unit, "m") == 0)
902  {
903  size_unit_type = SPACEDB_SIZE_UNIT_MBYTES;
904  }
905  else if (strcasecmp (size_unit, "g") == 0)
906  {
907  size_unit_type = SPACEDB_SIZE_UNIT_GBYTES;
908  }
909  else if (strcasecmp (size_unit, "t") == 0)
910  {
911  size_unit_type = SPACEDB_SIZE_UNIT_TBYTES;
912  }
913  else if (strcasecmp (size_unit, "h") != 0)
914  {
915  /* invalid option string */
916  goto print_space_usage;
917  }
918  }
919 
920  if (output_file == NULL)
921  {
922  outfp = stdout;
923  }
924  else
925  {
926  outfp = fopen (output_file, "w");
927  if (outfp == NULL)
928  {
930  output_file);
931  goto error_exit;
932  }
933  }
934 
935  if (check_database_name (database_name))
936  {
937  goto error_exit;
938  }
939 
940  /* error message log file */
941  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
942  er_init (er_msg_file, ER_NEVER_EXIT);
943 
944  /* tuning system parameters */
947 
948  /* should have little copyright herald message ? */
951  db_login ("DBA", NULL);
952 
953  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
954  {
956  goto error_exit;
957  }
958 
959  util_byte_to_size_string (io_size_str, 64, IO_PAGESIZE);
960  util_byte_to_size_string (log_size_str, 64, LOG_PAGESIZE);
961 
962  if (!summarize)
963  {
964  /* we need space info per each volume. set volsp to non-NULL value */
965  volsp = &vols;
966  }
967  if (purpose)
968  {
969  /* we need detailed space info for file usage. set filesp to non-NULL value */
970  filesp = files;
971  }
972 
973  if (netcl_spacedb (all, volsp, filesp) != NO_ERROR)
974  {
975  ASSERT_ERROR ();
977  db_shutdown ();
978  goto error_exit;
979  }
980 
981  /* print title */
983  io_size_str, log_size_str);
984  fprintf (outfp, "\n");
985 
986  /* print aggregated info */
987  /* print header */
988  if (size_unit_type == SPACEDB_SIZE_UNIT_PAGE)
989  {
991  }
992  else
993  {
995  }
996  /* print values. the format is:
997  * type, purpose, used pages/size, free pages/size, total pages/size */
998  /* print perm perm values */
999  for (i = 0; i < SPACEDB_ALL_COUNT; i++)
1000  {
1002  all[i].nvols, SPACEDB_TO_SIZE_ARG (1, all[i].npage_used),
1003  SPACEDB_TO_SIZE_ARG (2, all[i].npage_free),
1004  SPACEDB_TO_SIZE_ARG (3, all[i].npage_used + all[i].npage_free));
1005  }
1006  fprintf (outfp, "\n");
1007 
1008  if (volsp != NULL)
1009  {
1010  /* print information on all volumes */
1011  MSGCAT_SPACEDB_MSG msg_vols_format;
1012 
1013  /* print title */
1015  /* print header */
1016  if (size_unit_type == SPACEDB_SIZE_UNIT_PAGE)
1017  {
1018  fprintf (outfp,
1020  }
1021  else
1022  {
1024  }
1025 
1026  /* print each volume */
1027  for (i = 0; i < all[SPACEDB_TOTAL_ALL].nvols; i++)
1028  {
1029  if (vols[i].type == DB_PERMANENT_VOLTYPE)
1030  {
1031  if (vols[i].purpose == DB_PERMANENT_DATA_PURPOSE)
1032  {
1033  msg_vols_format = SPACEDB_MSG_VOLS_PERM_PERM_FORMAT;
1034  }
1035  else
1036  {
1037  msg_vols_format = SPACEDB_MSG_VOLS_PERM_TEMP_FORMAT;
1038  }
1039  }
1040  else
1041  {
1042  msg_vols_format = SPACEDB_MSG_VOLS_TEMP_TEMP_FORMAT;
1043  }
1044  /* the format is:
1045  * volid, type, purpose, used pages/size, free pages/size, total pages/size, volume name */
1046  fprintf (outfp, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_SPACEDB, msg_vols_format),
1047  vols[i].volid, SPACEDB_TO_SIZE_ARG (1, vols[i].npage_used),
1048  SPACEDB_TO_SIZE_ARG (2, vols[i].npage_free),
1049  SPACEDB_TO_SIZE_ARG (3, vols[i].npage_used + vols[i].npage_free), vols[i].name);
1050  }
1051  fprintf (outfp, "\n");
1052  }
1053 
1054  if (filesp != NULL)
1055  {
1056  /* print detailed files information */
1057 
1058  /* print title */
1060  /* print header */
1061  if (size_unit_type == SPACEDB_SIZE_UNIT_PAGE)
1062  {
1063  fprintf (outfp,
1065  }
1066  else
1067  {
1068  fprintf (outfp,
1070  }
1071 
1072  /* the format is:
1073  * data_type, file_count, used pages/size, ftab pages/size, reserved pages/size, total pages/size */
1074  for (i = 0; i < SPACEDB_FILE_COUNT; i++)
1075  {
1077  file_type_strings[i], files[i].nfile,
1078  SPACEDB_TO_SIZE_ARG (1, files[i].npage_user), SPACEDB_TO_SIZE_ARG (2, files[i].npage_ftab),
1079  SPACEDB_TO_SIZE_ARG (3, files[i].npage_reserved),
1080  SPACEDB_TO_SIZE_ARG (4, files[i].npage_user + files[i].npage_ftab + files[i].npage_reserved));
1081  }
1082  fprintf (outfp, "\n");
1083  }
1084 
1085  if (!summarize)
1086  {
1088  boot_get_lob_path ());
1089  }
1090 
1091  db_shutdown ();
1092  if (outfp != stdout)
1093  {
1094  fclose (outfp);
1095  }
1096 
1097  if (vols != NULL)
1098  {
1099  free_and_init (vols);
1100  }
1101 
1102  return EXIT_SUCCESS;
1103 
1104 print_space_usage:
1106  basename (arg->argv0));
1108 
1109 error_exit:
1110  if (outfp != stdout && outfp != NULL)
1111  {
1112  fclose (outfp);
1113  }
1114  if (vols != NULL)
1115  {
1116  free_and_init (vols);
1117  }
1118  return EXIT_FAILURE;
1119 
1120 #undef SPACEDB_TO_SIZE_ARG
1121 }
1122 
1123 /*
1124  * acldb() -
1125  * return: EXIT_SUCCESS/EXIT_FAILURE
1126  */
1127 int
1129 {
1130 #if defined (CS_MODE)
1131  UTIL_ARG_MAP *arg_map = arg->arg_map;
1132  char er_msg_file[PATH_MAX];
1133  const char *database_name;
1134  bool reload;
1135  int ret_code = EXIT_SUCCESS;
1136 
1137  if (utility_get_option_string_table_size (arg_map) != 1)
1138  {
1139  goto print_acl_usage;
1140  }
1141 
1142  reload = utility_get_option_bool_value (arg_map, ACLDB_RELOAD_S);
1143 
1144  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1145  if (database_name == NULL)
1146  {
1147  goto print_acl_usage;
1148  }
1149 
1150  if (check_database_name (database_name))
1151  {
1152  goto error_exit;
1153  }
1154 
1155  /* error message log file */
1156  sprintf (er_msg_file, "%s_%s.err", database_name, arg->command_name);
1157  er_init (er_msg_file, ER_NEVER_EXIT);
1158 
1159  /* should have little copyright herald message ? */
1162  db_login ("DBA", NULL);
1163 
1164  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
1165  {
1166  fprintf (stderr, "%s\n", db_error_string (3));
1167  goto error_exit;
1168  }
1169 
1170  if (reload)
1171  {
1172  ret_code = acl_reload ();
1173  if (ret_code != NO_ERROR)
1174  {
1175  fprintf (stderr, "%s\n", db_error_string (3));
1176  }
1177  }
1178  else
1179  {
1180  acl_dump (stdout);
1181  }
1182  db_shutdown ();
1183 
1184  return ret_code;
1185 
1186 print_acl_usage:
1188  basename (arg->argv0));
1189 error_exit:
1190  return EXIT_FAILURE;
1191 #else /* CS_MODE */
1193  basename (arg->argv0));
1194  return EXIT_FAILURE;
1195 #endif /* !CS_MODE */
1196 }
1197 
1198 /*
1199  * lockdb() - lockdb main routine
1200  * return: EXIT_SUCCESS/EXIT_FAILURE
1201  */
1202 int
1204 {
1205 #if defined (CS_MODE)
1206  UTIL_ARG_MAP *arg_map = arg->arg_map;
1207  char er_msg_file[PATH_MAX];
1208  const char *database_name;
1209  const char *output_file = NULL;
1210  FILE *outfp = NULL;
1211 
1212  if (utility_get_option_string_table_size (arg_map) != 1)
1213  {
1214  goto print_lock_usage;
1215  }
1216 
1217  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1218  if (database_name == NULL)
1219  {
1220  goto print_lock_usage;
1221  }
1222 
1223  output_file = utility_get_option_string_value (arg_map, LOCK_OUTPUT_FILE_S, 0);
1224  if (output_file == NULL)
1225  {
1226  outfp = stdout;
1227  }
1228  else
1229  {
1230  outfp = fopen (output_file, "w");
1231  if (outfp == NULL)
1232  {
1234  output_file);
1235  goto error_exit;
1236  }
1237  }
1238 
1239  if (check_database_name (database_name))
1240  {
1241  goto error_exit;
1242  }
1243 
1244  /* error message log file */
1245  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
1246  er_init (er_msg_file, ER_NEVER_EXIT);
1247 
1248  /* should have little copyright herald message ? */
1251  db_login ("DBA", NULL);
1252 
1253  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
1254  {
1255  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1256  goto error_exit;
1257  }
1258 
1260 
1261  lock_dump (outfp);
1262  db_shutdown ();
1263 
1264  if (outfp != stdout)
1265  {
1266  fclose (outfp);
1267  }
1268 
1269  return EXIT_SUCCESS;
1270 
1271 print_lock_usage:
1273  basename (arg->argv0));
1275 
1276 error_exit:
1277  if (outfp != stdout && outfp != NULL)
1278  {
1279  fclose (outfp);
1280  }
1281  return EXIT_FAILURE;
1282 #else /* CS_MODE */
1284  basename (arg->argv0));
1285  return EXIT_FAILURE;
1286 #endif /* !CS_MODE */
1287 }
1288 
1289 /*
1290  * isvalid_transaction() - test if transaction is valid
1291  * return: non-zero if valid transaction
1292  * tran(in)
1293  */
1294 static int
1296 {
1297  int valid;
1298 
1299  valid = (tran != NULL && tran->tran_index != -1 && tran->tran_index != tm_Tran_index);
1300 
1301  return valid;
1302 }
1303 
1304 /*
1305  * doesmatch_transaction() - test if matching transaction
1306  * return: non-zero if the information matches this transaction
1307  * tran(in)
1308  * tran_index_list(in)
1309  * index_list_size(in)
1310  * user_name(in)
1311  * hostname(in)
1312  * progname(in)
1313  */
1314 static bool
1315 doesmatch_transaction (const ONE_TRAN_INFO * tran, int *tran_index_list, int index_list_size, const char *username,
1316  const char *hostname, const char *progname, const char *sql_id)
1317 {
1318  int i;
1319 
1320  if (!isvalid_transaction (tran))
1321  {
1322  return false;
1323  }
1324 
1325  if ((username != NULL && strcmp (tran->login_name, username) == 0)
1326  || (hostname != NULL && strcmp (tran->host_name, hostname) == 0)
1327  || (progname != NULL && strcmp (tran->program_name, progname) == 0)
1328  || (sql_id != NULL && tran->query_exec_info.sql_id != NULL && strcmp (tran->query_exec_info.sql_id, sql_id) == 0))
1329  {
1330  return true;
1331  }
1332 
1333  for (i = 0; i < index_list_size; i++)
1334  {
1335  if (tran->tran_index == tran_index_list[i])
1336  {
1337  return true;
1338  }
1339  }
1340 
1341  return false;
1342 }
1343 
1344 /*
1345  * dump_trantb() - Displays information about all the currently
1346  * active transactions
1347  * return: none
1348  * info(in) :
1349  * dump_level(in) :
1350  */
1351 static void
1352 dump_trantb (TRANS_INFO * info, TRANDUMP_LEVEL dump_level, bool full_sqltext)
1353 {
1354  int i;
1355  int num_valid = 0;
1358 
1359  if (dump_level == TRANDUMP_FULL_INFO)
1360  {
1362  underscore = TRANLIST_MSG_FULL_INFO_UNDERSCORE;
1363  }
1364  else if (dump_level == TRANDUMP_QUERY_INFO)
1365  {
1368  }
1369 
1370  if (info != NULL && info->num_trans > 0)
1371  {
1372  /*
1373  * remember that we have to print the messages one at a time, mts_
1374  * reuses the message buffer on each call.
1375  */
1376  for (i = 0; i < info->num_trans; i++)
1377  {
1378  /*
1379  * Display transactions in transaction table that seems to be valid
1380  */
1381  if (isvalid_transaction (&info->tran[i]))
1382  {
1383  if (num_valid == 0)
1384  {
1385  /* Dump table header */
1386  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, header));
1387  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1388  }
1389 
1390  num_valid++;
1391  print_tran_entry (&info->tran[i], dump_level, full_sqltext);
1392  }
1393  }
1394  }
1395 
1396  if (num_valid > 0)
1397  {
1398  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1399  }
1400  else
1401  {
1402  fprintf (stdout,
1404  }
1405 
1406  if (info != NULL && (dump_level == TRANDUMP_QUERY_INFO || dump_level == TRANDUMP_FULL_INFO))
1407  {
1408  int j;
1409 
1410  fprintf (stdout, "\n");
1411  /* print query string info */
1412  for (i = 0; i < info->num_trans; i++)
1413  {
1414  if (isvalid_transaction (&info->tran[i]) && !XASL_ID_IS_NULL (&info->tran[i].query_exec_info.xasl_id))
1415  {
1417  info->tran[i].query_exec_info.sql_id);
1419  info->tran[i].tran_index);
1420 
1421  for (j = i + 1; j < info->num_trans; j++)
1422  {
1423  if (isvalid_transaction (&info->tran[j])
1425  {
1426  /* same query */
1427  fprintf (stdout, ", %d", info->tran[j].tran_index);
1428  /* reset xasl to skip in next search */
1430  }
1431  }
1432  fprintf (stdout, "\n");
1433 
1434  /* print query statement */
1435  fprintf (stdout, "%s\n\n", info->tran[i].query_exec_info.query_stmt);
1436  }
1437  }
1438  }
1439 }
1440 
1441 /*
1442  * kill_transactions() - kill transaction(s)
1443  * return: number of killed transactions
1444  * info(in/out)
1445  * tran_index(in)
1446  * username(in)
1447  * hostname(in)
1448  * progname(in)
1449  * verify(in)
1450  *
1451  * Note: Kill one or several transactions identified only one of the
1452  * above parameters. If the verification flag is set, the user is
1453  * prompted for verification wheheter or not to kill the
1454  * transaction(s).
1455  *
1456  * if tran_index_list != NULL && != ""
1457  * kill transactions in the tran_index comma list.
1458  * else if username != NULL && != ""
1459  * kill all transactions associated with given user.
1460  * else if hostname != NULL && != ""
1461  * kill all transactions associated with given host.
1462  * else if progname != NULL && != ""
1463  * kill all transactions associated with given program.
1464  * else
1465  * error.
1466  *
1467  * If verify is set, the transactions are only killed after prompting
1468  * for verification.
1469  */
1470 static int
1471 kill_transactions (TRANS_INFO * info, int *tran_index_list, int list_size, const char *username, const char *hostname,
1472  const char *progname, const char *sql_id, bool verify)
1473 {
1474  int i, ok;
1475  int nkills = 0, nfailures = 0;
1476  int ch;
1479  TRANDUMP_LEVEL dump_level = TRANDUMP_SUMMARY;
1480 
1481  if (sql_id != NULL)
1482  {
1483  /* print --query-exec-info table format */
1486  dump_level = TRANDUMP_QUERY_INFO;
1487  }
1488 
1489  /* see if we have anything do do */
1490  for (i = 0; i < info->num_trans; i++)
1491  {
1492  if (doesmatch_transaction (&info->tran[i], tran_index_list, list_size, username, hostname, progname, sql_id))
1493  {
1494  break;
1495  }
1496  }
1497 
1498  if (i >= info->num_trans)
1499  {
1500  /*
1501  * There is not matches
1502  */
1504  }
1505  else
1506  {
1507  if (!verify)
1508  {
1509  ok = 1;
1510  }
1511  else
1512  {
1513  ok = 0;
1514  /*
1515  * display the transactin identifiers that we are about to kill
1516  */
1518 
1519  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, header));
1520  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1521 
1522  for (i = 0; i < info->num_trans; i++)
1523  {
1524  if (doesmatch_transaction (&info->tran[i], tran_index_list, list_size, username, hostname, progname,
1525  sql_id))
1526  {
1527  print_tran_entry (&info->tran[i], dump_level, false);
1528  }
1529  }
1530  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1531 
1533  fflush (stdout);
1534 
1535  ch = getc (stdin);
1536  if (ch == 'Y' || ch == 'y')
1537  {
1538  ok = 1;
1539  }
1540  }
1541 
1542  if (ok)
1543  {
1544  for (i = 0; i < info->num_trans; i++)
1545  {
1546  if (doesmatch_transaction (&info->tran[i], tran_index_list, list_size, username, hostname, progname,
1547  sql_id))
1548  {
1549  fprintf (stdout,
1551  info->tran[i].tran_index);
1552  if (thread_kill_tran_index (info->tran[i].tran_index, info->tran[i].db_user, info->tran[i].host_name,
1553  info->tran[i].process_id) == NO_ERROR)
1554  {
1555  info->tran[i].tran_index = -1; /* Gone */
1556  nkills++;
1557  }
1558  else
1559  {
1560  /*
1561  * Fail to kill the transaction
1562  */
1563  if (nfailures == 0)
1564  {
1567  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, header));
1568  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1569  }
1570 
1571  print_tran_entry (&info->tran[i], dump_level, false);
1572 
1573  if (er_errid () != NO_ERROR)
1574  {
1575  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1576  }
1577  else /* probably it is the case of timeout */
1578  {
1581  }
1582  nfailures++;
1583  }
1584  }
1585  }
1586 
1587  if (nfailures > 0)
1588  {
1589  fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_TRANLIST, underscore));
1590  }
1591  }
1592  }
1593 
1594  return nkills;
1595 }
1596 
1597 /*
1598  * print_tran_entry()
1599  * return: NO_ERROR
1600  * tran_info(in) :
1601  * include_query_info(in) :
1602  */
1603 static int
1604 print_tran_entry (const ONE_TRAN_INFO * tran_info, TRANDUMP_LEVEL dump_level, bool full_sqltext)
1605 {
1606  char *buf = NULL;
1607  char *query_buf;
1608  char tmp_query_buf[32];
1609 
1610  if (tran_info == NULL)
1611  {
1612  assert_release (0);
1613  return ER_FAILED;
1614  }
1615 
1616  assert_release (dump_level <= TRANDUMP_FULL_INFO);
1617 
1618  if (dump_level == TRANDUMP_FULL_INFO || dump_level == TRANDUMP_QUERY_INFO)
1619  {
1621 
1622  if (tran_info->query_exec_info.query_stmt != NULL)
1623  {
1624  /* print 31 string */
1625  if (full_sqltext == true)
1626  {
1627  query_buf = tran_info->query_exec_info.query_stmt;
1628  }
1629  else
1630  {
1631  strncpy (tmp_query_buf, tran_info->query_exec_info.query_stmt, 32);
1632  tmp_query_buf[31] = '\0';
1633  query_buf = tmp_query_buf;
1634  }
1635  }
1636  }
1637 
1638  if (dump_level == TRANDUMP_FULL_INFO)
1639  {
1641  tran_info->tran_index, tran_get_tranlist_state_name (tran_info->state), tran_info->db_user,
1642  tran_info->host_name, tran_info->process_id, tran_info->program_name,
1643  tran_info->query_exec_info.query_time, tran_info->query_exec_info.tran_time, (buf == NULL ? "-1" : buf),
1644  ((tran_info->query_exec_info.sql_id) ? tran_info->query_exec_info.sql_id : "*** empty ***"),
1645  ((tran_info->query_exec_info.query_stmt) ? query_buf : " "));
1646  }
1647  else if (dump_level == TRANDUMP_QUERY_INFO)
1648  {
1650  tran_info->tran_index, tran_get_tranlist_state_name (tran_info->state),
1651  tran_info->process_id, tran_info->program_name, tran_info->query_exec_info.query_time,
1652  tran_info->query_exec_info.tran_time, (buf == NULL ? "-1" : buf),
1653  ((tran_info->query_exec_info.sql_id) ? tran_info->query_exec_info.sql_id : "*** empty ***"),
1654  ((tran_info->query_exec_info.query_stmt) ? query_buf : " "));
1655  }
1656  else
1657  {
1659  tran_info->tran_index, tran_get_tranlist_state_name (tran_info->state), tran_info->db_user,
1660  tran_info->host_name, tran_info->process_id, tran_info->program_name);
1661  }
1662 
1663  return NO_ERROR;
1664 }
1665 
1666 
1667 /*
1668  * tranlist() -
1669  * return: EXIT_SUCCESS/EXIT_FAILURE
1670  */
1671 int
1673 {
1674 #if defined (CS_MODE)
1675  UTIL_ARG_MAP *arg_map = arg->arg_map;
1676  char er_msg_file[PATH_MAX];
1677  const char *database_name;
1678 #if defined(NEED_PRIVILEGE_PASSWORD)
1679  const char *username;
1680  const char *password;
1681 #endif
1682  char *passbuf = NULL;
1683  TRANS_INFO *info = NULL;
1684  int error;
1685  bool is_summary, include_query_info, full_sqltext = false;
1686  TRANDUMP_LEVEL dump_level = TRANDUMP_FULL_INFO;
1687 
1688  if (utility_get_option_string_table_size (arg_map) != 1)
1689  {
1690  goto print_tranlist_usage;
1691  }
1692 
1693  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1694  if (database_name == NULL)
1695  {
1696  goto print_tranlist_usage;
1697  }
1698 
1699 #if defined(NEED_PRIVILEGE_PASSWORD)
1700  username = utility_get_option_string_value (arg_map, TRANLIST_USER_S, 0);
1701  password = utility_get_option_string_value (arg_map, TRANLIST_PASSWORD_S, 0);
1702 #endif
1703  is_summary = utility_get_option_bool_value (arg_map, TRANLIST_SUMMARY_S);
1706  full_sqltext = utility_get_option_bool_value (arg_map, TRANLIST_FULL_SQL_S);
1707 
1708 #if defined(NEED_PRIVILEGE_PASSWORD)
1709  if (username == NULL)
1710  {
1711  /* default : DBA user */
1712  username = "DBA";
1713  }
1714 #endif
1715 
1716  if (check_database_name (database_name) != NO_ERROR)
1717  {
1718  goto error_exit;
1719  }
1720 
1721  if (tranlist_Sort_column > 10 || tranlist_Sort_column < 0 || (is_summary && tranlist_Sort_column > 5))
1722  {
1725  goto error_exit;
1726  }
1727 
1728  /* error message log file */
1729  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
1730  er_init (er_msg_file, ER_NEVER_EXIT);
1731 
1732 #if defined(NEED_PRIVILEGE_PASSWORD)
1733  error = db_restart_ex (arg->command_name, database_name, username, password, NULL, DB_CLIENT_TYPE_ADMIN_UTILITY);
1734  if (error != NO_ERROR)
1735  {
1736  char msg_buf[64];
1737 
1738  if (error == ER_AU_INVALID_PASSWORD && password == NULL)
1739  {
1740  /*
1741  * prompt for a valid password and try again, need a reusable
1742  * password prompter so we can use getpass() on platforms that
1743  * support it.
1744  */
1745  snprintf (msg_buf, 64,
1747  username);
1748 
1749  passbuf = getpass (msg_buf);
1750 
1751  if (passbuf[0] == '\0')
1752  {
1753  passbuf = (char *) NULL;
1754  }
1755  password = passbuf;
1756 
1757  error =
1758  db_restart_ex (arg->command_name, database_name, username, password, NULL, DB_CLIENT_TYPE_ADMIN_UTILITY);
1759  }
1760 
1761  if (error != NO_ERROR)
1762  {
1763  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1764  goto error_exit;
1765  }
1766  }
1767 
1769  {
1771  username);
1772  db_shutdown ();
1773  goto error_exit;
1774  }
1775 #else
1778  if (db_login ("DBA", NULL) || db_restart (arg->command_name, TRUE, database_name))
1779  {
1780  PRINT_AND_LOG_ERR_MSG ("%s: %s. \n\n", arg->command_name, db_error_string (3));
1781  goto error_exit;
1782  }
1783 #endif
1784 
1785  /*
1786  * Get the current state of transaction table information. All the
1787  * transaction kills are going to be based on this information. The
1788  * transaction information may be changed back in the server if there
1789  * are new transactions starting and finishing. We need to do this way
1790  * since verification is required at this level, and we cannot freeze the
1791  * state of the server ()transaction table).
1792  */
1793  include_query_info = !is_summary;
1794 
1795  info = logtb_get_trans_info (include_query_info);
1796  if (info == NULL)
1797  {
1798  util_log_write_errstr ("%s\n", db_error_string (3));
1799  db_shutdown ();
1800  goto error_exit;
1801  }
1802 
1803  if (is_summary)
1804  {
1805  dump_level = TRANDUMP_SUMMARY;
1806  }
1807 
1808  if (tranlist_Sort_column > 0 || tranlist_Sort_desc == true)
1809  {
1810  qsort ((void *) info->tran, info->num_trans, sizeof (ONE_TRAN_INFO), tranlist_cmp_f);
1811  }
1812 
1813  (void) dump_trantb (info, dump_level, full_sqltext);
1814 
1815  if (info)
1816  {
1817  logtb_free_trans_info (info);
1818  }
1819 
1820  (void) db_shutdown ();
1821  return EXIT_SUCCESS;
1822 
1823 print_tranlist_usage:
1825  basename (arg->argv0));
1827 
1828 error_exit:
1829  return EXIT_FAILURE;
1830 #else /* CS_MODE */
1833  return EXIT_FAILURE;
1834 #endif /* !CS_MODE */
1835 }
1836 
1837 /*
1838  * killtran() - killtran main routine
1839  * return: EXIT_SUCCESS/EXIT_FAILURE
1840  */
1841 int
1843 {
1844 #if defined (CS_MODE)
1845  UTIL_ARG_MAP *arg_map = arg->arg_map;
1846  char er_msg_file[PATH_MAX];
1847  const char *database_name;
1848  const char *kill_tran_index;
1849  const char *kill_progname;
1850  const char *kill_user;
1851  const char *kill_host;
1852  const char *kill_sql_id;
1853  const char *dba_password;
1854  bool dump_trantab_flag;
1855  bool force = true;
1856  int isbatch;
1857  char *passbuf = NULL;
1858  TRANS_INFO *info = NULL;
1859  int error;
1860  bool include_query_exec_info;
1861  int tran_index_list[MAX_KILLTRAN_INDEX_LIST_NUM];
1862  int list_size = 0;
1863  int value;
1864  char delimiter = ',';
1865  const char *ptr;
1866  char *tmp;
1867 
1868  if (utility_get_option_string_table_size (arg_map) != 1)
1869  {
1870  goto print_killtran_usage;
1871  }
1872 
1873  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
1874  if (database_name == NULL)
1875  {
1876  goto print_killtran_usage;
1877  }
1878 
1882  kill_progname = utility_get_option_string_value (arg_map, KILLTRAN_KILL_PROGRAM_NAME_S, 0);
1883  kill_sql_id = utility_get_option_string_value (arg_map, KILLTRAN_KILL_SQL_ID_S, 0);
1884 
1886  dba_password = utility_get_option_string_value (arg_map, KILLTRAN_DBA_PASSWORD_S, 0);
1887  dump_trantab_flag = utility_get_option_bool_value (arg_map, KILLTRAN_DISPLAY_INFORMATION_S);
1888 
1889  include_query_exec_info = utility_get_option_bool_value (arg_map, KILLTRAN_DISPLAY_QUERY_INFO_S);
1890 
1891  if (check_database_name (database_name))
1892  {
1893  goto error_exit;
1894  }
1895 
1896  isbatch = 0;
1897  if (kill_tran_index != NULL && strlen (kill_tran_index) != 0)
1898  {
1899  isbatch++;
1900  }
1901  if (kill_user != NULL && strlen (kill_user) != 0)
1902  {
1903  isbatch++;
1904  }
1905  if (kill_host != NULL && strlen (kill_host) != 0)
1906  {
1907  isbatch++;
1908  }
1909  if (kill_progname != NULL && strlen (kill_progname) != 0)
1910  {
1911  isbatch++;
1912  }
1913  if (kill_sql_id != NULL && strlen (kill_sql_id) != 0)
1914  {
1915  isbatch++;
1916  }
1917 
1918  if (isbatch > 1)
1919  {
1921  goto error_exit;
1922  }
1923 
1924  /* error message log file */
1925  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
1926  er_init (er_msg_file, ER_NEVER_EXIT);
1927 
1928  /* disable password, if don't use kill option */
1929  if (isbatch == 0)
1930  {
1931  if (dba_password != NULL)
1932  {
1933  goto print_killtran_usage;
1934  }
1936  }
1937 
1939 
1940  if (db_login ("DBA", dba_password) != NO_ERROR)
1941  {
1942  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1943  goto error_exit;
1944  }
1945 
1946  /* first try to restart with the password given (possibly none) */
1947  error = db_restart (arg->command_name, TRUE, database_name);
1948  if (error)
1949  {
1950  if (error == ER_AU_INVALID_PASSWORD && (dba_password == NULL || strlen (dba_password) == 0))
1951  {
1952  /*
1953  * prompt for a valid password and try again, need a reusable
1954  * password prompter so we can use getpass() on platforms that
1955  * support it.
1956  */
1957 
1958  /* get password interactively if interactive mode */
1961  if (passbuf[0] == '\0') /* to fit into db_login protocol */
1962  {
1963  passbuf = (char *) NULL;
1964  }
1965  dba_password = passbuf;
1966  if (db_login ("DBA", dba_password) != NO_ERROR)
1967  {
1968  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1969  goto error_exit;
1970  }
1971  else
1972  {
1973  error = db_restart (arg->command_name, TRUE, database_name);
1974  }
1975  }
1976 
1977  if (error)
1978  {
1979  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
1980  goto error_exit;
1981  }
1982  }
1983 
1984  /*
1985  * Get the current state of transaction table information. All the
1986  * transaction kills are going to be based on this information. The
1987  * transaction information may be changed back in the server if there
1988  * are new transactions starting and finishing. We need to do this way
1989  * since verification is required at this level, and we cannot freeze the
1990  * state of the server ()transaction table).
1991  */
1992 
1993  info = logtb_get_trans_info (include_query_exec_info || kill_sql_id);
1994  if (info == NULL)
1995  {
1996  util_log_write_errstr ("%s\n", db_error_string (3));
1997  db_shutdown ();
1998  goto error_exit;
1999  }
2000 
2001  if (dump_trantab_flag || include_query_exec_info
2002  || ((kill_tran_index == NULL || strlen (kill_tran_index) == 0) && (kill_user == NULL || strlen (kill_user) == 0)
2003  && (kill_host == NULL || strlen (kill_host) == 0) && (kill_progname == NULL || strlen (kill_progname) == 0)
2004  && (kill_sql_id == NULL || strlen (kill_sql_id) == 0)))
2005  {
2006  TRANDUMP_LEVEL dump_level;
2007 
2008  dump_level = (include_query_exec_info) ? TRANDUMP_QUERY_INFO : TRANDUMP_SUMMARY;
2009  dump_trantb (info, dump_level, false);
2010  }
2011  else
2012  {
2013  if (kill_tran_index != NULL && strlen (kill_tran_index) > 0)
2014  {
2015  int result;
2016 
2017  ptr = kill_tran_index;
2018 
2019  tmp = (char *) strchr (ptr, delimiter);
2020  while (*ptr != '\0' && tmp)
2021  {
2022  if (list_size >= MAX_KILLTRAN_INDEX_LIST_NUM)
2023  {
2024  break;
2025  }
2026 
2027  *tmp = '\0';
2028  result = parse_int (&value, ptr, 10);
2029  if (result != 0 || value <= 0)
2030  {
2033  if (info)
2034  {
2035  logtb_free_trans_info (info);
2036  }
2037  db_shutdown ();
2038  goto error_exit;
2039  }
2040 
2041  tran_index_list[list_size++] = value;
2042  ptr = tmp + 1;
2043  tmp = (char *) strchr (ptr, delimiter);
2044  }
2045 
2046  result = parse_int (&value, ptr, 10);
2047  if (result != 0 || value <= 0)
2048  {
2051  if (info)
2052  {
2053  logtb_free_trans_info (info);
2054  }
2055  db_shutdown ();
2056  goto error_exit;
2057  }
2058 
2059  if (list_size < MAX_KILLTRAN_INDEX_LIST_NUM)
2060  {
2061  tran_index_list[list_size++] = value;
2062  }
2063  }
2064 
2065  /* some piece of transaction identifier was entered, try to use it */
2066  if (kill_transactions (info, tran_index_list, list_size, kill_user, kill_host, kill_progname, kill_sql_id, !force)
2067  <= 0)
2068  {
2069  if (info)
2070  {
2071  logtb_free_trans_info (info);
2072  }
2073  db_shutdown ();
2074  goto error_exit;
2075  }
2076  }
2077 
2078  if (info)
2079  {
2080  logtb_free_trans_info (info);
2081  }
2082 
2083  (void) db_shutdown ();
2084  return EXIT_SUCCESS;
2085 
2086 print_killtran_usage:
2088  basename (arg->argv0));
2090 
2091 error_exit:
2092  return EXIT_FAILURE;
2093 #else /* CS_MODE */
2096  return EXIT_FAILURE;
2097 #endif /* !CS_MODE */
2098 }
2099 
2100 /*
2101  * plandump() - plandump main routine
2102  * return: EXIT_SUCCESS/EXIT_FAILURE
2103  */
2104 int
2106 {
2107 #if defined (CS_MODE)
2108  UTIL_ARG_MAP *arg_map = arg->arg_map;
2109  char er_msg_file[PATH_MAX];
2110  const char *database_name;
2111  const char *output_file = NULL;
2112  bool drop_flag = false;
2113  FILE *outfp = NULL;
2114 
2115  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2116  if (database_name == NULL)
2117  {
2118  goto print_plandump_usage;
2119  }
2120 
2121  drop_flag = utility_get_option_bool_value (arg_map, PLANDUMP_DROP_S);
2122  output_file = utility_get_option_string_value (arg_map, PLANDUMP_OUTPUT_FILE_S, 0);
2123 
2124  if (utility_get_option_string_table_size (arg_map) != 1)
2125  {
2126  goto print_plandump_usage;
2127  }
2128 
2129  if (output_file == NULL)
2130  {
2131  outfp = stdout;
2132  }
2133  else
2134  {
2135  outfp = fopen (output_file, "w");
2136  if (outfp == NULL)
2137  {
2139  PLANDUMP_MSG_BAD_OUTPUT), output_file);
2140  goto error_exit;
2141  }
2142  }
2143 
2144  if (check_database_name (database_name))
2145  {
2146  goto error_exit;
2147  }
2148 
2149  /* error message log file */
2150  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
2151  er_init (er_msg_file, ER_NEVER_EXIT);
2152 
2153  /* should have little copyright herald message ? */
2156  db_login ("DBA", NULL);
2157 
2158  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
2159  {
2160  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2161  goto error_exit;
2162  }
2163 
2164  qmgr_dump_query_plans (outfp);
2165  if (drop_flag)
2166  {
2168  {
2169  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2170  db_shutdown ();
2171  goto error_exit;
2172  }
2173  }
2174  db_shutdown ();
2175 
2176  if (outfp != stdout)
2177  {
2178  fclose (outfp);
2179  }
2180 
2181  return EXIT_SUCCESS;
2182 
2183 print_plandump_usage:
2185  basename (arg->argv0));
2187 
2188 error_exit:
2189  if (outfp != stdout && outfp != NULL)
2190  {
2191  fclose (outfp);
2192  }
2193  return EXIT_FAILURE;
2194 #else /* CS_MODE */
2196  basename (arg->argv0));
2197  return EXIT_FAILURE;
2198 #endif /* !CS_MODE */
2199 }
2200 
2201 /*
2202  * paramdump() - paramdump main routine
2203  * return: EXIT_SUCCESS/EXIT_FAILURE
2204  */
2205 int
2207 {
2208  UTIL_ARG_MAP *arg_map = arg->arg_map;
2209  char er_msg_file[PATH_MAX];
2210  const char *database_name;
2211  const char *output_file = NULL;
2212  bool both_flag = false;
2213  FILE *outfp = NULL;
2214 
2215  if (utility_get_option_string_table_size (arg_map) != 1)
2216  {
2217  goto print_dumpparam_usage;
2218  }
2219 
2220  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2221  if (database_name == NULL)
2222  {
2223  goto print_dumpparam_usage;
2224  }
2225 
2226  output_file = utility_get_option_string_value (arg_map, PARAMDUMP_OUTPUT_FILE_S, 0);
2227  both_flag = utility_get_option_bool_value (arg_map, PARAMDUMP_BOTH_S);
2228 
2229  if (output_file == NULL)
2230  {
2231  outfp = stdout;
2232  }
2233  else
2234  {
2235  outfp = fopen (output_file, "w");
2236  if (outfp == NULL)
2237  {
2239  PARAMDUMP_MSG_BAD_OUTPUT), output_file);
2240  goto error_exit;
2241  }
2242  }
2243 
2244  if (check_database_name (database_name))
2245  {
2246  goto error_exit;
2247  }
2248 
2249  /* error message log file */
2250  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
2251  er_init (er_msg_file, ER_NEVER_EXIT);
2252 
2254 
2255 #if defined (CS_MODE)
2256  /* should have little copyright herald message ? */
2259  db_login ("DBA", NULL);
2260 
2261  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
2262  {
2263  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2264  goto error_exit;
2265  }
2266 
2267  if (both_flag)
2268  {
2270  sysprm_dump_parameters (outfp);
2271  fprintf (outfp, "\n");
2272  }
2274  database_name);
2276  db_shutdown ();
2277 #else /* CS_MODE */
2279  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) == NO_ERROR)
2280  {
2281  sysprm_dump_parameters (outfp);
2282  }
2283 #endif /* !CS_MODE */
2284 
2285  if (outfp != stdout)
2286  {
2287  fclose (outfp);
2288  }
2289 
2290  return EXIT_SUCCESS;
2291 
2292 print_dumpparam_usage:
2294  basename (arg->argv0));
2296 
2297 error_exit:
2298  if (outfp != stdout && outfp != NULL)
2299  {
2300  fclose (outfp);
2301  }
2302  return EXIT_FAILURE;
2303 }
2304 
2305 static void
2306 print_timestamp (FILE * outfp)
2307 {
2308  time_t tloc;
2309  struct tm tmloc;
2310  char str[80];
2311 
2312  tloc = time (NULL);
2313  utility_localtime (&tloc, &tmloc);
2314  strftime (str, 80, "%a %B %d %H:%M:%S %Z %Y", &tmloc);
2315  fprintf (outfp, "\n\t%s\n", str);
2316 }
2317 
2318 /*
2319  * statdump() - statdump main routine
2320  * return: EXIT_SUCCESS/EXIT_FAILURE
2321  */
2322 int
2324 {
2325 #if defined (CS_MODE)
2326  UTIL_ARG_MAP *arg_map = arg->arg_map;
2327  char er_msg_file[PATH_MAX];
2328  const char *database_name;
2329  const char *output_file = NULL;
2330  int interval;
2331  bool cumulative;
2332  const char *substr;
2333  FILE *outfp = NULL;
2334 
2335  if (utility_get_option_string_table_size (arg_map) != 1)
2336  {
2337  goto print_statdump_usage;
2338  }
2339 
2340  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2341  if (database_name == NULL)
2342  {
2343  goto print_statdump_usage;
2344  }
2345 
2346  output_file = utility_get_option_string_value (arg_map, STATDUMP_OUTPUT_FILE_S, 0);
2347  interval = utility_get_option_int_value (arg_map, STATDUMP_INTERVAL_S);
2348  if (interval < 0)
2349  {
2350  goto print_statdump_usage;
2351  }
2352  cumulative = utility_get_option_bool_value (arg_map, STATDUMP_CUMULATIVE_S);
2353  substr = utility_get_option_string_value (arg_map, STATDUMP_SUBSTR_S, 0);
2354 
2355  if (interval == 0)
2356  {
2357  cumulative = true;
2358  }
2359 
2360  if (output_file == NULL)
2361  {
2362  outfp = stdout;
2363  }
2364  else
2365  {
2366  outfp = fopen (output_file, "w");
2367  if (outfp == NULL)
2368  {
2370  STATDUMP_MSG_BAD_OUTPUT), output_file);
2371  goto error_exit;
2372  }
2373  }
2374 
2375  if (check_database_name (database_name))
2376  {
2377  goto error_exit;
2378  }
2379 
2380  /* error message log file */
2381  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
2382  er_init (er_msg_file, ER_NEVER_EXIT);
2383 
2384  /* should have little copyright herald message ? */
2387  db_login ("DBA", NULL);
2388 
2389  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
2390  {
2391  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2392  goto error_exit;
2393  }
2394 
2395  if (histo_start (true) != NO_ERROR)
2396  {
2397  goto error_exit;
2398  }
2399 
2400  if (interval > 0)
2401  {
2402  is_Sigint_caught = false;
2403 #if defined(WINDOWS)
2404  SetConsoleCtrlHandler ((PHANDLER_ROUTINE) intr_handler, TRUE);
2405 #else
2406  os_set_signal_handler (SIGINT, intr_handler);
2407 #endif
2408  }
2409 
2410  do
2411  {
2412  print_timestamp (outfp);
2413  if (histo_print_global_stats (outfp, cumulative, substr) != NO_ERROR)
2414  {
2415  histo_stop ();
2416  goto error_exit;
2417  }
2418  fflush (outfp);
2419  sleep (interval);
2420  }
2421  while (interval > 0 && !is_Sigint_caught);
2422 
2423  histo_stop ();
2424 
2425  db_shutdown ();
2426 
2427  if (outfp != stdout)
2428  {
2429  fclose (outfp);
2430  }
2431 
2432  return EXIT_SUCCESS;
2433 
2434 print_statdump_usage:
2436  basename (arg->argv0));
2438 
2439 error_exit:
2440  if (outfp != stdout && outfp != NULL)
2441  {
2442  fclose (outfp);
2443  }
2444  return EXIT_FAILURE;
2445 #else /* CS_MODE */
2448 
2449  return EXIT_FAILURE;
2450 #endif /* !CS_MODE */
2451 }
2452 
2453 #if defined (ENABLE_UNUSED_FUNCTION)
2454 /* check ha_mode is turned on in the server */
2455 static int
2456 check_server_ha_mode (void)
2457 {
2458  char prm_buf[LINE_MAX], *prm_val;
2459 
2460  strcpy (prm_buf, prm_get_name (PRM_ID_HA_MODE));
2461  if (db_get_system_parameters (prm_buf, LINE_MAX - 1) != NO_ERROR)
2462  {
2463  return ER_FAILED;
2464  }
2465  prm_val = strchr (prm_buf, '=');
2466  if (prm_val == NULL)
2467  {
2468  return ER_FAILED;
2469  }
2470  if (strcmp (prm_val + 1, "y") != 0)
2471  {
2472  return ER_FAILED;
2473  }
2474  return NO_ERROR;
2475 }
2476 #endif /* ENABLE_UNUSED_FUNCTION */
2477 
2478 /*
2479  * changemode() - changemode main routine
2480  * return: EXIT_SUCCESS/EXIT_FAILURE
2481  *
2482  * TODO: this is really confusing. changemode utility actually changes HA state and not HA mode. They are two different
2483  * things.
2484  */
2485 int
2487 {
2488 #if defined (WINDOWS)
2491 
2492  return EXIT_FAILURE;
2493 #else /* WINDOWS */
2494 #if defined (CS_MODE)
2495  UTIL_ARG_MAP *arg_map = arg->arg_map;
2496  char er_msg_file[PATH_MAX];
2497  const char *database_name;
2498  char *mode_name;
2499  int error;
2501  bool force;
2502  int timeout;
2503 
2504  if (utility_get_option_string_table_size (arg_map) != 1)
2505  {
2506  goto print_changemode_usage;
2507  }
2508 
2509  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2510  if (database_name == NULL)
2511  {
2512  goto print_changemode_usage;
2513  }
2514 
2515  mode_name = utility_get_option_string_value (arg_map, CHANGEMODE_MODE_S, 0);
2518 
2519  if (timeout == -1)
2520  {
2522  }
2523 
2524  if (check_database_name (database_name))
2525  {
2526  goto error_exit;
2527  }
2528 
2529  /* check mode_name option argument */
2530  if (mode_name != NULL)
2531  {
2532  int keyval = -1;
2533  if (changemode_keyword (&keyval, &mode_name) != NO_ERROR)
2534  {
2535  if (sscanf (mode_name, "%d", &keyval) != 1)
2536  {
2538  CHANGEMODE_MSG_BAD_MODE), mode_name);
2539  goto error_exit;
2540  }
2541  }
2542  ha_state = (HA_SERVER_STATE) keyval;
2543  if (!(ha_state == HA_SERVER_STATE_ACTIVE || ha_state == HA_SERVER_STATE_STANDBY
2544  || ha_state == HA_SERVER_STATE_MAINTENANCE))
2545  {
2547  CHANGEMODE_MSG_BAD_MODE), mode_name);
2548  goto error_exit;
2549  }
2550  }
2551 
2552  /* error message log file */
2553  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
2554  er_init (er_msg_file, ER_NEVER_EXIT);
2555 
2558  if (db_login ("DBA", NULL) != NO_ERROR)
2559  {
2560  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2561  goto error_exit;
2562  }
2563  error = db_restart (arg->command_name, TRUE, database_name);
2564  if (error != NO_ERROR)
2565  {
2566  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2567  goto error_exit;
2568  }
2569 
2570  if (HA_DISABLED ())
2571  {
2574  goto error_exit;
2575  }
2576 
2577  if (mode_name == NULL)
2578  {
2579  /* display the value of current ha_state */
2580  ha_state = boot_change_ha_mode (HA_SERVER_STATE_NA, false, timeout);
2581  }
2582  else
2583  {
2584  /* change server's HA state */
2585  ha_state = boot_change_ha_mode (ha_state, force, timeout);
2586  }
2587  if (ha_state != HA_SERVER_STATE_NA)
2588  {
2589  int keyval = (int) ha_state;
2590  mode_name = NULL;
2591  if (changemode_keyword (&keyval, &mode_name) != NO_ERROR)
2592  {
2594  (mode_name ? mode_name : "unknown"));
2595  }
2596  else
2597  {
2598  fprintf (stdout,
2600  database_name, mode_name);
2601  }
2602  ha_state = (HA_SERVER_STATE) keyval;
2603  }
2604  else
2605  {
2606  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2607  goto error_exit;
2608  }
2609 
2610  (void) db_shutdown ();
2611  return EXIT_SUCCESS;
2612 
2613 print_changemode_usage:
2615  basename (arg->argv0));
2617 
2618 error_exit:
2619  return EXIT_FAILURE;
2620 #else /* CS_MODE */
2623  return EXIT_FAILURE;
2624 #endif /* !CS_MODE */
2625 #endif /* !WINDOWS */
2626 }
2627 
2628 /*
2629  * copylogdb() - copylogdb main routine
2630  * return: EXIT_SUCCESS/EXIT_FAILURE
2631  */
2632 int
2634 {
2635 #if defined (WINDOWS)
2637  basename (arg->argv0));
2638  return EXIT_FAILURE;
2639 #else /* WINDOWS */
2640 #if defined (CS_MODE)
2641  UTIL_ARG_MAP *arg_map = arg->arg_map;
2642  char er_msg_file[PATH_MAX];
2643  const char *database_name;
2644  const char *log_path;
2645  char log_path_buf[PATH_MAX];
2646  char *mode_name;
2647  int mode = -1;
2648  int error = NO_ERROR;
2649  int retried = 0, sleep_nsecs = 1;
2650  bool need_er_reinit = false;
2651  unsigned long num_db_restarted = 0;
2652 #if !defined(WINDOWS)
2653  char *binary_name;
2654  char executable_path[PATH_MAX];
2655 #endif
2656  INT64 start_pageid = 0;
2657 
2658  if (utility_get_option_string_table_size (arg_map) != 1)
2659  {
2660  goto print_copylog_usage;
2661  }
2662 
2663  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2664  if (database_name == NULL)
2665  {
2666  goto print_copylog_usage;
2667  }
2668 
2669  log_path = utility_get_option_string_value (arg_map, COPYLOG_LOG_PATH_S, 0);
2670  mode_name = utility_get_option_string_value (arg_map, COPYLOG_MODE_S, 0);
2671 
2672  if (check_database_name (database_name))
2673  {
2674  goto error_exit;
2675  }
2676  if (log_path != NULL)
2677  {
2678  log_path = realpath (log_path, log_path_buf);
2679  }
2680  if (log_path == NULL)
2681  {
2682  goto print_copylog_usage;
2683  }
2684  /* check mode_name option argument */
2685  if (mode_name != NULL)
2686  {
2687  if (copylogdb_keyword (&mode, &mode_name) != NO_ERROR)
2688  {
2689  if (sscanf (mode_name, "%d", &mode) != 1)
2690  {
2692  COPYLOGDB_MSG_BAD_MODE), mode_name);
2693  goto error_exit;
2694  }
2695  }
2696  if (!(mode >= LOGWR_MODE_ASYNC && mode <= LOGWR_MODE_SYNC))
2697  {
2699  COPYLOGDB_MSG_BAD_MODE), mode_name);
2700  goto error_exit;
2701  }
2702  }
2703  else
2704  {
2705  mode = LOGWR_MODE_SYNC;
2706  }
2707 
2708  /* 'SEMISYNC' is treated as 'SYNC'. */
2709  if (mode == LOGWR_MODE_SEMISYNC)
2710  {
2711  mode = LOGWR_MODE_SYNC;
2712  }
2713 
2714  start_pageid = utility_get_option_bigint_value (arg_map, COPYLOG_START_PAGEID_S);
2715 
2716 #if defined(NDEBUG)
2718 #endif
2719 
2720  /* error message log file */
2721  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
2722  er_init (er_msg_file, ER_NEVER_EXIT);
2723 
2726  if (db_login ("DBA", NULL) != NO_ERROR)
2727  {
2728  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2729  goto error_exit;
2730  }
2731 #if !defined(WINDOWS)
2732  /* save executable path */
2733  binary_name = basename (arg->argv0);
2734  (void) envvar_bindir_file (executable_path, PATH_MAX, binary_name);
2735 
2736  hb_set_exec_path (executable_path);
2737  hb_set_argv (arg->argv);
2738 
2739  /* initialize system parameters */
2740  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
2741  {
2742  error = ER_FAILED;
2743  goto error_exit;
2744  }
2745 
2746  /*
2747  * Force error log file system parameter as copylogdb;
2748  * during a retry loop, `db_restart` will reset the error file name as :
2749  * er_init (prm_get_string_value (PRM_ID_ER_LOG_FILE), ... )
2750  */
2752 
2753  if (start_pageid < NULL_PAGEID && !HA_DISABLED ())
2754  {
2755  error = hb_process_init (database_name, log_path, HB_PTYPE_COPYLOGDB);
2756  if (error != NO_ERROR)
2757  {
2758  er_log_debug (ARG_FILE_LINE, "cannot connect to cub_master for heartbeat. \n");
2759  if (er_errid () != NO_ERROR)
2760  {
2761  util_log_write_errstr ("%s\n", db_error_string (3));
2762  }
2763 
2764  return EXIT_FAILURE;
2765  }
2766  er_set_ignore_uninit (true);
2767  }
2768 #endif
2769 
2770 retry:
2771  error = db_restart (arg->command_name, TRUE, database_name);
2772  if (error != NO_ERROR)
2773  {
2774  if (retried % 10 == 0)
2775  {
2776  fprintf (stderr, "%s\n", db_error_string (3));
2777  }
2778  goto error_exit;
2779  }
2780  num_db_restarted += 1;
2781 
2782  if (need_er_reinit)
2783  {
2784  er_init (er_msg_file, ER_NEVER_EXIT);
2785  need_er_reinit = false;
2786  }
2787 
2788  /* initialize system parameters */
2789  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
2790  {
2791  (void) db_shutdown ();
2792 
2793  error = ER_FAILED;
2794  goto error_exit;
2795  }
2796 
2797  /* PRM_LOG_BACKGROUND_ARCHIVING is always true in CUBRID HA */
2799 
2800  error = logwr_copy_log_file (database_name, log_path, mode, start_pageid);
2801  if (error != NO_ERROR)
2802  {
2803  fprintf (stderr, "%s\n", db_error_string (3));
2804  (void) db_shutdown ();
2805  goto error_exit;
2806  }
2807 
2808  (void) db_shutdown ();
2809  return EXIT_SUCCESS;
2810 
2811 print_copylog_usage:
2813  basename (arg->argv0));
2815 
2816  return EXIT_FAILURE;
2817 
2818 error_exit:
2819 #if !defined(WINDOWS)
2820  if (hb_Proc_shutdown)
2821  {
2822  return EXIT_SUCCESS;
2823  }
2824 #endif
2825 
2826  if (logwr_force_shutdown () == false
2827  && (error == ER_NET_SERVER_CRASHED || error == ER_NET_CANT_CONNECT_SERVER || error == ER_BO_CONNECT_FAILED
2829  {
2830  (void) sleep (sleep_nsecs);
2831  /* sleep 1, 2, 4, 8, etc; don't wait for more than 1/2 min */
2832  if (num_db_restarted > 0)
2833  {
2834  sleep_nsecs *= 2;
2835  if (sleep_nsecs > 30)
2836  {
2837  sleep_nsecs = 1;
2838  }
2839  }
2840 
2841  need_er_reinit = true;
2842  ++retried;
2843 
2844  er_init (er_msg_file, ER_NEVER_EXIT);
2845  goto retry;
2846  }
2847 
2848  return EXIT_FAILURE;
2849 #else /* CS_MODE */
2852  return EXIT_FAILURE;
2853 #endif /* !CS_MODE */
2854 #endif /* !WINDOWS */
2855 }
2856 
2857 /*
2858  * applylogdb() - applylogdb main routine
2859  * return: EXIT_SUCCESS/EXIT_FAILURE
2860  */
2861 int
2863 {
2864 #if defined (WINDOWS)
2867 
2868  return EXIT_FAILURE;
2869 #else /* WINDOWS */
2870 #if defined (CS_MODE)
2871  UTIL_ARG_MAP *arg_map = arg->arg_map;
2872  char er_msg_file[PATH_MAX];
2873  const char *database_name = NULL;
2874  const char *log_path = NULL;
2875  char log_path_buf[PATH_MAX];
2876  char *log_path_base;
2877  int max_mem_size = 0;
2878  int error = NO_ERROR;
2879  int retried = 0, sleep_nsecs = 1;
2880  bool need_er_reinit = false;
2881  char *replica_time_bound_str;
2882 #if !defined(WINDOWS)
2883  char *binary_name;
2884  char executable_path[PATH_MAX];
2885 #endif
2886 
2887  if (utility_get_option_string_table_size (arg_map) != 1)
2888  {
2889  goto print_applylog_usage;
2890  }
2891 
2892  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
2893  if (database_name == NULL)
2894  {
2895  goto print_applylog_usage;
2896  }
2897 
2898  log_path = utility_get_option_string_value (arg_map, APPLYLOG_LOG_PATH_S, 0);
2899  max_mem_size = utility_get_option_int_value (arg_map, APPLYLOG_MAX_MEM_SIZE_S);
2900 
2901  if (check_database_name (database_name))
2902  {
2903  goto error_exit;
2904  }
2905  if (log_path != NULL)
2906  {
2907  log_path = realpath (log_path, log_path_buf);
2908  }
2909  if (log_path == NULL)
2910  {
2911  goto print_applylog_usage;
2912  }
2913 
2914 #if defined(NDEBUG)
2916 #endif
2917 
2918  /* error message log file */
2919  log_path_base = strdup (log_path);
2920  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s_%s.err", database_name, arg->command_name,
2921  basename (log_path_base));
2922  free (log_path_base);
2923  er_init (er_msg_file, ER_NEVER_EXIT);
2924 
2927  if (db_login ("DBA", NULL) != NO_ERROR)
2928  {
2929  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
2930  goto error_exit;
2931  }
2932 
2933 #if !defined(WINDOWS)
2934  /* save executable path */
2935  binary_name = basename (arg->argv0);
2936  (void) envvar_bindir_file (executable_path, PATH_MAX, binary_name);
2937 
2938  hb_set_exec_path (executable_path);
2939  hb_set_argv (arg->argv);
2940 
2941  /* initialize system parameters */
2942  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
2943  {
2945  error = ER_FAILED;
2946  goto error_exit;
2947  }
2948 
2949  if (!HA_DISABLED ())
2950  {
2951  /* initialize heartbeat */
2952  error = hb_process_init (database_name, log_path, HB_PTYPE_APPLYLOGDB);
2953  if (error != NO_ERROR)
2954  {
2955  er_log_debug (ARG_FILE_LINE, "Cannot connect to cub_master for heartbeat. \n");
2956  if (er_errid () != NO_ERROR)
2957  {
2958  util_log_write_errstr ("%s\n", db_error_string (3));
2959  }
2960  return EXIT_FAILURE;
2961  }
2962  er_set_ignore_uninit (true);
2963  }
2964 
2965  if (HA_GET_MODE () == HA_MODE_REPLICA)
2966  {
2967  replica_time_bound_str = prm_get_string_value (PRM_ID_HA_REPLICA_TIME_BOUND);
2968  if (replica_time_bound_str != NULL)
2969  {
2970  if (util_str_to_time_since_epoch (replica_time_bound_str) == 0)
2971  {
2975  "(the correct format: YYYY-MM-DD hh:mm:ss)");
2976  return EXIT_FAILURE;
2977  }
2978  }
2979  }
2980 #endif
2981 
2982 retry:
2983  error = db_restart (arg->command_name, TRUE, database_name);
2984  if (error != NO_ERROR)
2985  {
2986  fprintf (stderr, "%s\n", db_error_string (3));
2987  goto error_exit;
2988  }
2989 
2990  /* applylogdb should not fire trigger action */
2991  db_disable_trigger ();
2992 
2993  if (need_er_reinit)
2994  {
2995  er_init (er_msg_file, ER_NEVER_EXIT);
2996  need_er_reinit = false;
2997  }
2998 
2999  /* set lock timeout to infinite */
3000  db_set_lock_timeout (-1);
3001 
3002  /* initialize system parameters */
3003  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
3004  {
3005  (void) db_shutdown ();
3006 
3007  error = ER_FAILED;
3008  goto error_exit;
3009  }
3010 
3011  if (HA_DISABLED ())
3012  {
3014  (void) db_shutdown ();
3015  goto error_exit;
3016  }
3017 
3018  error = la_apply_log_file (database_name, log_path, max_mem_size);
3019  if (error != NO_ERROR)
3020  {
3021  fprintf (stderr, "%s\n", db_error_string (3));
3022  (void) db_shutdown ();
3023  goto error_exit;
3024  }
3025 
3026  (void) db_shutdown ();
3027  return EXIT_SUCCESS;
3028 
3029 print_applylog_usage:
3031  basename (arg->argv0));
3033 
3034 error_exit:
3035 #if !defined(WINDOWS)
3036  if (hb_Proc_shutdown)
3037  {
3038  return EXIT_SUCCESS;
3039  }
3040 #endif
3041 
3042  if (la_force_shutdown () == false
3043  && (error == ER_NET_SERVER_CRASHED || error == ER_NET_CANT_CONNECT_SERVER
3046  {
3047  (void) sleep (sleep_nsecs);
3048  /* sleep 1, 2, 4, 8, etc; don't wait for more than 10 sec */
3049  if ((sleep_nsecs *= 2) > 10)
3050  {
3051  sleep_nsecs = 1;
3052  }
3053  need_er_reinit = true;
3054  ++retried;
3055  goto retry;
3056  }
3057 
3058  return EXIT_FAILURE;
3059 #else /* CS_MODE */
3062 
3063 error_exit:
3064  return EXIT_FAILURE;
3065 #endif /* !CS_MODE */
3066 #endif /* !WINDOWS */
3067 }
3068 
3069 /*
3070  * sig_interrupt() -
3071  * return: none
3072  * sig_no(in)
3073  */
3074 static void
3076 {
3077  db_set_interrupt (1);
3078 }
3079 
3080 STATIC_INLINE char *
3081 spacedb_get_size_str (char *buf, UINT64 num_pages, T_SPACEDB_SIZE_UNIT size_unit)
3082 {
3083 #define UNIT_STR(un) (((un) == SPACEDB_SIZE_UNIT_MBYTES) ? 'M' : ((un) == SPACEDB_SIZE_UNIT_GBYTES) ? 'G' : 'T')
3084  int pgsize, i;
3085  double size;
3086 
3087  assert (buf);
3088 
3089  if (size_unit == SPACEDB_SIZE_UNIT_PAGE)
3090  {
3091  sprintf (buf, "%13llu", (long long unsigned int) num_pages);
3092  }
3093  else
3094  {
3095  pgsize = IO_PAGESIZE / 1024;
3096  size = pgsize * ((double) num_pages);
3097 
3098  if (size_unit == SPACEDB_SIZE_UNIT_HUMAN_READABLE)
3099  {
3101  {
3102  size /= 1024;
3103 
3104  if (size < 1024)
3105  {
3106  break;
3107  }
3108  }
3109  sprintf (buf, "%9.1f %c", size, UNIT_STR (i));
3110  }
3111  else
3112  {
3113  for (i = size_unit; i > (int) SPACEDB_SIZE_UNIT_PAGE; i--)
3114  {
3115  size /= 1024;
3116  }
3117  sprintf (buf, "%9.1f %c", size, UNIT_STR (size_unit));
3118  }
3119  }
3120 
3121  return buf;
3122 #undef UNIT_STR
3123 }
3124 
3125 /*
3126  * applyinfo() - ApplyInfo main routine
3127  * return: EXIT_SUCCESS/EXIT_FAILURE
3128  */
3129 int
3131 {
3132 #if defined (WINDOWS)
3134  basename (arg->argv0));
3135 
3136  return EXIT_FAILURE;
3137 #else /* WINDOWS */
3138 #if defined (CS_MODE)
3139  UTIL_ARG_MAP *arg_map = arg->arg_map;
3140  char er_msg_file[PATH_MAX];
3141  const char *database_name;
3142  const char *master_node_name;
3143  char local_database_name[CUB_MAXHOSTNAMELEN];
3144  char master_database_name[CUB_MAXHOSTNAMELEN];
3145  bool check_applied_info, check_copied_info;
3146  bool check_master_info, check_replica_info;
3147  bool verbose;
3148  const char *log_path;
3149  char log_path_buf[PATH_MAX];
3150  int error = NO_ERROR;
3151  INT64 pageid = 0;
3152  int interval;
3153  float process_rate = 0.0f;
3154  char *replica_time_bound_str;
3155  /* log lsa to calculate the estimated delay */
3156  LOG_LSA master_eof_lsa, applied_final_lsa;
3157  LOG_LSA copied_append_lsa, copied_eof_lsa;
3158  LOG_LSA initial_copied_append_lsa, initial_applied_final_lsa;
3159  time_t start_time, cur_time;
3160 
3161  start_time = time (NULL);
3162 
3163  LSA_SET_NULL (&master_eof_lsa);
3164  LSA_SET_NULL (&applied_final_lsa);
3165  LSA_SET_NULL (&copied_append_lsa);
3166  LSA_SET_NULL (&copied_eof_lsa);
3167  LSA_SET_NULL (&initial_copied_append_lsa);
3168  LSA_SET_NULL (&initial_applied_final_lsa);
3169 
3170  if (utility_get_option_string_table_size (arg_map) != 1)
3171  {
3172  goto print_applyinfo_usage;
3173  }
3174 
3175  check_applied_info = check_copied_info = false;
3176  check_replica_info = check_master_info = false;
3177 
3178  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
3179  if (database_name == NULL)
3180  {
3181  goto print_applyinfo_usage;
3182  }
3183 
3184  /* initialize system parameters */
3185  if (sysprm_load_and_init (database_name, NULL, SYSPRM_LOAD_ALL) != NO_ERROR)
3186  {
3188  return EXIT_FAILURE;
3189  }
3190 
3191  master_node_name = utility_get_option_string_value (arg_map, APPLYINFO_REMOTE_NAME_S, 0);
3192  if (master_node_name != NULL)
3193  {
3194  check_master_info = true;
3195  }
3196 
3197  check_applied_info = utility_get_option_bool_value (arg_map, APPLYINFO_APPLIED_INFO_S);
3199  if (log_path != NULL)
3200  {
3201  log_path = realpath (log_path, log_path_buf);
3202  }
3203  if (log_path != NULL)
3204  {
3205  check_copied_info = true;
3206  }
3207 
3208  if (check_applied_info && (log_path == NULL))
3209  {
3210  goto print_applyinfo_usage;
3211  }
3212 
3213  check_replica_info = (HA_GET_MODE () == HA_MODE_REPLICA);
3216 
3217  interval = utility_get_option_int_value (arg_map, APPLYINFO_INTERVAL_S);
3218  if (interval < 0)
3219  {
3220  goto print_applyinfo_usage;
3221  }
3222 
3223  if (check_replica_info)
3224  {
3225  replica_time_bound_str = prm_get_string_value (PRM_ID_HA_REPLICA_TIME_BOUND);
3226  if (replica_time_bound_str != NULL)
3227  {
3228  if (util_str_to_time_since_epoch (replica_time_bound_str) == 0)
3229  {
3233  "(the correct format: YYYY-MM-DD hh:mm:ss)");
3234  return EXIT_FAILURE;
3235  }
3236  }
3237  }
3238 
3241 
3242  /* error message log file */
3243  sprintf (er_msg_file, "%s_%s.err", database_name, arg->command_name);
3244  er_init (er_msg_file, ER_NEVER_EXIT);
3245 
3246  is_Sigint_caught = false;
3247 #if defined(WINDOWS)
3248  SetConsoleCtrlHandler ((PHANDLER_ROUTINE) intr_handler, TRUE);
3249 #else
3250  os_set_signal_handler (SIGINT, intr_handler);
3251 #endif
3252 
3253  do
3254  {
3255 
3256  if (check_applied_info)
3257  {
3258  memset (local_database_name, 0x00, CUB_MAXHOSTNAMELEN);
3259  strcpy (local_database_name, database_name);
3260  strcat (local_database_name, "@localhost");
3261 
3263 
3264  if (check_database_name (local_database_name))
3265  {
3266  goto check_applied_info_end;
3267  }
3268  if (db_login ("DBA", NULL) != NO_ERROR)
3269  {
3270  goto check_applied_info_end;
3271  }
3272  error = db_restart (arg->command_name, TRUE, local_database_name);
3273  if (error != NO_ERROR)
3274  {
3275  goto check_applied_info_end;
3276  }
3277 
3278  if (HA_DISABLED ())
3279  {
3282  goto check_applied_info_end;
3283  }
3284 
3285  error = la_log_page_check (local_database_name, log_path, pageid, check_applied_info, check_copied_info,
3286  check_replica_info, verbose, &copied_eof_lsa, &copied_append_lsa,
3287  &applied_final_lsa);
3288  (void) db_shutdown ();
3289  }
3290  else if (check_copied_info)
3291  {
3292  memset (local_database_name, 0x00, CUB_MAXHOSTNAMELEN);
3293  strcpy (local_database_name, database_name);
3294  strcat (local_database_name, "@localhost");
3295 
3296  error = la_log_page_check (local_database_name, log_path, pageid, check_applied_info, check_copied_info,
3297  check_replica_info, verbose, &copied_eof_lsa, &copied_append_lsa,
3298  &applied_final_lsa);
3299  }
3300 
3301  check_applied_info_end:
3302  if (error != NO_ERROR)
3303  {
3304  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3305  }
3306  error = NO_ERROR;
3307 
3308  if (check_master_info)
3309  {
3310  memset (master_database_name, 0x00, CUB_MAXHOSTNAMELEN);
3311  strcpy (master_database_name, database_name);
3312  strcat (master_database_name, "@");
3313  strcat (master_database_name, master_node_name);
3314 
3316 
3317  if (check_database_name (master_database_name))
3318  {
3319  goto check_master_info_end;
3320  }
3321 
3322  if (db_login ("DBA", NULL) != NO_ERROR)
3323  {
3324  goto check_master_info_end;
3325  }
3326 
3327  error = db_restart (arg->command_name, TRUE, master_database_name);
3328  if (error != NO_ERROR)
3329  {
3330  goto check_master_info_end;
3331  }
3332 
3333  error = logwr_copy_log_header_check (master_database_name, verbose, &master_eof_lsa);
3334  if (error != NO_ERROR)
3335  {
3336  goto check_master_info_end;
3337  }
3338 
3339  (void) db_shutdown ();
3340  }
3341 
3342  check_master_info_end:
3343  if (error != NO_ERROR)
3344  {
3345  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3346  }
3347  error = NO_ERROR;
3348 
3349  /* print delay info */
3350  cur_time = time (NULL);
3351  if (check_copied_info && check_master_info)
3352  {
3353  if (!LSA_ISNULL (&initial_copied_append_lsa))
3354  {
3355  process_rate =
3356  (float) (copied_append_lsa.pageid - initial_copied_append_lsa.pageid) / (cur_time - start_time);
3357  }
3358  else
3359  {
3360  initial_copied_append_lsa = copied_append_lsa;
3361  process_rate = 0.0f;
3362  }
3363 
3364  printf ("\n *** Delay in Copying Active Log *** \n");
3365  la_print_delay_info (copied_append_lsa, master_eof_lsa, process_rate);
3366  }
3367 
3368  if (check_applied_info)
3369  {
3370  if (!LSA_ISNULL (&initial_applied_final_lsa))
3371  {
3372  process_rate =
3373  (float) (applied_final_lsa.pageid - initial_applied_final_lsa.pageid) / (cur_time - start_time);
3374  }
3375  else
3376  {
3377  initial_applied_final_lsa = applied_final_lsa;
3378  process_rate = 0.0f;
3379  }
3380 
3381  printf ("\n *** Delay in Applying Copied Log *** \n");
3382  la_print_delay_info (applied_final_lsa, copied_eof_lsa, process_rate);
3383  }
3384 
3385  sleep (interval);
3386  }
3387  while (interval > 0 && !is_Sigint_caught);
3388 
3389  return EXIT_SUCCESS;
3390 
3391 print_applyinfo_usage:
3393  basename (arg->argv0));
3395 
3396  return EXIT_FAILURE;
3397 #else /* CS_MODE */
3399  basename (arg->argv0));
3400  return EXIT_FAILURE;
3401 #endif /* !CS_MODE */
3402 #endif /* !WINDOWS */
3403 }
3404 
3405 /*
3406  * intr_handler() - Interrupt handler for utility
3407  * return: none
3408  * sig_no(in)
3409  */
3410 #if defined(WINDOWS)
3411 static BOOL WINAPI
3412 #else
3413 static void
3414 #endif
3415 intr_handler (int sig_no)
3416 {
3417  is_Sigint_caught = true;
3418 
3419 #if defined(WINDOWS)
3420  if (sig_no == CTRL_C_EVENT)
3421  {
3422  return TRUE;
3423  }
3424 
3425  return FALSE;
3426 #endif /* WINDOWS */
3427 }
3428 
3429 /*
3430  * tranlist_cmp_f() - qsort compare function used in tranlist().
3431  * return:
3432  */
3433 static int
3434 tranlist_cmp_f (const void *p1, const void *p2)
3435 {
3436  int ret;
3437  SORT_COLUMN_TYPE column_type;
3438  const ONE_TRAN_INFO *info1, *info2;
3439  const char *str_key1 = NULL, *str_key2 = NULL;
3440  double number_key1 = 0, number_key2 = 0;
3441 
3442  info1 = (ONE_TRAN_INFO *) p1;
3443  info2 = (ONE_TRAN_INFO *) p2;
3444 
3445  switch (tranlist_Sort_column)
3446  {
3447  case 0:
3448  case 1:
3449  number_key1 = info1->tran_index;
3450  number_key2 = info2->tran_index;
3451  column_type = SORT_COLUMN_TYPE_INT;
3452  break;
3453  case 2:
3454  str_key1 = info1->db_user;
3455  str_key2 = info2->db_user;
3456  column_type = SORT_COLUMN_TYPE_STR;
3457  break;
3458  case 3:
3459  str_key1 = info1->host_name;
3460  str_key2 = info2->host_name;
3461  column_type = SORT_COLUMN_TYPE_STR;
3462  break;
3463  case 4:
3464  number_key1 = info1->process_id;
3465  number_key2 = info2->process_id;
3466  column_type = SORT_COLUMN_TYPE_INT;
3467  break;
3468  case 5:
3469  str_key1 = info1->program_name;
3470  str_key2 = info2->program_name;
3471  column_type = SORT_COLUMN_TYPE_STR;
3472  break;
3473  case 6:
3474  number_key1 = info1->query_exec_info.query_time;
3475  number_key2 = info2->query_exec_info.query_time;
3476  column_type = SORT_COLUMN_TYPE_FLOAT;
3477  break;
3478  case 7:
3479  number_key1 = info1->query_exec_info.tran_time;
3480  number_key2 = info2->query_exec_info.tran_time;
3481  column_type = SORT_COLUMN_TYPE_FLOAT;
3482  break;
3483  case 8:
3484  str_key1 = info1->query_exec_info.wait_for_tran_index_string;
3485  str_key2 = info2->query_exec_info.wait_for_tran_index_string;
3486  column_type = SORT_COLUMN_TYPE_STR;
3487  break;
3488  case 9:
3489  str_key1 = info1->query_exec_info.sql_id;
3490  str_key2 = info2->query_exec_info.sql_id;
3491  column_type = SORT_COLUMN_TYPE_STR;
3492  break;
3493  case 10:
3494  str_key1 = info1->query_exec_info.query_stmt;
3495  str_key2 = info2->query_exec_info.query_stmt;
3496  column_type = SORT_COLUMN_TYPE_STR;
3497  break;
3498  default:
3499  assert (0);
3500  return 0;
3501  }
3502 
3503  switch (column_type)
3504  {
3505  case SORT_COLUMN_TYPE_INT:
3507  {
3508  if (number_key1 == number_key2)
3509  {
3510  ret = 0;
3511  }
3512  else if (number_key1 > number_key2)
3513  {
3514  ret = 1;
3515  }
3516  else
3517  {
3518  ret = -1;
3519  }
3520  }
3521  break;
3522  case SORT_COLUMN_TYPE_STR:
3523  {
3524  if (str_key1 == NULL && str_key2 == NULL)
3525  {
3526  ret = 0;
3527  }
3528  else if (str_key1 == NULL && str_key2 != NULL)
3529  {
3530  ret = -1;
3531  }
3532  else if (str_key1 != NULL && str_key2 == NULL)
3533  {
3534  ret = 1;
3535  }
3536  else
3537  {
3538  ret = strcmp (str_key1, str_key2);
3539  }
3540  }
3541  break;
3542  default:
3543  assert (0);
3544  ret = 0;
3545  }
3546 
3547  if (tranlist_Sort_desc == true)
3548  {
3549  ret *= (-1);
3550  }
3551 
3552  return ret;
3553 }
3554 
3555 /*
3556  * vacuumdb() - vacuumdb main routine
3557  * return: EXIT_SUCCESS/EXIT_FAILURE
3558  */
3559 int
3561 {
3562  UTIL_ARG_MAP *arg_map = arg->arg_map;
3563  char er_msg_file[PATH_MAX];
3564  const char *database_name, *output_file = NULL;
3565  bool dump_flag;
3566  FILE *outfp = NULL;
3567 
3568  if (utility_get_option_string_table_size (arg_map) < 1)
3569  {
3570  goto print_check_usage;
3571  }
3572 
3573  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
3574  if (database_name == NULL)
3575  {
3576  goto print_check_usage;
3577  }
3578 
3579  if (check_database_name (database_name))
3580  {
3581  goto error_exit;
3582  }
3583 
3584  dump_flag = utility_get_option_bool_value (arg_map, VACUUM_DUMP_S);
3585 
3586  if (dump_flag)
3587  {
3588  output_file = utility_get_option_string_value (arg_map, VACUUM_OUTPUT_FILE_S, 0);
3589  if (output_file == NULL)
3590  {
3591  outfp = stdout;
3592  }
3593  else
3594  {
3595  outfp = fopen (output_file, "w");
3596  if (outfp == NULL)
3597  {
3600  output_file);
3601  goto error_exit;
3602  }
3603  }
3604  }
3605 
3606 #if defined(SA_MODE)
3607  /* error message log file */
3608  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
3609  er_init (er_msg_file, ER_NEVER_EXIT);
3610 
3612 
3614  if (dump_flag)
3615  {
3617  }
3618  else
3619  {
3622  }
3623  db_login ("DBA", NULL);
3624  if (db_restart (arg->command_name, TRUE, database_name) == NO_ERROR)
3625  {
3627 
3628  if (dump_flag)
3629  {
3630  vacuum_dump (outfp);
3631 
3632  if (outfp != stdout)
3633  {
3634  fclose (outfp);
3635  }
3636  }
3637  else
3638  {
3639  if (cvacuum () != NO_ERROR)
3640  {
3641  const char *tmpname;
3642 
3643  if ((tmpname = er_get_msglog_filename ()) == NULL)
3644  {
3645  tmpname = "/dev/null";
3646  }
3649 
3650  util_log_write_errstr ("%s\n", db_error_string (3));
3651  db_shutdown ();
3652  goto error_exit;
3653  }
3654  }
3655  db_shutdown ();
3656  }
3657  else
3658  {
3659  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3660  goto error_exit;
3661  }
3662 
3663  return EXIT_SUCCESS;
3664 #else
3665  if (dump_flag)
3666  {
3667  /* error message log file */
3668  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
3669  er_init (er_msg_file, ER_NEVER_EXIT);
3670 
3673  db_login ("DBA", NULL);
3674 
3675  if (db_restart (arg->command_name, TRUE, database_name) != NO_ERROR)
3676  {
3677  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3678  goto error_exit;
3679  }
3680 
3682 
3683  vacuum_dump (outfp);
3684  db_shutdown ();
3685 
3686  if (outfp != stdout)
3687  {
3688  fclose (outfp);
3689  }
3690  }
3691  else
3692  {
3693  fprintf (stderr,
3697  }
3698 
3699  return EXIT_SUCCESS;
3700 #endif
3701 print_check_usage:
3703  basename (arg->argv0));
3705 
3706 error_exit:
3707 
3708  return EXIT_FAILURE;
3709 }
3710 
3711 /*
3712  * tde() - tde main routine
3713  * return: EXIT_SUCCESS/EXIT_FAILURE
3714  */
3715 int
3717 {
3718  UTIL_ARG_MAP *arg_map = arg->arg_map;
3719  char er_msg_file[PATH_MAX];
3720  char mk_path[PATH_MAX] = { 0, };
3721  const char *database_name;
3722  const char *dba_password;
3723  char *passbuf;
3724  int error = NO_ERROR;
3725  int vdes = NULL_VOLDES;
3726  bool gen_op;
3727  bool show_op;
3728  bool print_val;
3729  int change_op_idx;
3730  int delete_op_idx;
3731  int op_cnt = 0;
3732 
3733  if (utility_get_option_string_table_size (arg_map) != 1)
3734  {
3735  goto print_tde_usage;
3736  }
3737 
3738  database_name = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
3739  if (database_name == NULL)
3740  {
3741  goto print_tde_usage;
3742  }
3743 
3745  show_op = utility_get_option_bool_value (arg_map, TDE_SHOW_KEYS_S);
3746  change_op_idx = utility_get_option_int_value (arg_map, TDE_CHANGE_KEY_S);
3747  delete_op_idx = utility_get_option_int_value (arg_map, TDE_DELETE_KEY_S);
3748 
3750  dba_password = utility_get_option_string_value (arg_map, KILLTRAN_DBA_PASSWORD_S, 0);
3751 
3752  if (gen_op)
3753  {
3754  op_cnt++;
3755  }
3756  if (show_op)
3757  {
3758  op_cnt++;
3759  }
3760  if (change_op_idx != -1)
3761  {
3762  op_cnt++;
3763  }
3764  if (delete_op_idx != -1)
3765  {
3766  op_cnt++;
3767  }
3768 
3769  if (op_cnt != 1)
3770  {
3771  /* Only one and at least one operation has to be given */
3772  /* -c -1 -d -1 -n is now allowed, but it's trivial */
3773  goto print_tde_usage;
3774  }
3775 
3776  /* Checking input range, -1 means not the operation case */
3777  if (change_op_idx < -1)
3778  {
3779  goto print_tde_usage;
3780  }
3781  if (delete_op_idx < -1)
3782  {
3783  goto print_tde_usage;
3784  }
3785 
3786  /* extra validation */
3787  if (check_database_name (database_name))
3788  {
3789  goto error_exit;
3790  }
3791 
3792  /* error message log file */
3793  snprintf (er_msg_file, sizeof (er_msg_file) - 1, "%s_%s.err", database_name, arg->command_name);
3794  er_init (er_msg_file, ER_NEVER_EXIT);
3795 
3797  if (db_login ("DBA", dba_password) != NO_ERROR)
3798  {
3799  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3800  goto error_exit;
3801  }
3802 
3803  /* first try to restart with the password given (possibly none) */
3804  error = db_restart (arg->command_name, TRUE, database_name);
3805  if (error)
3806  {
3807  if (error == ER_AU_INVALID_PASSWORD && (dba_password == NULL || strlen (dba_password) == 0))
3808  {
3809  /*
3810  * prompt for a valid password and try again, need a reusable
3811  * password prompter so we can use getpass() on platforms that
3812  * support it.
3813  */
3814 
3815  /* get password interactively if interactive mode */
3817  if (passbuf[0] == '\0') /* to fit into db_login protocol */
3818  {
3819  passbuf = (char *) NULL;
3820  }
3821  dba_password = passbuf;
3822  if (db_login ("DBA", dba_password) != NO_ERROR)
3823  {
3824  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3825  goto error_exit;
3826  }
3827  else
3828  {
3829  error = db_restart (arg->command_name, TRUE, database_name);
3830  }
3831  }
3832 
3833  if (error)
3834  {
3835  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3836  goto error_exit;
3837  }
3838  }
3839 
3840  if (tde_get_mk_file_path (mk_path) != NO_ERROR)
3841  {
3842  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3843  db_shutdown ();
3844  goto error_exit;
3845  }
3846 
3847  printf ("Key File: %s\n", mk_path);
3848 
3849  /*
3850  * The file lock here is necessary to provide exclusiveness with backupdb in the current design.
3851  */
3852  vdes = fileio_mount (NULL, database_name, mk_path, LOG_DBTDE_KEYS_VOLID, 1, false);
3853  if (vdes == NULL_VOLDES)
3854  {
3855  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3856  db_shutdown ();
3857  goto error_exit;
3858  }
3859  /*
3860  * There is no need to call fileio_dismount() for 'vdes' later in this function
3861  * because it is dismounted in db_shutdown()
3862  * */
3863 
3864  printf ("\n");
3865  if (gen_op)
3866  {
3867  unsigned char master_key[TDE_MASTER_KEY_LENGTH];
3868  int mk_index = -1;
3869  time_t created_time;
3870  char ctime_buf[CTIME_MAX];
3871 
3872  if (tde_create_mk (master_key, &created_time) != NO_ERROR)
3873  {
3874  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3875  db_shutdown ();
3876  goto error_exit;
3877  }
3878  if (tde_add_mk (vdes, master_key, created_time, &mk_index) != NO_ERROR)
3879  {
3880  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3881  db_shutdown ();
3882  goto error_exit;
3883  }
3884  ctime_r (&created_time, ctime_buf);
3885  printf ("SUCCESS: ");
3887  if (print_val)
3888  {
3889  printf ("Key: ");
3890  tde_print_mk (master_key);
3891  printf ("\n");
3892  }
3893  }
3894  else if (show_op)
3895  {
3896  int mk_index;
3897  time_t created_time, set_time;
3898  char ctime_buf1[CTIME_MAX];
3899  char ctime_buf2[CTIME_MAX];
3900 
3901  printf ("The current key set on %s:\n", database_name);
3902  if (tde_get_mk_info (&mk_index, &created_time, &set_time) == NO_ERROR)
3903  {
3904  ctime_r (&created_time, ctime_buf1);
3905  ctime_r (&set_time, ctime_buf2);
3906 
3907  printf ("Key Index: %d\n", mk_index);
3908  printf ("Created on %s", ctime_buf1);
3909  printf ("Set on %s", ctime_buf2);
3910  }
3911  else
3912  {
3913  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3915  }
3916  printf ("\n");
3917  if (tde_dump_mks (vdes, print_val) != NO_ERROR)
3918  {
3919  PRINT_AND_LOG_ERR_MSG ("%s\n", db_error_string (3));
3920  db_shutdown ();
3921  goto error_exit;
3922  }
3923  }
3924  else if (change_op_idx != -1)
3925  {
3926  int prev_mk_idx;
3927  time_t created_time, set_time;
3928 
3929  if (tde_get_mk_info (&prev_mk_idx, &created_time, &set_time) != NO_ERROR)
3930  {
3931  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3932  db_shutdown ();
3933  goto error_exit;
3934  }
3935 
3937  change_op_idx);
3938  /* no need to check if the previous key exists or not. It is going to be checked on changing on server */
3939  if (tde_change_mk_on_server (change_op_idx) != NO_ERROR)
3940  {
3941  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3942  db_shutdown ();
3943  goto error_exit;
3944  }
3945 
3946  if (db_commit_transaction () != NO_ERROR)
3947  {
3948  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3949  db_shutdown ();
3950  goto error_exit;
3951  }
3952 
3953  printf ("SUCCESS: ");
3955  change_op_idx);
3956  }
3957  else if (delete_op_idx != -1)
3958  {
3959  int mk_index;
3960  time_t created_time, set_time;
3961 
3962  if (tde_get_mk_info (&mk_index, &created_time, &set_time) != NO_ERROR)
3963  {
3964  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3965  db_shutdown ();
3966  goto error_exit;
3967  }
3968  if (mk_index == delete_op_idx)
3969  {
3970  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s",
3973  db_shutdown ();
3974  goto error_exit;
3975  }
3976  if (tde_delete_mk (vdes, delete_op_idx) != NO_ERROR)
3977  {
3978  PRINT_AND_LOG_ERR_MSG ("FAILURE: %s\n", db_error_string (3));
3979  db_shutdown ();
3980  goto error_exit;
3981  }
3982  printf ("SUCCESS: ");
3984  }
3985 
3986  db_shutdown ();
3987 
3988  return EXIT_SUCCESS;
3989 
3990 print_tde_usage:
3993 error_exit:
3994  return EXIT_FAILURE;
3995 }
static int isvalid_transaction(const ONE_TRAN_INFO *tran)
Definition: util_cs.c:1295
#define KILLTRAN_KILL_TRANSACTION_INDEX_S
Definition: utility.h:1214
bool la_force_shutdown(void)
Definition: log_applier.c:591
#define APPLYINFO_COPIED_LOG_PATH_S
Definition: utility.h:1483
#define TDE_GENERATE_KEY_S
Definition: utility.h:1607
static void print_timestamp(FILE *outfp)
Definition: util_cs.c:2306
void db_set_interrupt(int set)
Definition: db_admin.c:1445
int vacuumdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:3560
MSGCAT_SPACEDB_MSG
Definition: utility.h:245
#define NO_ERROR
Definition: error_code.h:46
#define TRUE
Definition: broker_admin.c:49
char * dirname(const char *path)
Definition: porting.c:1066
static bool is_Sigint_caught
Definition: util_cs.c:102
#define APPLYLOG_MAX_MEM_SIZE_S
Definition: utility.h:1479
#define KILLTRAN_DISPLAY_QUERY_INFO_S
Definition: utility.h:1228
#define CHECK_FILE_TRACKER_S
Definition: utility.h:1177
void db_set_client_type(int client_type)
Definition: db_admin.c:495
#define IO_PAGESIZE
#define ASSERT_ERROR()
#define PRINT_AND_LOG_ERR_MSG(...)
Definition: util_func.h:49
static bool tranlist_Sort_desc
Definition: util_cs.c:100
int sysprm_set_force(const char *pname, const char *pvalue)
void util_redirect_stdout_to_null(void)
Definition: util_common.c:885
int util_size_string_to_byte(UINT64 *size_num, const char *size_str)
Definition: util_common.c:1027
int db_login(const char *name, const char *password)
Definition: db_admin.c:804
#define APPLYLOG_LOG_PATH_S
Definition: utility.h:1477
char * MOBJ
Definition: work_space.h:174
#define VACUUM_OUTPUT_FILE_S
Definition: utility.h:1581
int da_destroy(dynamic_array *da)
int tde_change_mk_on_server(int mk_index)
#define CHECK_REPAIR_S
Definition: utility.h:1167
int tm_Tran_index
int applyinfo(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:3130
int parse_int(int *ret_p, const char *str_p, int base)
Definition: porting.c:2290
const char * boot_get_lob_path(void)
Definition: boot_sr.c:479
#define ER_FAILED
Definition: error_code.h:47
#define AU_DISABLE_PASSWORDS
Definition: authenticate.h:140
const char * tran_get_tranlist_state_name(TRAN_STATE state)
int thread_kill_tran_index(int kill_tran_index, char *kill_user, char *kill_host, int kill_pid)
int histo_stop(void)
static OID * util_get_class_oids_and_index_btid(dynamic_array *darray, const char *index_name, BTID *index_btid)
Definition: util_cs.c:537
#define KILLTRAN_KILL_USER_NAME_S
Definition: utility.h:1216
int statdump(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2323
void qmgr_dump_query_plans(FILE *outfp)
#define assert_release(e)
Definition: error_manager.h:96
int util_get_table_list_from_file(char *fname, dynamic_array *darray)
Definition: util_common.c:1226
#define ER_NET_CANT_CONNECT_SERVER
Definition: error_code.h:261
#define SM_MAX_IDENTIFIER_LENGTH
#define VACUUM_DUMP_S
Definition: utility.h:1579
int db_shutdown(void)
Definition: db_admin.c:964
#define CHANGEMODE_TIMEOUT_S
Definition: utility.h:1465
int util_byte_to_size_string(char *buf, size_t len, UINT64 size_num)
Definition: util_common.c:955
int qmgr_drop_all_query_plans(void)
TRANS_INFO * logtb_get_trans_info(bool include_query_exec_info)
int check_volume_name(const char *name)
Definition: util_common.c:161
bool au_is_dba_group_member(MOP user)
void hb_set_exec_path(char *exec_path)
Definition: heartbeat.c:125
#define KILLTRAN_KILL_PROGRAM_NAME_S
Definition: utility.h:1220
#define CHECK_HEAP_ALLHEAPS_S
Definition: utility.h:1179
OID * ws_oid(MOP mop)
Definition: work_space.c:2884
#define BACKUP_SEPARATE_KEYS_S
Definition: utility.h:1058
#define COPYLOG_LOG_PATH_S
Definition: utility.h:1469
int lockdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:1203
int check_database_name(const char *name)
Definition: util_common.c:99
#define OID_SET_NULL(oidp)
Definition: oid.h:85
void sm_downcase_name(const char *name, char *buf, int maxlen)
int tde_get_mk_file_path(char *mk_path)
#define TDE_SHOW_KEYS_S
Definition: utility.h:1609
MOP locator_find_class(const char *classname)
Definition: locator_cl.c:3142
#define APPLYINFO_PAGE_S
Definition: utility.h:1485
FILE * output_file
Definition: unloaddb.c:48
#define TRANLIST_SORT_KEY_S
Definition: utility.h:1205
#define CHECK_LC_CLASSNAMES_S
Definition: utility.h:1185
static void intr_handler(int sig_no)
Definition: util_cs.c:3415
int er_errid(void)
#define PARAMDUMP_OUTPUT_FILE_S
Definition: utility.h:1437
static const char * progname
#define BACKUP_REMOVE_ARCHIVE_S
Definition: utility.h:1038
#define TRANLIST_FULL_SQL_S
Definition: utility.h:1209
#define BACKUP_NO_CHECK_S
Definition: utility.h:1048
#define er_log_debug(...)
#define APPLYINFO_APPLIED_INFO_S
Definition: utility.h:1489
#define TDE_PRINT_KEY_VALUE_S
Definition: utility.h:1611
void vacuum_dump(FILE *outfp)
#define CHECK_BTREE_ALL_BTREES_S
Definition: utility.h:1183
bool hb_Proc_shutdown
Definition: heartbeat.c:93
int util_log_write_errid(int message_id,...)
Definition: util_func.c:468
int la_log_page_check(const char *database_name, const char *log_path, INT64 page_num, bool check_applied_info, bool check_copied_info, bool check_replica_info, bool verbose, LOG_LSA *copied_eof_lsa, LOG_LSA *copied_append_lsa, LOG_LSA *applied_final_lsa)
Definition: log_applier.c:7046
#define XASL_ID_EQ(X1, X2)
Definition: xasl.h:572
bool db_disable_trigger(void)
Definition: db_admin.c:570
#define NULL_VOLDES
Definition: file_io.h:44
int db_set_lock_timeout(int seconds)
Definition: db_admin.c:1496
#define STATDUMP_CUMULATIVE_S
Definition: utility.h:1451
int er_init(const char *msglog_filename, int exit_ask)
#define FILEIO_BACKUP_SLEEP_MSECS_AUTO
Definition: file_io.h:60
#define CHECK_INPUT_FILE_S
Definition: utility.h:1169
#define STATDUMP_INTERVAL_S
Definition: utility.h:1449
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 STATDUMP_OUTPUT_FILE_S
Definition: utility.h:1447
#define CHECK_INDEXNAME_S
Definition: utility.h:1171
int utility_get_option_int_value(UTIL_ARG_MAP *arg_map, int arg_ch)
Definition: util_common.c:227
int tde_get_mk_info(int *mk_index, time_t *created_time, time_t *set_time)
const char * er_get_msglog_filename(void)
int tde_delete_mk(int vdes, int mk_index)
Definition: tde.c:1569
#define NULL_PAGEID
void util_print_deprecated(const char *option)
Definition: util_common.c:1205
void hb_set_argv(char **argv)
Definition: heartbeat.c:137
TRANDUMP_LEVEL
Definition: util_cs.c:85
int db_get_system_parameters(char *data, int len)
Definition: db_admin.c:2770
#define HA_GET_MODE()
static bool doesmatch_transaction(const ONE_TRAN_INFO *tran, int *tran_index_list, int index_list_size, const char *username, const char *hostname, const char *progname, const char *sql_id)
Definition: util_cs.c:1315
#define ADDVOL_COMMENT_S
Definition: utility.h:1085
UINT64 prm_get_bigint_value(PARAM_ID prm_id)
#define CHECK_LC_ALLENTRIES_OF_ALLBTREES_S
Definition: utility.h:1187
int boot_check_db_consistency(int check_flag, OID *oids, int num_oids, BTID *index_btid)
INT64 utility_get_option_bigint_value(UTIL_ARG_MAP *arg_map, int arg_ch)
Definition: util_common.c:294
void acl_dump(FILE *outfp)
int db_restart(const char *program, int print_version, const char *volume)
Definition: db_admin.c:868
int histo_print_global_stats(FILE *stream, bool cumulative, const char *substr)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int db_restart_ex(const char *program, const char *db_name, const char *db_user, const char *db_password, const char *preferred_hosts, int client_type)
Definition: db_admin.c:934
#define ERR_CSS_TCP_CONNECT_TIMEDOUT
Definition: error_code.h:1462
bool utility_get_option_bool_value(UTIL_ARG_MAP *arg_map, int arg_ch)
Definition: util_common.c:245
#define assert(x)
int acldb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:1128
#define ER_LC_PARTIALLY_FAILED_TO_FLUSH
Definition: error_code.h:1394
FILEIO_ZIP_LEVEL
Definition: file_io.h:113
#define TRANLIST_SUMMARY_S
Definition: utility.h:1203
int paramdump(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2206
int spacedb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:844
#define ER_GENERIC_ERROR
Definition: error_code.h:49
#define STATIC_INLINE
int da_get(dynamic_array *da, int pos, void *data)
static void dump_trantb(TRANS_INFO *info, TRANDUMP_LEVEL dump_level, bool full_sqltext)
Definition: util_cs.c:1352
T_SPACEDB_SIZE_UNIT
Definition: util_cs.c:76
int tde_add_mk(int vdes, const unsigned char *master_key, time_t created_time, int *mk_index)
Definition: tde.c:1351
#define SPACE_OUTPUT_FILE_S
Definition: utility.h:1115
static char executable_path[PATH_MAX]
Definition: server.c:73
static void backupdb_sig_interrupt_handler(int sig_no)
Definition: util_cs.c:3075
int sysprm_load_and_init(const char *db_name, const char *conf_file, const int load_flags)
int la_apply_log_file(const char *database_name, const char *log_path, const int max_mem_size)
Definition: log_applier.c:7810
void tde_print_mk(const unsigned char *master_key)
Definition: tde.c:1332
#define COPYLOG_MODE_S
Definition: utility.h:1471
int applylogdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2862
int utility_localtime(const time_t *ts, struct tm *result)
Definition: util_common.c:390
int plandump(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2105
int killtran(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:1842
const char * db_error_string(int level)
Definition: db_admin.c:2116
static enum scanner_mode mode
#define SPACE_PURPOSE_S
Definition: utility.h:1125
int da_size(dynamic_array *da)
#define TDE_CHANGE_KEY_S
Definition: utility.h:1617
char * envvar_bindir_file(char *path, size_t size, const char *filename)
int substr(std::string &result, bool &is_matched, const cub_regex_object &reg, const std::string &src, const int position, const int occurrence, const INTL_CODESET codeset)
#define ADDVOL_PURPOSE_S
Definition: utility.h:1087
int tranlist(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:1672
std::int64_t pageid
Definition: log_lsa.hpp:36
int tde_create_mk(unsigned char *master_key, time_t *created_time)
Definition: tde.c:1311
#define APPLYINFO_REMOTE_NAME_S
Definition: utility.h:1487
dynamic_array * da_create(int count, size_t len)
Definition: dynamic_array.c:30
#define BACKUP_OUTPUT_FILE_S
Definition: utility.h:1042
static int kill_transactions(TRANS_INFO *info, int *tran_index_list, int list_size, const char *username, const char *hostname, const char *progname, const char *sql_id, bool verify)
Definition: util_cs.c:1471
#define NULL
Definition: freelistheap.h:34
#define CTIME_MAX
Definition: porting.h:72
ONE_TRAN_INFO tran[1]
#define strncpy_bufsize(buf, str)
Definition: porting.h:340
#define KILLTRAN_DISPLAY_INFORMATION_S
Definition: utility.h:1226
#define ADDVOL_VOLUME_NAME_S
Definition: utility.h:1081
int addvoldb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:355
#define BACKUP_SLEEP_MSECS_S
Definition: utility.h:1056
void db_clear_host_connected(void)
Definition: db_admin.c:851
static int print_tran_entry(const ONE_TRAN_INFO *tran_info, TRANDUMP_LEVEL dump_level, bool full_sqltext)
Definition: util_cs.c:1604
int boot_backup(const char *backup_path, FILEIO_BACKUP_LEVEL backup_level, bool delete_unneeded_logarchives, const char *backup_verbose_file, int num_threads, FILEIO_ZIP_METHOD zip_method, FILEIO_ZIP_LEVEL zip_level, int skip_activelog, int sleep_msecs, bool separate_keys)
bool LSA_ISNULL(const log_lsa *lsa_ptr)
Definition: log_lsa.hpp:153
#define BTID_SET_NULL(btid)
void logtb_free_trans_info(TRANS_INFO *info)
#define CHANGEMODE_FORCE_S
Definition: utility.h:1463
int checkdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:621
void sysprm_dump_parameters(FILE *fp)
#define COPYLOG_START_PAGEID_S
Definition: utility.h:1473
int sysprm_set_to_default(const char *pname, bool set_to_force)
BTID * db_constraint_index(DB_CONSTRAINT *constraint, BTID *index)
Definition: db_info.c:2107
static struct timeval start_time
int hb_process_init(const char *server_name, const char *log_path, HB_PROC_TYPE type)
Definition: heartbeat.c:682
int db_set_isolation(DB_TRAN_ISOLATION isolation)
Definition: db_admin.c:1535
int utility_get_option_string_table_size(UTIL_ARG_MAP *arg_map)
Definition: util_common.c:305
#define HA_CHANGE_MODE_DEFAULT_TIMEOUT_IN_SECS
#define BACKUP_DESTINATION_PATH_S
Definition: utility.h:1036
#define KILLTRAN_KILL_HOST_NAME_S
Definition: utility.h:1218
int util_log_write_warnstr(const char *format,...)
Definition: util_func.c:516
HA_SERVER_STATE boot_change_ha_mode(HA_SERVER_STATE state, bool force, int timeout)
#define PARAMDUMP_BOTH_S
Definition: utility.h:1439
MOP Au_user
Definition: authenticate.c:343
static void error(const char *msg)
Definition: gencat.c:331
#define CHECK_CHECK_PREV_LINK_S
Definition: utility.h:1173
#define ER_AU_INVALID_PASSWORD
Definition: error_code.h:235
SM_CLASS_CONSTRAINT * classobj_find_class_index(SM_CLASS *class_, const char *name)
int histo_start(bool for_all_trans)
#define MAX_KILLTRAN_INDEX_LIST_NUM
Definition: util_cs.c:68
MSGCAT_TRANLIST_MSG
Definition: utility.h:332
#define ARG_FILE_LINE
Definition: error_manager.h:44
int changemode_keyword(int *keyval_p, char **keystr_p)
Definition: util_common.c:555
static char database_name[MAX_HA_DBINFO_LENGTH]
Definition: cas_execute.c:387
STATIC_INLINE char * spacedb_get_size_str(char *buf, UINT64 num_pages, T_SPACEDB_SIZE_UNIT size_unit)
Definition: util_cs.c:3081
#define SPACEDB_TO_SIZE_ARG(no, npage)
const VOLID LOG_DBTDE_KEYS_VOLID
Definition: log_volids.hpp:41
int db_add_volume_ex(DBDEF_VOL_EXT_INFO *ext_info)
Definition: db_admin.c:342
#define ADDVOL_VOLUME_SIZE_S
Definition: utility.h:1093
UTIL_ARG_MAP * arg_map
Definition: utility.h:1698
int da_add(dynamic_array *da, void *data)
Definition: dynamic_array.c:82
#define UNIT_STR(un)
#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)
void LSA_SET_NULL(log_lsa *lsa_ptr)
Definition: log_lsa.hpp:146
#define PLANDUMP_DROP_S
Definition: utility.h:1191
static int tranlist_cmp_f(const void *p1, const void *p2)
Definition: util_cs.c:3434
#define KILLTRAN_DBA_PASSWORD_S
Definition: utility.h:1224
#define CHECK_CAT_CONSISTENCY_S
Definition: utility.h:1181
SORT_COLUMN_TYPE
Definition: util_cs.c:92
#define ADDVOL_FILE_PATH_S
Definition: utility.h:1083
void lock_dump(FILE *outfp)
#define KILLTRAN_KILL_SQL_ID_S
Definition: utility.h:1222
int copylogdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2633
SM_CLASS_TYPE class_type
Definition: class_object.h:713
#define FALSE
Definition: broker_admin.c:50
#define BACKUP_COMPRESS_S
Definition: utility.h:1052
int util_log_write_errstr(const char *format,...)
Definition: util_func.c:493
char * basename(const char *path)
Definition: porting.c:1132
#define LOCK_OUTPUT_FILE_S
Definition: utility.h:1129
#define SPACE_SUMMARIZE_S
Definition: utility.h:1123
#define ONE_K
Definition: porting.h:62
int i
Definition: dynamic_load.c:954
char * msgcat_message(int cat_id, int set_id, int msg_id)
#define ERR_CSS_TCP_CANNOT_CONNECT_TO_MASTER
Definition: error_code.h:429
const char * prm_get_name(PARAM_ID prm_id)
#define ER_NET_SERVER_CRASHED
Definition: error_code.h:269
#define XASL_ID_IS_NULL(X)
Definition: xasl.h:560
bool logwr_force_shutdown(void)
#define ADDVOL_MAX_WRITESIZE_IN_SEC_S
Definition: utility.h:1095
#define PLANDUMP_OUTPUT_FILE_S
Definition: utility.h:1193
char * strdup(const char *str)
Definition: porting.c:901
const char * comments
#define HA_DISABLED()
#define LOG_PAGESIZE
void sysprm_dump_server_parameters(FILE *fp)
#define OPTION_STRING_TABLE
Definition: utility.h:813
#define BACKUP_SA_MODE_S
Definition: utility.h:1044
enum ha_server_state HA_SERVER_STATE
Definition: boot.h:126
time_t util_str_to_time_since_epoch(char *str)
Definition: util_func.c:310
#define TRANLIST_REVERSE_S
Definition: utility.h:1207
#define SPACE_SIZE_UNIT_S
Definition: utility.h:1121
int changemode(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:2486
int copylogdb_keyword(int *keyval_p, char **keystr_p)
Definition: util_common.c:536
DB_VOLPURPOSE purpose
#define CHECKDB_ALL_CHECK_EXCEPT_PREV_LINK
static int tranlist_Sort_column
Definition: util_cs.c:99
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
#define BACKUP_THREAD_COUNT_S
Definition: utility.h:1050
int ws_find(MOP mop, MOBJ *obj)
Definition: work_space.c:3112
#define ACLDB_RELOAD_S
Definition: utility.h:1457
#define KILLTRAN_FORCE_S
Definition: utility.h:1230
int backupdb(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:121
#define XASL_ID_SET_NULL(X)
Definition: xasl.h:546
#define FILEIO_BACKUP_NUM_THREADS_AUTO
Definition: file_io.h:59
int netcl_spacedb(SPACEDB_ALL *spaceall, SPACEDB_ONEVOL **spacevols, SPACEDB_FILES *spacefiles)
#define ER_NET_SERVER_COMM_ERROR
Definition: error_code.h:265
#define STATDUMP_SUBSTR_S
Definition: utility.h:1453
int logwr_copy_log_file(const char *db_name, const char *log_path, int mode, INT64 start_page_id)
Definition: log_writer.c:1960
FILEIO_BACKUP_LEVEL
Definition: file_io.h:96
int tde_dump_mks(int vdes, bool print_value)
Definition: tde.c:1629
FILEIO_ZIP_METHOD
Definition: file_io.h:104
int acl_reload()
void la_print_delay_info(LOG_LSA working_lsa, LOG_LSA target_lsa, float process_rate)
Definition: log_applier.c:7269
TRAN_QUERY_EXEC_INFO query_exec_info
#define BACKUP_LEVEL_S
Definition: utility.h:1040
const char * command_name
Definition: utility.h:1699
#define TDE_DELETE_KEY_S
Definition: utility.h:1619
#define TDE_MASTER_KEY_LENGTH
Definition: tde.h:54
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)
Definition: porting.c:1333
int tde(UTIL_FUNCTION_ARG *arg)
Definition: util_cs.c:3716
#define APPLYINFO_INTERVAL_S
Definition: utility.h:1493
const char ** p
Definition: dynamic_load.c:945
char * utility_get_option_string_value(UTIL_ARG_MAP *arg_map, int arg_ch, int index)
Definition: util_common.c:266
#define CHANGEMODE_MODE_S
Definition: utility.h:1461
int cvacuum(void)
int db_commit_transaction(void)
Definition: db_admin.c:1091
#define APPLYINFO_VERBOSE_S
Definition: utility.h:1491
#define CHECK_REPAIR_PREV_LINK_S
Definition: utility.h:1175
#define ADDVOL_SA_MODE_S
Definition: utility.h:1089
#define ER_BO_CONNECT_FAILED
Definition: error_code.h:821
#define MSGCAT_CATALOG_UTILS