The world's most popular open source database
#include "os0proc.h"#include "sync0sync.h"#include "ut0mem.h"#include "mem0mem.h"#include "mem0pool.h"#include "data0data.h"#include "data0type.h"#include "dict0dict.h"#include "buf0buf.h"#include "buf0flu.h"#include "buf0rea.h"#include "os0file.h"#include "os0thread.h"#include "fil0fil.h"#include "fsp0fsp.h"#include "rem0rec.h"#include "rem0cmp.h"#include "mtr0mtr.h"#include "log0log.h"#include "log0recv.h"#include "page0page.h"#include "page0cur.h"#include "trx0trx.h"#include "dict0boot.h"#include "dict0load.h"#include "trx0sys.h"#include "dict0crea.h"#include "btr0btr.h"#include "btr0pcur.h"#include "btr0cur.h"#include "btr0sea.h"#include "srv0srv.h"#include "que0que.h"#include "usr0sess.h"#include "lock0lock.h"#include "trx0roll.h"#include "trx0purge.h"#include "row0ins.h"#include "row0sel.h"#include "row0upd.h"#include "row0row.h"#include "row0mysql.h"#include "ibuf0ibuf.h"#include "pars0pars.h"#include "srv0start.h"Include dependency graph for srv0start.c:

Go to the source code of this file.
Defines | |
| #define | SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD |
| #define | SRV_MAX_N_PENDING_SYNC_IOS 100 |
| #define | SRV_PATH_SEPARATOR '/' |
Functions | |
| static char * | srv_parse_megabytes (char *str, ulint *megs) |
| ibool | srv_parse_data_file_paths_and_sizes (char *str, char ***data_file_names, ulint **data_file_sizes, ulint **data_file_is_raw_partition, ulint *n_data_files, ibool *is_auto_extending, ulint *max_auto_extend_size) |
| ibool | srv_parse_log_group_home_dirs (char *str, char ***log_group_home_dirs) |
| static os_thread_ret_t | io_handler_thread (void *arg) |
| void | srv_normalize_path_for_win (char *str __attribute__((unused))) |
| char * | srv_add_path_separator_if_needed (char *str) |
| static ulint | srv_calc_low32 (ulint file_size) |
| static ulint | srv_calc_high32 (ulint file_size) |
| static ulint | open_or_create_log_file (ibool create_new_db, ibool *log_file_created, ibool log_file_has_been_opened, ulint k, ulint i) |
| static ulint | open_or_create_data_files (ibool *create_new_db, dulint *min_flushed_lsn, dulint *max_flushed_lsn, ulint *sum_of_new_sizes) |
| int | innobase_start_or_create_for_mysql (void) |
| int | innobase_shutdown_for_mysql (void) |
Variables | |
| dulint | srv_start_lsn |
| dulint | srv_shutdown_lsn |
| ibool | srv_start_raw_disk_in_use = FALSE |
| ulint | srv_sizeof_trx_t_in_ha_innodb_cc |
| ibool | srv_startup_is_before_trx_rollback_phase = FALSE |
| ibool | srv_is_being_started = FALSE |
| static ibool | srv_start_has_been_called = FALSE |
| static ibool | srv_was_started = FALSE |
| ulint | srv_shutdown_state = 0 |
| static os_file_t | files [1000] |
| static mutex_t | ios_mutex |
| static ulint | ios |
| static ulint | n [SRV_MAX_N_IO_THREADS+5] |
| static os_thread_id_t | thread_ids [SRV_MAX_N_IO_THREADS+5] |
| static os_fast_mutex_t | srv_os_test_mutex |
| static char * | srv_monitor_file_name |
| #define SRV_MAX_N_PENDING_SYNC_IOS 100 |
| #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD |
| #define SRV_PATH_SEPARATOR '/' |
| int innobase_shutdown_for_mysql | ( | void | ) |
Definition at line 1716 of file srv0start.c.
References DB_SUCCESS, dict_foreign_err_file, lock_latest_err_file, logs_empty_and_mark_files_at_shutdown(), mem_free, mutex_free(), os_aio_wake_all_threads_at_shutdown(), os_event_count, os_event_set(), os_fast_mutex_count, os_mutex_count, os_mutex_enter(), os_mutex_exit(), os_sync_free(), os_sync_mutex, os_thread_count, os_thread_sleep(), srv_conc_n_threads, srv_dict_tmpfile, srv_dict_tmpfile_mutex, srv_fast_shutdown, srv_free(), srv_is_being_started, srv_lock_timeout_thread_event, srv_misc_tmpfile, srv_misc_tmpfile_mutex, srv_monitor_file, srv_monitor_file_mutex, srv_monitor_file_name, srv_print_verbose_log, SRV_SHUTDOWN_EXIT_THREADS, srv_shutdown_lsn, srv_shutdown_state, srv_wake_master_thread(), srv_was_started, sync_close(), trx_sys, ut_dulint_get_high(), ut_dulint_get_low(), ut_free_all_mem(), UT_LIST_GET_LEN, and ut_print_timestamp().
01718 : DB_SUCCESS or error code */ 01719 { 01720 ulint i; 01721 #ifdef __NETWARE__ 01722 extern ibool panic_shutdown; 01723 #endif 01724 if (!srv_was_started) { 01725 if (srv_is_being_started) { 01726 ut_print_timestamp(stderr); 01727 fprintf(stderr, 01728 " InnoDB: Warning: shutting down a not properly started\n" 01729 " InnoDB: or created database!\n"); 01730 } 01731 01732 return(DB_SUCCESS); 01733 } 01734 01735 /* 1. Flush the buffer pool to disk, write the current lsn to 01736 the tablespace header(s), and copy all log data to archive. 01737 The step 1 is the real InnoDB shutdown. The remaining steps 2 - ... 01738 just free data structures after the shutdown. */ 01739 01740 01741 if (srv_fast_shutdown == 2) { 01742 ut_print_timestamp(stderr); 01743 fprintf(stderr, 01744 " InnoDB: MySQL has requested a very fast shutdown without flushing " 01745 "the InnoDB buffer pool to data files. At the next mysqld startup " 01746 "InnoDB will do a crash recovery!\n"); 01747 } 01748 01749 #ifdef __NETWARE__ 01750 if(!panic_shutdown) 01751 #endif 01752 logs_empty_and_mark_files_at_shutdown(); 01753 01754 if (srv_conc_n_threads != 0) { 01755 fprintf(stderr, 01756 "InnoDB: Warning: query counter shows %ld queries still\n" 01757 "InnoDB: inside InnoDB at shutdown\n", 01758 srv_conc_n_threads); 01759 } 01760 01761 /* 2. Make all threads created by InnoDB to exit */ 01762 01763 srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS; 01764 01765 /* In a 'very fast' shutdown, we do not need to wait for these threads 01766 to die; all which counts is that we flushed the log; a 'very fast' 01767 shutdown is essentially a crash. */ 01768 01769 if (srv_fast_shutdown == 2) { 01770 return(DB_SUCCESS); 01771 } 01772 01773 /* All threads end up waiting for certain events. Put those events 01774 to the signaled state. Then the threads will exit themselves in 01775 os_thread_event_wait(). */ 01776 01777 for (i = 0; i < 1000; i++) { 01778 /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM 01779 HERE OR EARLIER */ 01780 01781 /* a. Let the lock timeout thread exit */ 01782 os_event_set(srv_lock_timeout_thread_event); 01783 01784 /* b. srv error monitor thread exits automatically, no need 01785 to do anything here */ 01786 01787 /* c. We wake the master thread so that it exits */ 01788 srv_wake_master_thread(); 01789 01790 /* d. Exit the i/o threads */ 01791 01792 os_aio_wake_all_threads_at_shutdown(); 01793 01794 os_mutex_enter(os_sync_mutex); 01795 01796 if (os_thread_count == 0) { 01797 /* All the threads have exited or are just exiting; 01798 NOTE that the threads may not have completed their 01799 exit yet. Should we use pthread_join() to make sure 01800 they have exited? Now we just sleep 0.1 seconds and 01801 hope that is enough! */ 01802 01803 os_mutex_exit(os_sync_mutex); 01804 01805 os_thread_sleep(100000); 01806 01807 break; 01808 } 01809 01810 os_mutex_exit(os_sync_mutex); 01811 01812 os_thread_sleep(100000); 01813 } 01814 01815 if (i == 1000) { 01816 fprintf(stderr, 01817 "InnoDB: Warning: %lu threads created by InnoDB had not exited at shutdown!\n", 01818 (ulong) os_thread_count); 01819 } 01820 01821 if (srv_monitor_file) { 01822 fclose(srv_monitor_file); 01823 srv_monitor_file = 0; 01824 if (srv_monitor_file_name) { 01825 unlink(srv_monitor_file_name); 01826 mem_free(srv_monitor_file_name); 01827 } 01828 } 01829 if (srv_dict_tmpfile) { 01830 fclose(srv_dict_tmpfile); 01831 srv_dict_tmpfile = 0; 01832 } 01833 01834 if (srv_misc_tmpfile) { 01835 fclose(srv_misc_tmpfile); 01836 srv_misc_tmpfile = 0; 01837 } 01838 01839 mutex_free(&srv_monitor_file_mutex); 01840 mutex_free(&srv_dict_tmpfile_mutex); 01841 mutex_free(&srv_misc_tmpfile_mutex); 01842 01843 /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside 01844 them */ 01845 sync_close(); 01846 01847 /* 4. Free the os_conc_mutex and all os_events and os_mutexes */ 01848 01849 srv_free(); 01850 os_sync_free(); 01851 01852 /* Check that all read views are closed except read view owned 01853 by a purge. */ 01854 01855 if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) { 01856 fprintf(stderr, 01857 "InnoDB: Error: all read views were not closed before shutdown:\n" 01858 "InnoDB: %lu read views open \n", 01859 UT_LIST_GET_LEN(trx_sys->view_list) - 1); 01860 } 01861 01862 /* 5. Free all allocated memory and the os_fast_mutex created in 01863 ut0mem.c */ 01864 01865 ut_free_all_mem(); 01866 01867 if (os_thread_count != 0 01868 || os_event_count != 0 01869 || os_mutex_count != 0 01870 || os_fast_mutex_count != 0) { 01871 fprintf(stderr, 01872 "InnoDB: Warning: some resources were not cleaned up in shutdown:\n" 01873 "InnoDB: threads %lu, events %lu, os_mutexes %lu, os_fast_mutexes %lu\n", 01874 (ulong) os_thread_count, (ulong) os_event_count, 01875 (ulong) os_mutex_count, (ulong) os_fast_mutex_count); 01876 } 01877 01878 if (dict_foreign_err_file) { 01879 fclose(dict_foreign_err_file); 01880 } 01881 if (lock_latest_err_file) { 01882 fclose(lock_latest_err_file); 01883 } 01884 01885 if (srv_print_verbose_log) { 01886 ut_print_timestamp(stderr); 01887 fprintf(stderr, 01888 " InnoDB: Shutdown completed; log sequence number %lu %lu\n", 01889 (ulong) ut_dulint_get_high(srv_shutdown_lsn), 01890 (ulong) ut_dulint_get_low(srv_shutdown_lsn)); 01891 } 01892 01893 return((int) DB_SUCCESS); 01894 }
Here is the call graph for this function:

| int innobase_start_or_create_for_mysql | ( | void | ) |
Definition at line 935 of file srv0start.c.
References __WIN__, log_struct::archiving_state, buf_pool_init(), DB_ERROR, DB_SUCCESS, dict_boot(), dict_check_tablespaces_and_store_max_id(), dict_create(), dict_create_or_check_foreign_constraint_tables(), err, errno, exit, FALSE, fil_init(), fil_open_log_and_system_tablespace_files(), fil_path_to_mysql_datadir, fsp_header_get_free_limit(), fsp_header_get_tablespace_size(), fsp_header_inc_size(), fsp_header_init(), fsp_init(), ibuf_is_empty(), ibuf_update_max_tablespace_id(), io_handler_thread(), lock_sys_create(), LOG_ARCH_OFF, log_archive_archivelog(), log_archive_noarchivelog(), log_buffer_flush_to_disk(), LOG_CHECKPOINT, log_do_write, log_init(), log_sys, mem_alloc, mtr_commit(), mtr_start(), log_struct::mutex, mutex_create, mutex_enter, mutex_exit(), n, NULL, off_t, open_or_create_data_files(), open_or_create_log_file(), os_aio_init(), os_aio_use_native_aio, os_fast_mutex_free(), os_fast_mutex_init(), os_fast_mutex_lock(), os_fast_mutex_trylock(), os_fast_mutex_unlock(), os_file_create_tmpfile(), os_get_os_version(), os_proc_get_number(), os_thread_create(), os_thread_sleep(), OS_WIN31, OS_WIN95, OS_WINNT, recv_needed_recovery, recv_recovery_from_checkpoint_finish(), recv_recovery_from_checkpoint_start(), recv_reset_logs(), srv_add_path_separator_if_needed(), srv_auto_extend_last_data_file, srv_awe_window_size, srv_boot(), srv_data_file_sizes, srv_dict_tmpfile, srv_dict_tmpfile_mutex, srv_error_monitor_thread(), srv_file_flush_method_str, srv_file_per_table, SRV_FORCE_NO_IBUF_MERGE, srv_force_recovery, srv_innodb_status, srv_is_being_started, srv_lock_table_size, srv_lock_timeout_and_monitor_thread(), srv_log_file_size, srv_log_group_home_dirs, srv_main_thread_op_info, srv_master_thread(), SRV_MAX_N_IO_THREADS, srv_max_n_open_files, SRV_MAX_N_PENDING_SYNC_IOS, srv_max_n_threads, srv_misc_tmpfile, srv_misc_tmpfile_mutex, srv_monitor_file, srv_monitor_file_mutex, srv_monitor_file_name, srv_n_data_files, srv_n_file_io_threads, srv_n_log_files, SRV_N_PENDING_IOS_PER_THREAD, srv_normalize_path_for_win(), srv_os_test_mutex, srv_pool_size, srv_print_verbose_log, srv_sizeof_trx_t_in_ha_innodb_cc, srv_start_has_been_called, srv_start_lsn, srv_startup_is_before_trx_rollback_phase, SRV_UNIX_FDATASYNC, srv_unix_file_flush_method, SRV_UNIX_LITTLESYNC, SRV_UNIX_NOSYNC, SRV_UNIX_O_DIRECT, SRV_UNIX_O_DSYNC, srv_use_adaptive_hash_indexes, srv_use_awe, srv_was_started, srv_win_file_flush_method, SRV_WIN_IO_NORMAL, SRV_WIN_IO_UNBUFFERED, strcmp(), strlen(), SYNC_ANY_LATCH, SYNC_DICT_OPERATION, SYNC_NO_ORDER_CHECK, sync_order_checks_on, thread_ids, TRUE, trx_doublewrite, trx_doublewrite_must_reset_space_ids, trx_sys_create(), trx_sys_create_doublewrite_buf(), trx_sys_init_at_db_start(), trx_sys_mark_upgraded_to_multiple_tablespaces(), UNIV_PAGE_SIZE, ut_a, ut_dulint_cmp(), ut_dulint_create(), ut_dulint_get_high(), ut_dulint_get_low(), ut_dulint_max, ut_print_timestamp(), and ut_strcmp().
00937 : DB_SUCCESS or error code */ 00938 { 00939 buf_pool_t* ret; 00940 ibool create_new_db; 00941 ibool log_file_created; 00942 ibool log_created = FALSE; 00943 ibool log_opened = FALSE; 00944 dulint min_flushed_lsn; 00945 dulint max_flushed_lsn; 00946 #ifdef UNIV_LOG_ARCHIVE 00947 ulint min_arch_log_no; 00948 ulint max_arch_log_no; 00949 #endif /* UNIV_LOG_ARCHIVE */ 00950 ulint sum_of_new_sizes; 00951 ulint sum_of_data_file_sizes; 00952 ulint tablespace_size_in_header; 00953 ulint err; 00954 ulint i; 00955 ibool srv_file_per_table_original_value = srv_file_per_table; 00956 mtr_t mtr; 00957 #ifdef HAVE_DARWIN_THREADS 00958 # ifdef F_FULLFSYNC 00959 /* This executable has been compiled on Mac OS X 10.3 or later. 00960 Assume that F_FULLFSYNC is available at run-time. */ 00961 srv_have_fullfsync = TRUE; 00962 # else /* F_FULLFSYNC */ 00963 /* This executable has been compiled on Mac OS X 10.2 00964 or earlier. Determine if the executable is running 00965 on Mac OS X 10.3 or later. */ 00966 struct utsname utsname; 00967 if (uname(&utsname)) { 00968 fputs("InnoDB: cannot determine Mac OS X version!\n", stderr); 00969 } else { 00970 srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0; 00971 } 00972 if (!srv_have_fullfsync) { 00973 fputs( 00974 "InnoDB: On Mac OS X, fsync() may be broken on internal drives,\n" 00975 "InnoDB: making transactions unsafe!\n", stderr); 00976 } 00977 # endif /* F_FULLFSYNC */ 00978 #endif /* HAVE_DARWIN_THREADS */ 00979 00980 if (sizeof(ulint) != sizeof(void*)) { 00981 fprintf(stderr, 00982 "InnoDB: Error: size of InnoDB's ulint is %lu, but size of void* is %lu.\n" 00983 "InnoDB: The sizes should be the same so that on a 64-bit platform you can\n" 00984 "InnoDB: allocate more than 4 GB of memory.", 00985 (ulong)sizeof(ulint), (ulong)sizeof(void*)); 00986 } 00987 00988 srv_file_per_table = FALSE; /* system tables are created in tablespace 00989 0 */ 00990 #ifdef UNIV_DEBUG 00991 fprintf(stderr, 00992 "InnoDB: !!!!!!!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!!!!!!!\n"); 00993 #endif 00994 00995 #ifdef UNIV_SYNC_DEBUG 00996 fprintf(stderr, 00997 "InnoDB: !!!!!!!!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!!!!!!!\n"); 00998 #endif 00999 01000 #ifdef UNIV_SEARCH_DEBUG 01001 fprintf(stderr, 01002 "InnoDB: !!!!!!!!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!!!!!!!\n"); 01003 #endif 01004 01005 #ifdef UNIV_MEM_DEBUG 01006 fprintf(stderr, 01007 "InnoDB: !!!!!!!!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!!!!!!!\n"); 01008 #endif 01009 01010 #ifdef UNIV_SIMULATE_AWE 01011 fprintf(stderr, 01012 "InnoDB: !!!!!!!!!!!!!! UNIV_SIMULATE_AWE switched on !!!!!!!!!!!!!!!!!\n"); 01013 #endif 01014 if (srv_sizeof_trx_t_in_ha_innodb_cc != (ulint)sizeof(trx_t)) { 01015 fprintf(stderr, 01016 "InnoDB: Error: trx_t size is %lu in ha_innodb.cc but %lu in srv0start.c\n" 01017 "InnoDB: Check that pthread_mutex_t is defined in the same way in these\n" 01018 "InnoDB: compilation modules. Cannot continue.\n", 01019 (ulong) srv_sizeof_trx_t_in_ha_innodb_cc, 01020 (ulong) sizeof(trx_t)); 01021 return(DB_ERROR); 01022 } 01023 01024 /* Since InnoDB does not currently clean up all its internal data 01025 structures in MySQL Embedded Server Library server_end(), we 01026 print an error message if someone tries to start up InnoDB a 01027 second time during the process lifetime. */ 01028 01029 if (srv_start_has_been_called) { 01030 fprintf(stderr, 01031 "InnoDB: Error:startup called second time during the process lifetime.\n" 01032 "InnoDB: In the MySQL Embedded Server Library you cannot call server_init()\n" 01033 "InnoDB: more than once during the process lifetime.\n"); 01034 } 01035 01036 srv_start_has_been_called = TRUE; 01037 01038 #ifdef UNIV_DEBUG 01039 log_do_write = TRUE; 01040 #endif /* UNIV_DEBUG */ 01041 /* yydebug = TRUE; */ 01042 01043 srv_is_being_started = TRUE; 01044 srv_startup_is_before_trx_rollback_phase = TRUE; 01045 os_aio_use_native_aio = FALSE; 01046 01047 #if !defined(__WIN2000__) && !defined(UNIV_SIMULATE_AWE) 01048 if (srv_use_awe) { 01049 01050 fprintf(stderr, 01051 "InnoDB: Error: You have specified innodb_buffer_pool_awe_mem_mb\n" 01052 "InnoDB: in my.cnf, but AWE can only be used in Windows 2000 and later.\n" 01053 "InnoDB: To use AWE, InnoDB must be compiled with __WIN2000__ defined.\n"); 01054 01055 return(DB_ERROR); 01056 } 01057 #endif 01058 01059 #ifdef __WIN__ 01060 if (os_get_os_version() == OS_WIN95 01061 || os_get_os_version() == OS_WIN31 01062 || os_get_os_version() == OS_WINNT) { 01063 01064 /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1, 01065 and NT use simulated aio. In NT Windows provides async i/o, 01066 but when run in conjunction with InnoDB Hot Backup, it seemed 01067 to corrupt the data files. */ 01068 01069 os_aio_use_native_aio = FALSE; 01070 } else { 01071 /* On Win 2000 and XP use async i/o */ 01072 os_aio_use_native_aio = TRUE; 01073 } 01074 #endif 01075 if (srv_file_flush_method_str == NULL) { 01076 /* These are the default options */ 01077 01078 srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; 01079 01080 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; 01081 #ifndef __WIN__ 01082 } else if (0 == ut_strcmp(srv_file_flush_method_str, "fdatasync")) { 01083 srv_unix_file_flush_method = SRV_UNIX_FDATASYNC; 01084 01085 } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) { 01086 srv_unix_file_flush_method = SRV_UNIX_O_DSYNC; 01087 01088 } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) { 01089 srv_unix_file_flush_method = SRV_UNIX_O_DIRECT; 01090 01091 } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) { 01092 srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC; 01093 01094 } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) { 01095 srv_unix_file_flush_method = SRV_UNIX_NOSYNC; 01096 #else 01097 } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) { 01098 srv_win_file_flush_method = SRV_WIN_IO_NORMAL; 01099 os_aio_use_native_aio = FALSE; 01100 01101 } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) { 01102 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; 01103 os_aio_use_native_aio = FALSE; 01104 01105 } else if (0 == ut_strcmp(srv_file_flush_method_str, 01106 "async_unbuffered")) { 01107 srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED; 01108 #endif 01109 } else { 01110 fprintf(stderr, 01111 "InnoDB: Unrecognized value %s for innodb_flush_method\n", 01112 srv_file_flush_method_str); 01113 return(DB_ERROR); 01114 } 01115 01116 /* Note that the call srv_boot() also changes the values of 01117 srv_pool_size etc. to the units used by InnoDB internally */ 01118 01119 /* Set the maximum number of threads which can wait for a semaphore 01120 inside InnoDB: this is the 'sync wait array' size, as well as the 01121 maximum number of threads that can wait in the 'srv_conc array' for 01122 their time to enter InnoDB. */ 01123 01124 #if defined(__WIN__) || defined(__NETWARE__) 01125 01126 /* Create less event semaphores because Win 98/ME had difficulty creating 01127 40000 event semaphores. 01128 Comment from Novell, Inc.: also, these just take a lot of memory on 01129 NetWare. */ 01130 srv_max_n_threads = 1000; 01131 #else 01132 if (srv_pool_size >= 1000 * 1024) { 01133 /* Here we still have srv_pool_size counted 01134 in kilobytes (in 4.0 this was in bytes) 01135 srv_boot() converts the value to 01136 pages; if buffer pool is less than 1000 MB, 01137 assume fewer threads. */ 01138 srv_max_n_threads = 50000; 01139 01140 } else if (srv_pool_size >= 8 * 1024) { 01141 01142 srv_max_n_threads = 10000; 01143 } else { 01144 srv_max_n_threads = 1000; /* saves several MB of memory, 01145 especially in 64-bit 01146 computers */ 01147 } 01148 #endif 01149 err = srv_boot(); /* This changes srv_pool_size to units of a page */ 01150 01151 if (err != DB_SUCCESS) { 01152 01153 return((int) err); 01154 } 01155 01156 mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK); 01157 01158 if (srv_innodb_status) { 01159 srv_monitor_file_name = mem_alloc( 01160 strlen(fil_path_to_mysql_datadir) + 01161 20 + sizeof "/innodb_status."); 01162 sprintf(srv_monitor_file_name, "%s/innodb_status.%lu", 01163 fil_path_to_mysql_datadir, os_proc_get_number()); 01164 srv_monitor_file = fopen(srv_monitor_file_name, "w+"); 01165 if (!srv_monitor_file) { 01166 fprintf(stderr, "InnoDB: unable to create %s: %s\n", 01167 srv_monitor_file_name, strerror(errno)); 01168 return(DB_ERROR); 01169 } 01170 } else { 01171 srv_monitor_file_name = NULL; 01172 srv_monitor_file = os_file_create_tmpfile(); 01173 if (!srv_monitor_file) { 01174 return(DB_ERROR); 01175 } 01176 } 01177 01178 mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION); 01179 01180 srv_dict_tmpfile = os_file_create_tmpfile(); 01181 if (!srv_dict_tmpfile) { 01182 return(DB_ERROR); 01183 } 01184 01185 mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH); 01186 01187 srv_misc_tmpfile = os_file_create_tmpfile(); 01188 if (!srv_misc_tmpfile) { 01189 return(DB_ERROR); 01190 } 01191 01192 /* Restrict the maximum number of file i/o threads */ 01193 if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) { 01194 01195 srv_n_file_io_threads = SRV_MAX_N_IO_THREADS; 01196 } 01197 01198 if (!os_aio_use_native_aio) { 01199 /* In simulated aio we currently have use only for 4 threads */ 01200 srv_n_file_io_threads = 4; 01201 01202 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD 01203 * srv_n_file_io_threads, 01204 srv_n_file_io_threads, 01205 SRV_MAX_N_PENDING_SYNC_IOS); 01206 } else { 01207 os_aio_init(SRV_N_PENDING_IOS_PER_THREAD 01208 * srv_n_file_io_threads, 01209 srv_n_file_io_threads, 01210 SRV_MAX_N_PENDING_SYNC_IOS); 01211 } 01212 01213 fil_init(srv_max_n_open_files); 01214 01215 if (srv_use_awe) { 01216 fprintf(stderr, 01217 "InnoDB: Using AWE: Memory window is %lu MB and AWE memory is %lu MB\n", 01218 (ulong) (srv_awe_window_size / ((1024 * 1024) / UNIV_PAGE_SIZE)), 01219 (ulong) (srv_pool_size / ((1024 * 1024) / UNIV_PAGE_SIZE))); 01220 01221 /* We must disable adaptive hash indexes because they do not 01222 tolerate remapping of pages in AWE */ 01223 01224 srv_use_adaptive_hash_indexes = FALSE; 01225 ret = buf_pool_init(srv_pool_size, srv_pool_size, 01226 srv_awe_window_size); 01227 } else { 01228 ret = buf_pool_init(srv_pool_size, srv_pool_size, 01229 srv_pool_size); 01230 } 01231 01232 if (ret == NULL) { 01233 fprintf(stderr, 01234 "InnoDB: Fatal error: cannot allocate the memory for the buffer pool\n"); 01235 01236 return(DB_ERROR); 01237 } 01238 01239 fsp_init(); 01240 log_init(); 01241 01242 lock_sys_create(srv_lock_table_size); 01243 01244 /* Create i/o-handler threads: */ 01245 01246 for (i = 0; i < srv_n_file_io_threads; i++) { 01247 n[i] = i; 01248 01249 os_thread_create(io_handler_thread, n + i, thread_ids + i); 01250 } 01251 01252 #ifdef UNIV_LOG_ARCHIVE 01253 if (0 != ut_strcmp(srv_log_group_home_dirs[0], srv_arch_dir)) { 01254 fprintf(stderr, 01255 "InnoDB: Error: you must set the log group home dir in my.cnf the\n" 01256 "InnoDB: same as log arch dir.\n"); 01257 01258 return(DB_ERROR); 01259 } 01260 #endif /* UNIV_LOG_ARCHIVE */ 01261 01262 if (srv_n_log_files * srv_log_file_size >= 262144) { 01263 fprintf(stderr, 01264 "InnoDB: Error: combined size of log files must be < 4 GB\n"); 01265 01266 return(DB_ERROR); 01267 } 01268 01269 sum_of_new_sizes = 0; 01270 01271 for (i = 0; i < srv_n_data_files; i++) { 01272 #ifndef __WIN__ 01273 if (sizeof(off_t) < 5 && srv_data_file_sizes[i] >= 262144) { 01274 fprintf(stderr, 01275 "InnoDB: Error: file size must be < 4 GB with this MySQL binary\n" 01276 "InnoDB: and operating system combination, in some OS's < 2 GB\n"); 01277 01278 return(DB_ERROR); 01279 } 01280 #endif 01281 sum_of_new_sizes += srv_data_file_sizes[i]; 01282 } 01283 01284 if (sum_of_new_sizes < 640) { 01285 fprintf(stderr, 01286 "InnoDB: Error: tablespace size must be at least 10 MB\n"); 01287 01288 return(DB_ERROR); 01289 } 01290 01291 err = open_or_create_data_files(&create_new_db, 01292 #ifdef UNIV_LOG_ARCHIVE 01293 &min_arch_log_no, &max_arch_log_no, 01294 #endif /* UNIV_LOG_ARCHIVE */ 01295 &min_flushed_lsn, &max_flushed_lsn, 01296 &sum_of_new_sizes); 01297 if (err != DB_SUCCESS) { 01298 fprintf(stderr, 01299 "InnoDB: Could not open or create data files.\n" 01300 "InnoDB: If you tried to add new data files, and it failed here,\n" 01301 "InnoDB: you should now edit innodb_data_file_path in my.cnf back\n" 01302 "InnoDB: to what it was, and remove the new ibdata files InnoDB created\n" 01303 "InnoDB: in this failed attempt. InnoDB only wrote those files full of\n" 01304 "InnoDB: zeros, but did not yet use them in any way. But be careful: do not\n" 01305 "InnoDB: remove old data files which contain your precious data!\n"); 01306 01307 return((int) err); 01308 } 01309 01310 #ifdef UNIV_LOG_ARCHIVE 01311 srv_normalize_path_for_win(srv_arch_dir); 01312 srv_arch_dir = srv_add_path_separator_if_needed(srv_arch_dir); 01313 #endif /* UNIV_LOG_ARCHIVE */ 01314 01315 for (i = 0; i < srv_n_log_files; i++) { 01316 err = open_or_create_log_file(create_new_db, &log_file_created, 01317 log_opened, 0, i); 01318 if (err != DB_SUCCESS) { 01319 01320 return((int) err); 01321 } 01322 01323 if (log_file_created) { 01324 log_created = TRUE; 01325 } else { 01326 log_opened = TRUE; 01327 } 01328 if ((log_opened && create_new_db) 01329 || (log_opened && log_created)) { 01330 fprintf(stderr, 01331 "InnoDB: Error: all log files must be created at the same time.\n" 01332 "InnoDB: All log files must be created also in database creation.\n" 01333 "InnoDB: If you want bigger or smaller log files, shut down the\n" 01334 "InnoDB: database and make sure there were no errors in shutdown.\n" 01335 "InnoDB: Then delete the existing log files. Edit the .cnf file\n" 01336 "InnoDB: and start the database again.\n"); 01337 01338 return(DB_ERROR); 01339 } 01340 } 01341 01342 /* Open all log files and data files in the system tablespace: we 01343 keep them open until database shutdown */ 01344 01345 fil_open_log_and_system_tablespace_files(); 01346 01347 if (log_created && !create_new_db 01348 #ifdef UNIV_LOG_ARCHIVE 01349 && !srv_archive_recovery 01350 #endif /* UNIV_LOG_ARCHIVE */ 01351 ) { 01352 if (ut_dulint_cmp(max_flushed_lsn, min_flushed_lsn) != 0 01353 #ifdef UNIV_LOG_ARCHIVE 01354 || max_arch_log_no != min_arch_log_no 01355 #endif /* UNIV_LOG_ARCHIVE */ 01356 ) { 01357 fprintf(stderr, 01358 "InnoDB: Cannot initialize created log files because\n" 01359 "InnoDB: data files were not in sync with each other\n" 01360 "InnoDB: or the data files are corrupt.\n"); 01361 01362 return(DB_ERROR); 01363 } 01364 01365 if (ut_dulint_cmp(max_flushed_lsn, ut_dulint_create(0, 1000)) 01366 < 0) { 01367 fprintf(stderr, 01368 "InnoDB: Cannot initialize created log files because\n" 01369 "InnoDB: data files are corrupt, or new data files were\n" 01370 "InnoDB: created when the database was started previous\n" 01371 "InnoDB: time but the database was not shut down\n" 01372 "InnoDB: normally after that.\n"); 01373 01374 return(DB_ERROR); 01375 } 01376 01377 mutex_enter(&(log_sys->mutex)); 01378 01379 #ifdef UNIV_LOG_ARCHIVE 01380 /* Do not + 1 arch_log_no because we do not use log 01381 archiving */ 01382 recv_reset_logs(max_flushed_lsn, max_arch_log_no, TRUE); 01383 #else 01384 recv_reset_logs(max_flushed_lsn, TRUE); 01385 #endif /* UNIV_LOG_ARCHIVE */ 01386 01387 mutex_exit(&(log_sys->mutex)); 01388 } 01389 01390 if (create_new_db) { 01391 mtr_start(&mtr); 01392 01393 fsp_header_init(0, sum_of_new_sizes, &mtr); 01394 01395 mtr_commit(&mtr); 01396 01397 trx_sys_create(); 01398 dict_create(); 01399 srv_startup_is_before_trx_rollback_phase = FALSE; 01400 01401 #ifdef UNIV_LOG_ARCHIVE 01402 } else if (srv_archive_recovery) { 01403 fprintf(stderr, 01404 "InnoDB: Starting archive recovery from a backup...\n"); 01405 err = recv_recovery_from_archive_start( 01406 min_flushed_lsn, 01407 srv_archive_recovery_limit_lsn, 01408 min_arch_log_no); 01409 if (err != DB_SUCCESS) { 01410 01411 return(DB_ERROR); 01412 } 01413 /* Since ibuf init is in dict_boot, and ibuf is needed 01414 in any disk i/o, first call dict_boot */ 01415 01416 dict_boot(); 01417 trx_sys_init_at_db_start(); 01418 srv_startup_is_before_trx_rollback_phase = FALSE; 01419 01420 /* Initialize the fsp free limit global variable in the log 01421 system */ 01422 fsp_header_get_free_limit(0); 01423 01424 recv_recovery_from_archive_finish(); 01425 #endif /* UNIV_LOG_ARCHIVE */ 01426 } else { 01427 /* We always try to do a recovery, even if the database had 01428 been shut down normally: this is the normal startup path */ 01429 01430 err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT, 01431 ut_dulint_max, 01432 min_flushed_lsn, 01433 max_flushed_lsn); 01434 if (err != DB_SUCCESS) { 01435 01436 return(DB_ERROR); 01437 } 01438 01439 /* Since the insert buffer init is in dict_boot, and the 01440 insert buffer is needed in any disk i/o, first we call 01441 dict_boot(). Note that trx_sys_init_at_db_start() only needs 01442 to access space 0, and the insert buffer at this stage already 01443 works for space 0. */ 01444 01445 dict_boot(); 01446 trx_sys_init_at_db_start(); 01447 01448 if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) { 01449 /* The following call is necessary for the insert 01450 buffer to work with multiple tablespaces. We must 01451 know the mapping between space id's and .ibd file 01452 names. 01453 01454 In a crash recovery, we check that the info in data 01455 dictionary is consistent with what we already know 01456 about space id's from the call of 01457 fil_load_single_table_tablespaces(). 01458 01459 In a normal startup, we create the space objects for 01460 every table in the InnoDB data dictionary that has 01461 an .ibd file. 01462 01463 We also determine the maximum tablespace id used. 01464 01465 TODO: We may have incomplete transactions in the 01466 data dictionary tables. Does that harm the scanning of 01467 the data dictionary below? */ 01468 01469 dict_check_tablespaces_and_store_max_id( 01470 recv_needed_recovery); 01471 } 01472 01473 srv_startup_is_before_trx_rollback_phase = FALSE; 01474 01475 /* Initialize the fsp free limit global variable in the log 01476 system */ 01477 fsp_header_get_free_limit(0); 01478 01479 /* recv_recovery_from_checkpoint_finish needs trx lists which 01480 are initialized in trx_sys_init_at_db_start(). */ 01481 01482 recv_recovery_from_checkpoint_finish(); 01483 } 01484 01485 if (!create_new_db && sum_of_new_sizes > 0) { 01486 /* New data file(s) were added */ 01487 mtr_start(&mtr); 01488 01489 fsp_header_inc_size(0, sum_of_new_sizes, &mtr); 01490 01491 mtr_commit(&mtr); 01492 01493 /* Immediately write the log record about increased tablespace 01494 size to disk, so that it is durable even if mysqld would crash 01495 quickly */ 01496 01497 log_buffer_flush_to_disk(); 01498 } 01499 01500 #ifdef UNIV_LOG_ARCHIVE 01501 /* Archiving is always off un

