📄 srv0start.c
字号:
#ifdef UNIV_LOG_ARCHIVE ulint min_arch_log_no; ulint max_arch_log_no;#endif /* UNIV_LOG_ARCHIVE */ ulint sum_of_new_sizes; ulint sum_of_data_file_sizes; ulint tablespace_size_in_header; ulint err; ulint i; ibool srv_file_per_table_original_value = srv_file_per_table; mtr_t mtr;#ifdef HAVE_DARWIN_THREADS# ifdef F_FULLFSYNC /* This executable has been compiled on Mac OS X 10.3 or later. Assume that F_FULLFSYNC is available at run-time. */ srv_have_fullfsync = TRUE;# else /* F_FULLFSYNC */ /* This executable has been compiled on Mac OS X 10.2 or earlier. Determine if the executable is running on Mac OS X 10.3 or later. */ struct utsname utsname; if (uname(&utsname)) { fputs("InnoDB: cannot determine Mac OS X version!\n", stderr); } else { srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0; } if (!srv_have_fullfsync) { fputs("InnoDB: On Mac OS X, fsync() may be broken on internal drives,\n""InnoDB: making transactions unsafe!\n", stderr); }# endif /* F_FULLFSYNC */#endif /* HAVE_DARWIN_THREADS */ if (sizeof(ulint) != sizeof(void*)) { fprintf(stderr,"InnoDB: Error: size of InnoDB's ulint is %lu, but size of void* is %lu.\n""InnoDB: The sizes should be the same so that on a 64-bit platform you can\n""InnoDB: allocate more than 4 GB of memory.", (ulong)sizeof(ulint), (ulong)sizeof(void*)); } srv_file_per_table = FALSE; /* system tables are created in tablespace 0 */#ifdef UNIV_DEBUG fprintf(stderr,"InnoDB: !!!!!!!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!!!!!!!\n"); #endif#ifdef UNIV_SYNC_DEBUG fprintf(stderr,"InnoDB: !!!!!!!!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!!!!!!!\n"); #endif#ifdef UNIV_SEARCH_DEBUG fprintf(stderr,"InnoDB: !!!!!!!!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!!!!!!!\n"); #endif#ifdef UNIV_MEM_DEBUG fprintf(stderr,"InnoDB: !!!!!!!!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!!!!!!!\n"); #endif#ifdef UNIV_SIMULATE_AWE fprintf(stderr,"InnoDB: !!!!!!!!!!!!!! UNIV_SIMULATE_AWE switched on !!!!!!!!!!!!!!!!!\n");#endif if (srv_sizeof_trx_t_in_ha_innodb_cc != (ulint)sizeof(trx_t)) { fprintf(stderr, "InnoDB: Error: trx_t size is %lu in ha_innodb.cc but %lu in srv0start.c\n" "InnoDB: Check that pthread_mutex_t is defined in the same way in these\n" "InnoDB: compilation modules. Cannot continue.\n", (ulong) srv_sizeof_trx_t_in_ha_innodb_cc, (ulong) sizeof(trx_t)); return(DB_ERROR); } /* Since InnoDB does not currently clean up all its internal data structures in MySQL Embedded Server Library server_end(), we print an error message if someone tries to start up InnoDB a second time during the process lifetime. */ if (srv_start_has_been_called) { fprintf(stderr,"InnoDB: Error:startup called second time during the process lifetime.\n""InnoDB: In the MySQL Embedded Server Library you cannot call server_init()\n""InnoDB: more than once during the process lifetime.\n"); } srv_start_has_been_called = TRUE;#ifdef UNIV_DEBUG log_do_write = TRUE;#endif /* UNIV_DEBUG *//* yydebug = TRUE; */ srv_is_being_started = TRUE; srv_startup_is_before_trx_rollback_phase = TRUE; os_aio_use_native_aio = FALSE;#if !defined(__WIN2000__) && !defined(UNIV_SIMULATE_AWE) if (srv_use_awe) { fprintf(stderr,"InnoDB: Error: You have specified innodb_buffer_pool_awe_mem_mb\n""InnoDB: in my.cnf, but AWE can only be used in Windows 2000 and later.\n""InnoDB: To use AWE, InnoDB must be compiled with __WIN2000__ defined.\n"); return(DB_ERROR); }#endif#ifdef __WIN__ if (os_get_os_version() == OS_WIN95 || os_get_os_version() == OS_WIN31 || os_get_os_version() == OS_WINNT) { /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1, and NT use simulated aio. In NT Windows provides async i/o, but when run in conjunction with InnoDB Hot Backup, it seemed to corrupt the data files. */ os_aio_use_native_aio = FALSE; } else { /* On Win 2000 and XP use async i/o */ os_aio_use_native_aio = TRUE; }#endif if (srv_file_flush_method_str == NULL) { /* These are the default options */ srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;#ifndef __WIN__ } else if (0 == ut_strcmp(srv_file_flush_method_str, "fdatasync")) { srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) { srv_unix_file_flush_method = SRV_UNIX_O_DSYNC; } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) { srv_unix_file_flush_method = SRV_UNIX_O_DIRECT; } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) { srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC; } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) { srv_unix_file_flush_method = SRV_UNIX_NOSYNC;#else } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) { srv_win_file_flush_method = SRV_WIN_IO_NORMAL; os_aio_use_native_aio = FALSE; } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) { srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; os_aio_use_native_aio = FALSE; } else if (0 == ut_strcmp(srv_file_flush_method_str, "async_unbuffered")) { srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; #endif } else { fprintf(stderr, "InnoDB: Unrecognized value %s for innodb_flush_method\n", srv_file_flush_method_str); return(DB_ERROR); } /* Note that the call srv_boot() also changes the values of srv_pool_size etc. to the units used by InnoDB internally */ /* Set the maximum number of threads which can wait for a semaphore inside InnoDB: this is the 'sync wait array' size, as well as the maximum number of threads that can wait in the 'srv_conc array' for their time to enter InnoDB. */#if defined(__WIN__) || defined(__NETWARE__)/* Create less event semaphores because Win 98/ME had difficulty creating40000 event semaphores.Comment from Novell, Inc.: also, these just take a lot of memory onNetWare. */ srv_max_n_threads = 1000;#else if (srv_pool_size >= 1000 * 1024) { /* Here we still have srv_pool_size counted in kilobytes (in 4.0 this was in bytes) srv_boot() converts the value to pages; if buffer pool is less than 1000 MB, assume fewer threads. */ srv_max_n_threads = 50000; } else if (srv_pool_size >= 8 * 1024) { srv_max_n_threads = 10000; } else { srv_max_n_threads = 1000; /* saves several MB of memory, especially in 64-bit computers */ }#endif err = srv_boot(); /* This changes srv_pool_size to units of a page */ if (err != DB_SUCCESS) { return((int) err); } mutex_create(&srv_monitor_file_mutex); mutex_set_level(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK); if (srv_innodb_status) { srv_monitor_file_name = mem_alloc( strlen(fil_path_to_mysql_datadir) + 20 + sizeof "/innodb_status."); sprintf(srv_monitor_file_name, "%s/innodb_status.%lu", fil_path_to_mysql_datadir, os_proc_get_number()); srv_monitor_file = fopen(srv_monitor_file_name, "w+"); if (!srv_monitor_file) { fprintf(stderr, "InnoDB: unable to create %s: %s\n", srv_monitor_file_name, strerror(errno)); return(DB_ERROR); } } else { srv_monitor_file_name = NULL; srv_monitor_file = os_file_create_tmpfile(); if (!srv_monitor_file) { return(DB_ERROR); } } mutex_create(&srv_dict_tmpfile_mutex); mutex_set_level(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION); srv_dict_tmpfile = os_file_create_tmpfile(); if (!srv_dict_tmpfile) { return(DB_ERROR); } mutex_create(&srv_misc_tmpfile_mutex); mutex_set_level(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH); srv_misc_tmpfile = os_file_create_tmpfile(); if (!srv_misc_tmpfile) { return(DB_ERROR); } /* Restrict the maximum number of file i/o threads */ if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) { srv_n_file_io_threads = SRV_MAX_N_IO_THREADS; } if (!os_aio_use_native_aio) { /* In simulated aio we currently have use only for 4 threads */ srv_n_file_io_threads = 4; os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD * srv_n_file_io_threads, srv_n_file_io_threads, SRV_MAX_N_PENDING_SYNC_IOS); } else { os_aio_init(SRV_N_PENDING_IOS_PER_THREAD * srv_n_file_io_threads, srv_n_file_io_threads, SRV_MAX_N_PENDING_SYNC_IOS); } fil_init(srv_max_n_open_files); if (srv_use_awe) { fprintf(stderr,"InnoDB: Using AWE: Memory window is %lu MB and AWE memory is %lu MB\n", (ulong) (srv_awe_window_size / ((1024 * 1024) / UNIV_PAGE_SIZE)), (ulong) (srv_pool_size / ((1024 * 1024) / UNIV_PAGE_SIZE))); /* We must disable adaptive hash indexes because they do not tolerate remapping of pages in AWE */ srv_use_adaptive_hash_indexes = FALSE; ret = buf_pool_init(srv_pool_size, srv_pool_size, srv_awe_window_size); } else { ret = buf_pool_init(srv_pool_size, srv_pool_size, srv_pool_size); } if (ret == NULL) { fprintf(stderr,"InnoDB: Fatal error: cannot allocate the memory for the buffer pool\n"); return(DB_ERROR); } fsp_init(); log_init(); lock_sys_create(srv_lock_table_size); /* Create i/o-handler threads: */ for (i = 0; i < srv_n_file_io_threads; i++) { n[i] = i; os_thread_create(io_handler_thread, n + i, thread_ids + i); }#ifdef UNIV_LOG_ARCHIVE if (0 != ut_strcmp(srv_log_group_home_dirs[0], srv_arch_dir)) { fprintf(stderr, "InnoDB: Error: you must set the log group home dir in my.cnf the\n" "InnoDB: same as log arch dir.\n"); return(DB_ERROR); }#endif /* UNIV_LOG_ARCHIVE */ if (srv_n_log_files * srv_log_file_size >= 262144) { fprintf(stderr, "InnoDB: Error: combined size of log files must be < 4 GB\n"); return(DB_ERROR); } sum_of_new_sizes = 0; for (i = 0; i < srv_n_data_files; i++) {#ifndef __WIN__ if (sizeof(off_t) < 5 && srv_data_file_sizes[i] >= 262144) { fprintf(stderr, "InnoDB: Error: file size must be < 4 GB with this MySQL binary\n" "InnoDB: and operating system combination, in some OS's < 2 GB\n"); return(DB_ERROR); }#endif sum_of_new_sizes += srv_data_file_sizes[i]; } if (sum_of_new_sizes < 640) { fprintf(stderr, "InnoDB: Error: tablespace size must be at least 10 MB\n"); return(DB_ERROR); } err = open_or_create_data_files(&create_new_db,#ifdef UNIV_LOG_ARCHIVE &min_arch_log_no, &max_arch_log_no,#endif /* UNIV_LOG_ARCHIVE */ &min_flushed_lsn, &max_flushed_lsn, &sum_of_new_sizes); if (err != DB_SUCCESS) { fprintf(stderr,"InnoDB: Could not open or create data files.\n""InnoDB: If you tried to add new data files, and it failed here,\n""InnoDB: you should now edit innodb_data_file_path in my.cnf back\n""InnoDB: to what it was, and remove the new ibdata files InnoDB created\n""InnoDB: in this failed attempt. InnoDB only wrote those files full of\n""InnoDB: zeros, but did not yet use them in any way. But be careful: do not\n""InnoDB: remove old data files which contain your precious data!\n"); return((int) err); }#ifdef UNIV_LOG_ARCHIVE srv_normalize_path_for_win(srv_arch_dir); srv_arch_dir = srv_add_path_separator_if_needed(srv_arch_dir);#endif /* UNIV_LOG_ARCHIVE */ for (i = 0; i < srv_n_log_files; i++) { err = open_or_create_log_file(create_new_db, &log_file_created, log_opened, 0, i); if (err != DB_SUCCESS) { return((int) err); } if (log_file_created) { log_created = TRUE; } else { log_opened = TRUE; } if ((log_opened && create_new_db) || (log_opened && log_created)) { fprintf(stderr, "InnoDB: Error: all log files must be created at the same time.\n" "InnoDB: All log files must be created also in database creation.\n" "InnoDB: If you want bigger or smaller log files, shut down the\n" "InnoDB: database and make sure there were no errors in shutdown.\n" "InnoDB: Then delete the existing log files. Edit the .cnf file\n" "InnoDB: and start the database again.\n"); return(DB_ERROR); } } /* Open all log files and data files in the system tablespace: we keep them open until database shutdown */ fil_open_log_and_system_tablespace_files(); if (log_created && !create_new_db#ifdef UNIV_LOG_ARCHIVE && !srv_archive_recovery#endif /* UNIV_LOG_ARCHIVE */ ) { if (ut_dulint_cmp(max_flushed_lsn, min_flushed_lsn) != 0#ifdef UNIV_LOG_ARCHIVE || max_arch_log_no != min_arch_log_no#endif /* UNIV_LOG_ARCHIVE */ ) { fprintf(stderr, "InnoDB: Cannot initialize created log files because\n" "InnoDB: data files were not in sync with each other\n" "InnoDB: or the data files are corrupt.\n"); return(DB_ERROR); } if (ut_dulint_cmp(max_flushed_lsn, ut_dulint_create(0, 1000)) < 0) { fprintf(stderr, "InnoDB: Cannot initialize created log files because\n" "InnoDB: data files are corrupt, or new data files were\n" "InnoDB: created when the database was started previous\n" "InnoDB: time but the database was not shut down\n" "InnoDB: normally after that.\n"); return(DB_ERROR); } mutex_enter(&(log_sys->mutex));#ifdef UNIV_LOG_ARCHIVE /* Do not + 1 arch_log_no because we do not use log archiving */ recv_reset_logs(max_flushed_lsn, max_arch_log_no, TRUE);#else recv_reset_logs(max_flushed_lsn, TRUE);#endif /* UNIV_LOG_ARCHIVE */ mutex_exit(&(log_sys->mutex)); } if (create_new_db) { mtr_start(&mtr); fsp_header_init(0, sum_of_new_sizes, &mtr); mtr_commit(&mtr); trx_sys_create(); dict_create(); srv_startup_is_before_trx_rollback_phase = FALSE;#ifdef UNIV_LOG_ARCHIVE } else if (srv_archive_recovery) { fprintf(stderr, "InnoDB: Starting archive recovery from a backup...\n"); err = recv_recovery_from_archive_start( min_flushed_lsn, srv_archive_recovery_limit_lsn, min_arch_log_no); if (err != DB_SUCCESS) { return(DB_ERROR); } /* Since ibuf init is in dict_boot, and ibuf is needed in any disk i/o, first call dict_boot */ dict_boot(); trx_sys_init_at_db_start(); srv_startup_is_before_trx_rollback_phase = FALSE; /* Initialize the fsp free limit global variable in the log system */ fsp_header_get_free_limit(0); recv_recovery_from_archive_finish();#endif /* UNIV_LOG_ARCHIVE */ } else { /* We always try to do a recovery, even if the database had
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -