CUBRID Engine  latest
boot_sr.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  * boot_sr.c - Boot management (at server)
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <setjmp.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 
34 #if defined(SOLARIS)
35 #include <netdb.h>
36 #endif /* SOLARIS */
37 
38 /* for getcwd, possibly a candidate for the os_ library ? */
39 #if defined(WINDOWS)
40 #include <direct.h>
41 #else /* WINDOWS */
42 #include <unistd.h>
43 #endif /* WINDOWS */
44 #include <assert.h>
45 
46 #include "boot_sr.h"
47 
48 #include "area_alloc.h"
49 #include "btree.h"
50 #include "chartype.h"
51 #include "dbtran_def.h"
52 #include "error_manager.h"
53 #include "system_parameter.h"
54 #include "object_primitive.h"
55 #include "locator_sr.h"
56 #include "heap_file.h"
57 #include "system_catalog.h"
58 #include "transform.h"
59 #include "databases_file.h"
60 #include "language_support.h"
61 #include "message_catalog.h"
62 #include "perf_monitor.h"
63 #include "porting_inline.hpp"
64 #include "set_object.h"
65 #include "util_func.h"
66 #include "intl_support.h"
67 #include "serial.h"
68 #include "server_interface.h"
69 #include "jansson.h"
70 #include "jsp_sr.h"
71 #include "xserver_interface.h"
72 #include "session.h"
73 #include "event_log.h"
74 #include "tz_support.h"
75 #include "filter_pred_cache.h"
76 #include "scan_manager.h"
77 #include "slotted_page.h"
78 #include "thread_manager.hpp"
79 #include "double_write_buffer.h"
80 #include "xasl_cache.h"
81 #include "log_volids.hpp"
82 #include "vacuum.h"
83 #include "tde.h"
84 #include "porting.h"
85 
86 #if defined(SERVER_MODE)
87 #include "connection_sr.h"
88 #include "server_support.h"
89 #endif /* SERVER_MODE */
90 
91 #if defined(WINDOWS)
92 #include "wintcp.h"
93 #else
94 #include "tcp.h"
95 #endif /* WINDOWS */
96 
97 #if defined(ENABLE_SYSTEMTAP)
98 #include "probes.h"
99 #endif /* ENABLE_SYSTEMTAP */
100 
101 #define BOOT_LEAVE_SAFE_OSDISK_PARTITION_FREE_SPACE \
102  (1250 * (IO_DEFAULT_PAGE_SIZE / IO_PAGESIZE)) /* 5 Mbytes */
103 
104 #define BOOT_FORMAT_MAX_LENGTH 500
105 #define BOOTSR_MAX_LINE 500
106 
107 typedef struct boot_dbparm BOOT_DB_PARM;
109 {
110  VFID trk_vfid; /* Tracker of files */
111  HFID hfid; /* Heap file where this information is stored. It is only used for validation purposes */
112  HFID rootclass_hfid; /* Heap file where classes are stored */
113 #if 1 /* TODO - not used */
114  EHID classname_table; /* The hash file of class names */
115 #endif
116  CTID ctid; /* The catalog file */
117  /* TODO: Remove me */
118  VFID query_vfid; /* Query file */
119  char rootclass_name[10]; /* Name of the root class */
120  OID rootclass_oid; /* OID of the root class */
121  VOLID nvols; /* Number of volumes that have been created */
122  VOLID temp_nvols; /* Number of temporary volumes that have been created */
123  VOLID last_volid; /* Next volume identifier */
124  VOLID temp_last_volid; /* Next temporary volume identifier. This goes from a higher number to a lower number */
125  int vacuum_log_block_npages; /* Number of pages for vacuum data file */
126  VFID vacuum_data_vfid; /* Vacuum data file identifier */
127  VFID dropped_files_vfid; /* Vacuum dropped files file identifier */
128  HFID tde_keyinfo_hfid; /* Heap file where tde key info (TDE_KEYINFO) is stored */
129 };
130 
134 
135 extern bool catcls_Enable;
136 extern int catcls_compile_catalog_classes (THREAD_ENTRY * thread_p);
138 extern int catcls_get_server_compat_info (THREAD_ENTRY * thread_p, INTL_CODESET * charset_id_p, char *lang_buf,
139  const int lang_buf_size, char *timezone_checksum);
140 extern int catcls_get_db_collation (THREAD_ENTRY * thread_p, LANG_COLL_COMPAT ** db_collations, int *coll_cnt);
141 extern int catcls_find_and_set_cached_class_oid (THREAD_ENTRY * thread_p);
142 
143 #if defined(SA_MODE)
144 extern void boot_client_all_finalize (bool is_er_final);
145 #endif /* SA_MODE */
146 
147 
149 
150 #if defined(SERVER_MODE)
151 /* boot_cl.c:boot_Host_name[] if CS_MODE and SA_MODE */
153 #endif /* SERVER_MODE */
154 
155 /*
156  * database parameter variables that do not change over time
157  */
158 static char boot_Db_full_name[PATH_MAX];
159 static OID boot_Header_oid; /* Location of parameters */
160 static BOOT_DB_PARM boot_Struct_db_parm; /* The structure */
163 static char boot_Lob_path[PATH_MAX + LOB_PATH_PREFIX_MAX] = "";
166 
167 #if defined(SERVER_MODE)
168 static bool boot_Set_server_at_exit = false;
169 static int boot_Server_process_id = 1;
170 #endif /* SERVER_MODE */
171 
172 
173 /* Functions */
174 static int boot_get_db_parm (THREAD_ENTRY * thread_p, BOOT_DB_PARM * dbparm, OID * dbparm_oid);
175 static int boot_remove_temp_volume (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel);
176 
177 static int boot_remove_all_temp_volumes (THREAD_ENTRY * thread_p, REMOVE_TEMP_VOL_ACTION delete_action);
178 static int boot_xremove_temp_volume (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel);
179 static void boot_make_temp_volume_fullname (char *temp_vol_fullname, VOLID temp_volid);
180 static void boot_remove_unknown_temp_volumes (THREAD_ENTRY * thread_p);
181 static int boot_parse_add_volume_extensions (THREAD_ENTRY * thread_p, const char *filename_addmore_vols);
182 static int boot_find_rest_volumes (THREAD_ENTRY * thread_p, BO_RESTART_ARG * r_args, VOLID volid,
183  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel, void *args),
184  void *args);
185 static int boot_find_rest_permanent_volumes (THREAD_ENTRY * thread_p, bool newvolpath, bool use_volinfo, VOLID volid,
186  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel,
187  void *args), void *args);
188 
189 static void boot_find_rest_temp_volumes (THREAD_ENTRY * thread_p, VOLID volid,
190  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel),
191  bool forward_dir, bool check_before_access);
192 static int boot_check_permanent_volumes (THREAD_ENTRY * thread_p);
193 static int boot_mount (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel, void *ignore_arg);
194 static char *boot_find_new_db_path (char *db_pathbuf, const char *fileof_vols_and_wherepaths);
195 static int boot_create_all_volumes (THREAD_ENTRY * thread_p, const BOOT_CLIENT_CREDENTIAL * client_credential,
196  const char *db_comments, DKNPAGES db_npages, const char *file_addmore_vols,
197  const char *log_path, const char *log_prefix, DKNPAGES log_npages,
198  int client_lock_wait, TRAN_ISOLATION client_isolation);
199 static int boot_remove_all_volumes (THREAD_ENTRY * thread_p, const char *db_fullname, const char *log_path,
200  const char *log_prefix, bool dirty_rem, bool force_delete);
201 static char *boot_volume_info_log_path (char *log_path);
202 static void boot_remove_useless_path_separator (const char *path, char *new_path);
203 static void boot_ctrl_c_in_init_server (int ignore_signo);
204 
205 #if defined(CUBRID_DEBUG)
206 static void boot_check_db_at_num_shutdowns (bool force_nshutdowns);
207 #endif /* CUBRID_DEBUG */
208 
209 #if defined(SERVER_MODE)
210 static void boot_shutdown_server_at_exit (void);
211 #endif /* SERVER_MODE */
212 
213 static INTL_CODESET boot_get_db_charset_from_header (THREAD_ENTRY * thread_p, const char *log_path,
214  const char *log_prefix);
216 
217 static int boot_after_copydb (THREAD_ENTRY * thread_p);
218 
219 static int boot_generate_tde_keys (THREAD_ENTRY * thread_p);
220 
221 /*
222  * bo_server) -set server's status, UP or DOWN
223  * return: void
224  * status(in) :
225  */
226 void
228 {
229  static const char *status_str[] = { "UNKNOWN", "UP", "DOWN", "MAINTENANCE" };
230  if (status >= BOOT_SERVER_UP && status <= BOOT_SERVER_MAINTENANCE)
231  {
232  boot_Server_status = status;
234 #if defined(SERVER_MODE)
235  if (boot_Set_server_at_exit == false)
236  {
237  boot_Set_server_at_exit = true;
238  boot_Server_process_id = getpid ();
239  (void) atexit (boot_shutdown_server_at_exit);
240  }
241 #endif /* SERVER_MODE */
242  }
243 }
244 
245 #if defined(SERVER_MODE)
246 /*
247  * bo_shutdown_server_at_exit () - make sure that the server is shutdown at exit
248  *
249  * return : nothing
250  *
251  * Note: This function is called when the invoked program terminates normally.
252  * This function make sure that the server is shutdown gracefully.
253  */
254 static void
255 boot_shutdown_server_at_exit (void)
256 {
257  if (BO_IS_SERVER_RESTARTED () && boot_Server_process_id == getpid ())
258  {
259  /* Avoid infinite looping if someone calls exit during shutdown */
260  boot_Server_process_id++;
262  (void) xboot_shutdown_server (thread_p, ER_ALL_FINAL);
263  }
264 }
265 
266 /*
267  * boot_donot_shutdown_server_at_exit () - do not shutdown server at exist.
268  *
269  * return : nothing
270  *
271  * Note: This function must be called when the system needs to exit without
272  * shutting down the system (e.g., in case of fatal failure).
273  */
274 void
275 boot_donot_shutdown_server_at_exit (void)
276 {
277  if (BO_IS_SERVER_RESTARTED () && boot_Server_process_id == getpid ())
278  {
279  boot_Server_process_id++;
280  }
281 }
282 #endif /* SERVER_MODE */
283 
284 /*
285  * boot_get_db_parm () - retrieve database parameters from disk
286  *
287  * return : NO_ERROR if all OK, ER_ status otherwise
288  *
289  * dbparm(out): database parameter structure
290  * dbparm_oid(in): oid of parameter object
291  *
292  * Note: Retrieve the database boot/restart parameters from disk.
293  */
294 static int
295 boot_get_db_parm (THREAD_ENTRY * thread_p, BOOT_DB_PARM * dbparm, OID * dbparm_oid)
296 {
297  RECDES recdes;
298  HEAP_SCANCACHE scan_cache;
299  SCAN_CODE scan = S_SUCCESS;
300 
301  recdes.area_size = recdes.length = DB_SIZEOF (*dbparm);
302  recdes.data = (char *) dbparm;
303 
304  heap_scancache_quick_start_with_class_hfid (thread_p, &scan_cache, &boot_Db_parm->hfid);
305  scan = heap_first (thread_p, &boot_Db_parm->hfid, NULL, dbparm_oid, &recdes, &scan_cache, COPY);
306  heap_scancache_end (thread_p, &scan_cache);
307 
308  if (scan != S_SUCCESS)
309  {
310  assert (false);
311  return ER_FAILED;
312  }
313 
314  return NO_ERROR;
315 }
316 
317 /*
318  * boot_find_root_heap () - find the root heap
319  *
320  * return: NO_ERROR
321  *
322  * Note: Find the heap where the classes are stored.
323  */
324 int
325 boot_find_root_heap (HFID * root_hfid_p)
326 {
327  assert (root_hfid_p != NULL);
328  assert (!HFID_IS_NULL (&boot_Db_parm->rootclass_hfid));
329 
330  HFID_COPY (root_hfid_p, &boot_Db_parm->rootclass_hfid);
331 
332  return NO_ERROR;
333 }
334 
335 /*
336  * xboot_find_number_permanent_volumes () - find the number of permanent volumes
337  *
338  * return : number of permanent volumes
339  */
340 int
342 {
343  int nvols;
344 
345  /* wait for disk extensions to finish. */
346  disk_lock_extend ();
347  nvols = boot_Db_parm->nvols;
349 
350  return nvols;
351 }
352 
353 /*
354  * xboot_find_number_temp_volumes () - find the number of temporary volumes
355  *
356  * return : number of temporary volumes
357  */
358 int
360 {
361  int nvols;
362 
363  /* wait for disk extensions to finish. */
364  disk_lock_extend ();
365  nvols = boot_Db_parm->temp_nvols;
367 
368  return nvols;
369 }
370 
371 /*
372  * xboot_find_last_permanent () - find the volid of last permanent volume
373  *
374  * return : volid of last permanent volume
375  */
376 VOLID
378 {
379  VOLID volid;
380 
381  /* wait for disk extensions to finish. */
382  disk_lock_extend ();
383  volid = boot_Db_parm->last_volid;
385 
386  return volid;
387 }
388 
389 /*
390  * xboot_peek_last_permanent () - peek the volid of last permanent volume
391  *
392  * return : volid of last permanent volume
393  * NOTE: this function does not wait for extensions to finish
394  */
395 VOLID
397 {
398  return boot_Db_parm->last_volid;
399 }
400 
401 /*
402  * xboot_find_last_temp () - find the volid of next temporary volume
403  *
404  * return : volid of next temporary volume
405  */
406 VOLID
408 {
409  VOLID volid;
410 
411  /* wait for disk extensions to finish. */
412  disk_lock_extend ();
413  volid = boot_Db_parm->temp_last_volid;
415 
416  return volid;
417 }
418 
419 /*
420  * boot_find_next_permanent_volid () - find next volid for a permanent volume
421  *
422  * return : next volid for a permanent volume
423  */
424 VOLID
426 {
427  VOLID volid;
428 
429  /* wait for disk extensions to finish. */
430  disk_lock_extend ();
431  volid = boot_Db_parm->last_volid + 1;
433 
434  return volid;
435 }
436 
437 /*
438  * boot_reset_db_parm () - reset database initialization parameters
439  * (must be used only be log/recovery manager)
440  *
441  * return : NO_ERROR if all OK, ER_ status otherwise
442  *
443  * Note: Reset database initialization parameters. It is used only during
444  * recovery of the database.
445  */
446 int
448 {
449  return boot_get_db_parm (thread_p, boot_Db_parm, boot_Db_parm_oid);
450 }
451 
452 /*
453  * boot_db_name () - find the name of the database
454  *
455  * return : name of the database
456  *
457  */
458 const char *
460 {
462 }
463 
464 /*
465  * boot_db_full_name () - return current database full name.
466  *
467  * return : database full name
468  */
469 const char *
471 {
472  return boot_Db_full_name;
473 }
474 
475 /*
476  * boot_get_lob_path - return the lob path which is read from databases.txt
477  */
478 const char *
480 {
481  return boot_Lob_path;
482 }
483 
484 /*
485  * boot_remove_temp_volume () - remove a volume from the database
486  *
487  * return : NO_ERROR if all OK, ER_ status otherwise
488  *
489  * volid(in): Volume identifier to remove
490  *
491  * Note: Remove a volume from the database. The deletion of the volume is done
492  * independently of the destiny of the current transaction. That is,
493  * if this function finishes successfully the removal is made permanent,
494  * if the function fails, whatever was done is aborted.
495  * Currently, we do not allow to remove permanent volumes. In the future
496  * we may allow the removal of any volume but the primary volume
497  * (LOG_DBFIRST_VOLID).
498  */
499 static int
500 boot_remove_temp_volume (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel)
501 {
502  /* Make sure that this is a temporary volume */
503  if (volid < boot_Db_parm->temp_last_volid)
504  {
505  if (volid >= LOG_DBFIRST_VOLID && volid <= boot_Db_parm->last_volid)
506  {
508  fileio_get_volume_label (volid, PEEK));
510  }
511  else
512  {
514  return ER_FILE_UNKNOWN_VOLID;
515  }
516  }
517 
518  /* Do the following for temporary volumes */
519  boot_Db_parm->temp_nvols--;
520  if (boot_Db_parm->temp_nvols <= 0)
521  {
522  boot_Db_parm->temp_last_volid = NULL_VOLID;
523  }
524  else if (boot_Db_parm->temp_last_volid == volid)
525  {
526  boot_Db_parm->temp_last_volid = volid + 1;
527  }
528 
529  /* The volume is not known by the system any longer. */
530  (void) pgbuf_invalidate_all (thread_p, volid);
531 
532  fileio_unformat (thread_p, vlabel);
533 
534  return NO_ERROR;
535 }
536 
537 /*
538  * xboot_add_volume_extension () - add a volume extension to the database
539  *
540  * return : volid or NULL_VOLID (in case of failure)
541  *
542  * ext_info(in): volume info
543  *
544  * Note: Add a volume extension to the database. The addition of the volume
545  * is a system operation that will be either aborted in case of failure
546  * or committed in case of success, independently on the destiny of the
547  * current transaction. The volume becomes immediately available to other
548  * transactions.
549  */
550 VOLID
552 {
553  VOLID volid;
554 
555  if (disk_add_volume_extension (thread_p, ext_info->purpose, ext_info->max_npages, ext_info->path, ext_info->name,
556  ext_info->comments, ext_info->max_writesize_in_sec, ext_info->overwrite, &volid)
557  != NO_ERROR)
558  {
559  ASSERT_ERROR ();
560  return NULL_VOLID;
561  }
562  assert (volid != NULL_VOLID);
563  return volid;
564 }
565 
566 /*
567  * boot_remove_useless_path_separator () - Remove useless PATH_SEPARATOR in path string
568  *
569  * return : true or false(in case of fail)
570  *
571  * path(in): Original path.
572  * new_path(out): Transformed path.
573  *
574  * Note: This function removes useless PATH_SEPARATOR in path string.
575  * For example,
576  * /home3/CUBRID/DB/ --> /home3/CUBRID/DB
577  * C:\CUBRID\\\Databases\\ --> C:\CUBRID\Databases
578  * \\pooh\user\ --> \\pooh\user
579  *
580  * After transform..
581  * If new path string is "/" or "\", don't remove the last slash.
582  * It is survived.
583  */
584 static void
585 boot_remove_useless_path_separator (const char *path, char *new_path)
586 {
587  int slash_num = 0; /* path separator counter */
588 
589  /* path must be not null */
590  assert (path != NULL);
591  assert (new_path != NULL);
592 
593  /*
594  * Before transform.
595  * / h o m e 3 / / w o r k / c u b r i d / / / w o r k /
596  *
597  * After transform.
598  * / h o m e 3 / w o r k / c u b r i d / w o r k
599  */
600 
601  /* Consume the preceding continuous slash chars. */
602  while (*path == PATH_SEPARATOR)
603  {
604  slash_num++;
605  path++;
606  }
607 
608  /* If there is preceding consumed slash, append PATH_SEPARATOR */
609  if (slash_num)
610  {
611  *new_path++ = PATH_SEPARATOR;
612 #if defined(WINDOWS)
613  /*
614  * In Windows/NT,
615  * If first duplicated PATH_SEPARATORs are appeared, they are survived.
616  * For example,
617  * \\pooh\user\ -> \\pooh\user(don't touch the first duplicated PATH_SEPARATORs)
618  */
619  if (slash_num > 1)
620  {
621  *new_path++ = PATH_SEPARATOR;
622  }
623 #endif /* WINDOWS */
624  }
625 
626  /* Initialize separator counter again. */
627  slash_num = 0;
628 
629  /*
630  * If current character is PATH_SEPARATOR,
631  * skip after increasing separator counter.
632  * If current character is normal character, copy to new_path.
633  */
634  while (*path)
635  {
636  if (*path == PATH_SEPARATOR)
637  {
638  slash_num++;
639  }
640  else
641  {
642  /*
643  * If there is consumed slash, append PATH_SEPARATOR.
644  * Initialize separator counter.
645  */
646  if (slash_num)
647  {
648  *new_path++ = PATH_SEPARATOR;
649  slash_num = 0;
650  }
651  *new_path++ = *path;
652  }
653  path++;
654  }
655 
656  /* Assure null terminated string */
657  *new_path = '\0';
658 }
659 
660 /*
661  * boot_parse_add_volume_extensions () - add a set of volume extensions
662  * to the database
663  *
664  * return : NO_ERROR if all OK, ER_ status otherwise
665  *
666  * filename_addmore_vols(in): File name where the volume specifications are
667  * found
668  *
669  * Note: A set of volume extensions are added to the database. The given
670  * parameter is a file which indicates the specifications for all
671  * the volumes to be created. A volume is specified by ONE LINE which
672  * can contain the following parameters:
673  * [NAME volname] [PATH volpath] [COMMENTS volcomments]
674  * [PURPOSE volpurpose] PAGES volnpages
675  *
676  * The additions of the volumes is a system operations that will be either
677  * aborted in case of failure or committed in case of success,
678  * independently on the destiny of the current transaction. The volume
679  * becomes immediately available to other transactions.
680  */
681 static int
682 boot_parse_add_volume_extensions (THREAD_ENTRY * thread_p, const char *filename_addmore_vols)
683 {
684  FILE *fp;
685  char input_buffer[BOOTSR_MAX_LINE + 1];
686  char *line;
687  char *token;
688  char *token_value;
689  char *ext_name;
690  char *ext_path;
691  char *ext_comments;
692  DKNPAGES ext_npages;
693  DISK_VOLPURPOSE ext_purpose;
694  int line_num = 0;
695  int error_code = NO_ERROR;
696  VOLID volid = NULL_VOLID;
697 
698  fp = fopen (filename_addmore_vols, "r");
699  if (fp == NULL)
700  {
703  }
704 
705  /*
706  * Get a line
707  * Continue parsing even in case of error, so that we can indicate as
708  * many errors as possible.
709  */
710 
711  while ((line = fgets (input_buffer, BOOTSR_MAX_LINE, fp)) != NULL)
712  {
713  line_num++;
714 
715  /* Ignore lines with comments */
716 
717  if (line[0] == '\0' || line[0] == '#')
718  {
719  continue;
720  }
721 
722  ext_npages = (DKNPAGES) strlen (line);
723  if (line[ext_npages - 1] != '\n')
724  {
725  line[ext_npages] = '\n';
726  line[ext_npages + 1] = '\0';
727  }
728 
729  /*
730  * Parse the line
731  */
732 
733  ext_name = NULL;
734  ext_path = NULL;
735  ext_comments = NULL;
736  ext_npages = 0;
737  ext_purpose = DB_PERMANENT_DATA_PURPOSE;
738 
739  while (true)
740  {
741  /*
742  * Read token.. skip leading whitespace and comments
743  */
744  while (char_isspace (line[0]))
745  {
746  line++;
747  }
748 
749  if (line[0] == '\0')
750  {
751  break;
752  }
753 
754  token = line;
755 
756  do
757  {
758  line++;
759  }
760  while (!char_isspace (line[0]));
761  line[0] = '\0';
762  line++;
763 
764  /*
765  * Skip any whitespace before the value.
766  */
767 
768  while (char_isspace (line[0]))
769  {
770  line++;
771  }
772 
773  token_value = line;
774 
775  /*
776  * If string in " xxx " or ' xxxx ' find its delimiter
777  */
778 
779  if (token_value[0] == '"' || token_value[0] == '\'')
780  {
781  int delim;
782 
783  delim = token_value[0];
784  token_value++;
785  do
786  {
787  line++;
788  }
789  while (line[0] != delim);
790  line[0] = '\0';
791  line++;
792  }
793  else
794  {
795  do
796  {
797  line++;
798  }
799  while (!char_isspace (line[0]));
800  line[0] = '\0';
801  line++;
802  }
803 
804  if (intl_mbs_casecmp (token, "NAME") == 0)
805  {
806  /* Name of volume */
807  ext_name = token_value;
808  }
809  else if (intl_mbs_casecmp (token, "PATH") == 0)
810  {
811  ext_path = token_value;
812  }
813  else if (intl_mbs_casecmp (token, "COMMENTS") == 0)
814  {
815  ext_comments = token_value;
816  }
817  else if (intl_mbs_casecmp (token, "PURPOSE") == 0)
818  {
819  if (intl_mbs_casecmp (token_value, "DATA") == 0)
820  {
821  ext_purpose = DB_PERMANENT_DATA_PURPOSE;
822  }
823  else if (intl_mbs_casecmp (token_value, "INDEX") == 0)
824  {
825  ext_purpose = DB_PERMANENT_DATA_PURPOSE;
826  }
827  else if (intl_mbs_casecmp (token_value, "TEMP") == 0)
828  {
829  ext_purpose = DB_TEMPORARY_DATA_PURPOSE;
830  }
831  else if (intl_mbs_casecmp (token_value, "GENERIC") == 0)
832  {
833  ext_purpose = DB_PERMANENT_DATA_PURPOSE;
834  }
835  else
836  {
838  line_num);
840  break;
841  }
842  }
843  else if (intl_mbs_casecmp (token, "NPAGES") == 0)
844  {
845  if (sscanf (token_value, "%i", (int *) &ext_npages) != 1)
846  {
849  break;
850  }
851  else if (ext_npages <= 0)
852  {
854  break;
855  }
856  }
857  else
858  {
860  }
861  }
862 
863  /*
864  * Add the volume
865  */
866  if (error_code != NO_ERROR || (ext_name == NULL && ext_path == NULL && ext_comments == NULL && ext_npages == 0))
867  {
868  continue;
869  }
870 
871  if (ext_npages <= 0)
872  {
875  continue;
876  }
877 
878  error_code =
879  disk_add_volume_extension (thread_p, ext_purpose, ext_npages, ext_path, ext_name, ext_comments, 0, false,
880  &volid);
881  if (error_code != NO_ERROR)
882  {
883  ASSERT_ERROR ();
884  break;
885  }
886  assert (volid != NULL_VOLID);
887  }
888  fclose (fp);
889 
890  return error_code;
891 }
892 
893 /*
894  * boot_remove_all_temp_volumes () - remove all temporary volumes from the database
895  *
896  * return: NO_ERROR if all OK, ER_ status otherwise
897  */
898 static int
900 {
901  int error_code = NO_ERROR;
902 
903  /* if volumes exist beyond bo_Dbparm.temp_last_volid, we remove the volumes.
904  * there is no logging to add or remove a temporary temp volume, but logging to update bo_Dbparm.
905  * so, unknown volumes can be possible to exist.
906  */
907  if (!BO_IS_SERVER_RESTARTED ())
908  {
910  }
911 
912  if (boot_Db_parm->temp_nvols == 0)
913  {
914  assert (boot_Db_parm->temp_last_volid == NULL_VOLID);
915  return NO_ERROR;
916  }
917 
919 
920  if (delete_action == ONLY_PHYSICAL_REMOVE_TEMP_VOL_ACTION)
921  {
922  return NO_ERROR;
923  }
924 
925  if (boot_Db_parm->temp_nvols != 0 || boot_Db_parm->temp_last_volid != NULL_VOLID)
926  {
927  /* something bad happened. Reset it anyway. */
928  boot_Db_parm->temp_nvols = 0;
929  boot_Db_parm->temp_last_volid = NULL_VOLID;
930  }
931 
932  error_code = boot_db_parm_update_heap (thread_p);
933  if (error_code != NO_ERROR)
934  {
935  ASSERT_ERROR ();
936  return error_code;
937  }
938 
939  return error_code;
940 }
941 
942 /*
943  * boot_xremove_temp_volume () - remove a temporary volume from the database
944  *
945  * return : NO_ERROR if all OK, ER_ status otherwise
946  *
947  * volid(in): Volume identifier to remove
948  * vlabel(in): Volume label
949  *
950  * Note: Pass control to boot_remove_temp_volume to remove the temporary volume.
951  */
952 static int
953 boot_xremove_temp_volume (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel)
954 {
955  return boot_remove_temp_volume (thread_p, volid, vlabel);
956 }
957 
958 static void
959 boot_make_temp_volume_fullname (char *temp_vol_fullname, VOLID temp_volid)
960 {
961  const char *temp_path;
962  const char *temp_name;
963  char *alloc_tempath = NULL;
964 
965  assert (temp_vol_fullname != NULL);
966 
967  temp_vol_fullname[0] = '\0';
968 
969  alloc_tempath = (char *) malloc (strlen (boot_Db_full_name) + 1);
970  if (alloc_tempath == NULL)
971  {
972  return;
973  }
974  temp_path = (char *) prm_get_string_value (PRM_ID_IO_TEMP_VOLUME_PATH);
975  if (temp_path == NULL || temp_path[0] == '\0')
976  {
977  temp_path = fileio_get_directory_path (alloc_tempath, boot_Db_full_name);
978  }
980 
981  fileio_make_volume_temp_name (temp_vol_fullname, temp_path, temp_name, temp_volid);
982 
983  if (alloc_tempath)
984  {
985  free_and_init (alloc_tempath);
986  }
987 }
988 
989 /*
990  * boot_remove_unknown_temp_volumes () -
991  *
992  * return: none
993  */
994 static void
996 {
997  VOLID temp_volid;
998  char temp_vol_fullname[PATH_MAX];
999 
1000  if (boot_Db_parm->temp_last_volid == NULL_VOLID)
1001  {
1002  temp_volid = LOG_MAX_DBVOLID;
1003  }
1004  else
1005  {
1006  temp_volid = boot_Db_parm->temp_last_volid - 1;
1007  }
1008 
1009  for (; temp_volid > boot_Db_parm->last_volid; temp_volid--)
1010  {
1011  boot_make_temp_volume_fullname (temp_vol_fullname, temp_volid);
1012  if (!fileio_is_volume_exist (temp_vol_fullname))
1013  {
1014  break;
1015  }
1017  fileio_unformat (thread_p, temp_vol_fullname);
1018  }
1019 }
1020 
1021 /*
1022  * boot_find_rest_volumes () - call function on the rest of vols
1023  *
1024  * return : NO_ERROR if all OK, ER_ status otherwise
1025  *
1026  * r_args(in): restart argument structure contains various options
1027  * volid(in): Volume identifier
1028  * fun(in): Function to call on volid, vlabel, and arguments
1029  * args(in): Extra arguments for function to call
1030  *
1031  * Note: The given function is called for every single volume which is different from the given one.
1032  */
1033 static int
1035  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel, void *args), void *args)
1036 {
1037  int error_code = NO_ERROR;
1038  bool check;
1039 
1040  if (r_args != NULL)
1041  {
1042  check = r_args->newvolpath;
1043  }
1044  else
1045  {
1046  check = false;
1047  }
1048 
1049  error_code = boot_find_rest_permanent_volumes (thread_p, check, true, volid, fun, args);
1050  if (error_code != NO_ERROR)
1051  {
1052  return error_code;
1053  }
1054 
1055  /* We don't want to mount temp vols during bootstrapping,
1056  * since temp vols might be inaccessible for a crash case and will be removed soon.
1057  */
1058 
1059  return error_code;
1060 }
1061 
1062 /*
1063  * boot_find_rest_permanent_volumes () - call function on the rest of permanent vols of database
1064  *
1065  * return : NO_ERROR if all OK, ER_ status otherwise
1066  *
1067  * newvolpath(in): restore the database and log volumes to the path specified in the database-loc-file.
1068  * use_volinfo(in): use volinfo indicator
1069  * volid(in): Volume identifier
1070  * fun(in): Function to call on volid, vlabel, and arguments
1071  * args(in): Extra arguments for function to call
1072  *
1073  * Note: The given function is called for every single permanent volume which is different from the given one.
1074  */
1075 static int
1076 boot_find_rest_permanent_volumes (THREAD_ENTRY * thread_p, bool newvolpath, bool use_volinfo, VOLID volid,
1077  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel, void *args),
1078  void *args)
1079 {
1080  DKNVOLS num_vols = 0;
1081  int error_code = NO_ERROR;
1082 
1083  if (newvolpath || !use_volinfo
1084  || (num_vols = logpb_scan_volume_info (thread_p, NULL, volid, LOG_DBFIRST_VOLID, fun, args)) == -1)
1085  {
1086  /* Don't use volume info .. or could not find volume info .. or it was bad */
1087  VOLID next_volid = LOG_DBFIRST_VOLID; /* Next volume identifier */
1088  char next_vol_fullname[PATH_MAX]; /* Next volume name */
1089 
1090  num_vols = 0;
1091 
1092  /* First the primary volume, then the rest of the volumes */
1093  /*
1094  * Do not assume that all the volumes are mounted. This function may be called to mount the volumes.
1095  * Thus, request to current volume for the next volume instead of going directly through the volume identifier.
1096  */
1097  strcpy (next_vol_fullname, boot_Db_full_name);
1098  for (next_volid = LOG_DBFIRST_VOLID; next_volid != NULL_VOLID;)
1099  {
1100  num_vols++;
1101  if (next_volid != volid)
1102  {
1103  error_code = (*fun) (thread_p, next_volid, next_vol_fullname, args);
1104  if (error_code != NO_ERROR)
1105  {
1106  return error_code;
1107  }
1108  }
1109  /* update next_volid and next_vol_fullname */
1110  if (disk_get_link (thread_p, next_volid, &next_volid, next_vol_fullname) == NULL)
1111  {
1112  return ER_FAILED;
1113  }
1114  }
1115 
1116  if (use_volinfo == true)
1117  {
1118  /* The volume info was not found.. Recreate it with the current information */
1119  (void) logpb_recreate_volume_info (thread_p);
1120  }
1121  }
1122  else
1123  {
1124  /* Add the volume that was ignored, as long as it is in the range of a valid one */
1125  if (volid != NULL_VOLID && volid >= LOG_DBFIRST_VOLID && volid <= boot_Db_parm->last_volid)
1126  {
1127  num_vols++;
1128  }
1129 
1130  if (num_vols != boot_Db_parm->nvols)
1131  {
1132  error_code = boot_find_rest_permanent_volumes (thread_p, newvolpath, false, volid, fun, args);
1133  if (error_code != NO_ERROR)
1134  {
1135  /* Still could not mount or find all necessary volumes */
1137  boot_Db_parm->nvols);
1138  return error_code;
1139  }
1140 
1141  (void) logpb_recreate_volume_info (thread_p);
1142  return NO_ERROR;
1143  }
1144  }
1145 
1146  if (num_vols < boot_Db_parm->nvols)
1147  {
1148  return ER_FAILED;
1149  }
1150 
1151  return error_code;
1152 }
1153 
1154 /*
1155  * bo_find_rest_tempvols () - call function on the rest of temporary vols of the database
1156  *
1157  * volid(in): Volume identifier
1158  * fun(in): Function to call on volid, vlabel, and arguments
1159  * forward_dir(in): direction of accessing the tempvols (forward/backward)
1160  * check_before_access(in): if true, check the existence of volume before access
1161  *
1162  * Note: The given function is called for every single temporary volume which is different from the given one.
1163  */
1164 static void
1166  int (*fun) (THREAD_ENTRY * thread_p, VOLID xvolid, const char *vlabel),
1167  bool forward_dir, bool check_before_access)
1168 {
1169  VOLID temp_volid;
1170  char temp_vol_fullname[PATH_MAX];
1171  const char *temp_path;
1172  const char *temp_name;
1173  char *alloc_tempath = NULL;
1174  int num_vols;
1175  bool go_to_access;
1176 
1177  /*
1178  * Get the name of the extension: ext_path|dbname|"ext"|volid
1179  */
1180 
1181  /* Use the directory where the primary volume is located */
1182  alloc_tempath = (char *) malloc (strlen (boot_Db_full_name) + 1);
1183  if (alloc_tempath == NULL)
1184  {
1185  return;
1186  }
1187  temp_path = (char *) prm_get_string_value (PRM_ID_IO_TEMP_VOLUME_PATH);
1188  if (temp_path == NULL || temp_path[0] == '\0')
1189  {
1190  temp_path = fileio_get_directory_path (alloc_tempath, boot_Db_full_name);
1191  }
1193 
1194  if (boot_Db_parm->temp_nvols > 0)
1195  {
1196  /* Cycle over all temporarily volumes, skip the given one */
1197  if (forward_dir)
1198  {
1199  for (num_vols = boot_Db_parm->temp_last_volid; num_vols <= LOG_MAX_DBVOLID; num_vols++)
1200  {
1201  temp_volid = (VOLID) num_vols;
1202  if (temp_volid != volid)
1203  {
1204  /* Find the name of the volume */
1205  fileio_make_volume_temp_name (temp_vol_fullname, temp_path, temp_name, temp_volid);
1206  go_to_access = false;
1207  if (check_before_access)
1208  {
1209  if (fileio_is_volume_exist (temp_vol_fullname) == true)
1210  {
1211  go_to_access = true;
1212  }
1213  }
1214  else
1215  {
1216  go_to_access = true;
1217  }
1218  if (go_to_access)
1219  { /* Call the function */
1220  (void) (*fun) (thread_p, temp_volid, temp_vol_fullname);
1221  }
1222  }
1223  }
1224  }
1225  else
1226  {
1227  for (num_vols = LOG_MAX_DBVOLID; num_vols >= boot_Db_parm->temp_last_volid; num_vols--)
1228  {
1229  temp_volid = (VOLID) num_vols;
1230  if (temp_volid != volid)
1231  {
1232  /* Find the name of the volume */
1233  fileio_make_volume_temp_name (temp_vol_fullname, temp_path, temp_name, temp_volid);
1234  go_to_access = false;
1235  if (check_before_access)
1236  {
1237  if (fileio_is_volume_exist (temp_vol_fullname) == true)
1238  {
1239  go_to_access = true;
1240  }
1241  }
1242  else
1243  {
1244  go_to_access = true;
1245  }
1246  if (go_to_access)
1247  { /* Call the function */
1248  (void) (*fun) (thread_p, temp_volid, temp_vol_fullname);
1249  }
1250  }
1251  }
1252  }
1253  }
1254 
1255  if (alloc_tempath)
1256  {
1257  free_and_init (alloc_tempath);
1258  }
1259 }
1260 
1261 /*
1262  * boot_check_permanent_volumes () - check consistency of permanent volume names and number
1263  *
1264  * return : NO_ERROR if all OK, ER_ status otherwise
1265  *
1266  * Note: Make sure that we can reach the expected number of volumes
1267  * using the internal link list of permananet volumes.
1268  */
1269 static int
1271 {
1272  VOLID num_vols = 0;
1273  VOLID volid = LOG_DBFIRST_VOLID; /* Current volume identifier */
1274  VOLID next_volid = LOG_DBFIRST_VOLID; /* Next volume identifier */
1275  char next_vol_fullname[PATH_MAX]; /* Next volume name */
1276  const char *vlabel;
1277 
1278  /*
1279  * Don't use volinfo .. or could not find volinfo
1280  */
1281 
1282  /* First the primary volume, then the rest of the volumes */
1283  num_vols = 0;
1284  strcpy (next_vol_fullname, boot_Db_full_name);
1285 
1286  /*
1287  * Do not assume that all the volumes are mounted. This function may be
1288  * called to mount the volumes. Thus, request to current volume for the
1289  * next volume instead of going directly through the volume identifier.
1290  */
1291  do
1292  {
1293  num_vols++;
1294  /* Have to make sure a label exists, before we try to use it below */
1295  vlabel = fileio_get_volume_label (volid, PEEK);
1296  if (vlabel == NULL)
1297  {
1299  return ER_GENERIC_ERROR;
1300  }
1301 
1302  if (util_compare_filepath (next_vol_fullname, vlabel) != 0)
1303  {
1304  /*
1305  * Names are different. The database was renamed outside the domain of
1306  * the database (e.g., in Unix), or this is not a database.
1307  * If volume information is not present, assume that this is not a
1308  * database
1309  */
1311  }
1312  if (disk_get_link (thread_p, volid, &next_volid, next_vol_fullname) == NULL)
1313  {
1314  return ER_GENERIC_ERROR;
1315  }
1316 
1317  volid = next_volid;
1318  }
1319  while (volid != NULL_VOLID);
1320 
1321  if (num_vols != boot_Db_parm->nvols)
1322  {
1324  boot_Db_parm->nvols);
1326  }
1327 
1328  return NO_ERROR;
1329 }
1330 
1331 /*
1332  * boot_mount () - mount given volume
1333  *
1334  * return : NO_ERROR if all OK, ER_ status otherwise
1335  *
1336  * volid(in): Volume identifier
1337  * vlabel(in): Volume label
1338  * arg_ignore: Unused
1339  */
1340 static int
1341 boot_mount (THREAD_ENTRY * thread_p, VOLID volid, const char *vlabel, void *ignore_arg)
1342 {
1343  char check_vlabel[PATH_MAX];
1344  int vdes;
1345 
1346  vdes = fileio_mount (thread_p, boot_Db_full_name, vlabel, volid, false, false);
1347  if (vdes == NULL_VOLDES)
1348  {
1349  return ER_FAILED;
1350  }
1351 
1352  /* Check the label and give a warning if labels are not the same */
1353  if (xdisk_get_fullname (thread_p, volid, check_vlabel) == NULL)
1354  {
1355  fileio_dismount (thread_p, vdes);
1356  return ER_FAILED;
1357  }
1358 
1359  if (util_compare_filepath (check_vlabel, vlabel) != 0)
1360  {
1361  /*
1362  * Names are different. The database was renamed outside the domain of
1363  * the database (e.g., in Unix), or this is not a database.
1364  * If volume information is not present, assume that this is not a
1365  * database
1366  */
1368  {
1370  return ER_BO_NOT_A_VOLUME;
1371  }
1373  }
1374 
1375  return NO_ERROR;
1376 }
1377 
1378 #if !defined(WINDOWS)
1380 #endif
1381 
1382 static bool boot_Init_server_is_canceled = false;
1383 
1384 /*
1385  * boot_ctrl_c_in_init_server () -
1386  *
1387  * return:
1388  */
1389 static void
1390 boot_ctrl_c_in_init_server (int ignore_signo)
1391 {
1392 #if !defined(WINDOWS)
1393  _longjmp (boot_Init_server_jmpbuf, 1);
1394 #else
1395  boot_Init_server_is_canceled = true;
1396 #endif
1397 }
1398 
1399 /*
1400  * xboot_initialize_server () - initialize server
1401  *
1402  * return : transaction index or NULL_TRAN_INDEX in the case of
1403  * error.
1404  *
1405  * print_version(in): Flag which indicates if the version of CUBRID server
1406  * is printed at the end of the initialization process.
1407  * db_name(in): Database Name
1408  * db_path(in): Directory where the database is created. It allows you
1409  * to specify the exact pathname of a directory in which
1410  * to create the new database. A NULL value is invalid.
1411  * db_comments(in): Database creation comments such as name of the user who
1412  * created the database, the date of the creation,the name
1413  * of the intended application, or nothing at all. NULL
1414  * can be passed if no comments are desired.
1415  * db_npages(in): Total number of pages to allocate for the database.
1416  * db_overwrite(in): Wheater to overwrite the database if it already exists.
1417  * file_addmore_vols(in): More volumes are created during the initialization
1418  * process.
1419  * log_path(in): Directory where the log and backups of the database are
1420  * created. We recommend placing log and backup in a
1421  * different directory and disk device from the directory
1422  * and disk device of the data volumes. A NULL value is
1423  * invalid.
1424  * db_server_host(in): Server host where the database will reside. The host is
1425  * needed in a client/server environment to identify the
1426  * server which will maintain (e.g., restart) the database
1427  * A NULL is invalid.
1428  * rootclass_oid(in): OID of root class (Set as a side effect)
1429  * rootclass_hfid(in): Heap for classes (Set as a side effect)
1430  * client_prog_name(in): Name of the client program or NULL
1431  * client_user_name(in): Name of the client user or NULL
1432  * client_host_name(in): Name of the client host or NULL
1433  * client_process_id(in): Identifier of the process of the host where the client
1434  * client transaction runs.
1435  * client_lock_wait(in): Wait for at least this number of milliseconds to acquire a
1436  * lock. Negative value is infinite
1437  * client_isolation(in): Isolation level. One of the following:
1438  * TRAN_REPEATABLE_READ
1439  * TRAN_READ_COMMITTED
1440  * TRAN_SERIALIZABLE
1441  * db_desired_pagesize(in): Desired pagesize for the new database. The given size
1442  * must be power of 2 and greater or equal than 512.
1443  *
1444  * Note: The first step of any CUBRID application is to initialize a
1445  * database. A database is composed of data volumes (or Unix file
1446  * system files), database backup files, and log files. A data
1447  * volume contains information on attributes, classes, indexes,
1448  * and objects created in the database. A database backup is a
1449  * fuzzy snapshot of the entire database. The backup is fuzzy
1450  * since it can be taken online when other transactions are
1451  * updating the database. The logs contain records that reflects
1452  * changes to the database. The log and backup files are used by
1453  * the system to recover committed and uncommitted transactions
1454  * in the event of system and media crashes. Logs are also used
1455  * to support user-initiated rollbacks.
1456  *
1457  * The rest of this function is identical to the restart. A
1458  * transaction for the current client session is automatically
1459  * started.
1460  */
1461 int
1462 xboot_initialize_server (const BOOT_CLIENT_CREDENTIAL * client_credential, BOOT_DB_PATH_INFO * db_path_info,
1463  bool db_overwrite, const char *file_addmore_vols, volatile DKNPAGES db_npages,
1464  PGLENGTH db_desired_pagesize, volatile DKNPAGES log_npages, PGLENGTH db_desired_log_page_size,
1465  OID * rootclass_oid, HFID * rootclass_hfid, int client_lock_wait,
1466  TRAN_ISOLATION client_isolation)
1467 {
1468  volatile int tran_index = NULL_TRAN_INDEX;
1469  const char *log_prefix = NULL;
1470  DB_INFO *db = NULL;
1471  DB_INFO *dir = NULL;
1472  volatile int dbtxt_vdes = NULL_VOLDES;
1473  char db_pathbuf[PATH_MAX];
1474  char vol_real_path[PATH_MAX];
1475  char log_pathbuf[PATH_MAX];
1476  char lob_pathbuf[LOB_PATH_PREFIX_MAX + PATH_MAX];
1477  char dbtxt_label[PATH_MAX];
1478  char fixed_pathbuf[PATH_MAX];
1479  char original_namebuf[PATH_MAX];
1480 #if defined (NDEBUG)
1481  char format[BOOT_FORMAT_MAX_LENGTH];
1482 #endif
1483  int error_code;
1484  void (*old_ctrl_c_handler) (int sig_no) = SIG_ERR;
1485  struct stat stat_buf;
1486  bool is_exist_volume;
1487  const char *db_path, *log_path, *lob_path;
1488  char *p;
1489  THREAD_ENTRY *thread_p = NULL;
1490 
1491  assert (client_credential != NULL);
1492  assert (db_path_info != NULL);
1493 
1494 #if defined(SERVER_MODE)
1495  if (lang_init () != NO_ERROR)
1496  {
1497  if (er_errid () == NO_ERROR)
1498  {
1499  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOC_INIT, 1, "Failed to initialize language module");
1500  }
1501  goto exit_on_error;
1502  }
1503 
1504  /* initialize time zone data, optional module */
1505  if (tz_load () != NO_ERROR)
1506  {
1507  if (er_errid () == NO_ERROR)
1508  {
1509  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_TZ_LOAD_ERROR, 1, "Failed to initialize timezone module");
1510  }
1511  goto exit_on_error;
1512  }
1513 
1514  /* open the system message catalog, before prm_ ? */
1515  if (msgcat_init () != NO_ERROR)
1516  {
1517  /* need an appropriate error */
1519  goto exit_on_error;
1520  }
1521 
1523  {
1525  goto exit_on_error;
1526  }
1527 
1528  area_init ();
1529  error_code = set_area_init ();
1530  if (error_code != NO_ERROR)
1531  {
1532  goto exit_on_error;
1533  }
1534  error_code = pr_area_init ();
1535  if (error_code != NO_ERROR)
1536  {
1537  goto exit_on_error;
1538  }
1539  error_code = tp_init ();
1540  if (error_code != NO_ERROR)
1541  {
1542  goto exit_on_error;
1543  }
1544 
1545  /* Initialize tsc-timer */
1546  tsc_init ();
1547 
1548  /* Clear error structure */
1549  er_clear ();
1550 #endif /* SERVER_MODE */
1551 
1552 #if defined(CUBRID_DEBUG)
1553  if ((int) strlen (ROOTCLASS_NAME) > DB_SIZEOF (boot_Db_parm->rootclass_name))
1554  {
1557  "xboot_initialize_server: ** SYSTEM COMPILATION ERROR **"
1558  " Length (i.e., %d) of ROOTCLASS_NAME(i.e, %s) is bigger than"
1559  " length (i.e., %d) of bo_Dbparm->rootclass_name field", strlen (ROOTCLASS_NAME) + 1,
1560  ROOTCLASS_NAME, DB_SIZEOF (boot_Db_parm->rootclass_name));
1561  /* Destroy everything */
1562  goto exit_on_error;
1563  }
1564 #endif /* CUBRID_DEBUG */
1565 
1566  if (client_credential->db_name.empty ())
1567  {
1569  goto exit_on_error;
1570  }
1571 
1572  /*
1573  * Make sure that the db_path and log_path and lob_path are the canonicalized
1574  * absolute pathnames
1575  */
1576 
1577  memset (db_pathbuf, 0, sizeof (db_pathbuf));
1578  memset (log_pathbuf, 0, sizeof (log_pathbuf));
1579  memset (lob_pathbuf, 0, sizeof (lob_pathbuf));
1580 
1581  /*
1582  * for db path,
1583  * convert to absolute path, remove useless PATH_SEPARATOR
1584  */
1585  db_path = db_path_info->db_path;
1586  if (realpath (db_path, fixed_pathbuf) != NULL)
1587  {
1588  db_path = fixed_pathbuf;
1589  }
1590  else
1591  {
1593  goto exit_on_error;
1594  }
1595  boot_remove_useless_path_separator (db_path, db_pathbuf);
1596  db_path = db_pathbuf;
1597 
1598  /*
1599  * for log path,
1600  * convert to absolute path, remove useless PATH_SEPARATOR
1601  */
1602  log_path = db_path_info->log_path;
1603  if (realpath (log_path, fixed_pathbuf) != NULL)
1604  {
1605  log_path = fixed_pathbuf;
1606  }
1607  else
1608  {
1610  goto exit_on_error;
1611  }
1612  boot_remove_useless_path_separator (log_path, log_pathbuf);
1613 
1614  /*
1615  * for lob path,
1616  * convert to absolute path, remove useless PATH_SEPARATOR
1617  */
1618  lob_path = db_path_info->lob_path;
1619  if (es_get_type (lob_path) == ES_NONE)
1620  {
1621  snprintf (lob_pathbuf, sizeof (lob_pathbuf), "%s%s", LOB_PATH_DEFAULT_PREFIX, lob_path);
1622  p = strchr (lob_pathbuf, ':') + 1;
1623  }
1624  else
1625  {
1626  p = strchr (strcpy (lob_pathbuf, lob_path), ':') + 1;
1627  }
1628  lob_path = p;
1629 
1630  if (lob_path == NULL)
1631  {
1633  return NULL_TRAN_INDEX;
1634  }
1635 
1636  if (es_get_type (lob_pathbuf) == ES_POSIX)
1637  {
1638 #if defined (WINDOWS)
1639  if (realpath (lob_path, fixed_pathbuf) != NULL
1640  && (stat (fixed_pathbuf, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)))
1641 #else
1642  if (realpath (lob_path, fixed_pathbuf) != NULL)
1643 #endif
1644  {
1645  lob_path = fixed_pathbuf;
1646  }
1647  else
1648  {
1650  if (mkdir (lob_path, 0777) < 0)
1651  {
1652  cub_dirname_r (lob_path, fixed_pathbuf, PATH_MAX);
1653  er_set_with_oserror (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "POSIX", fixed_pathbuf);
1654  goto exit_on_error;
1655  }
1656  }
1657  boot_remove_useless_path_separator (lob_path, p);
1658  }
1659 
1660  /*
1661  * Compose the full name of the database
1662  */
1663  if (snprintf (boot_Db_full_name, sizeof (boot_Db_full_name), "%s%c%s", db_pathbuf, PATH_SEPARATOR,
1664  client_credential->get_db_name ()) < 0)
1665  {
1666  assert_release (false);
1667  }
1668 
1669  /*
1670  * Initialize error structure, critical section, slotted page, heap, and
1671  * recovery managers
1672  */
1673 
1674 #if defined(SERVER_MODE)
1676 #endif /* SERVER_MODE */
1677 
1678  /* If the server is already restarted, shutdown the server */
1679  if (BO_IS_SERVER_RESTARTED ())
1680  {
1681  // not sure this can be true
1682  if (thread_p == NULL)
1683  {
1684  thread_p = thread_get_thread_entry_info ();
1685  }
1686  (void) xboot_shutdown_server (thread_p, ER_ALL_FINAL);
1687  assert (thread_p == NULL);
1688  }
1689 
1690  log_prefix = fileio_get_base_file_name (client_credential->get_db_name ());
1691 
1692  /*
1693  * Find logging information to create the log volume. If the page size is
1694  * not the same as the one in production mode, adjust the number of pages
1695  * allocated.
1696  */
1697 
1698  if (db_npages <= 0)
1699  {
1700  db_npages = (DKNPAGES) (prm_get_bigint_value (PRM_ID_DB_VOLUME_SIZE) / db_desired_pagesize);
1701  }
1702 
1703  if (log_npages <= 0)
1704  {
1705  log_npages = (DKNPAGES) (prm_get_bigint_value (PRM_ID_LOG_VOLUME_SIZE) / db_desired_log_page_size);
1706  }
1707 
1708  if (log_npages < 10)
1709  {
1710  log_npages = 10;
1711  }
1712 
1713  /* *INDENT-OFF* */
1714  cubthread::initialize (thread_p);
1715  error_code = cubthread::initialize_thread_entries ();
1716  if (error_code != NO_ERROR)
1717  {
1718  ASSERT_ERROR ();
1719  goto exit_on_error;
1720  }
1721  /* *INDENT-ON* */
1722 
1723  /*
1724  * get the database directory information in write mode.
1725  */
1726 
1727  if (cfg_maycreate_get_directory_filename (dbtxt_label) == NULL
1728 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
1729 /* Temporary fix for NT file locking problem */
1730  || (dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) == NULL_VOLDES
1731 #endif /* !WINDOWS || DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
1732  )
1733  {
1734  goto exit_on_error;
1735  }
1736 
1737  if (dbtxt_vdes != NULL_VOLDES)
1738  {
1739  if (cfg_read_directory_ex (dbtxt_vdes, &dir, true) != NO_ERROR)
1740  {
1741  goto exit_on_error;
1742  }
1743  }
1744  else
1745  {
1746  if (cfg_read_directory (&dir, true) != NO_ERROR)
1747  {
1748  goto exit_on_error;
1749  }
1750  }
1751 
1752  if (dir != NULL && ((db = cfg_find_db_list (dir, client_credential->get_db_name ())) != NULL))
1753  {
1754  if (db_overwrite == false)
1755  {
1756  /* There is a database with the same name and we cannot overwrite it */
1758  goto exit_on_error;
1759  }
1760  else
1761  {
1762  /*
1763  * Delete the database.. to make sure that all backups, log archives, and
1764  * so on are removed... then continue...
1765  *
1766  * Note: we do not call xboot_delete since it shuttdown the system and
1767  * update database.txt that we have a read copy of its content.
1768  */
1769 
1770  /* Note: for database replacement, we need to remove the old database with its original path! */
1771  memset (original_namebuf, 0, sizeof (original_namebuf));
1772 
1773  /* Compose the original full name of the database */
1774  snprintf (original_namebuf, sizeof (original_namebuf), "%s%c%s", db->pathname, PATH_SEPARATOR, db->name);
1775 
1776  error_code = boot_remove_all_volumes (thread_p, original_namebuf, db->logpath, log_prefix, false, true);
1777  if (error_code != NO_ERROR)
1778  {
1779  goto exit_on_error;
1780  }
1781  }
1782  }
1783 
1784  if (dbtxt_vdes != NULL_VOLDES)
1785  {
1786  fileio_dismount (thread_p, dbtxt_vdes); /* unlock the directory file */
1787  dbtxt_vdes = NULL_VOLDES;
1788  cfg_free_directory (dir);
1789  dir = NULL;
1790  }
1791 
1792  error_code =
1793  logpb_check_exist_any_volumes (thread_p, boot_Db_full_name, log_pathbuf, log_prefix, vol_real_path,
1794  &is_exist_volume);
1795  if (error_code != NO_ERROR || is_exist_volume)
1796  {
1797  goto exit_on_error;
1798  }
1799 
1800 #if !defined(WINDOWS)
1801  if (db_path_info->vol_path != NULL)
1802  {
1803  if (realpath ((char *) db_path_info->vol_path, vol_real_path) == NULL)
1804  {
1806  goto exit_on_error;
1807  }
1808  else
1809  {
1810  if (stat (vol_real_path, &stat_buf) != 0 /* file not exist */
1811  || S_ISDIR (stat_buf.st_mode))
1812  { /* is directory */
1814  goto exit_on_error;
1815  }
1816  (void) unlink (boot_Db_full_name);
1817  if (symlink (vol_real_path, boot_Db_full_name) != 0)
1818  {
1820  goto exit_on_error;
1821  }
1822  }
1823  }
1824 #endif /* !WINDOWS */
1825 
1826  (void) db_set_page_size (db_desired_pagesize, db_desired_log_page_size);
1827 
1828  if ((int) strlen (boot_Db_full_name) > DB_MAX_PATH_LENGTH - 1)
1829  {
1830  /* db_path + db_name is too long */
1832  client_credential->get_db_name (), strlen (boot_Db_full_name), DB_MAX_PATH_LENGTH - 1);
1833  goto exit_on_error;
1834  }
1835 
1836  old_ctrl_c_handler = os_set_signal_handler (SIGINT, boot_ctrl_c_in_init_server);
1837 
1838 #if !defined(WINDOWS)
1839  boot_Init_server_is_canceled = (_setjmp (boot_Init_server_jmpbuf) != 0);
1840 #endif
1841 
1842  if (!boot_Init_server_is_canceled)
1843  {
1844  tran_index =
1845  boot_create_all_volumes (thread_p, client_credential, db_path_info->db_comments, db_npages, file_addmore_vols,
1846  log_pathbuf, (const char *) log_prefix, log_npages, client_lock_wait,
1847  client_isolation);
1848 
1849  if (tran_index != NULL_TRAN_INDEX && !boot_Init_server_is_canceled)
1850  {
1851 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
1852  dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true);
1853  if (dbtxt_vdes == NULL_VOLDES)
1854  {
1855  goto exit_on_error;
1856  }
1857 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
1858 
1859  if (dbtxt_vdes != NULL_VOLDES)
1860  {
1861  if (cfg_read_directory_ex (dbtxt_vdes, &dir, true) != NO_ERROR)
1862  {
1863  goto exit_on_error;
1864  }
1865  }
1866  else
1867  {
1868  if (cfg_read_directory (&dir, true) != NO_ERROR)
1869  {
1870  goto exit_on_error;
1871  }
1872  }
1873 
1874  db = cfg_find_db_list (dir, client_credential->get_db_name ());
1875 
1876  /* Now create the entry in the database table */
1877  if (db == NULL)
1878  {
1879  db =
1880  cfg_add_db (&dir, client_credential->get_db_name (), db_pathbuf, log_pathbuf, lob_pathbuf,
1881  db_path_info->db_host);
1882  }
1883  else
1884  {
1885  cfg_update_db (db, db_pathbuf, log_pathbuf, lob_pathbuf, db_path_info->db_host);
1886  }
1887 
1888  if (db == NULL || db->name == NULL || db->pathname == NULL || db->logpath == NULL || db->lobpath == NULL
1889  || db->hosts == NULL)
1890  {
1891  goto exit_on_error;
1892  }
1893 
1894 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
1895  /* Under Windows/NT, it appears that locking a file prevents a subsequent open for write by the same process.
1896  * The cfg_write_directory will never succeed as long as the file is "mounted" by fileio_mount(). To allow
1897  * the cubrid.db file to be updated, dismount before calling cfg_. Note that this leaves an extremely small
1898  * windows where another process could steal our lock. */
1899  if (dbtxt_vdes != NULL_VOLDES)
1900  {
1901  fileio_dismount (thread_p, dbtxt_vdes);
1902  dbtxt_vdes = NULL_VOLDES;
1903  }
1904 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
1905 
1906  if (dbtxt_vdes != NULL_VOLDES)
1907  {
1908  cfg_write_directory_ex (dbtxt_vdes, dir);
1909  }
1910  else
1911  {
1912  cfg_write_directory (dir);
1913  }
1914  cfg_free_directory (dir);
1915  dir = NULL;
1916 
1917  if (dbtxt_vdes != NULL_VOLDES)
1918  {
1919  fileio_dismount (thread_p, dbtxt_vdes);
1920  dbtxt_vdes = NULL_VOLDES;
1921  }
1922  }
1923  }
1924 
1925  if (tran_index == NULL_TRAN_INDEX || boot_Init_server_is_canceled)
1926  {
1927  (void) boot_remove_all_volumes (thread_p, boot_Db_full_name, log_pathbuf, (const char *) log_prefix, true, true);
1928  if (boot_Init_server_is_canceled)
1929  {
1931  }
1932  else
1933  {
1934  if (db_path_info->vol_path != NULL)
1935  {
1936  (void) unlink (boot_Db_full_name);
1937  }
1939  client_credential->get_db_name (), er_get_msglog_filename ());
1940  }
1941 
1942  goto exit_on_error;
1943  }
1944 
1945  rootclass_oid->volid = boot_Db_parm->rootclass_oid.volid;
1946  rootclass_oid->pageid = boot_Db_parm->rootclass_oid.pageid;
1947  rootclass_oid->slotid = boot_Db_parm->rootclass_oid.slotid;
1948  if (boot_find_root_heap (rootclass_hfid) != NO_ERROR || HFID_IS_NULL (rootclass_hfid))
1949  {
1950  goto exit_on_error;
1951  }
1952 
1953  // sessions state is required to continue
1954  session_states_init (thread_p);
1955 
1956  /* print_version string */
1957 #if defined (NDEBUG)
1960  fprintf (stdout, format, rel_name (), rel_build_number ());
1961 #else /* NDEBUG */
1962  fprintf (stdout, "\n%s (%s) (%d %s build)\n\n", rel_name (), rel_build_number (), rel_bit_platform (),
1963  rel_build_type ());
1964 #endif /* !NDEBUG */
1965 
1966  if (old_ctrl_c_handler != SIG_ERR)
1967  {
1968  (void) os_set_signal_handler (SIGINT, old_ctrl_c_handler);
1969  }
1970 
1971  return tran_index;
1972 
1973 exit_on_error:
1974 
1975  if (old_ctrl_c_handler != SIG_ERR)
1976  {
1977  (void) os_set_signal_handler (SIGINT, old_ctrl_c_handler);
1978  }
1979 
1980  /* Destroy everything */
1981  if (dir)
1982  {
1983  cfg_free_directory (dir);
1984  }
1985 
1986  if (dbtxt_vdes != NULL_VOLDES)
1987  {
1988  fileio_dismount (thread_p, dbtxt_vdes);
1989  }
1990 
1991  if (tran_index != NULL_TRAN_INDEX)
1992  {
1993  logtb_release_tran_index (thread_p, tran_index);
1994  log_final (thread_p);
1995  }
1996 
1997  er_stack_push ();
1999  er_stack_pop ();
2000 
2001  // and now finalize thread entry
2003 
2004  return NULL_TRAN_INDEX;
2005 }
2006 
2007 static int
2009 {
2010  int err;
2011  UINT32 t;
2012  unsigned char ip[4];
2013 
2014  t = (UINT32) time (NULL);
2015  memcpy (boot_Server_session_key, &t, sizeof (UINT32));
2016  err = css_hostname_to_ip (boot_Host_name, ip);
2017  if (err != NO_ERROR)
2018  {
2019  ASSERT_ERROR ();
2020  return err;
2021  }
2022  boot_Server_session_key[4] = ip[0];
2023  boot_Server_session_key[5] = ip[1];
2024  boot_Server_session_key[6] = ip[2];
2025  boot_Server_session_key[7] = ip[3];
2026  return NO_ERROR;
2027 }
2028 
2029 /*
2030  * boot_restart_server () - restart server
2031  *
2032  * return : NO_ERROR if all OK, ER_ status otherwise
2033  *
2034  * print_restart(in): Flag which indicates if the version of CUBRID server
2035  * is printed at the end of the restart process.
2036  * db_name(in): Database Name
2037  * from_backup(in): Execute the restart from a backup..
2038  * check_db_coll(in): True if check DB collations with system collations
2039  * r_args(in): restart argument structure contains various options
2040  *
2041  * Note: The CUBRID server is restarted. Recovery process, no
2042  * related to media failures (i.e., disk crashes), takes place
2043  * during the restart process.
2044  */
2045 int
2046 boot_restart_server (THREAD_ENTRY * thread_p, bool print_restart, const char *db_name, bool from_backup,
2047  CHECK_ARGS * check_coll_and_timezone, BO_RESTART_ARG * r_args, bool skip_vacuum)
2048 {
2049  char log_path[PATH_MAX];
2050  const char *log_prefix;
2051  DB_INFO *db = NULL;
2052  DB_INFO *dir = NULL;
2053 #if defined (NDEBUG)
2054  char format[BOOT_FORMAT_MAX_LENGTH];
2055 #endif
2056  int tran_index = NULL_TRAN_INDEX;
2057  int dbtxt_vdes = NULL_VOLDES;
2058  char dbtxt_label[PATH_MAX];
2059 #if defined(SERVER_MODE)
2060  HA_MODE common_ha_mode;
2061 #endif
2062  int error_code = NO_ERROR;
2063  char *prev_err_msg;
2064  INTL_CODESET db_charset_db_header = INTL_CODESET_NONE;
2065  INTL_CODESET db_charset_db_root = INTL_CODESET_NONE;
2066  char db_lang[LANG_MAX_LANGNAME + 1];
2067  char timezone_checksum[32 + 1];
2068  const TZ_DATA *tzd;
2069  char *mk_path;
2070  int jsp_port;
2071  bool jsp;
2072 
2073  /* language data is loaded in context of server */
2074  if (lang_init () != NO_ERROR)
2075  {
2076  if (er_errid () == NO_ERROR)
2077  {
2078  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOC_INIT, 1, "Failed to initialize language module");
2079  }
2080  error_code = ER_LOC_INIT;
2081  goto error;
2082  }
2083 
2084  /* initialize time zone data, optional module */
2085  if (tz_load () != NO_ERROR)
2086  {
2087  if (er_errid () == NO_ERROR)
2088  {
2089  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_TZ_LOAD_ERROR, 1, "Failed to initialize timezone module");
2090  }
2091  error_code = ER_TZ_LOAD_ERROR;
2092  goto error;
2093  }
2094 
2095  if (msgcat_init () != NO_ERROR)
2096  {
2099  goto error;
2100  }
2101 
2102 #if defined(SERVER_MODE)
2104  {
2106  error_code = ER_BO_CANT_LOAD_SYSPRM;
2107  goto error;
2108  }
2109 
2110  common_ha_mode = HA_GET_MODE ();
2111 #endif /* SERVER_MODE */
2112 
2113  if (db_name == NULL)
2114  {
2116  error_code = ER_BO_UNKNOWN_DATABASE;
2117  goto error;
2118  }
2119 
2120  /*
2121  * Make sure that there is a database.txt and that the desired database
2122  * exists. We do not want to lock the database.txt at this point since we
2123  * are only reading it. However, if we do not find the desired database,
2124  * we must lock the file to make sure that we got a consistent view of
2125  * database.txt (database.txt is written from scratch when it is updated).
2126  * That is, don't complain that a database does not exist until we have
2127  * a lock of database.txt
2128  */
2129 
2130  if (cfg_read_directory (&dir, false) != NO_ERROR)
2131  {
2132  if (er_errid () == NO_ERROR)
2133  {
2135  }
2136  error_code = ER_CFG_NO_FILE;
2137  goto error;
2138  }
2139 
2140  if (dir == NULL || ((db = cfg_find_db_list (dir, db_name)) == NULL))
2141  {
2142  /*
2143  * Make sure that nobody was in the process of writing the
2144  * database.txt when we got a snapshot of it.
2145  */
2146  if (dir != NULL)
2147  {
2148  cfg_free_directory (dir);
2149  dir = NULL;
2150  }
2151 
2152  if (cfg_maycreate_get_directory_filename (dbtxt_label) != NULL
2153 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
2154 /* Temporary fix for NT file locking problem */
2155  && (dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) != NULL_VOLDES
2156 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
2157  )
2158  {
2159  if (dbtxt_vdes != NULL_VOLDES)
2160  {
2161  if (cfg_read_directory_ex (dbtxt_vdes, &dir, false) == NO_ERROR)
2162  {
2163  db = cfg_find_db_list (dir, db_name);
2164  }
2165  }
2166  else
2167  {
2168  if (cfg_read_directory (&dir, false) == NO_ERROR)
2169  {
2170  db = cfg_find_db_list (dir, db_name);
2171  }
2172  }
2173 
2174  fileio_dismount (thread_p, dbtxt_vdes);
2175  dbtxt_vdes = NULL_VOLDES;
2176  }
2177  if (db == NULL)
2178  {
2180  error_code = ER_BO_UNKNOWN_DATABASE;
2181  goto error;
2182  }
2183  }
2184 
2186  {
2187  strcpy (boot_Host_name, "(unknown)");
2188  }
2189  boot_Host_name[CUB_MAXHOSTNAMELEN - 1] = '\0'; /* bullet proof */
2190 
2192  error_code = boot_make_session_server_key ();
2193  if (error_code != NO_ERROR)
2194  {
2195  ASSERT_ERROR ();
2196  goto error;
2197  }
2198 
2199  if (boot_volume_info_log_path (log_path) == NULL)
2200  {
2201  strcpy (log_path, db->logpath);
2202  }
2203 
2204  if (db->lobpath != NULL)
2205  {
2206  strlcpy (boot_Lob_path, db->lobpath, sizeof (boot_Lob_path));
2207  }
2208  else
2209  {
2210  boot_Lob_path[0] = '\0';
2211  }
2212 
2213  /*
2214  * Initialize error structure, critical section, slotted page, heap, and
2215  * recovery managers
2216  */
2217 #if defined(SERVER_MODE)
2219  {
2221  error_code = ER_BO_CANT_LOAD_SYSPRM;
2222  goto error;
2223  }
2224 
2225  if (common_ha_mode != prm_get_integer_value (PRM_ID_HA_MODE) && !HA_DISABLED ())
2226  {
2228  prm_get_name (PRM_ID_HA_MODE), css_ha_mode_string (common_ha_mode), db_name,
2231  goto error;
2232  }
2233 
2234  /* reinit msg catalog to reflect PRM_MAX_THREADS */
2235  msgcat_final ();
2236  if (msgcat_init () != NO_ERROR)
2237  {
2239  goto error;
2240  }
2241 
2242  error_code = css_init_conn_list ();
2243  if (error_code != NO_ERROR)
2244  {
2245  goto error;
2246  }
2247 
2248  error_code = perfmon_initialize (MAX_NTRANS);
2249  if (error_code != NO_ERROR)
2250  {
2251  ASSERT_ERROR ();
2252  goto error;
2253  }
2254 
2255  /* note that thread entry was re-initialized */
2256  thread_p = thread_get_thread_entry_info ();
2257  assert (thread_p != NULL);
2258 
2260  {
2261  error_code = ER_FAILED;
2262  goto error;
2263  }
2264  er_clear ();
2265 
2266  event_log_init (db_name);
2267 
2268  /* initialize allocations areas for things we need, on the client, most of this is done inside ws_init(). */
2269  area_init ();
2270  error_code = set_area_init ();
2271  if (error_code != NO_ERROR)
2272  {
2273  goto error;
2274  }
2275  error_code = pr_area_init ();
2276  if (error_code != NO_ERROR)
2277  {
2278  goto error;
2279  }
2280 
2282 
2283  /* initialize the type/doain module (also sets up an area) */
2284  error_code = tp_init ();
2285  if (error_code != NO_ERROR)
2286  {
2287  goto error;
2288  }
2289 
2290  /* Initialize tsc-timer */
2291  tsc_init ();
2292 #endif /* !SERVER_MODE */
2293 
2294 
2295 #if defined (SA_MODE)
2296  // Initialize java stored procedure server for standalone mode
2298  if (jsp)
2299  {
2301  error_code = jsp_start_server (db_name, db->pathname, jsp_port);
2302  if (error_code != NO_ERROR)
2303  {
2304  goto error;
2305  }
2306  }
2307 
2308  /* *INDENT-OFF* */
2309  // thread_manager was not initialized
2310  assert (thread_p == NULL);
2311  cubthread::initialize (thread_p);
2312  assert (thread_p == thread_get_thread_entry_info ());
2313 #endif // SA_MODE
2314  error_code = cubthread::initialize_thread_entries ();
2315  if (error_code != NO_ERROR)
2316  {
2317  goto error;
2318  }
2319  /* *INDENT-ON* */
2320 
2322 
2323  /*
2324  * Compose the full name of the database and find location of logs
2325  */
2326 
2327  log_prefix = fileio_get_base_file_name (db_name);
2328 
2329  /* The database pagesize is set by log_get_io_page_size */
2330 
2331  if (log_get_io_page_size (thread_p, boot_Db_full_name, log_path, log_prefix) == -1)
2332  {
2333  if (from_backup == false || er_errid () == ER_IO_MOUNT_LOCKED)
2334  {
2335  error_code = ER_FAILED;
2336  goto error;
2337  }
2338  }
2339 
2340  /* Initialize the transaction table */
2341  logtb_define_trantable (thread_p, -1, -1);
2342 
2343  /*
2344  * How to restart the system ?
2345  */
2346  if (from_backup != false)
2347  {
2348  /*
2349  * RESTART FROM BACKUP
2350  */
2351 #if defined(SA_MODE)
2352  if (r_args->restore_slave)
2353  {
2354  (void) logpb_remove_all_in_log_path (thread_p, boot_Db_full_name, log_path, log_prefix);
2355  }
2356 #endif /* SA_MODE */
2357  error_code = logpb_restore (thread_p, boot_Db_full_name, log_path, log_prefix, r_args);
2358  if (error_code != NO_ERROR)
2359  {
2360  goto error;
2361  }
2362  }
2363 
2364  spage_boot (thread_p);
2365  error_code = heap_manager_initialize ();
2366  if (error_code != NO_ERROR)
2367  {
2368  goto error;
2369  }
2370 
2371  /*
2372  * Now continue the normal restart process. At this point the data volumes
2373  * are ok. However, some recovery may need to take place
2374  */
2375 
2376  /* Mount the data volume */
2377  error_code = boot_mount (thread_p, LOG_DBFIRST_VOLID, boot_Db_full_name, NULL);
2378  if (error_code != NO_ERROR)
2379  {
2380  goto error;
2381  }
2382 
2383  /* Find the location of the database parameters and read them */
2384  if (disk_get_boot_hfid (thread_p, LOG_DBFIRST_VOLID, &boot_Db_parm->hfid) == NULL)
2385  {
2386  error_code = ER_FAILED;
2387  goto error;
2388  }
2389 
2390  error_code = boot_get_db_parm (thread_p, boot_Db_parm, boot_Db_parm_oid);
2391  if (error_code != NO_ERROR)
2392  {
2393  goto error;
2394  }
2395 
2396  error_code = tde_cipher_initialize (thread_p, &boot_Db_parm->tde_keyinfo_hfid,
2397  r_args == NULL ? NULL : r_args->keys_file_path);
2398  if (error_code != NO_ERROR)
2399  {
2401  error_code = NO_ERROR;
2402  }
2403 
2404  /* we need to manually add root class HFID to cache */
2405  error_code =
2406  heap_cache_class_info (thread_p, &boot_Db_parm->rootclass_oid, &boot_Db_parm->rootclass_hfid, FILE_HEAP,
2407  boot_Db_parm->rootclass_name);
2408  if (error_code != NO_ERROR)
2409  {
2410  assert_release (false);
2411  goto error;
2412  }
2413 
2414  db_charset_db_header = boot_get_db_charset_from_header (thread_p, log_path, log_prefix);
2415  if (db_charset_db_header <= INTL_CODESET_NONE || INTL_CODESET_LAST < db_charset_db_header)
2416  {
2417  char er_msg[ERR_MSG_SIZE];
2418  snprintf (er_msg, sizeof (er_msg) - 1,
2419  "Cannot find a valid charset in log header or first volume header or different values have "
2420  "been found");
2422  error_code = ER_LOC_INIT;
2423  goto error;
2424  }
2425  else
2426  {
2427  lang_set_charset (db_charset_db_header);
2428  }
2429 
2430  /* Find the rest of the volumes and mount them */
2431 
2432  error_code = boot_find_rest_volumes (thread_p, from_backup ? r_args : NULL, LOG_DBFIRST_VOLID, boot_mount, NULL);
2433  if (error_code != NO_ERROR)
2434  {
2435  goto error;
2436  }
2437 
2438  /* initialize disk manager */
2439  error_code = disk_manager_init (thread_p, true);
2440  if (error_code != NO_ERROR)
2441  {
2442  ASSERT_ERROR ();
2443  goto error;
2444  }
2445 
2446  error_code = logtb_initialize_global_unique_stats_table (thread_p);
2447  if (error_code != NO_ERROR)
2448  {
2449  goto error;
2450  }
2451 
2452  error_code = file_tracker_load (thread_p, &boot_Db_parm->trk_vfid);
2453  if (error_code != NO_ERROR)
2454  {
2455  ASSERT_ERROR ();
2456  goto error;
2457  }
2458  catalog_initialize (&boot_Db_parm->ctid);
2459 
2461  {
2462  /* We need to load vacuum data and initialize vacuum routine before recovery. */
2463  error_code =
2464  vacuum_initialize (thread_p, boot_Db_parm->vacuum_log_block_npages, &boot_Db_parm->vacuum_data_vfid,
2465  &boot_Db_parm->dropped_files_vfid, r_args != NULL && r_args->is_restore_from_backup);
2466  if (error_code != NO_ERROR)
2467  {
2468  goto error;
2469  }
2470  }
2471 
2472  oid_set_root (&boot_Db_parm->rootclass_oid);
2473 
2474  /* Load and recover data pages before log recovery */
2475  error_code = dwb_load_and_recover_pages (thread_p, log_path, log_prefix);
2476  if (error_code != NO_ERROR)
2477  {
2478  ASSERT_ERROR ();
2479  goto error;
2480  }
2481 
2482  /*
2483  * Now restart the recovery manager and execute any recovery actions
2484  */
2485 
2486  log_initialize (thread_p, boot_Db_full_name, log_path, log_prefix, from_backup, r_args);
2487 
2488  error_code = boot_after_copydb (thread_p); // only does something if this is first boot after copydb
2489  if (error_code != NO_ERROR)
2490  {
2491  ASSERT_ERROR ();
2492  goto error;
2493  }
2494 
2495 #if defined(SERVER_MODE)
2496  pgbuf_daemons_init ();
2497  dwb_daemons_init ();
2498 #endif /* SERVER_MODE */
2499 
2500  // after recovery we can boot vacuum
2501  error_code = vacuum_boot (thread_p);
2502  if (error_code != NO_ERROR)
2503  {
2504  ASSERT_ERROR ();
2505  goto error;
2506  }
2507 
2508  /*
2509  * Initialize the catalog manager, the query evaluator, and install meta
2510  * classes
2511  */
2512 
2513  error_code = locator_initialize (thread_p);
2514  if (error_code != NO_ERROR)
2515  {
2516  error_code = ER_FAILED;
2517  goto error;
2518  }
2519 
2520  error_code = catcls_find_and_set_cached_class_oid (thread_p);
2521  if (error_code != NO_ERROR)
2522  {
2523  goto error;
2524  }
2525 
2526  error_code = xcache_initialize (thread_p);
2527  if (error_code != NO_ERROR)
2528  {
2529  ASSERT_ERROR ();
2530  goto error;
2531  }
2532 
2533  if (qmgr_initialize (thread_p) != NO_ERROR)
2534  {
2535  error_code = ER_FAILED;
2536  goto error;
2537  }
2538 
2539  error_code = qfile_initialize_list_cache (thread_p);
2540  if (error_code != NO_ERROR)
2541  {
2542  goto error;
2543  }
2544 
2545  error_code = fpcache_initialize (thread_p);
2546  if (error_code != NO_ERROR)
2547  {
2548  ASSERT_ERROR ();
2549  goto error;
2550  }
2551 
2552  /*
2553  * Initialize system locale using values from db_root system table
2554  */
2555  error_code =
2556  catcls_get_server_compat_info (thread_p, &db_charset_db_root, db_lang, sizeof (db_lang) - 1, timezone_checksum);
2557 
2558  if (error_code != NO_ERROR)
2559  {
2560  goto error;
2561  }
2562 
2563  if (db_charset_db_header != db_charset_db_root)
2564  {
2565  char er_msg[ERR_MSG_SIZE];
2566  snprintf (er_msg, sizeof (er_msg) - 1, "Invalid charset in db_root system table: expecting %s, found %s",
2567  lang_charset_cubrid_name (db_charset_db_header), lang_charset_cubrid_name (db_charset_db_root));
2569  error_code = ER_LOC_INIT;
2570  goto error;
2571  }
2572 
2573  error_code = lang_set_language (db_lang);
2574  if (error_code != NO_ERROR)
2575  {
2576  goto error;
2577  }
2578 
2579  /* Check server timezone checksum versus database checksum */
2580  if (check_coll_and_timezone->check_timezone == true)
2581  {
2582  tzd = tz_get_data ();
2583  assert (tzd != NULL);
2584 
2585  error_code = check_timezone_compat (tzd->checksum, timezone_checksum, "server", "database");
2586  if (error_code != NO_ERROR)
2587  {
2588  goto error;
2589  }
2590  }
2591 
2592 #if defined (SERVER_MODE)
2593  /* Cache serial index BTID. */
2594  /* Note that workspace manager is unavailable when restarting from backup. It is possible to allow SA_MODE
2595  * executables except restoredb to use the function, however, it is better not to use it in SA_MODE for clarity. */
2596  error_code = serial_cache_index_btid (thread_p);
2597  if (error_code != NO_ERROR)
2598  {
2599  goto error;
2600  }
2601 #endif /* SERVER_MODE */
2602 
2603  /*
2604  * Allocate a temporary transaction index to finish further system related
2605  * changes such as removal of temporary volumes and modifications of
2606  * system parameter
2607  */
2608 
2609  /* todo: I am not sure we really need a transaction here. but since we are hurrying to release 10.1 and we don't have
2610  * time to do changes that may have a significant impact on database behavior, I'd rather keep this for now.
2611  * We should rethink the boot_Db_parm implementation altogether and we can come back to this when we do it. */
2612  tran_index =
2615  if (tran_index == NULL_TRAN_INDEX)
2616  {
2617  error_code = ER_FAILED;
2618  goto error;
2619  }
2620 
2621  /*
2622  * Remove any database temporary volumes
2623  */
2624 
2626 
2627  if (boot_Lob_path[0] != '\0')
2628  {
2629  error_code = es_init (boot_Lob_path);
2630  if (error_code != NO_ERROR)
2631  {
2632  goto error;
2633  }
2634  }
2635  else
2636  {
2638  }
2639 
2640  if (xtran_server_commit (thread_p, false) != TRAN_UNACTIVE_COMMITTED)
2641  {
2642  assert_release (false);
2643  error_code = ER_FAILED;
2644  goto error;
2645  }
2646  logtb_free_tran_index (thread_p, tran_index);
2647  tran_index = NULL_TRAN_INDEX;
2648  logtb_set_to_system_tran_index (thread_p);
2649 
2651  {
2653  }
2654 
2656  {
2657  if (catcls_Enable != true)
2658  {
2659  error_code = catcls_compile_catalog_classes (thread_p);
2660  if (error_code != NO_ERROR)
2661  {
2663  goto error;
2664  }
2665  }
2666  }
2667 
2668  /* check server collations with database collations */
2669  if (check_coll_and_timezone->check_db_coll == true)
2670  {
2671  LANG_COLL_COMPAT *db_collations = NULL;
2672  int db_coll_cnt;
2673 
2674  error_code = catcls_get_db_collation (thread_p, &db_collations, &db_coll_cnt);
2675  if (error_code != NO_ERROR)
2676  {
2677  if (db_collations != NULL)
2678  {
2679  db_private_free (thread_p, db_collations);
2680  }
2681  goto error;
2682  }
2683 
2684  if (db_collations != NULL)
2685  {
2686  error_code = lang_check_coll_compat (db_collations, db_coll_cnt, "server", "database");
2687  db_private_free (thread_p, db_collations);
2688  if (error_code != NO_ERROR)
2689  {
2690  goto error;
2691  }
2692  }
2693  }
2694 
2695 #if defined (SA_MODE)
2696  /* Completely vacuum database. */
2697  if (r_args == NULL || r_args->is_restore_from_backup == false)
2698  {
2699  er_clear (); /* forget any warning or error to start vacuumming */
2700  if (!skip_vacuum)
2701  {
2702  xvacuum (thread_p);
2703  }
2704  }
2705 #endif
2706 
2707  /* read only mode ? */
2709  {
2710  logtb_disable_update (NULL);
2711  }
2712 
2713  error_code = serial_initialize_cache_pool (thread_p);
2714  if (error_code != NO_ERROR)
2715  {
2716  goto error;
2717  }
2718 
2719  session_states_init (thread_p);
2720 
2721 #if defined (SERVER_MODE)
2722  if (prm_get_bool_value (PRM_ID_ACCESS_IP_CONTROL) == true && from_backup == false)
2723  {
2724  error_code = css_set_accessible_ip_info ();
2725  if (error_code != NO_ERROR)
2726  {
2727  goto error;
2728  }
2729  }
2730 #endif
2731 
2732 #if defined (SERVER_MODE)
2733  /* set number of hosts */
2735  /* set server's starting mode for HA according to the 'ha_mode' parameter */
2738 #endif
2739 
2740  /* initialize partitions cache */
2741  error_code = partition_cache_init (thread_p);
2742  if (error_code != NO_ERROR)
2743  {
2744  goto error;
2745  }
2746 
2747  cfg_free_directory (dir);
2748 
2749  if (print_restart)
2750  {
2751 #if defined (NDEBUG)
2754  fprintf (stdout, format, rel_name ());
2755 #else /* NDEBUG */
2756  fprintf (stdout, "\n%s (%s) (%d %s build)\n\n", rel_name (), rel_build_number (), rel_bit_platform (),
2757  rel_build_type ());
2758 #endif /* !NDEBUG */
2759  }
2760 
2761  if (from_backup == true)
2762  {
2763  log_set_ha_promotion_time (thread_p, 0);
2764  log_set_db_restore_time (thread_p, (INT64) (time (0)));
2765  }
2766 
2767  /* server status could be changed by css_change_ha_server_state */
2769  {
2770  /* server is up! */
2772  }
2773 #if !defined(SA_MODE)
2774  json_set_alloc_funcs (malloc, free);
2775 #endif
2776 
2777  return NO_ERROR;
2778 
2779 error:
2780  if (dir != NULL)
2781  {
2782  cfg_free_directory (dir);
2783  dir = NULL;
2784  }
2785  prev_err_msg = (char *) er_msg ();
2786  if (prev_err_msg != NULL)
2787  {
2788  prev_err_msg = strdup (prev_err_msg);
2790  free_and_init (prev_err_msg);
2791  }
2792  else
2793  {
2795  }
2796 
2797  if (tran_index != NULL_TRAN_INDEX)
2798  {
2799  logtb_free_tran_index (thread_p, tran_index);
2800  }
2801 
2802  session_states_finalize (thread_p);
2804 
2805  vacuum_stop_workers (thread_p);
2806  vacuum_stop_master (thread_p);
2807 
2808 #if defined(SERVER_MODE)
2809  pgbuf_daemons_destroy ();
2810  dwb_daemons_destroy ();
2811 #endif
2812 
2813  log_final (thread_p);
2814  fpcache_finalize (thread_p);
2815  qfile_finalize_list_cache (thread_p);
2816  xcache_finalize (thread_p);
2817 
2818 #if defined(SERVER_MODE)
2820 #endif
2821 
2822  er_stack_push ();
2824  er_stack_pop ();
2825 
2826 #if defined (SA_MODE)
2828 #endif /* SA_MODE */
2829 
2830  return error_code;
2831 }
2832 
2833 /*
2834  * xboot_restart_from_backup () - restore the database system from backup.
2835  * used for media crash recovery
2836  *
2837  * return : Transaction index
2838  *
2839  * print_restart(in): Flag which indicates if the version of CUBRID server
2840  * is printed at the end of the restart process.
2841  * db_name(in): Database Name
2842  * r_args(in): restart argument structure contains various options
2843  *
2844  * Note: The database is restored from its backup and from all archive
2845  * and active logs with information recoded since the backup. If
2846  * these files are not actually placed in the location of the log
2847  * files, the system will request those files.
2848  */
2849 int
2850 xboot_restart_from_backup (THREAD_ENTRY * thread_p, int print_restart, const char *db_name, BO_RESTART_ARG * r_args)
2851 {
2852  CHECK_ARGS check_coll_and_timezone = { true, true };
2853 
2854  if (lang_init () != NO_ERROR)
2855  {
2856  if (er_errid () == NO_ERROR)
2857  {
2858  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOC_INIT, 1, "Failed to initialize language module");
2859  }
2860  return NULL_TRAN_INDEX;
2861  }
2862 
2863  /* initialize time zone data, optional module */
2864  if (tz_load () != NO_ERROR)
2865  {
2866  if (er_errid () == NO_ERROR)
2867  {
2868  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_TZ_LOAD_ERROR, 1, "Failed to initialize timezone module");
2869  }
2870  return NULL_TRAN_INDEX;
2871  }
2872 
2873  /* open the system message catalog, before prm_ ? */
2874  if (msgcat_init () != NO_ERROR)
2875  {
2877  return NULL_TRAN_INDEX;
2878  }
2879 
2880  /* initialize system parameters */
2882  {
2883  return NULL_TRAN_INDEX;
2884  }
2885 
2887 
2888  /*
2889  * We need to do some initialization that normally happens in
2890  * boot_restart_server(), but only if the SERVER_MODE CPP variable is
2891  * defined. Unfortunately, if we're here, then SERVER_MODE is not defined
2892  * so call the important initializers ourselves.
2893  *
2894  * Initialize allocations areas for things we need
2895  * Initialize the type/doain module (also sets up an area)
2896  */
2897 
2898  area_init ();
2899 
2900  if (tp_init () != NO_ERROR)
2901  {
2902  return NULL_TRAN_INDEX;
2903  }
2904 
2905  if (boot_restart_server (thread_p, print_restart, db_name, true, &check_coll_and_timezone, r_args, false) != NO_ERROR)
2906  {
2907  return NULL_TRAN_INDEX;
2908  }
2909  else
2910  {
2911  if (tde_Cipher.is_loaded)
2912  {
2913  if (boot_reset_mk_after_restart_from_backup (thread_p, r_args) != NO_ERROR)
2914  {
2915  return NULL_TRAN_INDEX;
2916  }
2917  }
2918  return LOG_FIND_THREAD_TRAN_INDEX (thread_p);
2919  }
2920 }
2921 
2922 /*
2923  * boot_reset_mk_after_restart_from_backup () - Reset after restarting from a backup volume
2924  *
2925  * return : Error code
2926  * thread_p (in) : Thread entry
2927  * r_args(in) : Restart argument structure contains various options
2928  *
2929  * There might be no proper master key after restoring database
2930  * even if we have a server mk file and the backup mk file (in the case of timed restore).
2931  *
2932  * There are several cases but we simplify it into two case:
2933  * (1) The master key set on the database can be found in the server _keys file
2934  * (2) not (1), which means no server mk file or no master key in the server mk file.
2935  *
2936  * For (1), we do nothing.
2937  * For (2), we copy backup mk file as the server mk file and set the first key in the key file
2938  * as the master key for database.
2939  */
2940 int
2942 {
2943  TDE_KEYINFO keyinfo;
2944  char mk_path[PATH_MAX] = { 0, };
2945  char mk_path_old[PATH_MAX] = { 0, };
2946  char ctime_buf[CTIME_MAX];
2947  unsigned char master_key[TDE_MASTER_KEY_LENGTH];
2948  time_t created_time;
2949  int mk_index;
2950  int server_mk_vdes = NULL_VOLDES;
2951  int backup_mk_vdes = NULL_VOLDES;
2952  int err = NO_ERROR;
2953 
2955 
2956  if (thread_p == NULL)
2957  {
2958  thread_p = thread_get_thread_entry_info ();
2959  }
2960 
2961  err = tde_get_keyinfo (thread_p, &keyinfo);
2962  if (err != NO_ERROR)
2963  {
2964  goto exit;
2965  }
2966 
2967  /* Check the mk file on the server */
2968  tde_make_keys_file_fullname (mk_path, boot_db_full_name (), false);
2969 
2970  server_mk_vdes = fileio_mount (thread_p, boot_db_full_name (), mk_path, LOG_DBTDE_KEYS_VOLID, 2, false);
2971  if (server_mk_vdes != NULL_VOLDES && tde_validate_keys_file (server_mk_vdes))
2972  {
2973  err = tde_load_mk (server_mk_vdes, &keyinfo, master_key);
2974  if (err == NO_ERROR)
2975  {
2976  /* case (1): There is the master key in the server key file:
2977  * Nothing to do */
2978  goto exit;
2979  }
2980  }
2981 
2982  /*
2983  * case (2):
2984  * There isn't the key set on the database in the server key file,
2985  * So we just copy the backup file as a new server key file
2986  * and set the first key in the file as the master key.
2987  */
2988 
2989  /* No need to mount. The mk file from backup is not accessed by others */
2990  backup_mk_vdes = fileio_open (r_args->keys_file_path, O_RDWR, 0600);
2991  if (backup_mk_vdes == NULL_VOLDES)
2992  {
2993  /* not expected. if it doens't exist, loading tde must have failed and this function shoudn't have been called. */
2994  assert (false);
2995  ASSERT_ERROR_AND_SET (err);
2996  goto exit;
2997  }
2998 
2999  if (tde_validate_keys_file (backup_mk_vdes) == false)
3000  {
3001  /* not expected. if it is not valid, loading tde must have failed and this function shoudn't have been called. */
3002  assert (false);
3005  goto exit;
3006  }
3007 
3008  err = tde_find_first_mk (backup_mk_vdes, &mk_index, master_key, &created_time);
3009  if (err != NO_ERROR)
3010  {
3011  goto exit;
3012  }
3013 
3014  fileio_close (backup_mk_vdes);
3015  backup_mk_vdes = NULL_VOLDES;
3016 
3017  /* if a server key file exists, move it */
3018  if (server_mk_vdes != NULL_VOLDES)
3019  {
3021 
3022  strcpy (mk_path_old, mk_path);
3023  strcat (mk_path_old, "_old");
3024  fileio_unformat_and_rename (thread_p, mk_path, mk_path_old);
3025  server_mk_vdes = NULL_VOLDES;
3026 
3028  }
3029 
3030  err = tde_copy_keys_file (thread_p, mk_path, r_args->keys_file_path, false, false);
3031  if (err != NO_ERROR)
3032  {
3033  goto exit;
3034  }
3035 
3037 
3038  err = tde_change_mk (thread_p, mk_index, master_key, created_time);
3039  if (err != NO_ERROR)
3040  {
3041  goto exit;
3042  }
3043 
3044  ctime_r (&keyinfo.created_time, ctime_buf);
3046  mk_index);
3047 
3048  if (xtran_server_commit (thread_p, false) != TRAN_UNACTIVE_COMMITTED)
3049  {
3050  ASSERT_ERROR ();
3051  err = er_errid ();
3052  goto exit;
3053  }
3054 
3055 exit:
3056  if (server_mk_vdes != NULL_VOLDES)
3057  {
3058  fileio_dismount (thread_p, server_mk_vdes);
3059  }
3060  if (backup_mk_vdes != NULL_VOLDES)
3061  {
3062  fileio_close (backup_mk_vdes);
3063  }
3064  return err;
3065 }
3066 
3067 /*
3068  * xboot_shutdown_server () - shutdown CUBRID server
3069  *
3070  * return : true
3071  *
3072  * thread_p (in/out) : input thread entry; outputs NULL if thread is finalized (SA_MODE)
3073  * is_er_final(in): Terminate the error module..
3074  *
3075  * Note: All active transactions of all clients are aborted and the
3076  * CUBRID server is terminated. Any database temporarily volume
3077  * is destroyed.
3078  */
3079 bool
3081 {
3082  if (!BO_IS_SERVER_RESTARTED ())
3083  {
3084  return true;
3085  }
3086 
3087 #if defined(CUBRID_DEBUG)
3088  boot_check_db_at_num_shutdowns (true);
3089 #endif /* CUBRID_DEBUG */
3090 
3092 
3093  /* Shutdown the system with the system transaction */
3094  logtb_set_to_system_tran_index (thread_p);
3096  vacuum_stop_workers (thread_p);
3097 
3098  /* before removing temp vols */
3100  qfile_finalize_list_cache (thread_p);
3101  xcache_finalize (thread_p);
3102  fpcache_finalize (thread_p);
3103  session_states_finalize (thread_p);
3104 
3106 
3107  // ha delays are registered and logged, and must be stopped before vacuum master
3109 
3110  // only after all logging is finished can this vacuum master be stopped; boot_remove_all_temp_volumes may add a final
3111  // log entry
3112  // hopefully, nothing else follows
3113  vacuum_stop_master (thread_p);
3114 
3115 #if defined(SERVER_MODE)
3116  pgbuf_daemons_destroy ();
3117 #endif
3118 
3119 #if defined (SA_MODE)
3120  vacuum_sa_reflect_last_blockid (thread_p);
3121 #endif // SA_MODE
3122  log_final (thread_p);
3123 
3124  /* Since all pages were flushed, now it's safe to destroy DWB. */
3125  (void) dwb_destroy (thread_p);
3126 
3127  if (is_er_final == ER_ALL_FINAL)
3128  {
3130  }
3131  else
3132  {
3133  er_stack_push ();
3135  er_stack_pop ();
3136  }
3137 
3138 #if defined (SA_MODE)
3139  // stop thread module
3141  thread_p = NULL;
3142 #endif // SA_MODE
3143 
3144  return true;
3145 }
3146 
3147 /*
3148  * xboot_get_server_session_key ()
3149  */
3150 const char *
3152 {
3153  return boot_Server_session_key;
3154 }
3155 
3156 /*
3157  * xboot_register_client () - register a client
3158  *
3159  * return : transaction index or NULL_TRAN_INDEX in the case of error.
3160  *
3161  * client_credential(in): Client's credential (see boot.h)
3162  * client_lock_wait(in): Wait for at least this number of milliseconds to acquire
3163  * a lock. Negative value is infinite
3164  * client_isolation(in): Isolation level. One of the following:
3165  * TRAN_REPEATABLE_READ
3166  * TRAN_READ_COMMITTED
3167  * TRAN_SERIALIZABLE
3168  * tran_state(out): State of transaction
3169  * server_credential(out): Server's credential (see boot.h)
3170  *
3171  * Note: If the CUBRID server is not already restarted, it is
3172  * restarted. The calling client is registered and a transaction
3173  * index is assigned to the client. If the last transaction
3174  * executed on behalf of the client has client loose ends
3175  * recovery tasks, such transaction is assigned to the client and
3176  * and the transaction state is returned as a side effect.
3177  */
3178 int
3179 xboot_register_client (THREAD_ENTRY * thread_p, BOOT_CLIENT_CREDENTIAL * client_credential, int client_lock_wait,
3180  TRAN_ISOLATION client_isolation, TRAN_STATE * tran_state,
3181  BOOT_SERVER_CREDENTIAL * server_credential)
3182 {
3183  // *INDENT-OFF*
3184  int tran_index;
3185  std::string db_user_save;
3186  char db_user_upper[DB_MAX_IDENTIFIER_LENGTH] = { '\0' };
3187  bool skip_vacuum = false;
3188 #if defined(SA_MODE)
3189  std::string adm_prg_file_name;
3190  CHECK_ARGS check_coll_and_timezone = { true, true };
3191 #endif /* SA_MODE */
3192  // *INDENT-ON*
3193 
3194 #if defined(SA_MODE)
3195  if (client_credential != NULL && !client_credential->program_name.empty ()
3196  && client_credential->client_type == DB_CLIENT_TYPE_ADMIN_UTILITY)
3197  {
3198  auto const sep_index = client_credential->program_name.find_last_of (PATH_SEPARATOR);
3199  if (sep_index != client_credential->program_name.npos)
3200  {
3201  adm_prg_file_name = client_credential->program_name.substr (sep_index + 1);
3202  }
3203  else
3204  {
3205  adm_prg_file_name = client_credential->program_name;
3206  }
3207  }
3208  if (!adm_prg_file_name.empty ())
3209  {
3210  if (strncasecmp (adm_prg_file_name.c_str (), "synccolldb", strlen ("synccolldb")) == 0
3211  || strncasecmp (adm_prg_file_name.c_str (), "migrate_", strlen ("migrate_")) == 0)
3212  {
3213  check_coll_and_timezone.check_db_coll = false;
3214  }
3215  if (strncasecmp (adm_prg_file_name.c_str (), "gen_tz", strlen ("gen_tz")) == 0)
3216  {
3217  check_coll_and_timezone.check_timezone = false;
3218  }
3219  }
3220 
3221  if (client_credential->client_type == DB_CLIENT_TYPE_SKIP_VACUUM_CSQL
3222  || client_credential->client_type == DB_CLIENT_TYPE_SKIP_VACUUM_ADMIN_CSQL)
3223  {
3224  skip_vacuum = true;
3225  }
3226 
3227  /* If the server is not restarted, restart the server at this moment */
3228  if (!BO_IS_SERVER_RESTARTED ()
3229  && boot_restart_server (thread_p, false, client_credential->get_db_name (), false, &check_coll_and_timezone,
3230  NULL, skip_vacuum) != NO_ERROR)
3231  {
3232  *tran_state = TRAN_UNACTIVE_UNKNOWN;
3233  return NULL_TRAN_INDEX;
3234  }
3235 #else /* SA_MODE */
3236  /* If the server is not restarted, returns an error */
3237  if (!BO_IS_SERVER_RESTARTED ())
3238  {
3239  *tran_state = TRAN_UNACTIVE_UNKNOWN;
3240  return NULL_TRAN_INDEX;
3241  }
3242 #endif /* SA_MODE */
3243 
3244  /* Initialize scan function pointers of show statements */
3245  showstmt_scan_init ();
3246 
3247  db_user_save = client_credential->get_db_user ();
3248  if (!client_credential->db_user.empty ())
3249  {
3250  intl_identifier_upper (client_credential->get_db_user (), db_user_upper);
3251  client_credential->db_user = db_user_upper;
3252  }
3253 
3254  /* Assign a transaction index to the client */
3255  tran_index =
3256  logtb_assign_tran_index (thread_p, NULL_TRANID, TRAN_ACTIVE, client_credential, tran_state, client_lock_wait,
3257  client_isolation);
3258 #if defined (SERVER_MODE)
3259  if (thread_p->conn_entry->status != CONN_OPEN)
3260  {
3261  /* the connection is going down. stop it */
3262  logtb_release_tran_index (thread_p, tran_index);
3263  tran_index = NULL_TRAN_INDEX;
3264  }
3265 #endif /* SERVER_MODE */
3266 
3267  if (tran_index != NULL_TRAN_INDEX)
3268  {
3269 #if defined (SERVER_MODE)
3270  thread_p->conn_entry->set_tran_index (tran_index);
3271 #endif /* SERVER_MODE */
3272  server_credential->db_full_name = boot_Db_full_name;
3273  server_credential->host_name = boot_Host_name;
3274  server_credential->lob_path = boot_Lob_path;
3275  server_credential->process_id = getpid ();
3276  COPY_OID (&server_credential->root_class_oid, &boot_Db_parm->rootclass_oid);
3277  if (boot_find_root_heap (&(server_credential->root_class_hfid)) != NO_ERROR
3278  || HFID_IS_NULL (&(server_credential->root_class_hfid)))
3279  {
3280  *tran_state = TRAN_UNACTIVE_UNKNOWN;
3281  return NULL_TRAN_INDEX;
3282  }
3283 
3284  server_credential->page_size = IO_PAGESIZE;
3285  server_credential->log_page_size = LOG_PAGESIZE;
3286  server_credential->disk_compatibility = rel_disk_compatible ();
3287 #if defined (SERVER_MODE)
3288  server_credential->ha_server_state = css_ha_server_state ();
3289 #else
3291 #endif
3293  server_credential->db_charset = lang_charset ();
3294  server_credential->db_lang = (char *) lang_get_Lang_name ();
3295 
3296 #if defined(SERVER_MODE)
3297  /* Check the server's state for HA action for this client */
3298  if (BOOT_NORMAL_CLIENT_TYPE (client_credential->client_type))
3299  {
3300  if (css_check_ha_server_state_for_client (thread_p, 1) != NO_ERROR)
3301  {
3302  logtb_release_tran_index (thread_p, tran_index);
3303  er_log_debug (ARG_FILE_LINE, "xboot_register_client: css_check_ha_server_state_for_client() error\n");
3304  *tran_state = TRAN_UNACTIVE_UNKNOWN;
3305  client_credential->db_user = db_user_save;
3306  return NULL_TRAN_INDEX;
3307  }
3308  }
3309  if (client_credential->client_type == DB_CLIENT_TYPE_LOG_APPLIER)
3310  {
3312  }
3313 #endif /* SERVER_MODE */
3314 
3316  client_credential->get_program_name (),
3317  client_credential->process_id, client_credential->get_host_name (), tran_index);
3318  }
3319 
3320 #if defined(ENABLE_SYSTEMTAP) && defined(SERVER_MODE)
3321  CUBRID_CONN_START (thread_p->conn_entry->client_id, client_credential->get_db_user ());
3322 #endif /* ENABLE_SYSTEMTAP */
3323 
3324  client_credential->db_user = db_user_save;
3325  return tran_index;
3326 }
3327 
3328 /*
3329  * xboot_unregister_client () - unregister a client
3330  *
3331  * return : NO_ERROR if all OK, ER_ status otherwise
3332  *
3333  * thread_p (in/out) : input thread entry; outputs NULL if thread is finalized (SA_MODE)
3334  * tran_index(in): Client transaction index
3335  *
3336  * Note: A client is unregistered. Any active transactions on that
3337  * client are aborted. This function is called when a client is
3338  * disconnected or when a crash of the client is detected by the
3339  * CUBRID server, to release resources acquired such as locks,
3340  * and allocated memory, on behalf of the client.
3341  */
3342 int
3343 xboot_unregister_client (REFPTR (THREAD_ENTRY, thread_p), int tran_index)
3344 {
3345  int save_index;
3346  LOG_TDES *tdes;
3347 #if defined(SERVER_MODE)
3348  int client_id;
3349  CSS_CONN_ENTRY *conn;
3350 #endif /* SERVER_MODE */
3351 
3352  if (BO_IS_SERVER_RESTARTED () && tran_index != NULL_TRAN_INDEX)
3353  {
3354  save_index = LOG_FIND_THREAD_TRAN_INDEX (thread_p);
3355 
3356  LOG_SET_CURRENT_TRAN_INDEX (thread_p, tran_index);
3357  tdes = LOG_FIND_TDES (tran_index);
3358 #if defined(SERVER_MODE)
3359  conn = thread_p->conn_entry;
3360  client_id = (conn != NULL) ? conn->client_id : -1;
3361  if (tdes == NULL || tdes->client_id != client_id)
3362  {
3363  thread_p->tran_index = save_index;
3364 
3365 #if defined(ENABLE_SYSTEMTAP)
3366  CUBRID_CONN_END (-1, "NULL");
3367 #endif /* ENABLE_SYSTEMTAP */
3368 
3369  return NO_ERROR;
3370  }
3371 
3372  /* check if the client was a log applier */
3374  {
3376  }
3377  /* Check the server's state for HA action for this client */
3379  {
3380  if (css_check_ha_server_state_for_client (thread_p, 2) != NO_ERROR)
3381  {
3382  er_log_debug (ARG_FILE_LINE, "xboot_unregister_client: css_check_ha_server_state_for_client() error\n");
3383  }
3384  }
3385 #else
3386  if (tdes == NULL)
3387  {
3388 #if defined(ENABLE_SYSTEMTAP)
3389  CUBRID_CONN_END (-1, "NULL");
3390 #endif /* ENABLE_SYSTEMTAP */
3391 
3392  return NO_ERROR;
3393  }
3394 #endif /* SERVER_MODE */
3395 
3396  /* If the transaction is active abort it */
3397  if (LOG_ISTRAN_ACTIVE (tdes)) /* logtb_is_current_active (thread_p) */
3398  {
3399  (void) xtran_server_abort (thread_p);
3400  }
3401 
3402  perfmon_stop_watch (thread_p);
3403 
3404 #if defined(ENABLE_SYSTEMTAP) && defined(SERVER_MODE)
3405  CUBRID_CONN_END (client_id, tdes->client.get_db_user ());
3406 #endif /* ENABLE_SYSTEMTAP */
3407 
3408  /* Release the transaction index */
3409  logtb_release_tran_index (thread_p, tran_index);
3410 
3411  LOG_SET_CURRENT_TRAN_INDEX (thread_p, save_index);
3412  }
3413 
3414 #if defined(CUBRID_DEBUG)
3415  boot_check_db_at_num_shutdowns (false);
3416 #endif /* CUBRID_DEBUG */
3417 
3418 #if defined(SA_MODE)
3419  (void) xboot_shutdown_server (thread_p, ER_ALL_FINAL);
3420 #endif /* SA_MODE */
3421 
3422  return NO_ERROR;
3423 }
3424 
3425 #if defined(SERVER_MODE)
3426 /*
3427  * xboot_notify_unregister_client () -
3428  *
3429  * return :
3430  *
3431  * tran_index(in) :
3432  *
3433  * Note:
3434  */
3435 void
3436 xboot_notify_unregister_client (THREAD_ENTRY * thread_p, int tran_index)
3437 {
3438  CSS_CONN_ENTRY *conn;
3439  LOG_TDES *tdes;
3440  int client_id;
3441 
3442  conn = thread_p->conn_entry;
3443 
3444  /* sboot_notify_unregister_client should hold conn->rmutex.
3445  * Please see the comment of sboot_notify_unregister_client.
3446  */
3447 
3448  client_id = conn->client_id;
3449  tdes = LOG_FIND_TDES (tran_index);
3450  if (tdes != NULL && tdes->client_id == client_id)
3451  {
3452  if (conn->status == CONN_OPEN)
3453  {
3454  conn->status = CONN_CLOSING;
3455  }
3456  }
3457 }
3458 #endif /* SERVER_MODE */
3459 
3460 #if defined(CUBRID_DEBUG)
3461 /*
3462  * boot_check_db_at_num_shutdowns () - run checkdb when a number of client
3463  * shutdowns has been executed.
3464  * This is a debugging function.
3465  *
3466  * force_nshutdowns(in): true if only forcing is desired.
3467  *
3468  * Note: Run checkdb when a number of client shutdowns has been
3469  * executed (at the same or across several server sessions) and
3470  * the env variable CUBRID_CHECKDB_ATNUM_SHUTDOWNS has a value
3471  * greater than zero at the server process. The environment value
3472  * indicates when to execute the checkdb.
3473  *
3474  * Side-effect: A file with the name ".checkdb_num_shutdowns" is created to
3475  * to save the number of client shutdowns. This file is removed
3476  * once the above env variable is not set.
3477  * Note this file is not associated with a particular database.
3478  * Therefore, the file could be modified (and removed) by several
3479  * servers (databases). This will work OK, for most practical
3480  * purposes. No a good reason, why it was implemented this way.
3481  * The author was lazy and it was for debugging only.
3482  */
3483 static void
3484 boot_check_db_at_num_shutdowns (bool force_nshutdowns)
3485 {
3486  const char *env_value;
3487  const char *checkdb_file_num_shutdowns = ".checkdb_num_shutdowns";
3488  FILE *fp;
3489  static int checkdb_every_nshutdowns = -1;
3490  static int num_current_shutdowns = -1;
3491 
3492  if (force_nshutdowns == true)
3493  {
3494  if (checkdb_every_nshutdowns > 0 && (fp = fopen (checkdb_file_num_shutdowns, "w")) != NULL)
3495  {
3496  fprintf (fp, "%d", num_current_shutdowns);
3497  fclose (fp);
3498  }
3499  return;
3500  }
3501 
3502  /*
3503  * Check the consistency of the database when the client is unregister
3504  */
3505 
3506  if (checkdb_every_nshutdowns == -1)
3507  {
3508  env_value = envvar_get ("CHECKDB_EVERY_NSHUTDOWNS");
3509  if (env_value != NULL)
3510  {
3511  checkdb_every_nshutdowns = atoi (env_value);
3512  }
3513  else
3514  {
3515  checkdb_every_nshutdowns = 0;
3516  }
3517 
3518  if (checkdb_every_nshutdowns <= 0)
3519  {
3520  checkdb_every_nshutdowns = 0; /* Don't check at all */
3521  (void) remove (checkdb_file_num_shutdowns);
3522  return;
3523  }
3524 
3525  fp = fopen (checkdb_file_num_shutdowns, "r");
3526  if (fp != NULL)
3527  {
3528  if (fscanf (fp, "%d", &num_current_shutdowns) != 1)
3529  {
3530  num_current_shutdowns = 0;
3531  }
3532  }
3533  else
3534  {
3535  num_current_shutdowns = 0;
3536  }
3537  }
3538 
3539  if (checkdb_every_nshutdowns > 0)
3540  {
3541  num_current_shutdowns++;
3542 
3543  if (num_current_shutdowns == checkdb_every_nshutdowns)
3544  {
3545  num_current_shutdowns = 0;
3547  {
3548  const char *tmpname;
3549  fflush (stderr);
3550  fflush (stdout);
3551  tmpname = er_get_msglog_filename ();
3552  if (tmpname == NULL)
3553  {
3554  tmpname = "/dev/null";
3555  }
3556  fprintf (stdout,
3557  "Some inconsistencies were detected in your database.\n Please consult error_log file = %s"
3558  " for additional information\n", tmpname);
3559  fflush (stdout);
3560  /*
3561  * The following is added so we can attach to the debugger on
3562  * a fatal error. It is of great help to stop execution when
3563  * running a set of sql scripts. (That is, find the script that
3564  * leave the DB inconsistent).
3565  */
3567  }
3568  }
3569  }
3570 }
3571 #endif /* CUBRID_DEBUG */
3572 
3573 enum
3574 {
3577 };
3578 
3579 /*
3580  * xboot_checkdb_table () - check consistency of table
3581  * as much as possible
3582  *
3583  * return :
3584  *
3585  */
3587 xboot_checkdb_table (THREAD_ENTRY * thread_p, int check_flag, OID * oid, BTID * index_btid)
3588 {
3589  int error_code;
3590  HFID hfid;
3591  bool repair = check_flag & CHECKDB_REPAIR;
3592  DISK_ISVALID allvalid, valid;
3593  HEAP_SCANCACHE scan_cache;
3594  RECDES peek_recdes;
3595 
3596  allvalid = DISK_VALID;
3597 
3598  if (check_flag & CHECKDB_CHECK_PREV_LINK)
3599  {
3600  valid = btree_repair_prev_link (thread_p, oid, index_btid, CHECK_ONLY);
3601  if (valid == DISK_ERROR)
3602  {
3603  return DISK_ERROR;
3604  }
3605  if (valid != DISK_VALID)
3606  {
3607  allvalid = valid;
3608  }
3609  }
3610 
3611  if (check_flag & CHECKDB_REPAIR_PREV_LINK)
3612  {
3613  valid = btree_repair_prev_link (thread_p, oid, index_btid, REPAIR_ALL);
3614  if (valid == DISK_ERROR)
3615  {
3616  return DISK_ERROR;
3617  }
3618  if (valid != DISK_VALID)
3619  {
3620  allvalid = valid;
3621  }
3622  }
3623 
3624  if (heap_get_class_info (thread_p, oid, &hfid, NULL, NULL) != NO_ERROR || HFID_IS_NULL (&hfid))
3625  {
3626  return DISK_ERROR;
3627  }
3628 
3629  if (index_btid == NULL)
3630  {
3631  /* if index name was specified, skip checking heap file */
3633  {
3634  return DISK_ERROR;
3635  }
3636  error_code = heap_scancache_quick_start_root_hfid (thread_p, &scan_cache);
3637  if (error_code != NO_ERROR)
3638  {
3639  lock_unlock_object (thread_p, oid, oid_Root_class_oid, IS_LOCK, true);
3640  return DISK_ERROR;
3641  }
3642  /* Check heap file is really exist. It can be removed. */
3643  if (heap_get_class_record (thread_p, oid, &peek_recdes, &scan_cache, PEEK) != S_SUCCESS)
3644  {
3645  heap_scancache_end (thread_p, &scan_cache);
3646  lock_unlock_object (thread_p, oid, oid_Root_class_oid, IS_LOCK, true);
3647  return DISK_ERROR;
3648  }
3649  heap_scancache_end (thread_p, &scan_cache);
3650 
3651  valid = heap_check_heap_file (thread_p, &hfid);
3652  if (valid == DISK_ERROR)
3653  {
3654  lock_unlock_object (thread_p, oid, oid_Root_class_oid, IS_LOCK, true);
3655  return DISK_ERROR;
3656  }
3657  if (valid != DISK_VALID)
3658  {
3659  allvalid = valid;
3660  }
3661 
3662  lock_unlock_object (thread_p, oid, oid_Root_class_oid, IS_LOCK, true);
3663  }
3664 
3665  valid = btree_check_by_class_oid (thread_p, oid, index_btid);
3666  if (valid == DISK_ERROR)
3667  {
3668  return DISK_ERROR;
3669  }
3670  if (valid != DISK_VALID)
3671  {
3672  allvalid = valid;
3673  }
3674 
3675  valid = locator_check_by_class_oid (thread_p, oid, &hfid, index_btid, repair);
3676  if (valid == DISK_ERROR)
3677  {
3678  return DISK_ERROR;
3679  }
3680  if (valid != DISK_VALID)
3681  {
3682  allvalid = valid;
3683  }
3684 
3685  return allvalid;
3686 }
3687 
3688 /*
3689  * xcallback_console_print -
3690  *
3691  * return:
3692  *
3693  * print_str(in):
3694  */
3695 #if defined (SA_MODE)
3696 int
3697 xcallback_console_print (THREAD_ENTRY * thread_p, char *print_str)
3698 {
3699  fprintf (stdout, print_str);
3700 
3701  return NO_ERROR;
3702 }
3703 #endif
3704 
3705 /*
3706  * xboot_check_db_consistency () - check consistency of database
3707  * as much as possible
3708  *
3709  * return : NO_ERROR if all OK, ER_ status otherwise
3710  *
3711  */
3712 int
3713 xboot_check_db_consistency (THREAD_ENTRY * thread_p, int check_flag, OID * oids, int num_oids, BTID * index_btid)
3714 {
3715  DISK_ISVALID isvalid = DISK_VALID;
3716  int i;
3717  bool repair = check_flag & CHECKDB_REPAIR;
3718  int error_code = NO_ERROR;
3719 
3720  disk_lock_extend ();
3721  error_code = boot_check_permanent_volumes (thread_p);
3722  disk_unlock_extend ();
3723 
3724  isvalid = disk_check (thread_p, repair);
3725  if (isvalid != DISK_VALID)
3726  {
3727  ASSERT_ERROR_AND_SET (error_code);
3728  }
3729 
3730  if (index_btid != NULL && BTID_IS_NULL (index_btid))
3731  {
3732  index_btid = NULL;
3733  }
3734 
3735  if (num_oids > 0)
3736  {
3737  for (i = 0; i < num_oids; i++)
3738  {
3739  if (OID_ISNULL (&oids[i]))
3740  {
3741  continue;
3742  }
3743  isvalid = xboot_checkdb_table (thread_p, check_flag, &oids[i], index_btid);
3744 
3745  if (isvalid != DISK_VALID)
3746  {
3747  error_code = ER_FAILED;
3748  }
3749  }
3750  return error_code;
3751  }
3752 
3753  if (check_flag & CHECKDB_CHECK_PREV_LINK)
3754  {
3755  if (isvalid != DISK_ERROR)
3756  {
3757  isvalid = btree_repair_prev_link (thread_p, NULL, NULL, CHECK_ONLY);
3758  if (isvalid != DISK_VALID)
3759  {
3760  error_code = ER_FAILED;
3761  }
3762  }
3763  }
3764 
3765  if (check_flag & CHECKDB_REPAIR_PREV_LINK)
3766  {
3767  if (isvalid != DISK_ERROR)
3768  {
3769  isvalid = btree_repair_prev_link (thread_p, NULL, NULL, REPAIR_ALL);
3770  if (isvalid != DISK_VALID)
3771  {
3772  error_code = ER_FAILED;
3773  }
3774  }
3775  }
3776 
3777  if (check_flag & CHECKDB_FILE_TRACKER_CHECK)
3778  {
3779  if (isvalid != DISK_ERROR)
3780  {
3781  isvalid = file_tracker_check (thread_p);
3782  if (isvalid != DISK_VALID)
3783  {
3784  assert (isvalid != DISK_INVALID);
3785  ASSERT_ERROR_AND_SET (error_code);
3786  }
3787  }
3788  }
3789 
3790  if (check_flag & CHECKDB_HEAP_CHECK_ALLHEAPS)
3791  {
3792  if (isvalid != DISK_ERROR)
3793  {
3794  isvalid = heap_check_all_heaps (thread_p);
3795  if (isvalid != DISK_VALID)
3796  {
3797  error_code = ER_FAILED;
3798  }
3799  }
3800  }
3801 
3802  if (check_flag & CHECKDB_CT_CHECK_CAT_CONSISTENCY)
3803  {
3804  if (isvalid != DISK_ERROR)
3805  {
3806  isvalid = catalog_check_consistency (thread_p);
3807  if (isvalid != DISK_VALID)
3808  {
3809  error_code = ER_FAILED;
3810  }
3811  }
3812  }
3813 
3814  if (check_flag & CHECKDB_BTREE_CHECK_ALL_BTREES)
3815  {
3816  if (isvalid != DISK_ERROR)
3817  {
3818  isvalid = btree_check_all (thread_p);
3819  if (isvalid != DISK_VALID)
3820  {
3821  error_code = ER_FAILED;
3822  }
3823  }
3824  }
3825 
3826  if (check_flag & CHECKDB_LC_CHECK_CLASSNAMES)
3827  {
3828  if (isvalid != DISK_ERROR)
3829  {
3830  isvalid = locator_check_class_names (thread_p);
3831  if (isvalid != DISK_VALID)
3832  {
3833  error_code = ER_FAILED;
3834  }
3835  }
3836  }
3837 
3839  {
3840  if (isvalid != DISK_ERROR)
3841  {
3842  isvalid = locator_check_all_entries_of_all_btrees (thread_p, repair);
3843  if (isvalid != DISK_VALID)
3844  {
3845  error_code = ER_FAILED;
3846  }
3847  }
3848  }
3849 
3850  return error_code;
3851 }
3852 
3853 /*
3854  * boot_server_all_finalize () - terminate every single module
3855  * except the log/recovery manager
3856  * is_er_final(in): Terminate the error module..
3857  * shutdown_common_modules(in): Terminate all common modules (for SA mode)
3858  * if SERVER_MODE, this is implied BOOT_SHUTDOWN_ALL_MODULES.
3859  *
3860  * Note: Every single module except the log/recovery manager are
3861  * uninitialized. All data volumes are unmounted.
3862  */
3863 void
3865  BOOT_SERVER_SHUTDOWN_MODE shutdown_common_modules)
3866 {
3868  locator_finalize (thread_p);
3869  spage_finalize (thread_p);
3870  catalog_finalize ();
3871  qmgr_finalize (thread_p);
3872  (void) heap_manager_finalize ();
3873  perfmon_finalize ();
3874  fileio_dismount_all (thread_p);
3875  disk_manager_final ();
3877 
3880  partition_cache_finalize (thread_p);
3881 
3882  // return lock-free transaction and destroy the system.
3885 
3886 #if defined(SERVER_MODE)
3887  /* server mode shuts down all modules */
3888  shutdown_common_modules = BOOT_SHUTDOWN_ALL_MODULES;
3889 #endif /* SERVER_MODE */
3890 
3891  if (shutdown_common_modules == BOOT_SHUTDOWN_ALL_MODULES)
3892  {
3893  es_final ();
3894  tp_final ();
3895  locator_free_areas ();
3896  set_final ();
3897  sysprm_final ();
3898  area_final ();
3899  msgcat_final ();
3900  if (is_er_final == ER_ALL_FINAL)
3901  {
3903  }
3904  lang_final ();
3905  tz_unload ();
3906  }
3907 
3908 #if defined(SERVER_MODE)
3910  event_log_final ();
3911 #endif
3912 }
3913 
3914 /*
3915  * xboot_backup () - a fuzzy backup of the database
3916  *
3917  * return : NO_ERROR if all OK, ER_ status otherwise
3918  *
3919  * backup_path(in): Location where information volumes are backed up. If NULL is given, the following defaults
3920  * are assumed to back up each information volume:
3921  * - If file "fileof_vols_and_backup_paths" is given, the path to backup each volume is found in
3922  * this file.
3923  * - All information volumes are backed up on the same location where the log files are located.
3924  * backup_level(in): backup levels allowed: 0 - Full (default),
3925  * 1 - Incremental1, 2 - Incremental
3926  * deleted_unneeded_logarchives(in): Whether to remove log archives that are not needed any longer to recovery from
3927  * crashes when the backup just created is used.
3928  * backup_verbose_file(in): verbose mode file path
3929  * num_threads: number of threads
3930  * zip_method: compression method
3931  * zip_level: compression level
3932  * sleep_msecs(in):
3933  *
3934  * Note: A fuzzy backup of the database is taken. The backup is written into the given backup_path location.
3935  * If the backup_path location is omitted (i.e, NULL is given), the log path location which was specified at
3936  * database creation is used to store the backup.
3937  */
3938 int
3939 xboot_backup (THREAD_ENTRY * thread_p, const char *backup_path, FILEIO_BACKUP_LEVEL backup_level,
3940  bool delete_unneeded_logarchives, const char *backup_verbose_file, int num_threads,
3941  FILEIO_ZIP_METHOD zip_method, FILEIO_ZIP_LEVEL zip_level, int skip_activelog, int sleep_msecs,
3942  bool separate_keys)
3943 {
3944  int error_code;
3945 
3946  error_code =
3947  logpb_backup (thread_p, boot_Db_parm->nvols, backup_path, backup_level, delete_unneeded_logarchives,
3948  backup_verbose_file, num_threads, zip_method, zip_level, skip_activelog, sleep_msecs, separate_keys);
3949  return error_code;
3950 }
3951 
3952 /*
3953  * xboot_copy () - copy the database to a new destination
3954  *
3955  * return : NO_ERROR if all OK, ER_ status otherwise
3956  *
3957  * thread_p (in/out) : input thread entry; outputs NULL if thread is finalized (SA_MODE)
3958  * fromdb_name(in): The database from where the copy is made.
3959  * newdb_name(in): Name of new database
3960  * newdb_path(in): Directory where the new database will reside
3961  * newlog_path(in): Directory where the log volumes of the new database will reside
3962  * newlob_path(in): Directory where the lob volumes of the new database will reside
3963  * newdb_server_host(in): Server host where the new database reside
3964  * new_volext_path(in): A path is included if all volumes are placed in one place/directory. If NULL is given,
3965  * - If file "fileof_vols_and_wherepaths" is given, the path is found in this file.
3966  * - Each volume is copied to same place where the volume resides.
3967  * Note: This parameter should be NULL, if the above file is given.
3968  * fileof_vols_and_wherepaths(in): A file is given when the user decides to control the copy/rename of the volume by
3969  * individual bases. That is, user decides to spread the volumes over several locations
3970  * and or to label the volumes with specific names.
3971  * Each volume entry consists of: volid from_fullvolname to_fullvolname
3972  * newdb_overwrite(in): Whether to overwrite the new database if it already exist.
3973  */
3974 int
3975 xboot_copy (REFPTR (THREAD_ENTRY, thread_p), const char *from_dbname, const char *new_db_name, const char *new_db_path,
3976  const char *new_log_path, const char *new_lob_path, const char *new_db_server_host,
3977  const char *new_volext_path, const char *fileof_vols_and_copypaths, bool new_db_overwrite)
3978 {
3979  DB_INFO *dir = NULL;
3980  DB_INFO *db = NULL;
3981  const char *new_log_prefix;
3982  char new_db_fullname[PATH_MAX];
3983  char new_db_pathbuf[PATH_MAX];
3984  char new_db_pathbuf2[PATH_MAX];
3985  char new_log_pathbuf[PATH_MAX];
3986  char new_lob_pathbuf2[PATH_MAX];
3987  char new_lob_pathbuf[PATH_MAX];
3988  char new_volext_pathbuf[PATH_MAX];
3989  char fixed_pathbuf[PATH_MAX];
3990  char new_db_server_host_buf[CUB_MAXHOSTNAMELEN + 1];
3991  char dbtxt_label[PATH_MAX];
3992  int dbtxt_vdes = NULL_VOLDES;
3993  int error_code = NO_ERROR;
3994 #if defined (WINDOWS)
3995  struct stat stat_buf;
3996 #endif
3997 
3998  assert (thread_p != NULL);
3999 
4000  /* If db_path and/or log_path are NULL find the defaults */
4001 
4002  if (new_db_path == NULL || fileof_vols_and_copypaths != NULL)
4003  {
4004  /*
4005  * If a newdb path was given, it is ignored since only one option must
4006  * be specified
4007  */
4008  new_db_path = boot_find_new_db_path (new_db_pathbuf, fileof_vols_and_copypaths);
4009  if (new_db_path == NULL)
4010  {
4011  error_code = ER_FAILED;
4012  goto error;
4013  }
4014  }
4015 
4016  /*
4017  * Make sure that the db_path and log_path are the canonicalized absolute
4018  * pathnames
4019  */
4020 
4021  if (new_db_path == NULL)
4022  {
4023  new_db_path = "";
4024  }
4025  else if (realpath ((char *) new_db_path, new_db_pathbuf2) != NULL)
4026  {
4027  new_db_path = new_db_pathbuf2;
4028  }
4029 
4030  if (new_log_path != NULL && realpath ((char *) new_log_path, new_log_pathbuf) != NULL)
4031  {
4032  new_log_path = new_log_pathbuf;
4033  }
4034 
4035  if (new_log_path == NULL)
4036  {
4037  /* Assign the data volume directory */
4038  strcpy (new_log_pathbuf, new_db_path);
4039  new_log_path = new_log_pathbuf;
4040  }
4041 
4042  if (new_lob_path == NULL)
4043  {
4044  assert_release (new_db_path != NULL);
4045  if (snprintf (new_lob_pathbuf2, sizeof (new_lob_pathbuf2), "%s%s/lob", LOB_PATH_DEFAULT_PREFIX, new_db_path) < 0)
4046  {
4047  assert_release (false);
4048  }
4049  new_lob_path = new_lob_pathbuf2;
4050  }
4051 
4052  if (new_lob_path != NULL)
4053  {
4054  ES_TYPE es_type = es_get_type (new_lob_path);
4055  char *p = NULL;
4056 
4057  switch (es_type)
4058  {
4059  case ES_NONE:
4060  /* prepend default prefix */
4061  if (snprintf (new_lob_pathbuf, sizeof (new_lob_pathbuf), "%s%s", LOB_PATH_DEFAULT_PREFIX, new_lob_path) < 0)
4062  {
4063  assert_release (false);
4064  }
4065  new_lob_path = new_lob_pathbuf;
4066  es_type = ES_POSIX;
4067  p = (char *) strchr (new_lob_path, ':') + 1;
4068  break;
4069  case ES_POSIX:
4070  p = strchr (strcpy (new_lob_pathbuf, new_lob_path), ':') + 1;
4071  break;
4072  case ES_OWFS:
4073 #if !defined (CUBRID_OWFS)
4075  error_code = ER_ES_INVALID_PATH;
4076  goto error;
4077 #endif /* !CUBRID_OWFS */
4078  case ES_LOCAL:
4079  default:
4080  break;
4081  }
4082 
4083  if (es_type == ES_POSIX && p != NULL)
4084  {
4085 #if defined (WINDOWS)
4086  if (realpath (p, fixed_pathbuf) != NULL
4087  && (stat (fixed_pathbuf, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)))
4088 #else
4089  if (realpath (p, fixed_pathbuf) != NULL)
4090 #endif
4091  {
4092  strcpy (p, fixed_pathbuf);
4093  }
4094  else
4095  {
4097  if (mkdir (p, 0777) < 0)
4098  {
4099  cub_dirname_r (p, fixed_pathbuf, PATH_MAX);
4100  er_set_with_oserror (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "POSIX", fixed_pathbuf);
4101  error_code = ER_BO_DIRECTORY_DOESNOT_EXIST;
4102  goto error;
4103  }
4104  }
4105  }
4106  }
4107 
4108  if (new_volext_path != NULL && realpath ((char *) new_volext_path, new_volext_pathbuf) != NULL)
4109  {
4110  new_volext_path = new_volext_pathbuf;
4111  }
4112 
4113  /* If a host was not given, assume the current host */
4114 
4115  if (new_db_server_host == NULL)
4116  {
4117 #if 0 /* use Unix-domain socket for localhost */
4118 /* *INDENT-OFF* */
4119  if (GETHOSTNAME (new_db_server_host_buf, CUB_MAXHOSTNAMELEN) != 0)
4120  {
4122  error_code = ER_BO_UNABLE_TO_FIND_HOSTNAME;
4123  goto error;
4124  }
4125 /* *INDENT-ON* */
4126 #else
4127  strcpy (new_db_server_host_buf, "localhost");
4128 #endif
4129  new_db_server_host = new_db_server_host_buf;
4130  }
4131 
4132  /* Make sure that the full path for the new database is not too long */
4133  if ((int) (strlen (new_db_name) + strlen (new_db_path) + 2) > DB_MAX_PATH_LENGTH)
4134  {
4135  /*
4136  * db_path + db_name is too long
4137  */
4139  strlen (new_db_name) + strlen (new_db_path) + 2, DB_MAX_PATH_LENGTH);
4141  goto error;
4142  }
4143 
4144  /* Get the log prefix */
4145  new_log_prefix = fileio_get_base_file_name (new_db_name);
4146 
4147  /*
4148  * get the database directory information in write mode
4149  */
4150  if (cfg_maycreate_get_directory_filename (dbtxt_label) == NULL
4151 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4152 /* Temporary fix for NT file locking problem */
4153  || (dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) == NULL_VOLDES
4154 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4155  )
4156  {
4157  error_code = ER_FAILED;
4158  goto error;
4159  }
4160 
4161  if (dbtxt_vdes != NULL_VOLDES)
4162  {
4163  error_code = cfg_read_directory_ex (dbtxt_vdes, &dir, true);
4164  if (error_code != NO_ERROR)
4165  {
4166  goto error;
4167  }
4168  }
4169  else
4170  {
4171  error_code = cfg_read_directory (&dir, true);
4172  if (error_code != NO_ERROR)
4173  {
4174  goto error;
4175  }
4176  }
4177 
4178  if (dir != NULL && ((db = cfg_find_db_list (dir, new_db_name)) != NULL))
4179  {
4180  if (new_db_overwrite == false)
4181  {
4182  /* There is a database with the same name and we cannot overwrite it */
4184  {
4185  error_code = ER_BO_DATABASE_EXISTS;
4186  goto error;
4187  }
4188  }
4189  else
4190  {
4191  /*
4192  * Delete the database.. to make sure that all backups, log archives, and
4193  * so on are removed... then continue...
4194  * Note: we do not call xboot_delete since it reverts a bunch of stuff.
4195  */
4196  CHECK_ARGS check_col_and_timezone = { true, true };
4197  cfg_free_directory (dir);
4198  dir = NULL;
4199 
4200  if (dbtxt_vdes != NULL_VOLDES)
4201  {
4202  fileio_dismount (thread_p, dbtxt_vdes);
4203  dbtxt_vdes = NULL_VOLDES;
4204  }
4205  (void) xboot_shutdown_server (thread_p, ER_THREAD_FINAL);
4206 
4207  error_code = xboot_delete (new_db_name, true, BOOT_SHUTDOWN_EXCEPT_COMMON_MODULES);
4208  if (error_code != NO_ERROR)
4209  {
4210  goto error;
4211  }
4212  check_col_and_timezone.check_db_coll = false;
4213  error_code = boot_restart_server (thread_p, false, from_dbname, false, &check_col_and_timezone, NULL, false);
4214  if (error_code != NO_ERROR)
4215  {
4216  goto error;
4217  }
4218 
4219  // get current thread entry
4220  thread_p = thread_get_thread_entry_info ();
4221  error_code =
4222  xboot_copy (thread_p, from_dbname, new_db_name, new_db_path, new_log_path, new_lob_path, new_db_server_host,
4223  new_volext_path, fileof_vols_and_copypaths, false);
4224  assert (thread_p == NULL);
4225 
4226  return error_code;
4227  }
4228  }
4229 
4230  if (dbtxt_vdes != NULL_VOLDES)
4231  {
4232  fileio_dismount (thread_p, dbtxt_vdes); /* unlock the directory file */
4233  dbtxt_vdes = NULL_VOLDES;
4234  cfg_free_directory (dir);
4235  dir = NULL;
4236  }
4237 
4238  /*
4239  * Compose the full name of the new database
4240  */
4241 
4242  COMPOSE_FULL_NAME (new_db_fullname, sizeof (new_db_fullname), new_db_path, new_db_name);
4243 
4244  /*
4245  * Copy the database
4246  */
4247 
4248  error_code =
4249  logpb_copy_database (thread_p, boot_Db_parm->nvols, new_db_fullname, new_log_path, new_log_prefix, new_volext_path,
4250  fileof_vols_and_copypaths);
4251  if (error_code != NO_ERROR)
4252  {
4253  (void) xtran_server_abort (NULL);
4254  }
4255  else
4256  {
4257  /* Now create the entry in the database table */
4258 
4259  if (xtran_server_commit (thread_p, false) != TRAN_UNACTIVE_COMMITTED)
4260  {
4261  error_code = ER_FAILED;
4262  goto error;
4263  }
4264 
4265 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4266  dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true);
4267  if (dbtxt_vdes == NULL_VOLDES)
4268  {
4269  error_code = ER_FAILED;
4270  goto error;
4271  }
4272 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4273 
4274  if (dbtxt_vdes != NULL_VOLDES)
4275  {
4276  error_code = cfg_read_directory_ex (dbtxt_vdes, &dir, true);
4277  if (error_code != NO_ERROR)
4278  {
4279  goto error;
4280  }
4281  }
4282  else
4283  {
4284  error_code = cfg_read_directory (&dir, true);
4285  if (error_code != NO_ERROR)
4286  {
4287  goto error;
4288  }
4289  }
4290  db = cfg_find_db_list (dir, new_db_name);
4291 
4292  if (db == NULL)
4293  {
4294  db = cfg_add_db (&dir, new_db_name, new_db_path, new_log_path, new_lob_path, new_db_server_host);
4295  }
4296  else
4297  {
4299  error_code = ER_BO_DATABASE_EXISTS;
4300  goto error;
4301  }
4302 
4303  if (dbtxt_vdes != NULL_VOLDES)
4304  {
4305  cfg_write_directory_ex (dbtxt_vdes, dir);
4306  }
4307  else
4308  {
4309  cfg_write_directory (dir);
4310  }
4311 
4312 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4313  if (dbtxt_vdes != NULL_VOLDES)
4314  {
4315  fileio_dismount (thread_p, dbtxt_vdes);
4316  dbtxt_vdes = NULL_VOLDES;
4317  }
4318 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4319  }
4320 
4321  cfg_free_directory (dir);
4322  if (dbtxt_vdes != NULL_VOLDES)
4323  {
4324  fileio_dismount (thread_p, dbtxt_vdes);
4325  }
4326 
4327  (void) xboot_shutdown_server (thread_p, ER_THREAD_FINAL);
4328  return error_code;
4329 
4330 error:
4331  if (dir != NULL)
4332  {
4333  cfg_free_directory (dir);
4334  }
4335 
4336  if (dbtxt_vdes != NULL_VOLDES)
4337  {
4338  fileio_dismount (thread_p, dbtxt_vdes);
4339  }
4340 
4341  (void) xboot_shutdown_server (thread_p, ER_THREAD_FINAL);
4342 
4343  return error_code;
4344 }
4345 
4346 /*
4347  * xboot_soft_rename () - a soft rename of a database on the same disk partitions
4348  *
4349  * return : NO_ERROR if all OK, ER_ status otherwise
4350  *
4351  * olddb_name(in): Name of new database
4352  * newdb_name(in): Directory where the new database will reside
4353  * newdb_path(in): Directory where the log volumes of the new database
4354  * will reside
4355  * newlog_path(in): Server host where the new database reside
4356  * newdb_server_host(in): Wheater to overwrite the new database if it already
4357  * exist.
4358  * new_volext_path(in): A path is included if all volumes are placed in one
4359  * place/directory. If NULL is given,
4360  * - If file "fileof_vols_and_wherepaths" is given, the
4361  * path is found in this file.
4362  * - Each volume is copied to same place where the
4363  * volume resides.
4364  * Note: This parameter should be NULL, if the above file
4365  * is given.
4366  * fileof_vols_and_renamepaths(in):A file is given when the user decides to
4367  * control the rename of the volume by
4368  * individual bases. That is, user decides to
4369  * spread the volumes over several locations and
4370  * or to label the volumes with specific names.
4371  * Each volume entry consists of:
4372  * volid from_fullvolname to_fullvolname
4373  * newdb_overwrite(in):Rename the volumes/files at OS too. If it is true,
4374  * the enw database cannot exist in database.txt
4375  * extern_rename(in): Rename the volumes/files at OS too. If it is true,
4376  * the enw database cannot exist in database.txt
4377  * force_delete(in): Force delete backup volumes and information file
4378  *
4379  */
4380 int
4381 xboot_soft_rename (THREAD_ENTRY * thread_p, const char *old_db_name, const char *new_db_name, const char *new_db_path,
4382  const char *new_log_path, const char *new_db_server_host, const char *new_volext_path,
4383  const char *fileof_vols_and_renamepaths, bool new_db_overwrite, bool extern_rename,
4384  bool force_delete)
4385 {
4386  DB_INFO *dir = NULL;
4387  DB_INFO *db = NULL;
4388  const char *newlog_prefix;
4389  char new_db_server_host_buf[CUB_MAXHOSTNAMELEN + 1];
4390  char new_db_fullname[PATH_MAX];
4391  char new_db_pathbuf[PATH_MAX];
4392  char new_log_pathbuf[PATH_MAX];
4393  int dbtxt_vdes = NULL_VOLDES;
4394  char dbtxt_label[PATH_MAX];
4395  char allocdb_path[PATH_MAX];
4396  char alloclog_path[PATH_MAX];
4397  int error_code = NO_ERROR;
4398 
4399  if (fileof_vols_and_renamepaths != NULL)
4400  {
4401  /*
4402  * If a newdb path was given, it is ignored since only one option must
4403  * be specified
4404  */
4405  new_db_path = boot_find_new_db_path (allocdb_path, fileof_vols_and_renamepaths);
4406  if (new_db_path == NULL)
4407  {
4408  error_code = ER_FAILED;
4409  goto end;
4410  }
4411  }
4412 
4413  if (new_db_path == NULL)
4414  {
4415  /*
4416  * Use the same location as the source database
4417  */
4418  new_db_path = fileio_get_directory_path (allocdb_path, boot_Db_full_name);
4419  if (new_db_path == NULL)
4420  {
4421  if (getcwd (allocdb_path, PATH_MAX) == NULL)
4422  {
4424  error_code = ER_BO_CWD_FAIL;
4425  goto end;
4426  }
4427  new_db_path = allocdb_path;
4428  }
4429  }
4430 
4431  if (new_log_path == NULL)
4432  {
4433  /*
4434  * Use the same log location as the source database
4435  */
4436  new_log_path = fileio_get_directory_path (alloclog_path, log_Name_active);
4437  if (new_log_path == NULL)
4438  {
4439  if (getcwd (alloclog_path, PATH_MAX) == NULL)
4440  {
4442  error_code = ER_BO_CWD_FAIL;
4443  goto end;
4444  }
4445  new_log_path = alloclog_path;
4446  }
4447  }
4448 
4449  /*
4450  * Make sure that the db_path and log_path are the canonicalized absolute
4451  * pathnames
4452  */
4453 
4454  if (realpath ((char *) new_db_path, new_db_pathbuf) != NULL)
4455  {
4456  new_db_path = new_db_pathbuf;
4457  }
4458 
4459  if (new_log_path != NULL && realpath ((char *) new_log_path, new_log_pathbuf) != NULL)
4460  {
4461  new_log_path = new_log_pathbuf;
4462  }
4463 
4464  /* If db_path and/or log_path are NULL find the defaults */
4465 
4466  if (new_log_path == NULL)
4467  {
4468  /* Assign the data volume directory */
4469  strncpy (new_log_pathbuf, new_db_path, PATH_MAX);
4470  new_log_path = new_log_pathbuf;
4471  }
4472 
4473  /* If a host was not given, assume the current host */
4474 
4475  if (new_db_server_host == NULL)
4476  {
4477 #if 0 /* use Unix-domain socekt for localhost */
4478 /* *INDENT-OFF* */
4479  if (GETHOSTNAME (new_db_server_host_buf, CUB_MAXHOSTNAMELEN) != 0)
4480  {
4482  error_code = ER_BO_UNABLE_TO_FIND_HOSTNAME;
4483  goto end;
4484  }
4485 /* *INDENT-ON* */
4486 #else
4487  strcpy (new_db_server_host_buf, "localhost");
4488 #endif
4489  new_db_server_host = new_db_server_host_buf;
4490  }
4491 
4492  /* Make sure that the full path for the new database is not too long */
4493  if ((int) (strlen (new_db_name) + strlen (new_db_path) + 2) > DB_MAX_PATH_LENGTH)
4494  {
4495  /*
4496  * db_path + db_name is too long
4497  */
4499  strlen (new_db_name) + strlen (new_db_path) + 2, DB_MAX_PATH_LENGTH);
4501  goto end;
4502  }
4503 
4504  /* Get the log prefix */
4505  newlog_prefix = fileio_get_base_file_name (new_db_name);
4506 
4507  /*
4508  * get the database directory information in write mode
4509  */
4510  if (cfg_maycreate_get_directory_filename (dbtxt_label) == NULL
4511 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4512 /* Temporary fix for NT file locking problem */
4513  || (dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) == NULL_VOLDES
4514 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4515  )
4516  {
4517  error_code = ER_FAILED;
4518  goto end;
4519  }
4520 
4521  if (dbtxt_vdes != NULL_VOLDES)
4522  {
4523  error_code = cfg_read_directory_ex (dbtxt_vdes, &dir, true);
4524  if (error_code != NO_ERROR)
4525  {
4526  goto end;
4527  }
4528  }
4529  else
4530  {
4531  error_code = cfg_read_directory (&dir, true);
4532  if (error_code != NO_ERROR)
4533  {
4534  goto end;
4535  }
4536  }
4537 
4538  if (dir != NULL && (db = cfg_find_db_list (dir, new_db_name)) == NULL && extern_rename != true)
4539  {
4541  error_code = ER_BO_UNKNOWN_DATABASE;
4542  goto end;
4543  }
4544 
4545  if (dir != NULL && db != NULL && extern_rename == true && new_db_overwrite == false)
4546  {
4547  /* There is a database with the same name and we cannot overwrite it */
4549  error_code = ER_BO_DATABASE_EXISTS;
4550  goto end;
4551  }
4552 
4553  /*
4554  * Compose the full name of the new database
4555  */
4556 
4557  COMPOSE_FULL_NAME (new_db_fullname, sizeof (new_db_fullname), new_db_path, new_db_name);
4558 
4559  /*
4560  * Rename the database
4561  */
4562 
4563  error_code =
4564  logpb_rename_all_volumes_files (thread_p, boot_Db_parm->nvols, new_db_fullname, new_log_path, newlog_prefix,
4565  new_volext_path, fileof_vols_and_renamepaths, extern_rename, force_delete);
4566  if (error_code != NO_ERROR)
4567  {
4568  goto end;
4569  }
4570 
4571  /* Now create the entry in the database table */
4572  if (extern_rename == true)
4573  {
4574  if (db == NULL)
4575  {
4576  const char *old_lob_path = NULL;
4577  char new_lob_pathbuf[PATH_MAX] = { '\0' };
4578  char *new_lob_path = NULL;
4579 
4580  old_lob_path = boot_get_lob_path ();
4581  if (*old_lob_path != '\0')
4582  {
4583  new_lob_path = strncpy_bufsize (new_lob_pathbuf, old_lob_path);
4584  }
4585 
4586  cfg_delete_db (&dir, old_db_name);
4587  db = cfg_add_db (&dir, new_db_name, new_db_path, new_log_path, new_lob_path, new_db_server_host);
4588  }
4589  else
4590  {
4591  cfg_update_db (db, new_db_path, new_log_path, NULL, new_db_server_host);
4592  }
4593 
4594  if (db == NULL || db->name == NULL || db->pathname == NULL || db->logpath == NULL || db->hosts == NULL)
4595  {
4596  error_code = ER_FAILED;
4597  goto end;
4598  }
4599  }
4600 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4601  /* must unlock this before we can open it again for writing */
4602  if (dbtxt_vdes != NULL_VOLDES)
4603  {
4604  fileio_dismount (thread_p, dbtxt_vdes);
4605  dbtxt_vdes = NULL_VOLDES;
4606  }
4607 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4608  if (dbtxt_vdes != NULL_VOLDES)
4609  {
4610  cfg_write_directory_ex (dbtxt_vdes, dir);
4611  }
4612  else
4613  {
4614  cfg_write_directory (dir);
4615  }
4616 
4617 end:
4618  if (dir != NULL)
4619  {
4620  cfg_free_directory (dir);
4621  }
4622 
4623  if (dbtxt_vdes != NULL_VOLDES)
4624  {
4625  fileio_dismount (thread_p, dbtxt_vdes);
4626  }
4627 
4628  return error_code;
4629 }
4630 
4631 /*
4632  * xboot_delete () - delete all log files and database backups
4633  *
4634  * return: NO_ERROR if all OK, ER_ status otherwise
4635  *
4636  * db_name(in):
4637  * force_delete(in):
4638  *
4639  * Note: All data, log, and backup files associated with the current
4640  * database are removed from the system.
4641  * This is a very dangerous operation since the database cannot
4642  * be recovered after this operation is executed. We strongly
4643  * recommend that you backup the database and put the backup on
4644  * tape or outside the log and backup directories before this
4645  * operation is done. After this operation is executed the system
4646  * is unavailable, that is, the system is shutdown by this
4647  * operation.
4648  *
4649  * Note: This function must be run offline, that is, it should not be
4650  * run when there are multiusers in the system.
4651  */
4652 int
4653 xboot_delete (const char *db_name, bool force_delete, BOOT_SERVER_SHUTDOWN_MODE shutdown_common_modules)
4654 {
4655  char log_path[PATH_MAX];
4656  const char *log_prefix = NULL;
4657  DB_INFO *db;
4658  DB_INFO *dir = NULL;
4659  int dbtxt_vdes = NULL_VOLDES;
4660  char dbtxt_label[PATH_MAX];
4661  int error_code = NO_ERROR;
4662  THREAD_ENTRY *thread_p = NULL;
4663 
4664  if (!BO_IS_SERVER_RESTARTED ())
4665  {
4666  /*
4667  * Compose the full name of the database and find location of logs
4668  */
4669  if (msgcat_init () != NO_ERROR)
4670  {
4672  return ER_FAILED;
4673  }
4674 
4676  {
4678  return ER_FAILED;
4679  }
4680 
4681  er_clear ();
4682  }
4683 
4684  /* *INDENT-OFF* */
4685  cubthread::initialize (thread_p);
4686  error_code = cubthread::initialize_thread_entries ();
4687  if (error_code != NO_ERROR)
4688  {
4689  ASSERT_ERROR ();
4690  return error_code;
4691  }
4692  /* *INDENT-ON* */
4693 
4694  error_code = perfmon_initialize (1); /* 1 transaction for SA_MDOE */
4695  if (error_code != NO_ERROR)
4696  {
4697  ASSERT_ERROR ();
4698  return error_code;
4699  }
4700 
4701  /* Find the prefix for the database */
4702  log_prefix = fileio_get_base_file_name (db_name);
4703 
4704  /*
4705  * get the database directory information in write mode.
4706  */
4707  if (cfg_maycreate_get_directory_filename (dbtxt_label) == NULL)
4708  {
4709  goto error_dirty_delete;
4710  }
4711 
4712 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4713  /* Temporary solution to NT file locking problem */
4714  dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true);
4715  if (dbtxt_vdes == NULL_VOLDES)
4716  {
4717  return ER_FAILED;
4718  }
4719 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4720 
4721  if (dbtxt_vdes != NULL_VOLDES)
4722  {
4723  error_code = cfg_read_directory_ex (dbtxt_vdes, &dir, true);
4724  }
4725  else
4726  {
4727  error_code = cfg_read_directory (&dir, true);
4728  }
4729 
4730  if (error_code != NO_ERROR)
4731  {
4732  /*
4733  * If I cannot obtain a Lock on database.txt, it is better to quite at
4734  * this moment. We will not even perform a dirty delete.
4735  */
4736  if (dbtxt_vdes != NULL_VOLDES)
4737  {
4738  fileio_dismount (thread_p, dbtxt_vdes);
4739  }
4740  return error_code;
4741  }
4742 
4743  if (dir == NULL || (db = cfg_find_db_list (dir, db_name)) == NULL)
4744  {
4745  if (dbtxt_vdes != NULL_VOLDES)
4746  {
4747  fileio_dismount (thread_p, dbtxt_vdes);
4748  }
4750  if (dir)
4751  {
4752  cfg_free_directory (dir);
4753  }
4754  goto error_dirty_delete;
4755  }
4756 
4757  /*
4758  * How can we perform the delete operation..without restarting the system
4759  * or restarted the system.
4760  */
4761 
4762  if (!BO_IS_SERVER_RESTARTED ())
4763  {
4764  /*
4765  * Compose the full name of the database and find location of logs
4766  */
4768  }
4769 
4770  if (boot_volume_info_log_path (log_path) == NULL)
4771  {
4772  strcpy (log_path, db->logpath);
4773  }
4774 
4775  if (dbtxt_vdes != NULL_VOLDES)
4776  {
4777  fileio_dismount (thread_p, dbtxt_vdes);
4778  dbtxt_vdes = NULL_VOLDES;
4779  cfg_free_directory (dir);
4780  dir = NULL;
4781  }
4782 
4783  /* Now delete the database. Normally, DWB was already removed at database shutdown. */
4784  error_code = boot_remove_all_volumes (thread_p, boot_Db_full_name, log_path, log_prefix, false, force_delete);
4785  if (error_code == NO_ERROR)
4786  {
4787 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4788  dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true);
4789  if (dbtxt_vdes == NULL_VOLDES)
4790  {
4791  goto error_dirty_delete;
4792  }
4793 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4794 
4795  if (dbtxt_vdes != NULL_VOLDES)
4796  {
4797  if (cfg_read_directory_ex (dbtxt_vdes, &dir, true) != NO_ERROR)
4798  {
4799  goto error_dirty_delete;
4800  }
4801  }
4802  else
4803  {
4804  if (cfg_read_directory (&dir, true) != NO_ERROR)
4805  {
4806  goto error_dirty_delete;
4807  }
4808  }
4809 
4810  db = cfg_find_db_list (dir, db_name);
4811 
4812  if (db && cfg_delete_db (&dir, db_name))
4813  {
4814 #if defined(WINDOWS) && !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
4815  /* must unlock it before opening it for write again */
4816  if (dbtxt_vdes != NULL_VOLDES)
4817  {
4818  fileio_dismount (thread_p, dbtxt_vdes);
4819  dbtxt_vdes = NULL_VOLDES;
4820  }
4821 #endif /* WINDOWS && !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
4822  if (dbtxt_vdes != NULL_VOLDES)
4823  {
4824  cfg_write_directory_ex (dbtxt_vdes, dir);
4825  }
4826  else
4827  {
4828  cfg_write_directory (dir);
4829  }
4830  }
4831  cfg_free_directory (dir);
4832  }
4833 
4834  if (dbtxt_vdes != NULL_VOLDES)
4835  {
4836  fileio_dismount (thread_p, dbtxt_vdes);
4837  }
4838 
4839  /* Shutdown the server */
4840  if (error_code == NO_ERROR)
4841  {
4842  boot_server_all_finalize (thread_p, ER_THREAD_FINAL, shutdown_common_modules);
4843  }
4844  else
4845  {
4846  er_stack_push ();
4847 #if defined (SERVER_MODE)
4849 #else
4850  boot_server_all_finalize (thread_p, ER_THREAD_FINAL, shutdown_common_modules);
4851 #endif
4852  er_stack_pop ();
4853  }
4854 
4855 #if defined (SA_MODE)
4857  thread_p = NULL;
4858 #endif // SA_MODE
4859 
4860  return error_code;
4861 
4862 error_dirty_delete:
4863 
4864  error_code = ER_FAILED;
4865 
4866  /* Shutdown the server */
4867  er_stack_push ();
4868 #if defined (SERVER_MODE)
4870 #else
4871  boot_server_all_finalize (thread_p, ER_THREAD_FINAL, shutdown_common_modules);
4872 #endif
4873  er_stack_pop ();
4874 
4875 #if defined (SA_MODE)
4877  thread_p = NULL;
4878 #endif // SA_MODE
4879 
4880  return error_code;
4881 }
4882 
4883 /*
4884  * boot_create_all_volumes () -
4885  *
4886  * return:
4887  *
4888  * db_comments(in):
4889  * db_npages(in):
4890  * file_addmore_vols(in):
4891  * log_path(in):
4892  * log_prefix(in):
4893  * log_npages(in):
4894  * client_prog_name(in):
4895  * client_user_name(in):
4896  * client_host_name(in):
4897  * client_process_id(in):
4898  * client_lock_wait(in):
4899  * client_isolation(in):
4900  */
4901 static int
4902 boot_create_all_volumes (THREAD_ENTRY * thread_p, const BOOT_CLIENT_CREDENTIAL * client_credential,
4903  const char *db_comments, DKNPAGES db_npages, const char *file_addmore_vols,
4904  const char *log_path, const char *log_prefix, DKNPAGES log_npages,
4905  int client_lock_wait, TRAN_ISOLATION client_isolation)
4906 {
4907  int tran_index = NULL_TRAN_INDEX;
4908  VOLID db_volid = NULL_VOLID;
4909  RECDES recdes;
4910  int error_code;
4911  DBDEF_VOL_EXT_INFO ext_info;
4912  HEAP_OPERATION_CONTEXT heapop_context;
4913 
4914  assert (client_credential != NULL);
4915 
4916  spage_boot (thread_p);
4917  error_code = heap_manager_initialize ();
4918  if (error_code != NO_ERROR)
4919  {
4920  goto error;
4921  }
4922 
4923  /* Create the active log and initialize the log and recovery manager */
4924  error_code = log_create (thread_p, boot_Db_full_name, log_path, log_prefix, log_npages);
4925  if (error_code != NO_ERROR || boot_Init_server_is_canceled)
4926  {
4927  goto error;
4928  }
4929  log_initialize (thread_p, boot_Db_full_name, log_path, log_prefix, false, NULL);
4930 
4931  /* Assign an index to current thread of execution (i.e., a client id) */
4932 
4933  tran_index =
4934  logtb_assign_tran_index (thread_p, NULL_TRANID, TRAN_ACTIVE, client_credential, NULL, client_lock_wait,
4935  client_isolation);
4936  if (tran_index == NULL_TRAN_INDEX)
4937  {
4938  goto error;
4939  }
4940 
4941  ext_info.name = boot_Db_full_name;
4942  ext_info.comments = db_comments;
4943  ext_info.max_npages = db_npages;
4944  ext_info.max_writesize_in_sec = 0;
4946  ext_info.extend_npages = db_npages;
4947 
4948  /* Create double write buffer if not already created. DWB creation must be done before first volume.
4949  * DWB file is created on log_path.
4950  */
4951  if (dwb_create (thread_p, log_path, log_prefix) != NO_ERROR)
4952  {
4953  goto error;
4954  }
4955 
4956  /* Format the first database volume */
4957  error_code = disk_format_first_volume (thread_p, boot_Db_full_name, db_comments, db_npages);
4958  if (error_code != NO_ERROR)
4959  {
4960  ASSERT_ERROR ();
4961  goto error;
4962  }
4963 
4965  {
4966  goto error;
4967  }
4968 
4969  /*
4970  * Initialize the database parameter table
4971  */
4972 
4973  boot_Db_parm->trk_vfid.volid = LOG_DBFIRST_VOLID;
4974  boot_Db_parm->hfid.vfid.volid = LOG_DBFIRST_VOLID;
4975  boot_Db_parm->rootclass_hfid.vfid.volid = LOG_DBFIRST_VOLID;
4976 #if 1 /* TODO */
4977  boot_Db_parm->classname_table.vfid.volid = LOG_DBFIRST_VOLID;
4978 #endif
4979  boot_Db_parm->ctid.vfid.volid = LOG_DBFIRST_VOLID;
4980 #if 1 /* TODO */
4981  boot_Db_parm->ctid.xhid.vfid.volid = LOG_DBFIRST_VOLID;
4982 #endif
4983 
4984  (void) strncpy (boot_Db_parm->rootclass_name, ROOTCLASS_NAME, DB_SIZEOF (boot_Db_parm->rootclass_name));
4985  boot_Db_parm->nvols = 1;
4986  boot_Db_parm->last_volid = LOG_DBFIRST_VOLID;
4987  boot_Db_parm->temp_nvols = 0;
4988  boot_Db_parm->temp_last_volid = NULL_VOLID;
4989 
4990  /* The query area has been removed */
4991  boot_Db_parm->query_vfid.volid = NULL_VOLID;
4992  boot_Db_parm->query_vfid.fileid = NULL_FILEID;
4993 
4994  OID_SET_NULL (&boot_Db_parm->rootclass_oid);
4995  oid_set_root (&boot_Db_parm->rootclass_oid);
4996 
4997  /* Get parameter value for vacuum data file size. Save it to boot_Db_parm to keep the value persistent even if the
4998  * server is restarted and the value in config file is changed. */
5000  VFID_SET_NULL (&boot_Db_parm->vacuum_data_vfid);
5001  VFID_SET_NULL (&boot_Db_parm->dropped_files_vfid);
5002 
5003  /* Create the needed files */
5004  error_code = file_tracker_create (thread_p, &boot_Db_parm->trk_vfid);
5005  if (error_code != NO_ERROR)
5006  {
5007  ASSERT_ERROR ();
5008  goto error;
5009  }
5010  error_code = xheap_create (thread_p, &boot_Db_parm->hfid, NULL, false);
5011  if (error_code != NO_ERROR)
5012  {
5013  ASSERT_ERROR ();
5014  goto error;
5015  }
5016  error_code = xheap_create (thread_p, &boot_Db_parm->rootclass_hfid, NULL, false);
5017  if (error_code != NO_ERROR)
5018  {
5019  ASSERT_ERROR ();
5020  goto error;
5021  }
5022 
5023  error_code = xheap_create (thread_p, &boot_Db_parm->tde_keyinfo_hfid, NULL, false);
5024  if (error_code != NO_ERROR)
5025  {
5026  ASSERT_ERROR ();
5027  goto error;
5028  }
5029 
5030  error_code = heap_assign_address (thread_p, &boot_Db_parm->rootclass_hfid, NULL, &boot_Db_parm->rootclass_oid, 0);
5031  if (error_code != NO_ERROR)
5032  {
5033  ASSERT_ERROR ();
5034  goto error;
5035  }
5036 
5037  oid_set_root (&boot_Db_parm->rootclass_oid);
5038  /* we need to manually add root class HFID to cache */
5039  error_code =
5040  heap_cache_class_info (thread_p, &boot_Db_parm->rootclass_oid, &boot_Db_parm->rootclass_hfid, FILE_HEAP,
5041  boot_Db_parm->rootclass_name);
5042  if (error_code != NO_ERROR)
5043  {
5044  assert_release (false);
5045  goto error;
5046  }
5047 
5048 #if 1 /* TODO */
5049  if (xehash_create (thread_p, &boot_Db_parm->classname_table, DB_TYPE_STRING, -1, &boot_Db_parm->rootclass_oid, -1,
5050  false) == NULL)
5051  {
5052  goto error;
5053  }
5054 #endif
5055 
5056  /* Initialize structures for global unique statistics */
5057  error_code = logtb_initialize_global_unique_stats_table (thread_p);
5058  if (error_code != NO_ERROR)
5059  {
5060  goto error;
5061  }
5062 
5063  if (catalog_create (thread_p, &boot_Db_parm->ctid) == NULL)
5064  {
5065  goto error;
5066  }
5067 
5068  error_code = disk_set_boot_hfid (thread_p, LOG_DBFIRST_VOLID, &boot_Db_parm->hfid);
5069  if (error_code != NO_ERROR)
5070  {
5071  goto error;
5072  }
5073 
5074  /* Store the parameter table */
5075  recdes.area_size = recdes.length = DB_SIZEOF (*boot_Db_parm);
5076  recdes.type = REC_HOME;
5077  recdes.data = (char *) boot_Db_parm;
5078 
5079  /* Prepare context */
5080  heap_create_insert_context (&heapop_context, &boot_Db_parm->hfid, &boot_Db_parm->rootclass_oid, &recdes, NULL);
5081 
5082  /* Insert and fetch location */
5083  if (heap_insert_logical (thread_p, &heapop_context, NULL) != NO_ERROR)
5084  {
5085  goto error;
5086  }
5087  COPY_OID (boot_Db_parm_oid, &heapop_context.res_oid);
5088 
5089  /* Create file for vacuum data */
5090  if (vacuum_create_file_for_vacuum_data (thread_p, &boot_Db_parm->vacuum_data_vfid) != NO_ERROR)
5091  {
5092  goto error;
5093  }
5094 
5095  /* Create file for dropped files (tracked by vacuum) */
5096  if (vacuum_create_file_for_dropped_files (thread_p, &boot_Db_parm->dropped_files_vfid) != NO_ERROR)
5097  {
5098  goto error;
5099  }
5100 
5101  /* Update boot_Db_parm */
5102  error_code = boot_db_parm_update_heap (thread_p);
5103  if (error_code != NO_ERROR)
5104  {
5105  ASSERT_ERROR ();
5106  goto error;
5107  }
5108 
5109  /*
5110  * Create the rest of the other volumes if any
5111  */
5112 
5113  if (file_addmore_vols != NULL)
5114  {
5115  error_code = boot_parse_add_volume_extensions (thread_p, file_addmore_vols);
5116  if (error_code != NO_ERROR)
5117  {
5118  goto error;
5119  }
5120  }
5121 
5122  error_code = locator_initialize (thread_p);
5123  if (error_code != NO_ERROR)
5124  {
5125  goto error;
5126  }
5127 
5128  error_code = pgbuf_flush_all (thread_p, NULL_VOLID);
5129  if (error_code != NO_ERROR)
5130  {
5131  goto error;
5132  }
5133 
5134  /*
5135  * Initialize the catalog manager, the query evaluator, and install meta
5136  * classes
5137  */
5138 
5139  oid_set_root (&boot_Db_parm->rootclass_oid);
5140  catalog_initialize (&boot_Db_parm->ctid);
5141 
5142  if (qmgr_initialize (thread_p) != NO_ERROR)
5143  {
5144  goto error;
5145  }
5146 
5147  error_code = tf_install_meta_classes ();
5148  if (error_code != NO_ERROR)
5149  {
5150  goto error;
5151  }
5152 
5153  error_code = tde_initialize (thread_p, &boot_Db_parm->tde_keyinfo_hfid);
5154  if (error_code != NO_ERROR)
5155  {
5156  goto error;
5157  }
5158 
5159  logpb_force_flush_pages (thread_p);
5160  (void) pgbuf_flush_all (thread_p, NULL_VOLID);
5161  (void) fileio_synchronize_all (thread_p, false);
5162 
5163  (void) logpb_checkpoint (thread_p);
5165 
5166  return tran_index;
5167 
5168  /* An error was found */
5169 error:
5170 
5171  if (db_volid != NULL_VOLID)
5172  {
5173  (void) logpb_delete (thread_p, boot_Db_parm->nvols, boot_Db_full_name, log_path, log_prefix, true);
5174  }
5175  else
5176  {
5177  if (tran_index != NULL_TRAN_INDEX)
5178  {
5179  logtb_release_tran_index (thread_p, tran_index);
5180  log_final (thread_p);
5181  }
5182  }
5183 
5184  er_stack_push ();
5186  er_stack_pop ();
5187 
5188  return NULL_TRAN_INDEX;
5189 }
5190 
5191 /*
5192  * boot_remove_all_volumes () - remove all log files, information volumes, and backups
5193  * of given full database name
5194  *
5195  * return: NO_ERROR if all OK, ER_ status otherwise
5196  *
5197  * db_fullname(in):Full name of the database (A path)
5198  * log_path(in): Path of log (cannot be NULL)
5199  * log_prefix(in): Prefix of log (cannot be NULL)
5200  * dirty_rem(in):
5201  * force_delete(in):
5202  *
5203  * Note: All data, log, and backup files associated with the given
5204  * database are removed from the system. However, the database is
5205  * not unregistered from the database.txt. That is, this function
5206  * does not know anything about database.txt.
5207  * See xboot_delete for deletion of database instead of volumes.
5208  */
5209 static int
5210 boot_remove_all_volumes (THREAD_ENTRY * thread_p, const char *db_fullname, const char *log_path, const char *log_prefix,
5211  bool dirty_rem, bool force_delete)
5212 {
5213  int error_code = NO_ERROR;
5214 
5215  if (dirty_rem)
5216  {
5217  goto error_rem_allvols;
5218  }
5219 
5220  /*
5221  * How can we perform the delete operation..without restarting the system
5222  * or restarted the system.
5223  */
5224 
5225  if (!BO_IS_SERVER_RESTARTED ())
5226  {
5227  /* System is not restarted. Read the system parameters */
5228  if (msgcat_init () != NO_ERROR)
5229  {
5231  return ER_FAILED;
5232  }
5233 
5235  {
5237  return ER_FAILED;
5238  }
5239 
5240  /*
5241  * Initialize error structure, critical section, slotted page, heap, and
5242  * recovery managers
5243  */
5244 
5245  er_clear ();
5246 
5247  /* Initialize the transaction table */
5248  logtb_define_trantable (thread_p, -1, -1);
5249 
5250  /* The database pagesize is set by log_get_io_page_size */
5251 
5252  if (log_get_io_page_size (thread_p, db_fullname, log_path, log_prefix) == -1)
5253  {
5254  /*
5255  * There is something wrong with this database... We will only remove
5256  * as much as we can
5257  */
5258  goto error_rem_allvols;
5259  }
5260  if (!fileio_is_volume_exist (db_fullname))
5261  {
5262  goto error_rem_allvols;
5263  }
5264  if (!logpb_exist_log (thread_p, db_fullname, log_path, log_prefix))
5265  {
5266  goto error_rem_allvols;
5267  }
5268  error_code = boot_mount (thread_p, LOG_DBFIRST_VOLID, db_fullname, NULL);
5269  if (error_code != NO_ERROR)
5270  {
5271  goto error_rem_allvols;
5272  }
5273  if (disk_get_boot_hfid (thread_p, LOG_DBFIRST_VOLID, &boot_Db_parm->hfid) == NULL)
5274  {
5275  goto error_rem_allvols;
5276  }
5277  error_code = boot_get_db_parm (thread_p, boot_Db_parm, boot_Db_parm_oid);
5278  if (error_code != NO_ERROR)
5279  {
5280  goto error_rem_allvols;
5281  }
5282  error_code = tde_cipher_initialize (thread_p, &boot_Db_parm->tde_keyinfo_hfid, NULL);
5283  if (error_code != NO_ERROR)
5284  {
5285  goto error_rem_allvols;
5286  }
5287 
5288  /* Find the rest of the volumes and mount them */
5289  error_code = boot_find_rest_volumes (thread_p, NULL, LOG_DBFIRST_VOLID, boot_mount, NULL);
5290  if (error_code != NO_ERROR)
5291  {
5292  goto error_rem_allvols;
5293  }
5294  error_code = disk_manager_init (thread_p, true);
5295  if (error_code != NO_ERROR)
5296  {
5297  goto error_rem_allvols;
5298  }
5299 
5300  log_restart_emergency (thread_p, db_fullname, log_path, log_prefix);
5301 
5304  log_final (thread_p);
5305 
5306  }
5307 
5308  /* Now delete the database */
5309  error_code = logpb_delete (thread_p, boot_Db_parm->nvols, db_fullname, log_path, log_prefix, force_delete);
5310  return error_code;
5311 
5312 error_rem_allvols:
5313 
5314  error_code = logpb_delete (thread_p, -1, db_fullname, log_path, log_prefix, force_delete);
5315 
5316  return error_code;
5317 }
5318 
5319 /*
5320  * xboot_emergency_patch () - patch the database for emergency restart
5321  *
5322  * return: NO_ERROR if all OK, ER_ status otherwise
5323  *
5324  * db_name(in): Database Name
5325  * recreate_log(in): true if the log is missing
5326  * log_npages(in):
5327  * user_db_charset(in): charset to use when recreating log
5328  * out_fp(in):
5329  *
5330  * Note: The database is patched for future restarts. The patch will
5331  * remove any indication of recovery to be performed. If a log
5332  * is not available, the recreate_flag must be given
5333  */
5334 int
5335 xboot_emergency_patch (const char *db_name, bool recreate_log, DKNPAGES log_npages, const char *db_locale,
5336  FILE * out_fp)
5337 {
5338  char log_path[PATH_MAX];
5339  const char *log_prefix;
5340  DB_INFO *db = NULL;
5341  DB_INFO *dir = NULL;
5342  int dbtxt_vdes = NULL_VOLDES;
5343  char dbtxt_label[PATH_MAX];
5344  int error_code = NO_ERROR;
5345  INTL_CODESET db_charset_db_header = INTL_CODESET_ERROR;
5346  INTL_CODESET db_charset_db_root = INTL_CODESET_ERROR;
5347  char dummy_timezone_checksum[32 + 1];
5348  char db_lang[LANG_MAX_LANGNAME];
5349  THREAD_ENTRY *thread_p = NULL;
5350 
5351  if (lang_init () != NO_ERROR)
5352  {
5353  if (er_errid () == NO_ERROR)
5354  {
5355  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LOC_INIT, 1, "Failed to initialize language module");
5356  }
5357  error_code = ER_LOC_INIT;
5358  goto error_exit;
5359  }
5360 
5361  (void) msgcat_init ();
5363  {
5365  error_code = ER_BO_CANT_LOAD_SYSPRM;
5366  goto error_exit;
5367  }
5368 
5369  if (db_name == NULL)
5370  {
5372  error_code = ER_BO_UNKNOWN_DATABASE;
5373  goto error_exit;
5374  }
5375 
5376  /* *INDENT-OFF* */
5377  cubthread::initialize (thread_p);
5378  error_code = cubthread::initialize_thread_entries ();
5379  if (error_code != NO_ERROR)
5380  {
5381  ASSERT_ERROR ();
5382  goto error_exit;
5383  }
5384  /* *INDENT-ON* */
5385 
5386  /*
5387  * Compose the full name of the database and find location of logs
5388  */
5389  if (cfg_read_directory (&dir, false) != NO_ERROR)
5390  {
5392  error_code = ER_CFG_NO_FILE;
5393  goto error_exit;
5394  }
5395 
5396  if (dir == NULL || ((db = cfg_find_db_list (dir, db_name)) == NULL))
5397  {
5398  /*
5399  * Make sure that nobody was in the process of writing the
5400  * database.txt when we got a snapshot of it.
5401  */
5402  if (dir != NULL)
5403  {
5404  cfg_free_directory (dir);
5405  dir = NULL;
5406  }
5407 
5408  if (cfg_maycreate_get_directory_filename (dbtxt_label) != NULL
5409 #if !defined(WINDOWS) || !defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS)
5410  /* Temporary solution to NT file locking problem. */
5411  && (dbtxt_vdes = fileio_mount (thread_p, dbtxt_label, dbtxt_label, LOG_DBTXT_VOLID, 2, true)) != NULL_VOLDES
5412 #endif /* !WINDOWS || !DONT_USE_MANDATORY_LOCK_IN_WINDOWS */
5413  )
5414  {
5415  if (dbtxt_vdes != NULL_VOLDES)
5416  {
5417  if (cfg_read_directory_ex (dbtxt_vdes, &dir, false) == NO_ERROR)
5418  {
5419  db = cfg_find_db_list (dir, db_name);
5420  }
5421  }
5422  else
5423  {
5424  if (cfg_read_directory (&dir, false) == NO_ERROR)
5425  {
5426  db = cfg_find_db_list (dir, db_name);
5427  }
5428  }
5429 
5430  fileio_dismount (thread_p, dbtxt_vdes);
5431  dbtxt_vdes = NULL_VOLDES;
5432  }
5433  if (db == NULL)
5434  {
5435  if (dir != NULL)
5436  {
5437  cfg_free_directory (dir);
5438  }
5440  error_code = ER_BO_UNKNOWN_DATABASE;
5441  goto error_exit;
5442  }
5443  }
5444 
5446 
5447  if (boot_volume_info_log_path (log_path) == NULL)
5448  {
5449  strcpy (log_path, db->logpath);
5450  }
5451 
5452  cfg_free_directory (dir);
5453 
5454  log_prefix = fileio_get_base_file_name (db_name);
5455 
5457  {
5459  error_code = ER_BO_CANT_LOAD_SYSPRM;
5460  goto error_exit;
5461  }
5462 
5463  /*
5464  * Initialize error structure, critical section, slotted page, heap, and
5465  * recovery managers
5466  */
5467 
5468  /* The database pagesize is set by log_get_io_page_size */
5469 
5470  if (log_get_io_page_size (thread_p, boot_Db_full_name, log_path, log_prefix) == -1)
5471  {
5472  if (recreate_log != 0)
5473  {
5474  /*
5475  * User must indicate the database pagesize through its own environment
5476  */
5478  }
5479  else
5480  {
5481  error_code = ER_FAILED;
5482  goto error_exit;
5483  }
5484  }
5485 
5486  /* Initialize the transaction table */
5487  logtb_define_trantable (thread_p, -1, -1);
5488 
5489  spage_boot (thread_p);
5490  error_code = heap_manager_initialize ();
5491  if (error_code != NO_ERROR)
5492  {
5493  goto error_exit;
5494  }
5495 
5496  /* Mount the data volume */
5497  error_code = boot_mount (thread_p, LOG_DBFIRST_VOLID, boot_Db_full_name, NULL);
5498  if (error_code != NO_ERROR)
5499  {
5500  goto error_exit;
5501  }
5502 
5503  /* Find the location of the database parameters and read them */
5504  if (disk_get_boot_hfid (thread_p, LOG_DBFIRST_VOLID, &boot_Db_parm->hfid) == NULL)
5505  {
5506  error_code = ER_FAILED;
5507  goto error_exit;
5508  }
5509  error_code = boot_get_db_parm (thread_p, boot_Db_parm, boot_Db_parm_oid);
5510  if (error_code != NO_ERROR)
5511  {
5512  error_code = ER_FAILED;
5513  goto error_exit;
5514  }
5515 
5516  if (recreate_log == false)
5517  {
5518  db_charset_db_header = boot_get_db_charset_from_header (thread_p, log_path, log_prefix);
5519  if (db_charset_db_header <= INTL_CODESET_NONE || INTL_CODESET_LAST < db_charset_db_header)
5520  {
5521  char er_msg[ERR_MSG_SIZE];
5522  snprintf (er_msg, sizeof (er_msg) - 1,
5523  "Cannot found a valid charset in volumes header or there is a missmatch.");
5525  error_code = ER_LOC_INIT;
5526  goto error_exit;
5527  }
5528  else
5529  {
5530  lang_set_charset (db_charset_db_header);
5531  }
5532  }
5533  else
5534  {
5535  error_code = lang_set_charset_lang (db_locale);
5536  if (error_code != NO_ERROR)
5537  {
5538  goto error_exit;
5539  }
5540  db_charset_db_header = lang_charset ();
5541  }
5542 
5543  /* Find the rest of the volumes and mount them */
5544 
5545  error_code = boot_find_rest_volumes (thread_p, NULL, LOG_DBFIRST_VOLID, boot_mount, NULL);
5546  if (error_code != NO_ERROR)
5547  {
5548  goto error_exit;
5549  }
5550  error_code = disk_manager_init (thread_p, true);
5551  if (error_code != NO_ERROR)
5552  {
5553  ASSERT_ERROR ();
5554  goto error_exit;
5555  }
5556 
5557  error_code = logtb_initialize_global_unique_stats_table (thread_p);
5558  if (error_code != NO_ERROR)
5559  {
5560  goto error_exit;
5561  }
5562 
5563  error_code = file_tracker_load (thread_p, &boot_Db_parm->trk_vfid);
5564  if (error_code != NO_ERROR)
5565  {
5566  ASSERT_ERROR ();
5567  goto error_exit;
5568  }
5569  catalog_initialize (&boot_Db_parm->ctid);
5570 
5572  {
5573  /* We need initialize vacuum routine before recovery. */
5574  error_code =
5575  vacuum_initialize (thread_p, boot_Db_parm->vacuum_log_block_npages, &boot_Db_parm->vacuum_data_vfid,
5576  &boot_Db_parm->dropped_files_vfid, false);
5577  if (error_code != NO_ERROR)
5578  {
5579  goto error_exit;
5580  }
5581  }
5582 
5583  error_code = tp_init ();
5584  if (error_code != NO_ERROR)
5585  {
5586  goto error_exit;
5587  }
5588 
5589  if (recreate_log == false)
5590  {
5591  log_restart_emergency (thread_p, boot_Db_full_name, log_path, log_prefix);
5592  }
5593 
5594  /*
5595  * Initialize the catalog manager, the query evaluator, and install meta
5596  * classes
5597  */
5598 
5599  error_code = locator_initialize (thread_p);
5600  if (error_code != NO_ERROR)
5601  {
5602  goto error_exit;
5603  }
5604 
5605  oid_set_root (&boot_Db_parm->rootclass_oid);
5606 
5607  /* Initialize tsc-timer */
5608  tsc_init ();
5609 
5610  error_code =
5611  catcls_get_server_compat_info (thread_p, &db_charset_db_root, db_lang, sizeof (db_lang) - 1,
5612  dummy_timezone_checksum);
5613  if (error_code != NO_ERROR)
5614  {
5615  goto error_exit;
5616  }
5617 
5618  if (db_charset_db_header != db_charset_db_root)
5619  {
5620  char er_msg[ERR_MSG_SIZE];
5621  snprintf (er_msg, sizeof (er_msg) - 1, "Invalid charset in db_root system table: expecting %s, found %s",
5622  lang_charset_cubrid_name (db_charset_db_header), lang_charset_cubrid_name (db_charset_db_root));
5624  error_code = ER_LOC_INIT;
5625  goto error_exit;
5626  }
5627 
5628  if (recreate_log == true)
5629  {
5630  if (log_npages <= 0)
5631  {
5632  /* Use the default that is the size of the database */
5633  log_npages = xdisk_get_total_numpages (thread_p, LOG_DBFIRST_VOLID);
5634 
5635  if (log_npages < 10)
5636  {
5637  log_npages = 10;
5638  }
5639  }
5640 
5641  error_code = log_recreate (thread_p, boot_Db_full_name, log_path, log_prefix, log_npages, out_fp);
5642  if (error_code != NO_ERROR)
5643  {
5644  goto error_exit;
5645  }
5646  }
5647 
5649 
5650  (void) xtran_server_commit (thread_p, false);
5651  (void) xboot_shutdown_server (thread_p, ER_ALL_FINAL);
5652 
5653  return error_code;
5654 
5655 error_exit:
5656 
5657  if (error_code != NO_ERROR)
5658  {
5659  error_code = ER_FAILED;
5660  }
5661 
5663 
5664  return error_code;
5665 }
5666 
5667 /*
5668  * boot_find_new_db_path () - find the new path of database
5669  *
5670  * return: db_pathbuf or NULL
5671  *
5672  * db_pathbuf(in): The database path buffer (Set as a side effect)
5673  * The size of this buffer muts be at least PATH_MAX
5674  * fileof_vols_and_wherepaths(in):A file of volumes and path or NULL.
5675  * Each volume entry consists of:
5676  * volid from_fullvolname to_fullvolname
5677  *
5678  * Note: Find the new database path from either the given wherepath
5679  * file or the current working directory.
5680  */
5681 static char *
5682 boot_find_new_db_path (char *db_pathbuf, const char *fileof_vols_and_wherepaths)
5683 {
5684  FILE *where_paths_fp;
5685  char from_volname[PATH_MAX]; /* Name of new volume */
5686  int from_volid;
5687  char *name;
5688  char format_string[32];
5689 #if !defined(WINDOWS)
5690  struct stat stat_buf;
5691 #endif
5692 
5693  if (fileof_vols_and_wherepaths != NULL)
5694  {
5695  /*
5696  * Obtain the new database path from where paths file
5697  */
5698  where_paths_fp = fopen (fileof_vols_and_wherepaths, "r");
5699  if (where_paths_fp == NULL)
5700  {
5702  fileof_vols_and_wherepaths);
5703  return NULL;
5704  }
5705 
5706  *db_pathbuf = '\0';
5707  *from_volname = '\0';
5708 
5709  sprintf (format_string, "%%d %%%ds %%%ds", PATH_MAX - 1, PATH_MAX - 1);
5710  if (fscanf (where_paths_fp, format_string, &from_volid, from_volname, db_pathbuf) != 3
5711  || from_volid != LOG_DBFIRST_VOLID)
5712  {
5713  fclose (where_paths_fp);
5715  0, from_volid, from_volname, db_pathbuf, LOG_DBFIRST_VOLID, boot_Db_full_name);
5716  return NULL;
5717  }
5718  fclose (where_paths_fp);
5719 
5720 #if !defined(WINDOWS)
5721  if (stat (db_pathbuf, &stat_buf) != -1 && S_ISCHR (stat_buf.st_mode))
5722  {
5723  if (getcwd (db_pathbuf, PATH_MAX) == NULL)
5724  {
5726  *db_pathbuf = '0';
5727  return NULL;
5728  }
5729 
5730  return db_pathbuf;
5731  }
5732 #endif /* !WINDOWS */
5733 
5734  name = strrchr (db_pathbuf, PATH_SEPARATOR);
5735 #if defined(WINDOWS)
5736  {
5737  char *name_tmp = strrchr (db_pathbuf, '/');
5738 
5739  if (name < name_tmp)
5740  {
5741  name = name_tmp;
5742  }
5743  }
5744 #endif /* WINDOWS */
5745  if (name == NULL)
5746  {
5747  /* It does not look like a path name. Use working directory */
5748  if (getcwd (db_pathbuf, PATH_MAX) == NULL)
5749  {
5751  *db_pathbuf = '\0';
5752  return NULL;
5753  }
5754  }
5755  else
5756  {
5757  *name = '\0';
5758  }
5759  }
5760  else
5761  {
5762  /* Use current working directory */
5763  if (getcwd (db_pathbuf, PATH_MAX) == NULL)
5764  {
5766  *db_pathbuf = '\0';
5767  return NULL;
5768  }
5769  }
5770 
5771  return db_pathbuf;
5772 }
5773 
5774 /*
5775  * boot_volume_info_log_path () - find path for log in volinfo
5776  *
5777  * return: log_path or NULL
5778  *
5779  * log_path(in): Storage for log path
5780  *
5781  * Note: Find path for the log in the volume information.
5782  */
5783 static char *
5785 {
5786  int read_int_volid = NULL_VOLID;
5787  char *slash;
5788  FILE *volinfo_fp = NULL; /* Pointer to new volinfo */
5789  char format_string[32];
5790 
5792  volinfo_fp = fopen (log_path, "r");
5793  if (volinfo_fp == NULL)
5794  {
5796  return NULL;
5797  }
5798 
5799  sprintf (format_string, "%%d %%%ds", PATH_MAX - 1);
5800  while (true)
5801  {
5802  if (fscanf (volinfo_fp, format_string, &read_int_volid, log_path) != 2)
5803  {
5804  read_int_volid = NULL_VOLID;
5805  break;
5806  }
5807  if (LOG_DBLOG_ACTIVE_VOLID == (VOLID) read_int_volid)
5808  {
5809  break;
5810  }
5811  }
5812  fclose (volinfo_fp);
5813 
5814  if (LOG_DBLOG_ACTIVE_VOLID == (VOLID) read_int_volid)
5815  {
5816  slash = strrchr (log_path, PATH_SEPARATOR);
5817 #if defined(WINDOWS)
5818  {
5819  char *r_slash = strrchr (log_path, '/');
5820 
5821  if (slash < r_slash)
5822  {
5823  slash = r_slash;
5824  }
5825  }
5826 #endif /* WINDOWS */
5827  if (slash != NULL)
5828  {
5829  *slash = '\0';
5830  }
5831  return log_path;
5832  }
5833 
5834  return NULL;
5835 }
5836 
5837 /*
5838  * xboot_compact_db () - compact the database
5839  *
5840  * return : NO_ERROR if all OK, ER_ status otherwise
5841  *
5842  * class_oids(in): the class oids list to process
5843  * n_classes(in): the length of class_oids
5844  * space_to_process(in): the maximum space to process
5845  * instance_lock_timeout(in): the lock timeout for instances
5846  * class_lock_timeout(in): the lock timeout for classes
5847  * delete_old_repr(in): drop old class representations
5848  * last_processed_class_oid(in,out): last processed class oid
5849  * last_processed_oid(in,out): last processed oid
5850  * total_objects(in,out): count processed objects for each class
5851  * failed_objects(in,out): count failed objects for each class
5852  * modified_objects(in,out): count modified objects for each class
5853  * big_objects(in,out): count big objects for each class
5854  * initial_last_repr_id(in,out): the list of last class representation
5855  *
5856  * Note:
5857  */
5858 
5859 int
5860 xboot_compact_db (THREAD_ENTRY * thread_p, OID * class_oids, int n_classes, int space_to_process,
5861  int instance_lock_timeout, int class_lock_timeout, bool delete_old_repr,
5862  OID * last_processed_class_oid, OID * last_processed_oid, int *total_objects, int *failed_objects,
5863  int *modified_objects, int *big_objects, int *initial_last_repr_id)
5864 {
5865  return boot_compact_db (thread_p, class_oids, n_classes, space_to_process, instance_lock_timeout, class_lock_timeout,
5866  delete_old_repr, last_processed_class_oid, last_processed_oid, total_objects, failed_objects,
5867  modified_objects, big_objects, initial_last_repr_id);
5868 }
5869 
5870 /*
5871  * xboot_heap_compact () - compact all pages from hfid of specified class OID
5872  * return: error_code
5873  * class_oid(in): the class oid
5874  */
5875 int
5876 xboot_heap_compact (THREAD_ENTRY * thread_p, OID * class_oid)
5877 {
5878  return boot_heap_compact_pages (thread_p, class_oid);
5879 }
5880 
5881 /*
5882  * xboot_compact_start () - start database compaction
5883  * return: error_code
5884  */
5885 int
5887 {
5888  return boot_compact_start (thread_p);
5889 }
5890 
5891 /*
5892  * xboot_compact_stop () - stop database compaction
5893  * return: error_code
5894  */
5895 int
5897 {
5898  return boot_compact_stop (thread_p);
5899 }
5900 
5901 bool
5903 {
5904  bool old_val = skip_to_check_ct_classes_for_rebuild;
5906  return old_val;
5907 }
5908 
5909 /*
5910  * boot_get_db_charset_from_header () - Get DB charset from volumes
5911  * (log or generic)
5912  * return: charset
5913  * thread_p(in):
5914  * log_path(in):
5915  * log_prefix(in):
5916  */
5917 static INTL_CODESET
5918 boot_get_db_charset_from_header (THREAD_ENTRY * thread_p, const char *log_path, const char *log_prefix)
5919 {
5920  INTL_CODESET vol_header_db_charset = INTL_CODESET_ERROR;
5921  INTL_CODESET log_header_db_charset = INTL_CODESET_ERROR;
5922 
5923  log_header_db_charset =
5924  (INTL_CODESET) log_get_charset_from_header_page (thread_p, boot_Db_full_name, log_path, log_prefix);
5925 
5926  if (disk_get_boot_db_charset (thread_p, LOG_DBFIRST_VOLID, &vol_header_db_charset) != NO_ERROR)
5927  {
5928  vol_header_db_charset = INTL_CODESET_ERROR;
5929  }
5930 
5931  if (log_header_db_charset == INTL_CODESET_ERROR)
5932  {
5933  return vol_header_db_charset;
5934  }
5935  else if (vol_header_db_charset == INTL_CODESET_ERROR)
5936  {
5937  return log_header_db_charset;
5938  }
5939  else if (vol_header_db_charset != log_header_db_charset)
5940  {
5941  return INTL_CODESET_ERROR;
5942  }
5943 
5944  assert (vol_header_db_charset == log_header_db_charset);
5945 
5946  return vol_header_db_charset;
5947 }
5948 
5949 const char *
5951 {
5952  switch (type)
5953  {
5955  return "SYSTEM_INTERNAL";
5957  return "DEFAULT";
5958  case DB_CLIENT_TYPE_CSQL:
5959  return "CSQL";
5961  return "READ_ONLY_CSQL";
5962  case DB_CLIENT_TYPE_BROKER:
5963  return "BROKER";
5965  return "READ_ONLY_BROKER";
5967  return "SLAVE_ONLY_BROKER";
5969  return "ADMIN_UTILITY";
5971  return "ADMIN_CSQL";
5973  return "LOG_COPIER";
5975  return "LOG_APPLIER";
5977  return "RW_BROKER_REPLICA_ONLY";
5979  return "RO_BROKER_REPLICA_ONLY";
5981  return "SO_BROKER_REPLICA_ONLY";
5983  return "ADMIN_CSQL_WOS";
5985  return "SKIP_VACUUM_CSQL";
5987  return "SKIP_VACUUM_ADMIN_CSQL";
5989  default:
5990  return "UNKNOWN";
5991  }
5992 }
5993 
5994 int
5995 boot_get_new_volume_name_and_id (THREAD_ENTRY * thread_p, DB_VOLTYPE voltype, const char *given_path,
5996  const char *given_name, char *fullname_newvol_out, VOLID * volid_newvol_out)
5997 {
5998  char buf_temp_path[PATH_MAX];
5999  const char *temp_path = NULL;
6000  const char *temp_name = NULL;
6001 
6002  if (voltype == DB_PERMANENT_VOLTYPE)
6003  {
6004  *volid_newvol_out = boot_Db_parm->last_volid + 1;
6005  if (*volid_newvol_out > LOG_MAX_DBVOLID
6006  || (boot_Db_parm->temp_nvols > 0 && *volid_newvol_out >= boot_Db_parm->temp_last_volid))
6007  {
6008  /* should be caught early */
6009  assert (false);
6012  }
6013 
6014  if (given_path != NULL)
6015  {
6016  temp_path = given_path;
6017  }
6018  else
6019  {
6021  if (temp_path == NULL)
6022  {
6023  temp_path = fileio_get_directory_path (buf_temp_path, boot_Db_full_name);
6024  if (temp_path == NULL)
6025  {
6026  buf_temp_path[0] = '\0';
6027  temp_path = buf_temp_path;
6028  }
6029  }
6030 
6031  }
6032  if (given_name != NULL)
6033  {
6034  temp_name = given_name;
6035 
6036  fileio_make_volume_ext_given_name (fullname_newvol_out, temp_path, given_name);
6037  }
6038  else
6039  {
6041  fileio_make_volume_ext_name (fullname_newvol_out, temp_path, temp_name, *volid_newvol_out);
6042  }
6043  }
6044  else
6045  {
6046  *volid_newvol_out = boot_Db_parm->temp_nvols > 0 ? boot_Db_parm->temp_last_volid - 1 : LOG_MAX_DBVOLID;
6047  if (*volid_newvol_out <= boot_Db_parm->last_volid)
6048  {
6049  /* should be caught early */
6050  assert (false);
6053  }
6054  assert (given_path == NULL && given_name == NULL);
6055 
6056  temp_path = (char *) prm_get_string_value (PRM_ID_IO_TEMP_VOLUME_PATH);
6057  if (temp_path == NULL || temp_path[0] == '\0')
6058  {
6059  temp_path = fileio_get_directory_path (buf_temp_path, boot_Db_full_name);
6060  }
6062  fileio_make_volume_temp_name (fullname_newvol_out, temp_path, temp_name, *volid_newvol_out);
6063  }
6064 
6065  return NO_ERROR;
6066 }
6067 
6068 int
6070 {
6071  VPID vpid_boot_bp_parm;
6072  BOOT_DB_PARM save_boot_db_parm = *boot_Db_parm;
6073 
6074  int error_code = NO_ERROR;
6075 
6077 
6078  if (voltype == DB_PERMANENT_VOLTYPE)
6079  {
6080  assert (boot_Db_parm->nvols >= 0);
6081  if (volid != boot_Db_parm->last_volid + 1)
6082  {
6083  assert_release (false);
6084  error_code = ER_FAILED;
6085  goto exit;
6086  }
6087  boot_Db_parm->last_volid = volid;
6088  boot_Db_parm->nvols++;
6089  }
6090  else
6091  {
6092  if (boot_Db_parm->temp_nvols < 0 || (boot_Db_parm->temp_nvols == 0 && volid != LOG_MAX_DBVOLID)
6093  || (boot_Db_parm->temp_nvols > 0 && boot_Db_parm->temp_last_volid - 1 != volid))
6094  {
6095  /* invalid volid */
6096  assert_release (false);
6097  error_code = ER_FAILED;
6098  goto exit;
6099  }
6100  boot_Db_parm->temp_nvols++;
6101  boot_Db_parm->temp_last_volid = volid;
6102  }
6103 
6104  /* todo: is flush needed? */
6105  VPID_GET_FROM_OID (&vpid_boot_bp_parm, boot_Db_parm_oid);
6106  log_append_undo_data2 (thread_p, RVPGBUF_FLUSH_PAGE, NULL, NULL, 0, sizeof (vpid_boot_bp_parm), &vpid_boot_bp_parm);
6107 
6108  error_code = boot_db_parm_update_heap (thread_p);
6109  if (error_code != NO_ERROR)
6110  {
6111  ASSERT_ERROR ();
6112  *boot_Db_parm = save_boot_db_parm;
6113  goto exit;
6114  }
6115 
6116  /* flush the boot_Db_parm object. this is not necessary but it is recommended in order to mount every known volume
6117  * during restart. that may not be possible during media crash though. */
6118  heap_flush (thread_p, boot_Db_parm_oid);
6119  fileio_synchronize (thread_p, fileio_get_volume_descriptor (boot_Db_parm_oid->volid), NULL, FILEIO_SYNC_ALSO_FLUSH_DWB); /* label? */
6120 
6121 exit:
6122  return error_code;
6123 }
6124 
6125 /*
6126  * boot_db_parm_update_heap () - update heap record for boot_Db_parm
6127  *
6128  * return : error code
6129  * thread_p (in) : thread entry
6130  */
6131 STATIC_INLINE int
6133 {
6134  HEAP_SCANCACHE scan_cache;
6135  HEAP_OPERATION_CONTEXT update_context;
6136  RECDES recdes;
6137 
6138  int error_code = NO_ERROR;
6139 
6140  recdes.length = recdes.area_size = sizeof (*boot_Db_parm);
6141  recdes.data = (char *) boot_Db_parm;
6142 
6143  /* note that we start a scan cache with NULL class_oid. That's because boot_Db_parm_oid doesn't really have a class!
6144  * we have to start the scan cache this way so it can cache also cache file type for heap_update_logical.
6145  * otherwise it will try to read it from cache using root class OID. which actually has its own heap file and its own
6146  * heap file type.
6147  */
6148  error_code = heap_scancache_start_modify (thread_p, &scan_cache, &boot_Db_parm->hfid, NULL, SINGLE_ROW_UPDATE, NULL);
6149  if (error_code != NO_ERROR)
6150  {
6151  ASSERT_ERROR ();
6152  return error_code;
6153  }
6154 
6155  /* hack the class to avoid heap_scancache_check_with_hfid. */
6156  scan_cache.node.class_oid = *oid_Root_class_oid;
6157  heap_create_update_context (&update_context, &boot_Db_parm->hfid, boot_Db_parm_oid, &boot_Db_parm->rootclass_oid,
6158  &recdes, &scan_cache, UPDATE_INPLACE_CURRENT_MVCCID);
6159  error_code = heap_update_logical (thread_p, &update_context);
6160  if (error_code != NO_ERROR)
6161  {
6162  ASSERT_ERROR ();
6163  }
6164  heap_scancache_end (thread_p, &scan_cache);
6165  return error_code;
6166 }
6167 
6168 //
6169 // boot_after_copydb - do whatever checks and changes necessary on first boot of copied database.
6170 // copydb is quite rudimentary; it will just copy page by page as is, and then reset the LSA's.
6171 // some of database stuff may be contextual (e.g. stuff that depend on log like vacuum), and
6172 // here that stuff must be handled
6173 //
6174 static int
6176 {
6177  if (!log_Gl.hdr.was_copied)
6178  {
6179  // this is not after copydb
6180  return NO_ERROR;
6181  }
6182 
6183  int error_code = vacuum_reset_data_after_copydb (thread_p);
6184  if (error_code != NO_ERROR)
6185  {
6186  ASSERT_ERROR ();
6187  return error_code;
6188  }
6189 
6190  // finished booting after copydb
6191  log_Gl.hdr.was_copied = false;
6192 
6193  // flush log and header to disk to make sure everything is saved
6195 
6196  er_log_debug (ARG_FILE_LINE, "Complete boot_after_copydb \n");
6197 
6198  return NO_ERROR;
6199 }
int css_free_accessible_ip_info(void)
int lang_set_charset(const INTL_CODESET codeset)
#define ER_LOG_USER_FILE_UNKNOWN
Definition: error_code.h:160
int char_isspace(int c)
Definition: chartype.c:109
int status
#define ROOTCLASS_NAME
Definition: oid.h:32
void fileio_make_volume_ext_name(char *vol_ext_full_name_p, const char *ext_path_p, const char *ext_name_p, VOLID vol_id)
Definition: file_io.c:5654
int xboot_heap_compact(THREAD_ENTRY *thread_p, OID *class_oid)
Definition: boot_sr.c:5876
int xboot_compact_stop(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:5896
int set_area_init(void)
Definition: set_object.c:149
char * cfg_maycreate_get_directory_filename(char *buffer)
int lang_set_language(const char *lang_str)
char * lob_path
Definition: boot.h:107
OID * oid_Root_class_oid
Definition: oid.c:73
void log_initialize(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname, int ismedia_crash, BO_RESTART_ARG *r_args)
Definition: log_manager.c:1005
DISK_ISVALID xboot_checkdb_table(THREAD_ENTRY *thread_p, int check_flag, OID *oid, BTID *index_btid)
Definition: boot_sr.c:3587
int mk_index
Definition: tde.h:160
cubthread::entry * thread_get_thread_entry_info(void)
#define NO_ERROR
Definition: error_code.h:46
static void boot_find_rest_temp_volumes(THREAD_ENTRY *thread_p, VOLID volid, int(*fun)(THREAD_ENTRY *thread_p, VOLID xvolid, const char *vlabel), bool forward_dir, bool check_before_access)
Definition: boot_sr.c:1165
int check_timezone_compat(const char *client_checksum, const char *server_checksum, const char *client_text, const char *server_text)
Definition: tz_support.c:5043
int boot_heap_compact_pages(THREAD_ENTRY *thread_p, OID *class_oid)
Definition: compactdb_sr.c:679
int area_size
void fileio_unformat_and_rename(THREAD_ENTRY *thread_p, const char *vol_label_p, const char *new_label_p)
Definition: file_io.c:2736
int pr_Enable_string_compression
void session_states_finalize(THREAD_ENTRY *thread_p)
Definition: session.c:607
#define __attribute__(X)
Definition: porting.h:36
void er_stack_push(void)
void thread_return_lock_free_transaction_entries(void)
int lang_init(void)
VOLID xboot_find_last_permanent(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:377
void logtb_disable_update(THREAD_ENTRY *thread_p)
#define ER_TDE_RESTORE_MAKE_KEYS_FILE_OLD
Definition: error_code.h:1619
VOLID xboot_peek_last_permanent(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:396
char * db_path
Definition: boot.h:104
bool restore_slave
Definition: boot_sr.h:103
#define IO_PAGESIZE
#define BO_IS_SERVER_RESTARTED()
Definition: boot_sr.h:84
PGLENGTH log_get_io_page_size(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
Definition: log_manager.c:8572
static int boot_check_permanent_volumes(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:1270
#define ER_TDE_RESTORE_KEY_FOUND_ONLY_FROM_BACKUP
Definition: error_code.h:1618
#define ASSERT_ERROR()
SCAN_CODE
int boot_compact_stop(THREAD_ENTRY *thread_p)
Definition: compactdb_sr.c:724
#define HA_CHANGE_MODE_IMMEDIATELY
VOLID xboot_add_volume_extension(THREAD_ENTRY *thread_p, DBDEF_VOL_EXT_INFO *ext_info)
Definition: boot_sr.c:551
float rel_disk_compatible(void)
int sysprm_set_force(const char *pname, const char *pvalue)
bool check_db_coll
Definition: boot_sr.h:80
int vacuum_reset_data_after_copydb(THREAD_ENTRY *thread_p)
Definition: vacuum.c:7849
char rootclass_name[10]
Definition: boot_sr.c:119
float disk_compatibility
Definition: boot.h:146
VOLID temp_last_volid
Definition: boot_sr.c:124
void showstmt_scan_init(void)
Definition: show_scan.c:100
int heap_scancache_start_modify(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache, const HFID *hfid, const OID *class_oid, int op_type, MVCC_SNAPSHOT *mvcc_snapshot)
Definition: heap_file.c:6867
static int boot_get_db_parm(THREAD_ENTRY *thread_p, BOOT_DB_PARM *dbparm, OID *dbparm_oid)
Definition: boot_sr.c:295
META_CLASS tf_Metaclass_class
Definition: transform.c:221
const char * boot_client_type_to_string(BOOT_CLIENT_TYPE type)
Definition: boot_sr.c:5950
static char * boot_find_new_db_path(char *db_pathbuf, const char *fileof_vols_and_wherepaths)
Definition: boot_sr.c:5682
int css_hostname_to_ip(const char *host, unsigned char *ip_addr)
Definition: tcp.c:227
int tp_init(void)
int boot_reset_db_parm(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:447
char * db_comments
Definition: boot.h:109
int xboot_unregister_client(REFPTR(THREAD_ENTRY, thread_p), int tran_index)
Definition: boot_sr.c:3343
enum db_client_type BOOT_CLIENT_TYPE
bool logpb_find_volume_info_exist(void)
void logtb_release_tran_index(THREAD_ENTRY *thread_p, int tran_index)
PAGEID DKNPAGES
void vacuum_stop_master(THREAD_ENTRY *thread_p)
Definition: vacuum.c:1359
#define ER_TDE_RESTORE_COPY_KEYS_FILE
Definition: error_code.h:1620
#define ER_ES_INVALID_PATH
Definition: error_code.h:1272
int tf_install_meta_classes()
Definition: transform.c:603
#define ER_BO_INCONSISTENT_NPERM_VOLUMES
Definition: error_code.h:863
int heap_manager_finalize(void)
Definition: heap_file.c:5111
const char * boot_get_lob_path(void)
Definition: boot_sr.c:479
int vacuum_log_block_npages
Definition: boot_sr.c:125
#define DISK_VOLPURPOSE
int file_tracker_load(THREAD_ENTRY *thread_p, const VFID *vfid)
#define ER_FAILED
Definition: error_code.h:47
int logpb_remove_all_in_log_path(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
const TZ_DATA * tz_get_data(void)
Definition: tz_support.c:687
LOG_GLOBAL log_Gl
LOG_HEADER hdr
Definition: log_impl.h:653
#define ALWAYS_INLINE
#define NULL_TRANID
int boot_restart_server(THREAD_ENTRY *thread_p, bool print_restart, const char *db_name, bool from_backup, CHECK_ARGS *check_coll_and_timezone, BO_RESTART_ARG *r_args, bool skip_vacuum)
Definition: boot_sr.c:2046
const char * boot_db_name(void)
Definition: boot_sr.c:459
static void boot_ctrl_c_in_init_server(int ignore_signo)
Definition: boot_sr.c:1390
static OID * boot_Db_parm_oid
Definition: boot_sr.c:162
int dwb_load_and_recover_pages(THREAD_ENTRY *thread_p, const char *dwb_path_p, const char *db_name_p)
int catcls_finalize_class_oid_to_oid_hash_table(THREAD_ENTRY *thread_p)
int rel_bit_platform(void)
void css_final_conn_list(void)
#define TRAN_DEFAULT_ISOLATION_LEVEL()
Definition: dbtran_def.h:58
void fileio_unformat(THREAD_ENTRY *thread_p, const char *vol_label_p)
Definition: file_io.c:2721
void boot_client_all_finalize(bool is_er_final)
Definition: boot_cl.c:1536
int pr_area_init(void)
void logpb_force_flush_pages(THREAD_ENTRY *thread_p)
#define ER_BO_PARSE_ADDVOLS_NOGIVEN_NPAGES
Definition: error_code.h:189
int css_change_ha_server_state(THREAD_ENTRY *thread_p, HA_SERVER_STATE state, bool force, int timeout, bool heartbeat)
EHID classname_table
Definition: boot_sr.c:114
void logtb_set_to_system_tran_index(THREAD_ENTRY *thread_p)
#define MSGCAT_GENERAL_DATABASE_INIT
#define ASSERT_ERROR_AND_SET(error_code)
#define ER_BO_PARSE_ADDVOLS_UNKNOWN_PURPOSE
Definition: error_code.h:187
static int boot_after_copydb(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:6175
#define assert_release(e)
Definition: error_manager.h:96
#define ER_BO_CANT_LOAD_SYSPRM
Definition: error_code.h:1346
remove_temp_vol_action
Definition: boot_sr.c:131
const char * get_host_name() const
VOLID logpb_add_volume(const char *db_fullname, VOLID new_volid, const char *new_volfullname, DISK_VOLPURPOSE new_volpurpose)
void log_append_undo_data2(THREAD_ENTRY *thread_p, LOG_RCVINDEX rcvindex, const VFID *vfid, PAGE_PTR pgptr, PGLENGTH offset, int length, const void *data)
Definition: log_manager.c:1933
void locator_free_areas(void)
Definition: locator.c:206
INT16 VOLID
int lock_object(THREAD_ENTRY *thread_p, const OID *oid, const OID *class_oid, LOCK lock, int cond_flag)
char log_Name_active[PATH_MAX]
Definition: log_global.c:90
static BOOT_DB_PARM boot_Struct_db_parm
Definition: boot_sr.c:160
#define ER_IO_MOUNT_LOCKED
Definition: error_code.h:60
int tde_initialize(THREAD_ENTRY *thread_p, HFID *keyinfo_hfid)
Definition: tde.c:106
const VOLID LOG_DBLOG_ACTIVE_VOLID
Definition: log_volids.hpp:49
void cfg_update_db(DB_INFO *db_info_p, const char *path, const char *logpath, const char *lobpath, const char *host)
int heap_scancache_quick_start_root_hfid(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache)
Definition: heap_file.c:19255
void catalog_initialize(CTID *catalog_id_p)
char * db_host
Definition: boot.h:108
int xboot_find_number_permanent_volumes(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:341
#define ER_BO_FULL_DATABASE_NAME_IS_TOO_LONG
Definition: error_code.h:178
TRAN_STATE xtran_server_commit(THREAD_ENTRY *thrd, bool retain_lock)
#define OID_SET_NULL(oidp)
Definition: oid.h:85
int log_get_charset_from_header_page(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
Definition: log_manager.c:8645
static void boot_make_temp_volume_fullname(char *temp_vol_fullname, VOLID temp_volid)
Definition: boot_sr.c:959
void logtb_define_trantable(THREAD_ENTRY *thread_p, int num_expected_tran_indices, int num_expected_locks)
char * data
int tz_load(void)
Definition: tz_support.c:337
bool fileio_is_volume_exist(const char *vol_label_p)
Definition: file_io.c:5094
LOG_TDES * LOG_FIND_TDES(int tran_index)
Definition: log_impl.h:1095
int dwb_create(THREAD_ENTRY *thread_p, const char *dwb_path_p, const char *db_name_p)
#define ER_BO_PARSE_ADDVOLS_BAD_NPAGES
Definition: error_code.h:188
const VOLID LOG_MAX_DBVOLID
Definition: log_volids.hpp:34
static int boot_mount(THREAD_ENTRY *thread_p, VOLID volid, const char *vlabel, void *ignore_arg)
Definition: boot_sr.c:1341
#define MAX_NTRANS
VOLID nvols
Definition: boot_sr.c:121
int er_errid(void)
DISK_ISVALID locator_check_by_class_oid(THREAD_ENTRY *thread_p, OID *cls_oid, HFID *hfid, BTID *index_btid, bool repair)
Definition: locator_sr.c:10421
DISK_ISVALID btree_check_by_class_oid(THREAD_ENTRY *thread_p, OID *cls_oid, BTID *idx_btid)
Definition: btree.c:7885
int xboot_restart_from_backup(THREAD_ENTRY *thread_p, int print_restart, const char *db_name, BO_RESTART_ARG *r_args)
Definition: boot_sr.c:2850
#define ER_BO_NOT_A_VOLUME
Definition: error_code.h:175
TRAN_STATE xtran_server_abort(THREAD_ENTRY *thrd)
void oid_set_root(const OID *oid)
Definition: oid.c:118
int disk_format_first_volume(THREAD_ENTRY *thread_p, const char *full_dbname, const char *dbcomments, DKNPAGES npages)
const VOLID LOG_DBTXT_VOLID
Definition: log_volids.hpp:37
#define ER_FILE_UNKNOWN_VOLID
Definition: error_code.h:87
#define er_log_debug(...)
#define DATABASES_FILENAME
#define ER_BO_CANNOT_CREATE_LINK
Definition: error_code.h:971
enum remove_temp_vol_action REMOVE_TEMP_VOL_ACTION
Definition: boot_sr.c:133
static INTL_CODESET boot_get_db_charset_from_header(THREAD_ENTRY *thread_p, const char *log_path, const char *log_prefix)
Definition: boot_sr.c:5918
time_t created_time
Definition: tde.h:161
int heap_scancache_end(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache)
Definition: heap_file.c:7195
void sysprm_final(void)
#define ER_BO_CLIENT_CONNECTED
Definition: error_code.h:1212
int xboot_emergency_patch(const char *db_name, bool recreate_log, DKNPAGES log_npages, const char *db_locale, FILE *out_fp)
Definition: boot_sr.c:5335
char * fileio_get_directory_path(char *path_p, const char *full_name_p)
Definition: file_io.c:5567
#define pgbuf_invalidate_all(thread_p, volid)
Definition: page_buffer.h:286
#define NULL_VOLDES
Definition: file_io.h:44
BOOT_SERVER_STATUS boot_Server_status
Definition: boot_sr.c:148
static int boot_generate_tde_keys(THREAD_ENTRY *thread_p)
int er_init(const char *msglog_filename, int exit_ask)
HFID hfid
Definition: boot_sr.c:111
#define COPY_OID(dest_oid_ptr, src_oid_ptr)
Definition: oid.h:63
const char * rel_build_number(void)
int logpb_scan_volume_info(THREAD_ENTRY *thread_p, const char *db_fullname, VOLID ignore_volid, VOLID start_volid, int(*fun)(THREAD_ENTRY *thread_p, VOLID xvolid, const char *vlabel, void *args), void *args)
VOLID xboot_find_last_temp(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:407
OID rootclass_oid
Definition: boot_sr.c:120
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
int vacuum_create_file_for_dropped_files(THREAD_ENTRY *thread_p, VFID *dropped_files_vfid)
Definition: vacuum.c:4456
const char * er_get_msglog_filename(void)
#define LOB_PATH_PREFIX_MAX
Definition: boot.h:155
int boot_reset_mk_after_restart_from_backup(THREAD_ENTRY *thread_p, BO_RESTART_ARG *r_args)
Definition: boot_sr.c:2941
void area_init(void)
Definition: area_alloc.c:100
void css_set_ha_num_of_hosts(int num)
void lf_destroy_transaction_systems(void)
Definition: lock_free.c:520
void THREAD_ENTRY
#define ER_BO_CANNOT_CREATE_VOL
Definition: error_code.h:184
HEAP_SCANCACHE_NODE node
Definition: heap_file.h:144
VFID vfid
int disk_add_volume_extension(THREAD_ENTRY *thread_p, DB_VOLPURPOSE purpose, DKNPAGES npages, const char *path, const char *name, const char *comments, int max_write_size_in_sec, bool overwrite, VOLID *volid_out)
VOLID DKNVOLS
void logpb_force_flush_header_and_pages(THREAD_ENTRY *thread_p)
VOLID last_volid
Definition: boot_sr.c:123
char server_session_key[SERVER_SESSION_KEY_SIZE]
Definition: boot.h:148
#define HA_GET_MODE()
void spage_finalize(THREAD_ENTRY *thread_p)
Definition: slotted_page.c:816
int heap_cache_class_info(THREAD_ENTRY *thread_p, const OID *class_oid, HFID *hfid, FILE_TYPE ftype, const char *classname_in)
Definition: heap_file.c:23392
char boot_Host_name[CUB_MAXHOSTNAMELEN]
Definition: boot_cl.c:158
#define ER_BO_PARSE_ADDVOLS_UNKNOWN_TOKEN
Definition: error_code.h:190
int css_set_accessible_ip_info(void)
UINT64 prm_get_bigint_value(PARAM_ID prm_id)
const char * rel_build_type(void)
INTL_CODESET lang_charset(void)
STATIC_INLINE int boot_db_parm_update_heap(THREAD_ENTRY *thread_p) __attribute__((ALWAYS_INLINE))
Definition: boot_sr.c:6132
int boot_find_root_heap(HFID *root_hfid_p)
Definition: boot_sr.c:325
int catcls_compile_catalog_classes(THREAD_ENTRY *thread_p)
void es_final(void)
Definition: es.c:116
PGLENGTH log_page_size
Definition: boot.h:145
#define ER_BO_UNKNOWN_DATABASE
Definition: error_code.h:177
int locator_initialize(THREAD_ENTRY *thread_p)
Definition: locator_sr.c:246
int xcache_initialize(THREAD_ENTRY *thread_p)
Definition: xasl_cache.c:280
const char * boot_db_full_name()
Definition: boot_sr.c:470
PGLENGTH page_size
Definition: boot.h:144
EHID * xehash_create(THREAD_ENTRY *thread_p, EHID *ehid, DB_TYPE key_type, int exp_num_entries, OID *class_oid, int attr_id, bool is_tmp)
int client_id
Definition: log_impl.h:481
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
enum boot_server_status BOOT_SERVER_STATUS
Definition: boot_sr.h:69
char * xdisk_get_fullname(THREAD_ENTRY *thread_p, VOLID volid, char *vol_fullname)
db_client_type client_type
int jsp_start_server(const char *db_name, const char *path, int port)
Definition: jsp_sr.c:536
char * fileio_get_volume_label(VOLID vol_id, bool is_peek)
Definition: file_io.c:6182
const char * get_program_name() const
#define ER_BO_TRYING_TO_REMOVE_PERMANENT_VOLUME
Definition: error_code.h:182
#define BOOT_NORMAL_CLIENT_TYPE(client_type)
Definition: boot.h:33
const char * fileio_get_base_file_name(const char *full_name_p)
Definition: file_io.c:5533
#define assert(x)
void er_final(ER_FINAL_CODE do_global_final)
char checksum[TZ_CHECKSUM_SIZE+1]
FILEIO_ZIP_LEVEL
Definition: file_io.h:113
#define ER_LOG_USER_FILE_UNORDERED_ENTRIES
Definition: error_code.h:162
const VOLID LOG_DBFIRST_VOLID
Definition: log_volids.hpp:38
static int boot_find_rest_permanent_volumes(THREAD_ENTRY *thread_p, bool newvolpath, bool use_volinfo, VOLID volid, int(*fun)(THREAD_ENTRY *thread_p, VOLID xvolid, const char *vlabel, void *args), void *args)
Definition: boot_sr.c:1076
static char boot_Lob_path[PATH_MAX+LOB_PATH_PREFIX_MAX]
Definition: boot_sr.c:163
bool check_timezone
Definition: boot_sr.h:81
char * disk_get_link(THREAD_ENTRY *thread_p, INT16 volid, INT16 *next_volid, char *next_volext_fullname)
void log_final(THREAD_ENTRY *thread_p)
Definition: log_manager.c:1664
int32_t fileid
Definition: dbtype_def.h:886
int xboot_compact_db(THREAD_ENTRY *thread_p, OID *class_oids, int n_classes, int space_to_process, int instance_lock_timeout, int class_lock_timeout, bool delete_old_repr, OID *last_processed_class_oid, OID *last_processed_oid, int *total_objects, int *failed_objects, int *modified_objects, int *big_objects, int *initial_last_repr_id)
Definition: boot_sr.c:5860
int prm_get_integer_value(PARAM_ID prm_id)
VOLID temp_nvols
Definition: boot_sr.c:122
#define ER_GENERIC_ERROR
Definition: error_code.h:49
#define STATIC_INLINE
DISK_ISVALID heap_check_all_heaps(THREAD_ENTRY *thread_p)
Definition: heap_file.c:13996
static int boot_make_session_server_key(void)
Definition: boot_sr.c:2008
int xcallback_console_print(THREAD_ENTRY *thread_p, char *print_str)
void fileio_make_volume_temp_name(char *vol_tmp_full_name_p, const char *tmp_path_p, const char *tmp_name_p, VOLID vol_id)
Definition: file_io.c:5690
#define LOG_ISTRAN_ACTIVE(tdes)
Definition: log_impl.h:182
void fileio_close(int vol_fd)
Definition: file_io.c:2078
static jmp_buf boot_Init_server_jmpbuf
Definition: boot_sr.c:1379
int xboot_register_client(THREAD_ENTRY *thread_p, BOOT_CLIENT_CREDENTIAL *client_credential, int client_lock_wait, TRAN_ISOLATION client_isolation, TRAN_STATE *tran_state, BOOT_SERVER_CREDENTIAL *server_credential)
Definition: boot_sr.c:3179
#define REFPTR(T, name)
Definition: porting.h:1089
#define ER_BO_MISSING_OR_INVALID_CATALOG
Definition: error_code.h:1135
TDE_CIPHER tde_Cipher
Definition: tde.c:69
int css_init_conn_list(void)
VFID dropped_files_vfid
Definition: boot_sr.c:127
int logpb_recreate_volume_info(THREAD_ENTRY *thread_p)
#define SINGLE_ROW_UPDATE
Definition: btree.h:54
int logtb_initialize_global_unique_stats_table(THREAD_ENTRY *thread_p)
void boot_server_all_finalize(THREAD_ENTRY *thread_p, ER_FINAL_CODE is_er_final, BOOT_SERVER_SHUTDOWN_MODE shutdown_common_modules)
Definition: boot_sr.c:3864
HFID * disk_get_boot_hfid(THREAD_ENTRY *thread_p, INT16 volid, HFID *hfid)
int sysprm_load_and_init(const char *db_name, const char *conf_file, const int load_flags)
static int boot_xremove_temp_volume(THREAD_ENTRY *thread_p, VOLID volid, const char *vlabel)
Definition: boot_sr.c:953
int heap_update_logical(THREAD_ENTRY *thread_p, HEAP_OPERATION_CONTEXT *context)
Definition: heap_file.c:22771
int catcls_get_server_compat_info(THREAD_ENTRY *thread_p, INTL_CODESET *charset_id_p, char *lang_buf, const int lang_buf_size, char *timezone_checksum)
void session_states_init(THREAD_ENTRY *thread_p)
Definition: session.c:582
void xcache_finalize(THREAD_ENTRY *thread_p)
Definition: xasl_cache.c:344
void tde_make_keys_file_fullname(char *keys_vol_fullname, const char *db_full_name, bool ignore_parm)
Definition: tde.c:492
#define DB_MAX_IDENTIFIER_LENGTH
Definition: dbtype_def.h:495
void heap_create_update_context(HEAP_OPERATION_CONTEXT *context, HFID *hfid_p, OID *oid_p, OID *class_oid_p, RECDES *recdes_p, HEAP_SCANCACHE *scancache_p, UPDATE_INPLACE_STYLE in_place)
Definition: heap_file.c:22378
static char boot_Db_full_name[PATH_MAX]
Definition: boot_sr.c:158
void tp_final(void)
int heap_manager_initialize(void)
Definition: heap_file.c:5070
void heap_create_insert_context(HEAP_OPERATION_CONTEXT *context, HFID *hfid_p, OID *class_oid_p, RECDES *recdes_p, HEAP_SCANCACHE *scancache_p)
Definition: heap_file.c:22324
int xboot_backup(THREAD_ENTRY *thread_p, 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)
Definition: boot_sr.c:3939
int disk_manager_init(THREAD_ENTRY *thread_p, bool load_from_disk)
bool is_restore_from_backup
Definition: boot_sr.h:104
#define TRAN_LOCK_INFINITE_WAIT
Definition: log_comm.h:29
void lock_unlock_object(THREAD_ENTRY *thread_p, const OID *oid, const OID *class_oid, LOCK lock, bool force)
DB_TRAN_ISOLATION
Definition: dbtran_def.h:26
void log_restart_emergency(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
Definition: log_manager.c:1811
char keys_file_path[PATH_MAX]
Definition: boot_sr.h:107
int qmgr_initialize(THREAD_ENTRY *thread_p)
int initialize_thread_entries(bool with_lock_free)
int disk_set_boot_hfid(THREAD_ENTRY *thread_p, INT16 volid, const HFID *hfid)
void logtb_finalize_global_unique_stats_table(THREAD_ENTRY *thread_p)
std::string db_user
#define ER_PRM_CONFLICT_EXISTS_ON_MULTIPLE_SECTIONS
Definition: error_code.h:1233
int tde_get_keyinfo(THREAD_ENTRY *thread_p, TDE_KEYINFO *keyinfo)
Definition: tde.c:557
CTID ctid
Definition: boot_sr.c:116
int boot_dbparm_save_volume(THREAD_ENTRY *thread_p, DB_VOLTYPE voltype, VOLID volid)
Definition: boot_sr.c:6069
int cub_dirname_r(const char *path, char *pathbuf, size_t buflen)
Definition: porting.c:989
int xheap_create(THREAD_ENTRY *thread_p, HFID *hfid, const OID *class_oid, bool reuse_oid)
Definition: heap_file.c:5772
void partition_cache_finalize(THREAD_ENTRY *thread_p)
Definition: partition.c:748
void fileio_dismount(THREAD_ENTRY *thread_p, int vol_fd)
Definition: file_io.c:3134
#define DB_MAX_PATH_LENGTH
int perfmon_initialize(int num_trans)
void lang_final(void)
VFID vfid
int heap_insert_logical(THREAD_ENTRY *thread_p, HEAP_OPERATION_CONTEXT *context, PGBUF_WATCHER *home_hint_p)
Definition: heap_file.c:22426
const char * rel_name(void)
int fileio_synchronize_all(THREAD_ENTRY *thread_p, bool is_include)
Definition: file_io.c:4618
#define DB_SIZEOF(val)
Definition: memory_alloc.h:54
void vacuum_stop_workers(THREAD_ENTRY *thread_p)
Definition: vacuum.c:1332
void locator_initialize_areas(void)
Definition: locator.c:166
void fileio_dismount_all(THREAD_ENTRY *thread_p)
Definition: file_io.c:3374
int log_create(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname, DKNPAGES npages)
Definition: log_manager.c:749
HFID rootclass_hfid
Definition: boot_sr.c:112
void locator_finalize(THREAD_ENTRY *thread_p)
Definition: locator_sr.c:364
#define NULL
Definition: freelistheap.h:34
void event_log_final(void)
Definition: event_log.c:208
static int total_objects
Definition: compactdb.c:56
#define CTIME_MAX
Definition: porting.h:72
#define strncpy_bufsize(buf, str)
Definition: porting.h:340
const char * er_msg(void)
void disk_manager_final(void)
char * vol_path
Definition: boot.h:105
int logpb_backup(THREAD_ENTRY *thread_p, int num_perm_vols, const char *allbackup_path, FILEIO_BACKUP_LEVEL backup_level, bool delete_unneeded_logarchives, const char *backup_verbose_file_path, int num_threads, FILEIO_ZIP_METHOD zip_method, FILEIO_ZIP_LEVEL zip_level, int skip_activelog, int sleep_msecs, bool separate_keys)
int xboot_compact_start(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:5886
void log_stop_ha_delay_registration()
Definition: log_manager.c:1790
if(extra_options)
Definition: dynamic_load.c:958
#define ER_LOC_INIT
Definition: error_code.h:1370
EHID xhid
DKNPAGES xdisk_get_total_numpages(THREAD_ENTRY *thread_p, VOLID volid)
static char boot_Server_session_key[SERVER_SESSION_KEY_SIZE]
Definition: boot_sr.c:165
int util_compare_filepath(const char *file1, const char *file2)
Definition: util_func.c:111
int logtb_reflect_global_unique_stats_to_btree(THREAD_ENTRY *thread_p)
bool logpb_exist_log(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname)
#define err(fd,...)
Definition: porting.h:431
int logtb_assign_tran_index(THREAD_ENTRY *thread_p, TRANID trid, TRAN_STATE state, const BOOT_CLIENT_CREDENTIAL *client_credential, TRAN_STATE *current_state, int wait_msecs, TRAN_ISOLATION isolation)
int catcls_find_and_set_cached_class_oid(THREAD_ENTRY *thread_p)
int xvacuum(THREAD_ENTRY *thread_p)
Definition: vacuum.c:962
bool cfg_delete_db(DB_INFO **dir_info_p, const char *name)
int es_init(const char *uri)
Definition: es.c:53
void catalog_finalize(void)
int logpb_restore(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname, bo_restart_arg *r_args)
static void boot_remove_useless_path_separator(const char *path, char *new_path)
Definition: boot_sr.c:585
static int failed_objects
Definition: compactdb.c:57
std::string program_name
void perfmon_finalize(void)
#define db_private_free(thrd, ptr)
Definition: memory_alloc.h:229
HA_SERVER_STATE ha_server_state
Definition: boot.h:147
int tde_find_first_mk(int vdes, int *mk_index, unsigned char *master_key, time_t *created_time)
Definition: tde.c:1504
VFID vfid
VFID vacuum_data_vfid
Definition: boot_sr.c:126
int tde_change_mk(THREAD_ENTRY *thread_p, const int mk_index, const unsigned char *master_key, const time_t created_time)
Definition: tde.c:649
int msgcat_init(void)
#define NULL_FILEID
void COMPOSE_FULL_NAME(char *buf, size_t buf_size, const char *path, const char *name)
Definition: boot.h:161
int cfg_read_directory_ex(int vdes, DB_INFO **info_p, bool write_flag)
static int boot_find_rest_volumes(THREAD_ENTRY *thread_p, BO_RESTART_ARG *r_args, VOLID volid, int(*fun)(THREAD_ENTRY *thread_p, VOLID xvolid, const char *vlabel, void *args), void *args)
Definition: boot_sr.c:1034
static int boot_remove_temp_volume(THREAD_ENTRY *thread_p, VOLID volid, const char *vlabel)
Definition: boot_sr.c:500
#define ER_BO_UNKNOWN_VOLUME
Definition: error_code.h:1072
#define MSGCAT_SET_GENERAL
char * db_name
CLIENTIDS client
Definition: log_impl.h:484
#define ER_BO_MAXNUM_VOLS_HAS_BEEN_EXCEEDED
Definition: error_code.h:181
#define LOG_SET_CURRENT_TRAN_INDEX(thrd, index)
Definition: log_impl.h:178
ES_TYPE
Definition: es_common.h:28
int pgbuf_flush_all(THREAD_ENTRY *thread_p, VOLID volid)
Definition: page_buffer.c:3083
static bool skip_to_check_ct_classes_for_rebuild
Definition: boot_sr.c:164
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
#define IO_DEFAULT_PAGE_SIZE
DB_INFO * cfg_add_db(DB_INFO **dir, const char *name, const char *path, const char *logpath, const char *lobpath, const char *host)
#define MSGCAT_CATALOG_CUBRID
int tde_load_mk(int vdes, const TDE_KEYINFO *keyinfo, unsigned char *master_key)
Definition: tde.c:693
const char * lang_charset_cubrid_name(const INTL_CODESET codeset)
const char * css_ha_mode_string(HA_MODE mode)
void serial_finalize_cache_pool(void)
Definition: serial.c:1111
int xboot_check_db_consistency(THREAD_ENTRY *thread_p, int check_flag, OID *oids, int num_oids, BTID *index_btid)
Definition: boot_sr.c:3713
#define ER_BO_UNABLE_TO_FIND_HOSTNAME
Definition: error_code.h:180
void er_stack_pop(void)
SCAN_CODE heap_first(THREAD_ENTRY *thread_p, const HFID *hfid, OID *class_oid, OID *oid, RECDES *recdes, HEAP_SCANCACHE *scan_cache, int ispeeking)
Definition: heap_file.c:8097
static int boot_parse_add_volume_extensions(THREAD_ENTRY *thread_p, const char *filename_addmore_vols)
Definition: boot_sr.c:682
void set_final(void)
Definition: set_object.c:297
void tf_compile_meta_classes()
Definition: transform.c:550
void boot_server_status(BOOT_SERVER_STATUS status)
Definition: boot_sr.c:227
const char * envvar_get(const char *name)
#define NULL_TRAN_INDEX
static void error(const char *msg)
Definition: gencat.c:331
#define ER_BO_SERVER_STATUS
Definition: error_code.h:1213
int lang_set_charset_lang(const char *lang_charset)
#define ER_BO_UNABLE_TO_RESTART_SERVER
Definition: error_code.h:174
DISK_ISVALID locator_check_class_names(THREAD_ENTRY *thread_p)
Definition: locator_sr.c:1923
#define ER_INTERRUPTED
Definition: error_code.h:51
void logtb_free_tran_index(THREAD_ENTRY *thread_p, int tran_index)
bool log_check_system_op_is_started(THREAD_ENTRY *thread_p)
Definition: log_manager.c:4166
#define ER_BO_DIRECTORY_DOESNOT_EXIST
Definition: error_code.h:1269
void log_set_db_restore_time(THREAD_ENTRY *thread_p, INT64 db_restore_time)
Definition: log_manager.c:9351
#define LOG_FIND_THREAD_TRAN_INDEX(thrd)
Definition: perf_monitor.h:158
#define HFID_IS_NULL(hfid)
#define ARG_FILE_LINE
Definition: error_manager.h:44
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: porting.c:2584
void tsc_init(void)
Definition: tsc_timer.c:67
int vacuum_initialize(THREAD_ENTRY *thread_p, int vacuum_log_block_npages, VFID *vacuum_data_vfid, VFID *dropped_files_vfid, bool is_restore)
Definition: vacuum.c:1160
const VOLID LOG_DBTDE_KEYS_VOLID
Definition: log_volids.hpp:41
void spage_boot(THREAD_ENTRY *thread_p)
Definition: slotted_page.c:798
static char * boot_volume_info_log_path(char *log_path)
Definition: boot_sr.c:5784
static const bool COPY
int vacuum_boot(THREAD_ENTRY *thread_p)
Definition: vacuum.c:1261
bool boot_set_skip_check_ct_classes(bool val)
Definition: boot_sr.c:5902
DB_VOLTYPE
Definition: dbtype_def.h:192
bool tde_validate_keys_file(int vdes)
Definition: tde.c:358
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
int tde_cipher_initialize(THREAD_ENTRY *thread_p, const HFID *keyinfo_hfid, const char *mk_path_given)
Definition: tde.c:232
int fileio_synchronize(THREAD_ENTRY *thread_p, int vol_fd, const char *vlabel, FILEIO_SYNC_OPTION sync_dwb)
Definition: file_io.c:4441
INT16 PGLENGTH
enum boot_server_shutdown_mode BOOT_SERVER_SHUTDOWN_MODE
Definition: boot_sr.h:74
int xboot_soft_rename(THREAD_ENTRY *thread_p, const char *old_db_name, const char *new_db_name, const char *new_db_path, const char *new_log_path, const char *new_db_server_host, const char *new_volext_path, const char *fileof_vols_and_renamepaths, bool new_db_overwrite, bool extern_rename, bool force_delete)
Definition: boot_sr.c:4381
CTID * catalog_create(THREAD_ENTRY *thread_p, CTID *catalog_id_p)
void disk_unlock_extend(void)
#define ER_ES_GENERAL
Definition: error_code.h:1271
int logpb_check_exist_any_volumes(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname, char *first_vol, bool *is_exist)
#define BOOT_FORMAT_MAX_LENGTH
Definition: boot_sr.c:104
void fpcache_finalize(THREAD_ENTRY *thread_p)
int serial_initialize_cache_pool(THREAD_ENTRY *thread_p)
Definition: serial.c:1073
const char * get_db_user() const
int disk_get_boot_db_charset(THREAD_ENTRY *thread_p, INT16 volid, INTL_CODESET *db_charset)
int msgcat_final(void)
#define free_and_init(ptr)
Definition: memory_alloc.h:147
int heap_scancache_quick_start_with_class_hfid(THREAD_ENTRY *thread_p, HEAP_SCANCACHE *scan_cache, const HFID *hfid)
Definition: heap_file.c:19308
int fpcache_initialize(THREAD_ENTRY *thread_p)
#define strlen(s1)
Definition: intl_support.c:43
char * prm_get_string_value(PARAM_ID prm_id)
bool xboot_shutdown_server(REFPTR(THREAD_ENTRY, thread_p), ER_FINAL_CODE is_er_final)
Definition: boot_sr.c:3080
DISK_ISVALID heap_check_heap_file(THREAD_ENTRY *thread_p, HFID *hfid)
Definition: heap_file.c:13941
int tde_copy_keys_file(THREAD_ENTRY *thread_p, const char *dest_fullname, const char *src_fullname, bool keep_dest_mount, bool keep_src_mount)
Definition: tde.c:398
void fileio_make_volume_ext_given_name(char *vol_ext_full_name_p, const char *ext_path_p, const char *ext_name_p)
Definition: file_io.c:5672
enum intl_codeset INTL_CODESET
Definition: intl_support.h:190
int qfile_initialize_list_cache(THREAD_ENTRY *thread_p)
Definition: list_file.c:4895
bool prm_get_bool_value(PARAM_ID prm_id)
bool is_loaded
Definition: tde.h:148
int logpb_copy_database(THREAD_ENTRY *thread_p, VOLID num_perm_vols, const char *to_db_fullname, const char *to_logpath, const char *to_prefix_logname, const char *toext_path, const char *fileof_vols_and_copypaths)
int intl_mbs_casecmp(const char *mbs1, const char *mbs2)
Definition: intl_support.c:358
int css_check_ha_server_state_for_client(THREAD_ENTRY *thread_p, int whence)
VFID query_vfid
Definition: boot_sr.c:118
HA_SERVER_STATE css_ha_server_state(void)
#define ER_BO_CWD_FAIL
Definition: error_code.h:179
int boot_compact_start(THREAD_ENTRY *thread_p)
Definition: compactdb_sr.c:694
void er_clear(void)
int boot_get_new_volume_name_and_id(THREAD_ENTRY *thread_p, DB_VOLTYPE voltype, const char *given_path, const char *given_name, char *fullname_newvol_out, VOLID *volid_newvol_out)
Definition: boot_sr.c:5995
int log_recreate(THREAD_ENTRY *thread_p, const char *db_fullname, const char *logpath, const char *prefix_logname, DKNPAGES log_npages, FILE *out_fp)
Definition: log_manager.c:8449
VFID trk_vfid
Definition: boot_sr.c:110
static int boot_remove_all_temp_volumes(THREAD_ENTRY *thread_p, REMOVE_TEMP_VOL_ACTION delete_action)
Definition: boot_sr.c:899
int catcls_get_db_collation(THREAD_ENTRY *thread_p, LANG_COLL_COMPAT **db_collations, int *coll_cnt)
void heap_flush(THREAD_ENTRY *thread_p, const OID *oid)
Definition: heap_file.c:5974
int i
Definition: dynamic_load.c:954
static int boot_remove_all_volumes(THREAD_ENTRY *thread_p, const char *db_fullname, const char *log_path, const char *log_prefix, bool dirty_rem, bool force_delete)
Definition: boot_sr.c:5210
void vacuum_sa_reflect_last_blockid(THREAD_ENTRY *thread_p)
Definition: vacuum.c:7647
char * msgcat_message(int cat_id, int set_id, int msg_id)
const char * prm_get_name(PARAM_ID prm_id)
int heap_assign_address(THREAD_ENTRY *thread_p, const HFID *hfid, OID *class_oid, OID *oid, int expected_length)
Definition: heap_file.c:5914
int xboot_find_number_temp_volumes(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:359
void log_abort_all_active_transaction(THREAD_ENTRY *thread_p)
Definition: log_manager.c:1552
enum ha_mode HA_MODE
#define SERVER_SESSION_KEY_SIZE
INT16 type
char * strdup(const char *str)
Definition: porting.c:901
int xboot_delete(const char *db_name, bool force_delete, BOOT_SERVER_SHUTDOWN_MODE shutdown_common_modules)
Definition: boot_sr.c:4653
#define NULL_VOLID
const char * comments
#define HA_DISABLED()
void event_log_init(const char *db_name)
Definition: event_log.c:70
TRAN_STATE
Definition: log_comm.h:36
void initialize(entry *&my_entry)
DISK_ISVALID btree_repair_prev_link(THREAD_ENTRY *thread_p, OID *oid, BTID *index_btid, bool repair)
Definition: btree.c:8203
static bool boot_Init_server_is_canceled
Definition: boot_sr.c:1382
#define LOG_PAGESIZE
#define BTID_IS_NULL(btid)
void area_final(void)
Definition: area_alloc.c:119
DISK_ISVALID disk_check(THREAD_ENTRY *thread_p, bool repair)
short volid
Definition: dbtype_def.h:887
int dwb_destroy(THREAD_ENTRY *thread_p)
const char * xboot_get_server_session_key(void)
Definition: boot_sr.c:3151
#define ER_TDE_INVALID_KEYS_FILE
Definition: error_code.h:1608
int mc_n_variable
Definition: transform.h:53
static OID boot_Header_oid
Definition: boot_sr.c:159
enum ha_server_state HA_SERVER_STATE
Definition: boot.h:126
#define VPID_GET_FROM_OID(vpid_ptr, oid_ptr)
Definition: page_buffer.h:46
int vacuum_create_file_for_vacuum_data(THREAD_ENTRY *thread_p, VFID *vacuum_data_vfid)
Definition: vacuum.c:4357
int file_tracker_create(THREAD_ENTRY *thread_p, VFID *vfid_tracker_out)
#define ER_BO_CANNOT_ACCESS_MESSAGE_CATALOG
Definition: error_code.h:183
#define OID_ISNULL(oidp)
Definition: oid.h:81
void cfg_write_directory_ex(int vdes, const DB_INFO *databases)
void disk_lock_extend(void)
void finalize(void)
int logpb_delete(THREAD_ENTRY *thread_p, VOLID num_perm_vols, const char *db_fullname, const char *logpath, const char *prefix_logname, bool force_delete)
int xboot_initialize_server(const BOOT_CLIENT_CREDENTIAL *client_credential, BOOT_DB_PATH_INFO *db_path_info, bool db_overwrite, const char *file_addmore_vols, volatile DKNPAGES db_npages, PGLENGTH db_desired_pagesize, volatile DKNPAGES log_npages, PGLENGTH db_desired_log_page_size, OID *rootclass_oid, HFID *rootclass_hfid, int client_lock_wait, TRAN_ISOLATION client_isolation)
Definition: boot_sr.c:1462
int lang_check_coll_compat(const LANG_COLL_COMPAT *coll_array, const int coll_cnt, const char *client_text, const char *server_text)
LOG_PAGEID logpb_checkpoint(THREAD_ENTRY *thread_p)
#define BOOTSR_MAX_LINE
Definition: boot_sr.c:105
DB_VOLPURPOSE purpose
void prm_set_bool_value(PARAM_ID prm_id, bool value)
#define ER_TDE_CIPHER_LOAD_FAIL
Definition: error_code.h:1615
#define ER_BO_DATABASE_EXISTS
Definition: error_code.h:176
#define LANG_MAX_LANGNAME
int qfile_finalize_list_cache(THREAD_ENTRY *thread_p)
Definition: list_file.c:5010
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
int heap_get_class_info(THREAD_ENTRY *thread_p, const OID *class_oid, HFID *hfid_out, FILE_TYPE *ftype_out, char **classname_out)
Definition: heap_file.c:16733
static BOOT_DB_PARM * boot_Db_parm
Definition: boot_sr.c:161
char * db_full_name
Definition: boot.h:138
#define strncpy_size(buf, str, size)
Definition: porting.h:326
#define LOB_PATH_DEFAULT_PREFIX
Definition: boot.h:156
DISK_ISVALID btree_check_all(THREAD_ENTRY *thread_p)
Definition: btree.c:8271
bool catcls_Enable
#define ER_CFG_NO_FILE
Definition: error_code.h:238
#define PEEK
Definition: file_io.h:74
DISK_ISVALID locator_check_all_entries_of_all_btrees(THREAD_ENTRY *thread_p, bool repair)
Definition: locator_sr.c:10501
#define ER_TZ_LOAD_ERROR
Definition: error_code.h:1487
VOLID boot_find_next_permanent_volid(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:425
void log_set_ha_promotion_time(THREAD_ENTRY *thread_p, INT64 ha_promotion_time)
Definition: log_manager.c:9334
const char * lang_get_Lang_name(void)
FILEIO_BACKUP_LEVEL
Definition: file_io.h:96
FILEIO_ZIP_METHOD
Definition: file_io.h:104
HFID tde_keyinfo_hfid
Definition: boot_sr.c:128
int fileio_open(const char *vol_label_p, int flags, int mode)
Definition: file_io.c:1957
int xboot_copy(REFPTR(THREAD_ENTRY, thread_p), const char *from_dbname, const char *new_db_name, const char *new_db_path, const char *new_log_path, const char *new_lob_path, const char *new_db_server_host, const char *new_volext_path, const char *fileof_vols_and_copypaths, bool new_db_overwrite)
Definition: boot_sr.c:3975
void cfg_free_directory(DB_INFO *databases)
void qmgr_finalize(THREAD_ENTRY *thread_p)
#define HFID_COPY(hfid_ptr1, hfid_ptr2)
#define PATH_SEPARATOR
Definition: porting.h:347
void fileio_make_volume_info_name(char *vol_info_name_p, const char *db_full_name_p)
Definition: file_io.c:5636
#define ER_TDE_RESTORE_CHANGE_MASTER_KEY
Definition: error_code.h:1621
void tz_unload(void)
Definition: tz_support.c:381
int boot_compact_db(THREAD_ENTRY *thread_p, OID *class_oids, int n_classes, int space_to_process, int instance_lock_timeout, int class_lock_timeout, bool delete_old_repr, OID *last_processed_class_oid, OID *last_processed_oid, int *total_objects, int *failed_objects, int *modified_objects, int *big_objects, int *initial_last_repr_id)
Definition: compactdb_sr.c:516
#define TDE_MASTER_KEY_LENGTH
Definition: tde.h:54
int css_notify_ha_log_applier_state(THREAD_ENTRY *thread_p, HA_LOG_APPLIER_STATE state)
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)
Definition: porting.c:1333
#define GETHOSTNAME(p, l)
Definition: porting.h:381
#define VFID_SET_NULL(vfid_ptr)
Definition: file_manager.h:65
ES_TYPE es_get_type(const char *uri)
Definition: es_common.c:43
const char ** p
Definition: dynamic_load.c:945
bool newvolpath
Definition: boot_sr.h:99
int partition_cache_init(THREAD_ENTRY *thread_p)
Definition: partition.c:711
int db_set_page_size(PGLENGTH io_page_size, PGLENGTH log_page_size)
DISK_ISVALID
Definition: disk_manager.h:53
#define ERR_MSG_SIZE
int intl_identifier_upper(const char *src, char *dst)
DISK_ISVALID catalog_check_consistency(THREAD_ENTRY *thread_p)
enum er_final_code ER_FINAL_CODE
#define ER_ES_NO_LOB_PATH
Definition: error_code.h:1274
DISK_ISVALID file_tracker_check(THREAD_ENTRY *thread_p)
const char * get_db_name() const
char * log_path
Definition: boot.h:106
static int boot_create_all_volumes(THREAD_ENTRY *thread_p, const BOOT_CLIENT_CREDENTIAL *client_credential, const char *db_comments, DKNPAGES db_npages, const char *file_addmore_vols, const char *log_path, const char *log_prefix, DKNPAGES log_npages, int client_lock_wait, TRAN_ISOLATION client_isolation)
Definition: boot_sr.c:4902
int client_id
DB_INFO * cfg_find_db_list(DB_INFO *db_info_list_p, const char *name)
int fileio_get_volume_descriptor(VOLID vol_id)
Definition: file_io.c:6488
#define ER_BO_CANNOT_FINE_VOLINFO
Definition: error_code.h:650
int logpb_rename_all_volumes_files(THREAD_ENTRY *thread_p, VOLID num_perm_vols, const char *to_db_fullname, const char *to_logpath, const char *to_prefix_logname, const char *toext_path, const char *fileof_vols_and_renamepaths, bool extern_rename, bool force_delete)
void cfg_write_directory(const DB_INFO *databases)
SCAN_CODE heap_get_class_record(THREAD_ENTRY *thread_p, const OID *class_oid, RECDES *recdes_p, HEAP_SCANCACHE *scan_cache, int ispeeking)
Definition: heap_file.c:24780
static void boot_remove_unknown_temp_volumes(THREAD_ENTRY *thread_p)
Definition: boot_sr.c:995