57
57
#include "que0que.h"
59
59
/* Log sequence number immediately after startup */
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
61
61
/* Log sequence number at shutdown */
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
62
dulint srv_shutdown_lsn;
64
64
#ifdef HAVE_DARWIN_THREADS
65
65
# include <sys/utsname.h>
66
UNIV_INTERN ibool srv_have_fullfsync = FALSE;
66
ibool srv_have_fullfsync = FALSE;
69
UNIV_INTERN ibool srv_start_raw_disk_in_use = FALSE;
71
UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
72
UNIV_INTERN ibool srv_is_being_started = FALSE;
73
UNIV_INTERN ibool srv_was_started = FALSE;
69
ibool srv_start_raw_disk_in_use = FALSE;
71
ulint srv_sizeof_trx_t_in_ha_innodb_cc;
73
ibool srv_startup_is_before_trx_rollback_phase = FALSE;
74
ibool srv_is_being_started = FALSE;
74
75
#ifndef UNIV_HOTBACKUP
75
76
static ibool srv_start_has_been_called = FALSE;
77
static ibool srv_was_started = FALSE;
76
78
#endif /* !UNIV_HOTBACKUP */
78
80
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
79
81
and then to SRV_SHUTDOWN_LAST_PHASE */
80
UNIV_INTERN ulint srv_shutdown_state = 0;
82
ulint srv_shutdown_state = 0;
82
84
#ifndef UNIV_HOTBACKUP
83
85
static os_file_t files[1000];
148
150
/*************************************************************************
149
151
Reads the data files and their sizes from a character string given in
150
152
the .cnf file. */
153
155
srv_parse_data_file_paths_and_sizes(
154
156
/*================================*/
456
458
/*************************************************************************
457
459
Normalizes a directory path for Windows: converts slashes to backslashes. */
460
462
srv_normalize_path_for_win(
461
463
/*=======================*/
475
477
/*************************************************************************
476
478
Adds a slash or a backslash to the end of a string if it is missing
477
479
and the string is not empty. */
480
482
srv_add_path_separator_if_needed(
481
483
/*=============================*/
650
652
which is for this log group */
652
654
fil_space_create(name,
653
2 * k + SRV_LOG_SPACE_FIRST_ID, 0, FIL_LOG);
655
2 * k + SRV_LOG_SPACE_FIRST_ID, FIL_LOG);
656
658
ut_a(fil_validate());
665
667
if (k == 0 && i == 0) {
666
668
arch_space_id = 2 * k + 1 + SRV_LOG_SPACE_FIRST_ID;
668
fil_space_create("arch_log_space", arch_space_id, 0, FIL_LOG);
670
fil_space_create("arch_log_space", arch_space_id, FIL_LOG);
670
672
arch_space_id = ULINT_UNDEFINED;
688
690
open_or_create_data_files(
689
691
/*======================*/
690
/* out: DB_SUCCESS or error code */
691
ibool* create_new_db, /* out: TRUE if new database should be
692
/* out: DB_SUCCESS or error code */
693
ibool* create_new_db, /* out: TRUE if new database should be
693
695
#ifdef UNIV_LOG_ARCHIVE
694
ulint* min_arch_log_no,/* out: min of archived log
695
numbers in data files */
696
ulint* max_arch_log_no,/* out: max of archived log
697
numbers in data files */
696
ulint* min_arch_log_no,/* out: min of archived log numbers in data
698
ulint* max_arch_log_no,/* out: */
698
699
#endif /* UNIV_LOG_ARCHIVE */
699
ib_uint64_t* min_flushed_lsn,/* out: min of flushed lsn
700
values in data files */
701
ib_uint64_t* max_flushed_lsn,/* out: max of flushed lsn
702
values in data files */
703
ulint* sum_of_new_sizes)/* out: sum of sizes of the
700
dulint* min_flushed_lsn,/* out: min of flushed lsn values in data
702
dulint* max_flushed_lsn,/* out: */
703
ulint* sum_of_new_sizes)/* out: sum of sizes of the new files added */
940
fil_space_create(name, 0, 0, FIL_TABLESPACE);
939
fil_space_create(name, 0, FIL_TABLESPACE);
943
942
ut_a(fil_validate());
945
fil_node_create(name, srv_data_file_sizes[i], 0,
946
srv_data_file_is_raw_partition[i] != 0);
944
if (srv_data_file_is_raw_partition[i]) {
946
fil_node_create(name, srv_data_file_sizes[i], 0, TRUE);
948
fil_node_create(name, srv_data_file_sizes[i], 0,
957
961
Starts InnoDB and creates a new database if database files
958
962
are not found and the user wants. Server parameters are
959
963
read from a file of name "srv_init" in the ib_home directory. */
962
966
innobase_start_or_create_for_mysql(void)
963
967
/*====================================*/
964
968
/* out: DB_SUCCESS or error code */
968
ibool log_file_created;
969
ibool log_created = FALSE;
970
ibool log_opened = FALSE;
971
ib_uint64_t min_flushed_lsn;
972
ib_uint64_t max_flushed_lsn;
972
ibool log_file_created;
973
ibool log_created = FALSE;
974
ibool log_opened = FALSE;
975
dulint min_flushed_lsn;
976
dulint max_flushed_lsn;
973
977
#ifdef UNIV_LOG_ARCHIVE
974
ulint min_arch_log_no;
975
ulint max_arch_log_no;
978
ulint min_arch_log_no;
979
ulint max_arch_log_no;
976
980
#endif /* UNIV_LOG_ARCHIVE */
977
ulint sum_of_new_sizes;
978
ulint sum_of_data_file_sizes;
979
ulint tablespace_size_in_header;
982
my_bool srv_file_per_table_original_value
983
= srv_file_per_table;
981
ulint sum_of_new_sizes;
982
ulint sum_of_data_file_sizes;
983
ulint tablespace_size_in_header;
986
ibool srv_file_per_table_original_value = srv_file_per_table;
985
988
#ifdef HAVE_DARWIN_THREADS
986
989
# ifdef F_FULLFSYNC
987
990
/* This executable has been compiled on Mac OS X 10.3 or later.
1015
1018
(ulong)sizeof(ulint), (ulong)sizeof(void*));
1018
/* System tables are created in tablespace 0. Thus, we must
1019
temporarily clear srv_file_per_table. This is ok, because the
1020
server will not accept connections (which could modify
1021
innodb_file_per_table) until this function has returned. */
1022
srv_file_per_table = FALSE;
1021
srv_file_per_table = FALSE; /* system tables are created in tablespace
1023
1023
#ifdef UNIV_DEBUG
1024
1024
fprintf(stderr,
1025
1025
"InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1046
1046
"InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1049
#ifdef UNIV_SIMULATE_AWE
1051
"InnoDB: !!!!!!!! UNIV_SIMULATE_AWE switched on !!!!!!!!!\n");
1053
if (srv_sizeof_trx_t_in_ha_innodb_cc != (ulint)sizeof(trx_t)) {
1055
"InnoDB: Error: trx_t size is %lu in ha_innodb.cc"
1056
" but %lu in srv0start.c\n"
1057
"InnoDB: Check that pthread_mutex_t is defined"
1058
" in the same way in these\n"
1059
"InnoDB: compilation modules. Cannot continue.\n",
1060
(ulong) srv_sizeof_trx_t_in_ha_innodb_cc,
1061
(ulong) sizeof(trx_t));
1049
1065
/* Since InnoDB does not currently clean up all its internal data
1050
1066
structures in MySQL Embedded Server Library server_end(), we
1051
1067
print an error message if someone tries to start up InnoDB a
1072
1088
srv_startup_is_before_trx_rollback_phase = TRUE;
1073
1089
os_aio_use_native_aio = FALSE;
1091
#if !defined(__WIN2000__) && !defined(UNIV_SIMULATE_AWE)
1095
"InnoDB: Error: You have specified"
1096
" innodb_buffer_pool_awe_mem_mb\n"
1097
"InnoDB: in my.cnf, but AWE can only"
1098
" be used in Windows 2000 and later.\n"
1099
"InnoDB: To use AWE, InnoDB must"
1100
" be compiled with __WIN2000__ defined.\n");
1076
1107
if (os_get_os_version() == OS_WIN95
1077
1108
|| os_get_os_version() == OS_WIN31
1133
1164
/* Note that the call srv_boot() also changes the values of
1134
some variables to the units used by InnoDB internally */
1165
srv_pool_size etc. to the units used by InnoDB internally */
1136
1167
/* Set the maximum number of threads which can wait for a semaphore
1137
1168
inside InnoDB: this is the 'sync wait array' size, as well as the
1138
1169
maximum number of threads that can wait in the 'srv_conc array' for
1139
1170
their time to enter InnoDB. */
1141
#if defined(__NETWARE__)
1143
/* Create less event semaphores because Win 98/ME had
1144
difficulty creating 40000 event semaphores. Comment from
1145
Novell, Inc.: also, these just take a lot of memory on
1147
srv_max_n_threads = 1000;
1149
if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1150
/* If buffer pool is less than 1000 MB,
1172
if (srv_pool_size >= 1000 * 1024) {
1173
/* Here we still have srv_pool_size counted
1174
in kilobytes (in 4.0 this was in bytes)
1175
srv_boot() converts the value to
1176
pages; if buffer pool is less than 1000 MB,
1151
1177
assume fewer threads. */
1152
1178
srv_max_n_threads = 50000;
1154
} else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1180
} else if (srv_pool_size >= 8 * 1024) {
1156
1182
srv_max_n_threads = 10000;
1227
1252
fil_init(srv_max_n_open_files);
1229
ret = buf_pool_init();
1256
"InnoDB: Using AWE: Memory window is %lu MB"
1257
" and AWE memory is %lu MB\n",
1258
(ulong) (srv_awe_window_size / ((1024 * 1024)
1260
(ulong) (srv_pool_size / ((1024 * 1024)
1261
/ UNIV_PAGE_SIZE)));
1263
/* We must disable adaptive hash indexes because they do not
1264
tolerate remapping of pages in AWE */
1266
srv_use_adaptive_hash_indexes = FALSE;
1267
ret = buf_pool_init(srv_pool_size, srv_pool_size,
1268
srv_awe_window_size);
1270
ret = buf_pool_init(srv_pool_size, srv_pool_size,
1231
1274
if (ret == NULL) {
1232
1275
fprintf(stderr,
1365
1408
&& !srv_archive_recovery
1366
1409
#endif /* UNIV_LOG_ARCHIVE */
1368
if (max_flushed_lsn != min_flushed_lsn
1411
if (ut_dulint_cmp(max_flushed_lsn, min_flushed_lsn) != 0
1369
1412
#ifdef UNIV_LOG_ARCHIVE
1370
1413
|| max_arch_log_no != min_arch_log_no
1371
1414
#endif /* UNIV_LOG_ARCHIVE */
1442
1485
/* Initialize the fsp free limit global variable in the log
1444
fsp_header_get_free_limit();
1487
fsp_header_get_free_limit(0);
1446
1489
recv_recovery_from_archive_finish();
1447
1490
#endif /* UNIV_LOG_ARCHIVE */
1450
/* Check if we support the max format that is stamped
1451
on the system tablespace. */
1452
err = trx_sys_file_format_max_check(
1453
srv_check_file_format_at_startup);
1455
if (err != DB_SUCCESS) {
1459
1492
/* We always try to do a recovery, even if the database had
1460
1493
been shut down normally: this is the normal startup path */
1462
1495
err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
1464
1497
min_flushed_lsn,
1465
1498
max_flushed_lsn);
1466
1499
if (err != DB_SUCCESS) {
1507
1540
/* Initialize the fsp free limit global variable in the log
1509
fsp_header_get_free_limit();
1542
fsp_header_get_free_limit(0);
1511
1544
/* recv_recovery_from_checkpoint_finish needs trx lists which
1512
1545
are initialized in trx_sys_init_at_db_start(). */
1562
1595
/* Create the thread which warns of long semaphore waits */
1563
1596
os_thread_create(&srv_error_monitor_thread, NULL,
1564
1597
thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1598
srv_was_started = TRUE;
1565
1599
srv_is_being_started = FALSE;
1567
1601
if (trx_doublewrite == NULL) {
1590
1624
sum_of_data_file_sizes += srv_data_file_sizes[i];
1593
tablespace_size_in_header = fsp_header_get_tablespace_size();
1627
tablespace_size_in_header = fsp_header_get_tablespace_size(0);
1595
1629
if (!srv_auto_extend_last_data_file
1596
1630
&& sum_of_data_file_sizes != tablespace_size_in_header) {
1674
1708
if (srv_print_verbose_log) {
1675
1709
ut_print_timestamp(stderr);
1676
1710
fprintf(stderr,
1677
" InnoDB Plugin %s started; "
1678
"log sequence number %"PRIu64"\n",
1679
INNODB_VERSION_STR, srv_start_lsn);
1711
" InnoDB: Started; log sequence number %lu %lu\n",
1712
(ulong) ut_dulint_get_high(srv_start_lsn),
1713
(ulong) ut_dulint_get_low(srv_start_lsn));
1682
1716
if (srv_force_recovery > 0) {
1749
1783
srv_file_per_table = srv_file_per_table_original_value;
1751
srv_was_started = TRUE;
1753
1785
return((int) DB_SUCCESS);
1756
1788
/********************************************************************
1757
1789
Shuts down the InnoDB database. */
1760
1792
innobase_shutdown_for_mysql(void)
1761
1793
/*=============================*/
1762
1794
/* out: DB_SUCCESS or error code */
1766
extern ibool panic_shutdown;
1768
1797
if (!srv_was_started) {
1769
1798
if (srv_is_being_started) {
1770
1799
ut_print_timestamp(stderr);
1941
1964
ut_print_timestamp(stderr);
1942
1965
fprintf(stderr,
1943
1966
" InnoDB: Shutdown completed;"
1944
" log sequence number %"PRIu64"\n",
1967
" log sequence number %lu %lu\n",
1968
(ulong) ut_dulint_get_high(srv_shutdown_lsn),
1969
(ulong) ut_dulint_get_low(srv_shutdown_lsn));
1948
srv_was_started = FALSE;
1950
1972
return((int) DB_SUCCESS);
1954
void set_panic_flag_for_netware()
1956
extern ibool panic_shutdown;
1957
panic_shutdown = TRUE;
1959
#endif /* __NETWARE__ */
1960
1975
#endif /* !UNIV_HOTBACKUP */