66 #ifndef UNIV_HOTBACKUP
100 #ifdef HAVE_DARWIN_THREADS
101 # include <sys/utsname.h>
103 UNIV_INTERN ibool srv_have_fullfsync = FALSE;
117 static ibool srv_start_has_been_called = FALSE;
127 static ulint
n[SRV_MAX_N_IO_THREADS + 6];
136 static char* srv_monitor_file_name;
140 static const ulint SRV_UNDO_TABLESPACE_SIZE_IN_PAGES =
141 ((1024 * 1024) * 10) / UNIV_PAGE_SIZE_DEF;
144 #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
145 #define SRV_MAX_N_PENDING_SYNC_IOS 100
147 #ifdef UNIV_PFS_THREAD
149 UNIV_INTERN mysql_pfs_key_t io_handler_thread_key;
150 UNIV_INTERN mysql_pfs_key_t srv_lock_timeout_thread_key;
151 UNIV_INTERN mysql_pfs_key_t srv_error_monitor_thread_key;
152 UNIV_INTERN mysql_pfs_key_t srv_monitor_thread_key;
153 UNIV_INTERN mysql_pfs_key_t srv_master_thread_key;
154 UNIV_INTERN mysql_pfs_key_t srv_purge_thread_key;
171 size = strtoul(str, &endp, 10);
202 memset(&stat, 0x0,
sizeof(stat));
206 if (err == DB_FAIL) {
209 "os_file_get_status() failed on '%s'. Can't determine "
210 "file permissions", name);
214 }
else if (err == DB_SUCCESS) {
218 if (stat.
type == OS_FILE_TYPE_FILE) {
222 "%s can't be opened in %s mode",
225 ?
"read" :
"read-write");
233 "'%s' not a regular file.", name);
263 srv_auto_extend_last_data_file = FALSE;
264 srv_last_file_size_max = 0;
265 srv_data_file_names = NULL;
266 srv_data_file_sizes = NULL;
267 srv_data_file_is_raw_partition = NULL;
275 while (*str !=
'\0') {
278 while ((*str !=
':' && *str !=
'\0')
280 && (*(str + 1) ==
'\\' || *(str + 1) ==
'/'
281 || *(str + 1) ==
':'))) {
291 str = srv_parse_megabytes(str, &size);
293 if (0 == strncmp(str,
":autoextend",
294 (
sizeof ":autoextend") - 1)) {
296 str += (
sizeof ":autoextend") - 1;
298 if (0 == strncmp(str,
":max:",
299 (
sizeof ":max:") - 1)) {
301 str += (
sizeof ":max:") - 1;
303 str = srv_parse_megabytes(str, &size);
315 && *(str + 2) ==
'w') {
319 if (*str ==
'r' && *(str + 1) ==
'a' && *(str + 2) ==
'w') {
331 }
else if (*str !=
'\0') {
344 srv_data_file_names =
static_cast<char**
>(
345 malloc(i *
sizeof *srv_data_file_names));
347 srv_data_file_sizes =
static_cast<ulint*
>(
348 malloc(i *
sizeof *srv_data_file_sizes));
350 srv_data_file_is_raw_partition =
static_cast<ulint*
>(
351 malloc(i *
sizeof *srv_data_file_is_raw_partition));
353 srv_n_data_files =
i;
360 while (*str !=
'\0') {
368 while ((*str !=
':' && *str !=
'\0')
370 && (*(str + 1) ==
'\\' || *(str + 1) ==
'/'
371 || *(str + 1) ==
':'))) {
381 str = srv_parse_megabytes(str, &size);
383 srv_data_file_names[
i] = path;
384 srv_data_file_sizes[
i] =
size;
386 if (0 == strncmp(str,
":autoextend",
387 (
sizeof ":autoextend") - 1)) {
389 srv_auto_extend_last_data_file = TRUE;
391 str += (
sizeof ":autoextend") - 1;
393 if (0 == strncmp(str,
":max:",
394 (
sizeof ":max:") - 1)) {
396 str += (
sizeof ":max:") - 1;
398 str = srv_parse_megabytes(
399 str, &srv_last_file_size_max);
408 (srv_data_file_is_raw_partition)[i] = 0;
413 && *(str + 2) ==
'w') {
418 if (*str ==
'r' && *(str + 1) ==
'a' && *(str + 2) ==
'w') {
421 if ((srv_data_file_is_raw_partition)[
i] == 0) {
444 free(srv_data_file_names);
445 srv_data_file_names = NULL;
446 free(srv_data_file_sizes);
447 srv_data_file_sizes = NULL;
448 free(srv_data_file_is_raw_partition);
449 srv_data_file_is_raw_partition = NULL;
452 #ifndef UNIV_HOTBACKUP
456 extern "C" UNIV_INTERN
465 segment = *((ulint*) arg);
467 #ifdef UNIV_DEBUG_THREAD_CREATION
468 fprintf(stderr,
"Io handler thread %lu starts, id %lu\n", segment,
472 #ifdef UNIV_PFS_THREAD
473 pfs_register_thread(io_handler_thread_key);
487 OS_THREAD_DUMMY_RETURN;
497 char* str __attribute__((unused)))
501 for (; *str; str++) {
510 #ifndef UNIV_HOTBACKUP
514 static __attribute__((nonnull, warn_unused_result))
523 *file = os_file_create(
524 innodb_file_log_key, name,
529 ib_logf(IB_LOG_LEVEL_ERROR,
"Cannot create %s", name);
534 "Setting log file %s size to %lu MB",
535 name, (ulong) srv_log_file_size
536 >> (20 - UNIV_PAGE_SIZE_SHIFT));
540 << UNIV_PAGE_SIZE_SHIFT);
542 ib_logf(IB_LOG_LEVEL_ERROR,
"Cannot set log file"
543 " %s to size %lu MB", name, (ulong) srv_log_file_size
544 >> (20 - UNIV_PAGE_SIZE_SHIFT));
548 ret = os_file_close(*file);
555 #define INIT_LOG_FILE0 (SRV_N_LOG_FILES_MAX + 1)
558 # define RECOVERY_CRASH(x) do {} while(0)
560 # define RECOVERY_CRASH(x) do { \
561 if (srv_force_recovery_crash == x) { \
562 fprintf(stderr, "innodb_force_recovery_crash=%lu\n", \
563 srv_force_recovery_crash); \
586 "Cannot create log files in read-only mode");
593 if (!create_new_db) {
596 sprintf(logfilename + dirnamelen,
"ib_logfile%u",
i);
602 DeleteFile((LPCTSTR) logfilename);
618 for (
unsigned i = 0;
i < srv_n_log_files;
i++) {
619 sprintf(logfilename + dirnamelen,
622 dberr_t err = create_log_file(&files[
i], logfilename);
624 if (err != DB_SUCCESS) {
634 sprintf(logfilename + dirnamelen,
"ib_logfile%u",
INIT_LOG_FILE0);
638 fsp_flags_set_page_size(0, UNIV_PAGE_SIZE),
643 logfilename, (ulint) srv_log_file_size,
647 for (
unsigned i = 1;
i < srv_n_log_files;
i++) {
648 sprintf(logfilename + dirnamelen,
"ib_logfile%u",
i);
652 (ulint) srv_log_file_size,
659 srv_log_file_size * UNIV_PAGE_SIZE,
666 mutex_enter(&log_sys->
mutex);
667 ut_d(recv_no_log_write = FALSE);
669 mutex_exit(&log_sys->
mutex);
678 create_log_files_rename(
694 sprintf(logfilename + dirnamelen,
"ib_logfile%u", 0);
699 "Renaming log file %s to %s", logfile0, logfilename);
701 mutex_enter(&log_sys->
mutex);
702 ut_ad(strlen(logfile0) == 2 + strlen(logfilename));
703 ibool success = os_file_rename(
704 innodb_file_log_key, logfile0, logfilename);
710 strcpy(logfile0, logfilename);
711 mutex_exit(&log_sys->
mutex);
715 ib_logf(IB_LOG_LEVEL_WARN,
"New log files created, LSN=" LSN_PF, lsn);
721 static __attribute__((nonnull, warn_unused_result))
731 *file = os_file_create(innodb_file_log_key, name,
735 ib_logf(IB_LOG_LEVEL_ERROR,
"Unable to open '%s'", name);
741 ret = os_file_close(*file);
749 static __attribute__((nonnull, warn_unused_result))
751 open_or_create_data_files(
753 ibool* create_new_db,
755 #ifdef UNIV_LOG_ARCHIVE
756 ulint* min_arch_log_no,
758 ulint* max_arch_log_no,
761 lsn_t* min_flushed_lsn,
763 lsn_t* max_flushed_lsn,
765 ulint* sum_of_new_sizes)
770 ibool one_opened = FALSE;
771 ibool one_created = FALSE;
775 ulint rounded_size_pages;
778 if (srv_n_data_files >= 1000) {
781 "Can only have < 1000 data files, you have "
782 "defined %lu", (ulong) srv_n_data_files);
787 *sum_of_new_sizes = 0;
789 *create_new_db = FALSE;
793 for (i = 0; i < srv_n_data_files; i++) {
797 dirnamelen = strlen(srv_data_home);
799 ut_a(dirnamelen + strlen(srv_data_file_names[i])
800 < (
sizeof name) - 1);
802 memcpy(name, srv_data_home, dirnamelen);
805 if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
806 name[dirnamelen++] = SRV_PATH_SEPARATOR;
809 strcpy(name + dirnamelen, srv_data_file_names[i]);
813 if (!srv_file_check_mode(name)) {
817 }
else if (srv_data_file_is_raw_partition[i] == 0) {
822 files[
i] = os_file_create(
833 "Opening %s failed!", name);
839 != OS_FILE_ALREADY_EXISTS
849 "Creating or opening %s failed!",
855 }
else if (srv_data_file_is_raw_partition[i] ==
SRV_NEW_RAW) {
863 srv_created_new_raw = TRUE;
865 files[
i] = os_file_create(
871 "Error in opening %s", name);
875 }
else if (srv_data_file_is_raw_partition[i] ==
SRV_OLD_RAW) {
884 const char* check_msg;
889 "Data files can only be added at "
890 "the end of a tablespace, but "
891 "data file %s existed beforehand.",
895 if (srv_data_file_is_raw_partition[i] ==
SRV_OLD_RAW) {
897 files[
i] = os_file_create(
898 innodb_file_data_key,
902 files[
i] = os_file_create(
903 innodb_file_data_key,
907 files[
i] = os_file_create(
908 innodb_file_data_key,
918 "Can't open '%s'", name);
923 if (srv_data_file_is_raw_partition[i] ==
SRV_OLD_RAW) {
925 goto skip_size_check;
933 rounded_size_pages = (ulint)
934 (size >> UNIV_PAGE_SIZE_SHIFT);
936 if (i == srv_n_data_files - 1
937 && srv_auto_extend_last_data_file) {
939 if (srv_data_file_sizes[i] > rounded_size_pages
940 || (srv_last_file_size_max > 0
941 && srv_last_file_size_max
942 < rounded_size_pages)) {
947 "of a different size "
948 "%lu pages (rounded "
949 "down to MB) than specified "
951 "initial %lu pages, "
952 "max %lu (relevant if "
955 (ulong) rounded_size_pages,
956 (ulong) srv_data_file_sizes[i],
958 srv_last_file_size_max);
963 srv_data_file_sizes[
i] = rounded_size_pages;
966 if (rounded_size_pages != srv_data_file_sizes[i]) {
969 "Data file %s is of a different "
970 "size %lu pages (rounded down to MB) "
971 "than specified in the .cnf file "
974 (ulong) rounded_size_pages,
975 (ulong) srv_data_file_sizes[i]);
981 files[i], one_opened, &flags, &space,
982 #ifdef UNIV_LOG_ARCHIVE
983 min_arch_log_no, max_arch_log_no,
985 min_flushed_lsn, max_flushed_lsn);
989 "%s in data file %s",
997 ut_a(one_opened || space == TRX_SYS_SPACE);
1006 "Data file \"%s\" uses page size %lu,"
1007 "but the start-up parameter "
1008 "is --innodb-page-size=%lu",
1025 "Data file %s did not"
1026 " exist: new to be created",
1030 "The first specified "
1031 "data file %s did not exist: "
1032 "a new database to be created!",
1035 *create_new_db = TRUE;
1039 "Setting file %s size to %lu MB",
1041 (ulong) (srv_data_file_sizes[i]
1042 >> (20 - UNIV_PAGE_SIZE_SHIFT)));
1045 "Database physically writes the"
1046 " file full: wait...");
1051 << UNIV_PAGE_SIZE_SHIFT);
1055 "Error in creating %s: "
1056 "probably out of disk space",
1062 *sum_of_new_sizes += srv_data_file_sizes[
i];
1065 ret = os_file_close(files[i]);
1069 flags = fsp_flags_set_page_size(0, UNIV_PAGE_SIZE);
1076 srv_data_file_is_raw_partition[i] != 0)) {
1089 srv_undo_tablespace_create(
1100 fh = os_file_create(
1101 innodb_file_data_key,
1108 "%s opened in read-only mode", name);
1109 }
else if (ret == FALSE) {
1119 "Can't create UNDO tablespace %s", name);
1122 "Creating system tablespace with"
1123 " existing undo tablespaces is not"
1124 " supported. Please delete all undo"
1125 " tablespaces before creating new"
1126 " system tablespace.");
1135 "Data file %s did not exist: new to be created",
1139 "Setting file %s size to %lu MB",
1140 name, size >> (20 - UNIV_PAGE_SIZE_SHIFT));
1143 "Database physically writes the file full: wait...");
1149 "Error in creating %s: probably out of "
1150 "disk space", name);
1166 srv_undo_tablespace_open(
1176 if (!srv_file_check_mode(name)) {
1178 "UNDO tablespaces must be %s!",
1184 fh = os_file_create(
1185 innodb_file_data_key, name,
1201 ret = os_file_close(fh);
1214 flags = fsp_flags_set_page_size(0, UNIV_PAGE_SIZE);
1238 srv_undo_tablespaces_init(
1240 ibool create_new_db,
1242 const ulint n_conf_tablespaces,
1250 ulint prev_space_id = 0;
1251 ulint n_undo_tablespaces;
1252 ulint undo_tablespace_ids[TRX_SYS_N_RSEGS + 1];
1256 ut_a(n_conf_tablespaces <= TRX_SYS_N_RSEGS);
1258 memset(undo_tablespace_ids, 0x0,
sizeof(undo_tablespace_ids));
1268 for (i = 0; create_new_db && i < n_conf_tablespaces; ++
i) {
1269 char name[OS_FILE_MAX_PATH];
1277 err = srv_undo_tablespace_create(
1278 name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
1280 if (err != DB_SUCCESS) {
1283 "Could not create undo tablespace '%s'.",
1295 if (!create_new_db) {
1297 undo_tablespace_ids);
1299 n_undo_tablespaces = n_conf_tablespaces;
1301 for (i = 1; i <= n_undo_tablespaces; ++
i) {
1302 undo_tablespace_ids[i - 1] =
i;
1305 undo_tablespace_ids[
i] = ULINT_UNDEFINED;
1313 for (i = 0; i < n_undo_tablespaces; ++
i) {
1314 char name[OS_FILE_MAX_PATH];
1320 undo_tablespace_ids[i]);
1323 ut_a(prev_space_id + 1 == undo_tablespace_ids[i]);
1326 ut_a(undo_tablespace_ids[i] != 0);
1327 ut_a(undo_tablespace_ids[i] != ULINT_UNDEFINED);
1331 err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]);
1333 if (err != DB_SUCCESS) {
1336 "Unable to open undo tablespace '%s'.", name);
1341 prev_space_id = undo_tablespace_ids[
i];
1351 for (i = prev_space_id + 1; i < TRX_SYS_N_RSEGS; ++
i) {
1352 char name[OS_FILE_MAX_PATH];
1359 err = srv_undo_tablespace_open(name, i);
1361 if (err != DB_SUCCESS) {
1365 ++n_undo_tablespaces;
1374 if (n_conf_tablespaces > n_undo_tablespaces) {
1377 " InnoDB: Expected to open %lu undo "
1378 "tablespaces but was able\n",
1379 n_conf_tablespaces);
1382 " InnoDB: to find only %lu undo "
1383 "tablespaces.\n", n_undo_tablespaces);
1387 "innodb_undo_tablespaces parameter to "
1391 " InnoDB: correct value and retry. Suggested "
1392 "value is %lu\n", n_undo_tablespaces);
1394 return(err != DB_SUCCESS ? err : DB_ERROR);
1396 }
else if (n_undo_tablespaces > 0) {
1398 ib_logf(IB_LOG_LEVEL_INFO,
"Opened %lu undo tablespaces",
1399 n_undo_tablespaces);
1401 if (n_conf_tablespaces == 0) {
1403 "Using the system tablespace for all UNDO "
1404 "logging because innodb_undo_tablespaces=0");
1408 if (create_new_db) {
1414 for (i = 1; i <= n_undo_tablespaces; ++
i) {
1417 i, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
1430 srv_start_wait_for_purge_to_start()
1450 "Waiting for purge to start");
1471 ibool create_new_db;
1472 lsn_t min_flushed_lsn;
1473 lsn_t max_flushed_lsn;
1474 #ifdef UNIV_LOG_ARCHIVE
1475 ulint min_arch_log_no;
1476 ulint max_arch_log_no;
1478 ulint sum_of_new_sizes;
1479 ulint sum_of_data_file_sizes;
1480 ulint tablespace_size_in_header;
1483 ulint srv_n_log_files_found = srv_n_log_files;
1487 ulint n_recovered_trx;
1488 char logfilename[10000];
1489 char* logfile0 = NULL;
1493 ib_logf(IB_LOG_LEVEL_INFO,
"Started in read only mode");
1496 #ifdef HAVE_DARWIN_THREADS
1500 srv_have_fullfsync = TRUE;
1505 struct utsname utsname;
1506 if (uname(&utsname)) {
1508 fputs(
" InnoDB: cannot determine Mac OS X version!\n", stderr);
1510 srv_have_fullfsync = strcmp(utsname.release,
"7.") >= 0;
1512 if (!srv_have_fullfsync) {
1514 fputs(
" InnoDB: On Mac OS X, fsync() may be "
1515 "broken on internal drives,\n", stderr);
1517 fputs(
" InnoDB: making transactions unsafe!\n", stderr);
1522 if (
sizeof(ulint) !=
sizeof(
void*)) {
1525 " InnoDB: Error: size of InnoDB's ulint is %lu, "
1526 "but size of void*\n", (ulong)
sizeof(ulint));
1529 " InnoDB: is %lu. The sizes should be the same "
1530 "so that on a 64-bit\n",
1531 (ulong)
sizeof(
void*));
1534 " InnoDB: platforms you can allocate more than 4 GB "
1541 " InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1544 #ifdef UNIV_IBUF_DEBUG
1547 " InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n");
1548 # ifdef UNIV_IBUF_COUNT_DEBUG
1551 " InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on "
1555 " InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n");
1559 #ifdef UNIV_BLOB_DEBUG
1561 "InnoDB: !!!!!!!! UNIV_BLOB_DEBUG switched on !!!!!!!!!\n"
1562 "InnoDB: Server restart may fail with UNIV_BLOB_DEBUG\n");
1565 #ifdef UNIV_SYNC_DEBUG
1568 " InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n");
1571 #ifdef UNIV_SEARCH_DEBUG
1574 " InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1577 #ifdef UNIV_LOG_LSN_DEBUG
1580 " InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n");
1582 #ifdef UNIV_MEM_DEBUG
1585 " InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1588 if (srv_use_sys_malloc) {
1590 "The InnoDB memory heap is disabled");
1593 #if defined(COMPILER_HINTS_ENABLED)
1595 " InnoDB: Compiler hints enabled.");
1602 "Compressed tables use zlib " ZLIB_VERSION
1603 #ifdef UNIV_ZIP_DEBUG
1607 #ifdef UNIV_ZIP_COPY
1608 ib_logf(IB_LOG_LEVEL_INFO,
"and extra copying");
1617 if (srv_start_has_been_called) {
1619 fprintf(stderr,
" InnoDB: Error: startup called second time "
1620 "during the process\n");
1622 fprintf(stderr,
" InnoDB: lifetime. In the MySQL Embedded "
1623 "Server Library you\n");
1625 fprintf(stderr,
" InnoDB: cannot call server_init() more "
1626 "than once during the\n");
1628 fprintf(stderr,
" InnoDB: process lifetime.\n");
1631 srv_start_has_been_called = TRUE;
1642 switch (os_get_os_version()) {
1651 srv_use_native_aio = FALSE;
1657 srv_use_native_aio = TRUE;
1662 srv_use_native_aio = TRUE;
1663 srv_use_native_conditions = TRUE;
1667 #elif defined(LINUX_NATIVE_AIO)
1669 if (srv_use_native_aio) {
1670 ib_logf(IB_LOG_LEVEL_INFO,
"Using Linux native AIO");
1676 srv_use_native_aio = FALSE;
1679 if (srv_file_flush_method_str == NULL) {
1686 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"fsync")) {
1689 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DSYNC")) {
1692 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DIRECT")) {
1695 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DIRECT_NO_FSYNC")) {
1698 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"littlesync")) {
1701 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"nosync")) {
1704 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"normal")) {
1706 srv_use_native_aio = FALSE;
1708 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"unbuffered")) {
1710 srv_use_native_aio = FALSE;
1712 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
1713 "async_unbuffered")) {
1718 "Unrecognized value %s for innodb_flush_method",
1719 srv_file_flush_method_str);
1739 srv_buf_pool_instances = 1;
1742 srv_buf_pool_instances = 1;
1753 "%s CPU crc32 instructions",
1754 ut_crc32_sse2_enabled ?
"Using" :
"Not using");
1758 mutex_create(srv_monitor_file_mutex_key,
1759 &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1761 if (srv_innodb_status) {
1763 srv_monitor_file_name =
static_cast<char*
>(
1766 + 20 +
sizeof "/innodb_status."));
1768 sprintf(srv_monitor_file_name,
"%s/innodb_status.%lu",
1777 "Unable to create %s: %s",
1778 srv_monitor_file_name,
1784 srv_monitor_file_name = NULL;
1792 mutex_create(srv_dict_tmpfile_mutex_key,
1801 mutex_create(srv_misc_tmpfile_mutex_key,
1814 if (srv_n_file_io_threads != 4) {
1816 "innodb_file_io_threads is deprecated. Please use "
1817 "innodb_read_io_threads and innodb_write_io_threads "
1822 srv_n_file_io_threads = srv_n_read_io_threads;
1826 srv_n_file_io_threads += 2;
1827 srv_n_file_io_threads += srv_n_write_io_threads;
1830 "Disabling background IO write threads.");
1832 srv_n_write_io_threads = 0;
1835 ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
1837 io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1843 if (srv_use_native_aio) {
1844 io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1848 if (!os_aio_init(io_limit,
1849 srv_n_read_io_threads,
1850 srv_n_write_io_threads,
1851 SRV_MAX_N_PENDING_SYNC_IOS)) {
1854 "Fatal : Cannot initialize AIO sub-system");
1874 "Initializing buffer pool, size = %.1f%c", size, unit);
1878 if (err != DB_SUCCESS) {
1880 "Cannot allocate memory for the buffer pool");
1886 "Completed initialization of buffer pool");
1895 "Small buffer pool size (%luM), the flst_validate() "
1896 "debug function can cause a deadlock if the "
1897 "buffer pool fills up.",
1909 for (i = 0; i < srv_n_file_io_threads; ++
i) {
1916 #ifdef UNIV_LOG_ARCHIVE
1917 if (0 !=
ut_strcmp(srv_log_group_home_dir, srv_arch_dir)) {
1919 fprintf(stderr,
" InnoDB: Error: you must set the log group home dir in my.cnf\n");
1921 fprintf(stderr,
" InnoDB: the same as log arch dir.\n");
1927 if (srv_n_log_files * srv_log_file_size * UNIV_PAGE_SIZE
1928 >= 512ULL * 1024ULL * 1024ULL * 1024ULL) {
1935 "Combined size of log files must be < 512 GB");
1940 if (srv_n_log_files * srv_log_file_size >= ULINT_MAX) {
1948 " InnoDB: Error: combined size of log files"
1949 " must be < %lu GB\n",
1950 ULINT_MAX / 1073741824 * UNIV_PAGE_SIZE);
1955 sum_of_new_sizes = 0;
1957 for (i = 0; i < srv_n_data_files; i++) {
1959 if (
sizeof(off_t) < 5
1960 && srv_data_file_sizes[i]
1961 >= (ulint) (1 << (32 - UNIV_PAGE_SIZE_SHIFT))) {
1964 " InnoDB: Error: file size must be < 4 GB"
1965 " with this MySQL binary\n");
1968 " InnoDB: and operating system combination,"
1969 " in some OS's < 2 GB\n");
1974 sum_of_new_sizes += srv_data_file_sizes[
i];
1977 if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
1979 "Tablespace size must be at least 10 MB");
1984 err = open_or_create_data_files(&create_new_db,
1985 #ifdef UNIV_LOG_ARCHIVE
1986 &min_arch_log_no, &max_arch_log_no,
1988 &min_flushed_lsn, &max_flushed_lsn,
1990 if (err == DB_FAIL) {
1993 "The system tablespace must be writable!");
1997 }
else if (err != DB_SUCCESS) {
2000 "Could not open or create the system tablespace. If "
2001 "you tried to add new data files to the system "
2002 "tablespace, and it failed here, you should now "
2003 "edit innodb_data_file_path in my.cnf back to what "
2004 "it was, and remove the new ibdata files InnoDB "
2005 "created in this failed attempt. InnoDB only wrote "
2006 "those files full of zeros, but did not yet use "
2007 "them in any way. But be careful: do not remove "
2008 "old data files which contain your precious data!");
2013 #ifdef UNIV_LOG_ARCHIVE
2018 dirnamelen = strlen(srv_log_group_home_dir);
2019 ut_a(dirnamelen < (
sizeof logfilename) - 10 -
sizeof "ib_logfile");
2020 memcpy(logfilename, srv_log_group_home_dir, dirnamelen);
2023 if (dirnamelen && logfilename[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
2024 logfilename[dirnamelen++] = SRV_PATH_SEPARATOR;
2027 srv_log_file_size_requested = srv_log_file_size;
2029 if (create_new_db) {
2033 min_flushed_lsn = max_flushed_lsn =
log_get_lsn();
2037 err = create_log_files(create_new_db, logfilename, dirnamelen,
2038 max_flushed_lsn, logfile0);
2040 if (err != DB_SUCCESS) {
2048 sprintf(logfilename + dirnamelen,
2052 logfilename, &stat_info,
false);
2057 != min_flushed_lsn) {
2060 " log files because"
2064 " with each other");
2068 if (max_flushed_lsn < (lsn_t) 1000) {
2071 " log files because"
2075 " shut down cleanly"
2077 " the data files.");
2081 err = create_log_files(
2082 create_new_db, logfilename,
2083 dirnamelen, max_flushed_lsn,
2086 if (err != DB_SUCCESS) {
2090 create_log_files_rename(
2091 logfilename, dirnamelen,
2092 max_flushed_lsn, logfile0);
2096 max_flushed_lsn = min_flushed_lsn
2102 "Only one log file found.");
2110 if (!srv_file_check_mode(logfilename)) {
2114 err = open_log_file(&files[i], logfilename, &size);
2116 if (err != DB_SUCCESS) {
2122 if (size & ((1 << UNIV_PAGE_SIZE_SHIFT) - 1)) {
2125 UINT64PF
" is not a multiple of"
2126 " innodb_page_size",
2131 size >>= UNIV_PAGE_SIZE_SHIFT;
2134 srv_log_file_size =
size;
2135 }
else if (size != srv_log_file_size) {
2138 " of different size "UINT64PF
" bytes"
2140 " files "UINT64PF
" bytes!",
2142 size << UNIV_PAGE_SIZE_SHIFT,
2144 << UNIV_PAGE_SIZE_SHIFT);
2149 srv_n_log_files_found =
i;
2153 sprintf(logfilename + dirnamelen,
"ib_logfile%u", 0);
2157 fsp_flags_set_page_size(0, UNIV_PAGE_SIZE),
2164 ut_a(srv_log_file_size <= ULINT_MAX);
2166 for (
unsigned j = 0; j <
i; j++) {
2167 sprintf(logfilename + dirnamelen,
"ib_logfile%u", j);
2170 (ulint) srv_log_file_size,
2176 #ifdef UNIV_LOG_ARCHIVE
2194 err = srv_undo_tablespaces_init(
2202 if (err != DB_SUCCESS
2218 if (create_new_db) {
2244 if (err != DB_SUCCESS) {
2253 min_flushed_lsn = max_flushed_lsn =
log_get_lsn();
2262 create_log_files_rename(logfilename, dirnamelen,
2263 max_flushed_lsn, logfile0);
2264 #ifdef UNIV_LOG_ARCHIVE
2265 }
else if (srv_archive_recovery) {
2268 " Starting archive recovery from a backup...");
2270 err = recv_recovery_from_archive_start(
2271 min_flushed_lsn, srv_archive_recovery_limit_lsn,
2273 if (err != DB_SUCCESS) {
2282 if (err != DB_SUCCESS) {
2296 recv_recovery_from_archive_finish();
2315 if (err != DB_SUCCESS) {
2330 LOG_CHECKPOINT, LSN_MAX,
2331 min_flushed_lsn, max_flushed_lsn);
2333 if (err != DB_SUCCESS) {
2346 if (err != DB_SUCCESS) {
2383 }
else if (n_recovered_trx) {
2394 && (srv_log_file_size_requested != srv_log_file_size
2395 || srv_n_log_files_found != srv_n_log_files)) {
2400 "Cannot resize log files "
2401 "in read-only mode.");
2407 ULINT_MAX, LSN_MAX, NULL);
2412 min_flushed_lsn = max_flushed_lsn =
log_get_lsn();
2415 "Resizing redo log from %u*%u to %u*%u pages"
2418 (
unsigned) srv_log_file_size,
2419 (
unsigned) srv_n_log_files,
2420 (
unsigned) srv_log_file_size_requested,
2438 ut_d(recv_no_log_write = TRUE);
2445 max_flushed_lsn, 0);
2461 "Starting to delete and rewrite log files.");
2463 srv_log_file_size = srv_log_file_size_requested;
2465 err = create_log_files(create_new_db, logfilename,
2466 dirnamelen, max_flushed_lsn,
2469 if (err != DB_SUCCESS) {
2473 create_log_files_rename(logfilename, dirnamelen,
2474 max_flushed_lsn, logfile0);
2488 if (!create_new_db && sum_of_new_sizes > 0) {
2503 #ifdef UNIV_LOG_ARCHIVE
2505 if (!srv_log_archive_on) {
2508 mutex_enter(&(log_sys->
mutex));
2510 start_archive = FALSE;
2512 if (log_sys->archiving_state == LOG_ARCH_OFF) {
2513 start_archive = TRUE;
2516 mutex_exit(&(log_sys->
mutex));
2518 if (start_archive) {
2546 ut_a(srv_undo_logs > 0);
2547 ut_a(srv_undo_logs <= TRX_SYS_N_RSEGS);
2556 if (srv_available_undo_logs == ULINT_UNDEFINED) {
2560 srv_undo_logs = ULONG_UNDEFINED;
2575 NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
2580 NULL, thread_ids + 3 + SRV_MAX_N_IO_THREADS);
2585 NULL, thread_ids + 4 + SRV_MAX_N_IO_THREADS);
2590 if (err != DB_SUCCESS) {
2596 if (err != DB_SUCCESS) {
2611 NULL, thread_ids + (1 + SRV_MAX_N_IO_THREADS));
2619 NULL, thread_ids + 5 + SRV_MAX_N_IO_THREADS);
2621 ut_a(UT_ARR_SIZE(thread_ids)
2622 > 5 + srv_n_purge_threads + SRV_MAX_N_IO_THREADS);
2625 for (i = 1; i < srv_n_purge_threads; ++
i) {
2628 thread_ids + 5 + i + SRV_MAX_N_IO_THREADS);
2631 srv_start_wait_for_purge_to_start();
2644 sum_of_data_file_sizes = 0;
2646 for (i = 0; i < srv_n_data_files; i++) {
2647 sum_of_data_file_sizes += srv_data_file_sizes[
i];
2653 && !srv_auto_extend_last_data_file
2654 && sum_of_data_file_sizes != tablespace_size_in_header) {
2658 " InnoDB: Error: tablespace size"
2659 " stored in header is %lu pages, but\n",
2660 (ulong) tablespace_size_in_header);
2663 "InnoDB: the sum of data file sizes is %lu pages\n",
2664 (ulong) sum_of_data_file_sizes);
2667 && sum_of_data_file_sizes < tablespace_size_in_header) {
2673 " InnoDB: Cannot start InnoDB."
2674 " The tail of the system tablespace is\n");
2677 " InnoDB: missing. Have you edited"
2678 " innodb_data_file_path in my.cnf in an\n");
2681 " InnoDB: inappropriate way, removing"
2682 " ibdata files from there?\n");
2685 " InnoDB: You can set innodb_force_recovery=1"
2686 " in my.cnf to force\n");
2689 " InnoDB: a startup if you are trying"
2690 " to recover a badly corrupt database.\n");
2697 && srv_auto_extend_last_data_file
2698 && sum_of_data_file_sizes < tablespace_size_in_header) {
2702 " InnoDB: Error: tablespace size stored in header"
2703 " is %lu pages, but\n",
2704 (ulong) tablespace_size_in_header);
2707 " InnoDB: the sum of data file sizes"
2708 " is only %lu pages\n",
2709 (ulong) sum_of_data_file_sizes);
2715 " InnoDB: Cannot start InnoDB. The tail of"
2716 " the system tablespace is\n");
2719 " InnoDB: missing. Have you edited"
2720 " innodb_data_file_path in my.cnf in an\n");
2723 " InnoDB: inappropriate way, removing"
2724 " ibdata files from there?\n");
2727 " InnoDB: You can set innodb_force_recovery=1"
2728 " in my.cnf to force\n");
2731 " InnoDB: a startup if you are trying to"
2732 " recover a badly corrupt database.\n");
2739 os_fast_mutex_init(PFS_NOT_INSTRUMENTED, &srv_os_test_mutex);
2744 " InnoDB: Error: pthread_mutex_trylock returns"
2745 " an unexpected value on\n");
2748 " InnoDB: success! Cannot continue.\n");
2752 os_fast_mutex_unlock(&srv_os_test_mutex);
2754 os_fast_mutex_lock(&srv_os_test_mutex);
2756 os_fast_mutex_unlock(&srv_os_test_mutex);
2758 os_fast_mutex_free(&srv_os_test_mutex);
2760 if (srv_print_verbose_log) {
2762 "%s started; log sequence number " LSN_PF
"",
2768 "!!! innodb_force_recovery is set to %lu !!!",
2783 os_thread_create(buf_dump_thread, NULL, NULL);
2809 fts_t* fts = table->fts;
2818 fts_t* fts = table->fts;
2840 "Shutting down an improperly started, "
2841 "or created database!");
2863 "Query counter shows %ld queries still "
2864 "inside InnoDB at shutdown",
2876 for (i = 0; i < 1000; i++) {
2927 "%lu threads created by InnoDB"
2928 " had not exited at shutdown!",
2935 if (srv_monitor_file_name) {
2936 unlink(srv_monitor_file_name);
2968 mutex_free(&srv_monitor_file_mutex);
3003 || os_event_count != 0
3004 || os_mutex_count != 0
3005 || os_fast_mutex_count != 0) {
3007 "Some resources were not cleaned up in shutdown: "
3008 "threads %lu, events %lu, os_mutexes %lu, "
3009 "os_fast_mutexes %lu",
3011 (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
3014 if (dict_foreign_err_file) {
3015 fclose(dict_foreign_err_file);
3018 if (srv_print_verbose_log) {
3020 "Shutdown completed; log sequence number " LSN_PF
"",
3025 srv_start_has_been_called = FALSE;
3037 srv_shutdown_table_bg_threads(
void)
3051 fts_t* fts = table->fts;
3090 ut_a(first == table);
3093 fts_t* fts = table->fts;
3101 if (table == last) {
3122 static const ulint suffix_len = strlen(
".cfg");
3136 ut_a(max_len >= len);
3138 suffix = path + (len - suffix_len);
3139 if (strncmp(suffix,
".cfg", suffix_len) == 0) {
3140 strcpy(filename, path);
3142 ut_ad(strncmp(suffix,
".ibd", suffix_len) == 0);
3144 strncpy(filename, path, len - suffix_len);
3145 suffix = filename + (len - suffix_len);
3146 strcpy(suffix,
".cfg");