diff options
Diffstat (limited to 'sql/mysqld.cc')
-rw-r--r-- | sql/mysqld.cc | 654 |
1 files changed, 376 insertions, 278 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d53ed0f8594..85d088f8173 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -34,6 +34,8 @@ #include <ft_global.h> #include <assert.h> +#define mysqld_charset my_charset_latin1 + #ifndef DBUG_OFF #define ONE_THREAD #endif @@ -180,11 +182,9 @@ static char szPipeName [ 257 ]; static SECURITY_ATTRIBUTES saPipeSecurity; static SECURITY_DESCRIPTOR sdPipeDescriptor; static HANDLE hPipe = INVALID_HANDLE_VALUE; -static uint handler_count; static bool opt_enable_named_pipe = 0; #endif #ifdef __WIN__ -static bool opt_console=0,start_mode=0; static pthread_cond_t COND_handler_count; static uint handler_count; static bool opt_console=0, start_mode=0, use_opt_args; @@ -206,7 +206,7 @@ static char **opt_argv; #else #define MYSQL_SERVER_SUFFIX "" #endif /* __NT__ */ -#endif +#endif /* __WIN__ */ #ifdef HAVE_BERKELEY_DB SHOW_COMP_OPTION have_berkeley_db=SHOW_OPTION_YES; @@ -247,6 +247,12 @@ SHOW_COMP_OPTION have_query_cache=SHOW_OPTION_NO; const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"}; bool opt_large_files= sizeof(my_off_t) > 4; +#if SIZEOF_OFF_T > 4 && defined(BIG_TABLES) +#define GET_HA_ROWS GET_ULL +#else +#define GET_HA_ROWS GET_ULONG +#endif + /* Variables to store startup options @@ -282,7 +288,7 @@ static my_bool opt_noacl=0, opt_bootstrap=0, opt_myisam_log=0; my_bool opt_safe_user_create = 0, opt_no_mix_types = 0; my_bool lower_case_table_names, opt_old_rpl_compat; my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0; -my_bool opt_log_slave_updates= 0, opt_old_passwords=0; +my_bool opt_log_slave_updates= 0, opt_old_passwords=0, use_old_passwords=0; volatile bool mqh_used = 0; FILE *bootstrap_file=0; @@ -345,8 +351,8 @@ arg_cmp_func Arg_comparator::comparator_matrix[4][2] = {&Arg_comparator::compare_int, &Arg_comparator::compare_e_int}, {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row}}; #ifdef HAVE_SMEM -static char *shared_memory_base_name=default_shared_memory_base_name; -static bool opt_enable_shared_memory = 0; +char *shared_memory_base_name=default_shared_memory_base_name; +bool opt_enable_shared_memory = 0; #endif volatile ulong cached_thread_count=0; @@ -418,12 +424,12 @@ double log_10[32]; /* 10 potences */ I_List<THD> threads,thread_cache; time_t start_time; -ulong opt_sql_mode = 0L; const char *sql_mode_names[] = { "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "SERIALIZE", "ONLY_FULL_GROUP_BY", "NO_UNSIGNED_SUBTRACTION", - "POSTGRESQL", "ORACLE", "MSSQL", "SAPDB", + "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "SAPDB", "NO_KEY_OPTIONS", + "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", NullS }; TYPELIB sql_mode_typelib= {array_elements(sql_mode_names)-1,"", @@ -485,7 +491,9 @@ extern "C" pthread_handler_decl(handle_slave,arg); static uint set_maximum_open_files(uint max_file_limit); #endif static ulong find_bit_type(const char *x, TYPELIB *bit_lib); +static void clean_up(bool print_message); +#ifndef EMBEDDED_LIBRARY /**************************************************************************** ** Code to end mysqld ****************************************************************************/ @@ -661,6 +669,7 @@ static void close_connections(void) DBUG_PRINT("quit",("close_connections thread")); DBUG_VOID_RETURN; } +#endif /*EMBEDDED_LIBRARY*/ static void close_server_sock() { @@ -752,18 +761,19 @@ void kill_mysql(void) DBUG_VOID_RETURN; } +#ifndef EMBEDDED_LIBRARY /* Force server down. kill all connections and threads and exit */ #if defined(OS2) extern "C" void kill_server(int sig_ptr) -#define RETURN_FROM_KILL_SERVER return +#define RETURN_FROM_KILL_SERVER DBUG_RETURN #elif !defined(__WIN__) static void *kill_server(void *sig_ptr) -#define RETURN_FROM_KILL_SERVER return 0 +#define RETURN_FROM_KILL_SERVER DBUG_RETURN(0) #else static void __cdecl kill_server(int sig_ptr) -#define RETURN_FROM_KILL_SERVER return +#define RETURN_FROM_KILL_SERVER DBUG_VOID_RETURN #endif { int sig=(int) (long) sig_ptr; // This is passed a int @@ -792,13 +802,16 @@ static void __cdecl kill_server(int sig_ptr) RETURN_FROM_KILL_SERVER; } +#endif /* EMBEDDED_LIBRARY */ #ifdef USE_ONE_SIGNAL_HAND extern "C" pthread_handler_decl(kill_server_thread,arg __attribute__((unused))) { SHUTDOWN_THD; my_thread_init(); // Initialize new thread +#ifndef EMBEDDED_LIBRARY kill_server(0); +#endif /* EMBEDDED_LIBRARY */ my_thread_end(); // Normally never reached return 0; } @@ -842,7 +855,7 @@ extern "C" sig_handler print_signal_warning(int sig) void unireg_end(void) { - clean_up(); + clean_up(1); my_thread_end(); #ifdef SIGNALS_DONT_BREAK_READ exit(0); @@ -857,7 +870,7 @@ extern "C" void unireg_abort(int exit_code) DBUG_ENTER("unireg_abort"); if (exit_code) sql_print_error("Aborting\n"); - clean_up(); /* purecov: inspected */ + clean_up(1); /* purecov: inspected */ DBUG_PRINT("quit",("done with cleanup in unireg_abort")); my_thread_end(); exit(exit_code); /* purecov: inspected */ @@ -869,8 +882,10 @@ void clean_up(bool print_message) DBUG_PRINT("exit",("clean_up")); if (cleanup_done++) return; /* purecov: inspected */ +#ifdef HAVE_REPLICATION if (use_slave_mask) bitmap_free(&slave_error_mask); +#endif acl_free(1); grant_free(); query_cache_destroy(); @@ -892,22 +907,26 @@ void clean_up(bool print_message) free_defaults(defaults_argv); my_free(charsets_list, MYF(MY_ALLOW_ZERO_PTR)); free_tmpdir(&mysql_tmpdir_list); +#ifdef HAVE_REPLICATION my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR)); +#endif x_free(opt_bin_logname); x_free(opt_relay_logname); bitmap_free(&temp_pool); free_max_user_conn(); +#ifdef HAVE_REPLICATION end_slave_list(); +#endif #ifdef USE_REGEX regex_end(); #endif + if (print_message && errmesg) + sql_print_error(ER(ER_SHUTDOWN_COMPLETE),my_progname); #if !defined(__WIN__) && !defined(EMBEDDED_LIBRARY) if (!opt_bootstrap) (void) my_delete(pidfile_name,MYF(0)); // This may not always exist #endif - if (print_message && errmesg) - sql_print_error(ER(ER_SHUTDOWN_COMPLETE),my_progname); x_free((gptr) my_errmsg[ERRMAPP]); /* Free messages */ DBUG_PRINT("quit", ("Error messages freed")); /* Tell main we are ready */ @@ -917,6 +936,10 @@ void clean_up(bool print_message) /* do the broadcast inside the lock to ensure that my_end() is not called */ (void) pthread_cond_broadcast(&COND_thread_count); (void) pthread_mutex_unlock(&LOCK_thread_count); + /* + The following lines may never be executed as the main thread may have + killed us + */ DBUG_PRINT("quit", ("done with cleanup")); } /* clean_up */ @@ -982,7 +1005,7 @@ static void set_user(const char *user) { // allow a numeric uid to be used const char *pos; - for (pos=user; my_isdigit(system_charset_info,*pos); pos++) ; + for (pos=user; my_isdigit(mysqld_charset,*pos); pos++) ; if (*pos) // Not numeric id { fprintf(stderr,"Fatal error: Can't change to run as user '%s' ; Please check that the user exists!\n",user); @@ -1179,7 +1202,7 @@ void yyerror(const char *s) thd->lex.yylineno); } - +#ifndef EMBEDDED_LIBRARY void close_connection(NET *net,uint errcode,bool lock) { st_vio* vio; @@ -1199,6 +1222,7 @@ void close_connection(NET *net,uint errcode,bool lock) (void) pthread_mutex_unlock(&LOCK_thread_count); DBUG_VOID_RETURN; } +#endif /* Called when a thread is aborted */ /* ARGSUSED */ @@ -1496,7 +1520,7 @@ static void init_signals(void) /* Change limits so that we will get a core file */ struct rlimit rl; rl.rlim_cur = rl.rlim_max = RLIM_INFINITY; - if (setrlimit(RLIMIT_CORE, &rl)) + if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings) sql_print_error("Warning: setrlimit could not change the size of core files to 'infinity'; We may not be able to generate a core file on signals"); } #endif @@ -1537,7 +1561,7 @@ static void start_signal_handler(void) (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_attr_setprio(&thr_attr,INTERRUPT_PRIOR); - pthread_attr_setstacksize(&thr_attr,32768); + pthread_attr_setstacksize(&thr_attr, 129*1024); #endif (void) pthread_mutex_lock(&LOCK_thread_count); @@ -1565,8 +1589,11 @@ extern "C" void *signal_hand(void *arg __attribute__((unused))) my_thread_init(); // Init new thread DBUG_ENTER("signal_hand"); SIGNAL_THD; - /* Setup alarm handler */ - init_thr_alarm(max_connections+max_insert_delayed_threads); + /* + Setup alarm handler + The two extra handlers are for slave threads + */ + init_thr_alarm(max_connections+max_insert_delayed_threads+2); #if SIGINT != THR_KILL_SIGNAL (void) sigemptyset(&set); // Setup up SIGINT for debug (void) sigaddset(&set,SIGINT); // For debugging @@ -1654,12 +1681,15 @@ extern "C" void *signal_hand(void *arg __attribute__((unused))) } break; case SIGHUP: - reload_acl_and_cache((THD*) 0, - (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST | - REFRESH_STATUS | REFRESH_GRANT | REFRESH_THREADS | - REFRESH_HOSTS), - (TABLE_LIST*) 0); // Flush logs - mysql_print_status((THD*) 0); // Send debug some info + if (!abort_loop) + { + reload_acl_and_cache((THD*) 0, + (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST | + REFRESH_STATUS | REFRESH_GRANT | + REFRESH_THREADS | REFRESH_HOSTS), + (TABLE_LIST*) 0); // Flush logs + mysql_print_status((THD*) 0); // Send debug some info + } break; #ifdef USE_ONE_SIGNAL_HAND case THR_SERVER_ALARM: @@ -1714,7 +1744,7 @@ extern "C" int my_message_sql(uint error, const char *str, void clear_error_message(THD *thd) { - thd->net.last_error[0]= 0; + thd->clear_error(); } @@ -1827,28 +1857,15 @@ bool open_log(MYSQL_LOG *log, const char *hostname, } - -#ifdef __WIN__ -int win_main(int argc, char **argv) -#else -int main(int argc, char **argv) -#endif +static int init_common_variables(const char *conf_file_name, int argc, char **argv, + const char **groups) { - DEBUGGER_OFF; - my_umask=0660; // Default umask for new files my_umask_dir=0700; // Default umask for new directories - MAIN_THD; - /* - Initialize signal_th and shutdown_th to main_th for default value - as we need to initialize them to something safe. They are used - when compiled with safemalloc. - */ - SIGNAL_THD; - SHUTDOWN_THD; - MY_INIT(argv[0]); // init my_sys library & pthreads + umask(((~my_umask) & 0666)); tzset(); // Set tzname + max_system_variables.pseudo_thread_id= (ulong)~0; start_time=time((time_t*) 0); #ifdef OS2 { @@ -1878,21 +1895,15 @@ int main(int argc, char **argv) strmov(glob_hostname,"mysql"); strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5); strmov(fn_ext(pidfile_name),".pid"); // Add proper extension + #ifndef DBUG_OFF strxmov(strend(server_version),MYSQL_SERVER_SUFFIX,"-debug",NullS); #else strmov(strend(server_version),MYSQL_SERVER_SUFFIX); #endif -#ifdef _CUSTOMSTARTUPCONFIG_ - if (_cust_check_startup()) - { - /* _cust_check_startup will report startup failure error */ - exit( 1 ); - } -#endif - load_defaults(MYSQL_CONFIG_NAME,load_default_groups,&argc,&argv); - defaults_argv=argv; + load_defaults(conf_file_name, groups, &argc, &argv); + defaults_argv=argv; set_options(); get_options(argc,argv); if (opt_log || opt_update_log || opt_slow_log || opt_bin_log) @@ -1900,8 +1911,46 @@ int main(int argc, char **argv) DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, server_version, SYSTEM_TYPE,MACHINE_TYPE)); - /* These must be set early */ +#if defined( SET_RLIMIT_NOFILE) || defined( OS2) + /* connections and databases needs lots of files */ + { + uint wanted_files=10+(uint) max(max_connections*5, + max_connections+table_cache_size*2); + set_if_bigger(wanted_files, open_files_limit); + // Note that some system returns 0 if we succeed here: + uint files=set_maximum_open_files(wanted_files); + if (files && files < wanted_files && ! open_files_limit) + { + max_connections= (ulong) min((files-10),max_connections); + table_cache_size= (ulong) max((files-10-max_connections)/2,64); + DBUG_PRINT("warning", + ("Changed limits: max_connections: %ld table_cache: %ld", + max_connections,table_cache_size)); + sql_print_error("Warning: Changed limits: max_connections: %ld table_cache: %ld",max_connections,table_cache_size); + } + } +#endif + unireg_init(opt_specialflag); /* Set up extern variabels */ + init_errmessage(); /* Read error messages from file */ + lex_init(); + item_init(); + set_var_init(); + mysys_uses_curses=0; +#ifdef USE_REGEX + regex_init(); +#endif + if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME))) + return 1; + charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG)); + if (use_temp_pool && bitmap_init(&temp_pool,1024,1)) + return 2; + + return 0; +} + +static int init_thread_environement() +{ (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_Acl,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_open,MY_MUTEX_INIT_FAST); @@ -1918,7 +1967,9 @@ int main(int argc, char **argv) (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_timezone,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST); +#ifdef HAVE_REPLICATION (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST); +#endif (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST); (void) my_rwlock_init(&LOCK_grant, NULL); @@ -1927,13 +1978,30 @@ int main(int argc, char **argv) (void) pthread_cond_init(&COND_thread_cache,NULL); (void) pthread_cond_init(&COND_flush_thread_cache,NULL); (void) pthread_cond_init(&COND_manager,NULL); +#ifdef HAVE_REPLICATION (void) pthread_cond_init(&COND_rpl_status, NULL); - init_signals(); +#endif + /* Parameter for threads created for connections */ + (void) pthread_attr_init(&connection_attrib); + (void) pthread_attr_setdetachstate(&connection_attrib, + PTHREAD_CREATE_DETACHED); + pthread_attr_setstacksize(&connection_attrib,thread_stack); + pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM); - if (set_default_charset_by_name(sys_charset.value, MYF(MY_WME))) - exit(1); - charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG)); + if (pthread_key_create(&THR_THD,NULL) || + pthread_key_create(&THR_MALLOC,NULL)) + { + sql_print_error("Can't create thread-keys"); + return 1; + } + + (void) thr_setconcurrency(concurrency); // 10 by default + + return 0; +} +static void init_ssl() +{ #ifdef HAVE_OPENSSL if (opt_use_ssl) { @@ -1945,70 +2013,13 @@ int main(int argc, char **argv) if (!ssl_acceptor_fd) opt_use_ssl = 0; } + if (des_key_file) + load_des_key_file(des_key_file); #endif /* HAVE_OPENSSL */ +} -#ifdef HAVE_LIBWRAP - libwrapName= my_progname+dirname_length(my_progname); - openlog(libwrapName, LOG_PID, LOG_AUTH); -#endif - - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_setprio(pthread_self(),CONNECT_PRIOR); - /* Parameter for threads created for connections */ - (void) pthread_attr_init(&connection_attrib); - (void) pthread_attr_setdetachstate(&connection_attrib, - PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&connection_attrib,thread_stack); - - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); - pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM); - -#if defined( SET_RLIMIT_NOFILE) || defined( OS2) - /* connections and databases needs lots of files */ - { - uint wanted_files=10+(uint) max(max_connections*5, - max_connections+table_cache_size*2); - set_if_bigger(wanted_files, open_files_limit); - // Note that some system returns 0 if we succeed here: - uint files=set_maximum_open_files(wanted_files); - if (files && files < wanted_files && ! open_files_limit) - { - max_connections= (ulong) min((files-10),max_connections); - table_cache_size= (ulong) max((files-10-max_connections)/2,64); - DBUG_PRINT("warning", - ("Changed limits: max_connections: %ld table_cache: %ld", - max_connections,table_cache_size)); - sql_print_error("Warning: Changed limits: max_connections: %ld table_cache: %ld",max_connections,table_cache_size); - } - } -#endif - unireg_init(opt_specialflag); /* Set up extern variabels */ - init_errmessage(); /* Read error messages from file */ - lex_init(); - item_init(); - set_var_init(); - mysys_uses_curses=0; -#ifdef USE_REGEX - regex_init(); -#endif - select_thread=pthread_self(); - select_thread_in_use=1; - if (use_temp_pool && bitmap_init(&temp_pool,1024,1)) - unireg_abort(1); - - /* - We have enough space for fiddling with the argv, continue - */ - umask(((~my_umask) & 0666)); - if (my_setwd(mysql_real_data_home,MYF(MY_WME))) - { - unireg_abort(1); /* purecov: inspected */ - } - mysql_data_home= mysql_data_home_buff; - mysql_data_home[0]=FN_CURLIB; // all paths are relative from here - mysql_data_home[1]=0; - server_init(); +static int init_server_components() +{ table_cache_init(); hostname_cache_init(); query_cache_result_size_limit(query_cache_limit); @@ -2016,12 +2027,9 @@ int main(int argc, char **argv) randominit(&sql_rand,(ulong) start_time,(ulong) start_time/2); reset_floating_point_exceptions(); init_thr_lock(); +#ifdef HAVE_REPLICATION init_slave_list(); -#ifdef HAVE_OPENSSL - if (des_key_file) - load_des_key_file(des_key_file); -#endif /* HAVE_OPENSSL */ - +#endif /* Setup log files */ if (opt_log) open_log(&mysql_log, glob_hostname, opt_logname, ".log", NullS, @@ -2032,26 +2040,17 @@ int main(int argc, char **argv) NullS, LOG_NEW); using_update_log=1; } - + if (opt_slow_log) open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log", NullS, LOG_NORMAL); -#ifdef __WIN__ -#define MYSQL_ERR_FILE "mysql.err" - if (!opt_console) - { - freopen(MYSQL_ERR_FILE,"a+",stdout); - freopen(MYSQL_ERR_FILE,"a+",stderr); - } -#endif if (ha_init()) { sql_print_error("Can't init databases"); - if (unix_sock != INVALID_SOCKET) - unlink(mysql_unix_port); - exit(1); + return 1; } ha_key_cache(); + #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) if (locked_in_memory && !geteuid()) { @@ -2070,71 +2069,9 @@ int main(int argc, char **argv) (void) mi_log( 1 ); ft_init_stopwords(ft_precompiled_stopwords); -#ifdef __WIN__ - if (!opt_console) - FreeConsole(); // Remove window -#endif - - /* - init signals & alarm - After this we can't quit by a simple unireg_abort - */ - error_handler_hook = my_message_sql; - if (pthread_key_create(&THR_THD,NULL) || - pthread_key_create(&THR_MALLOC,NULL)) - { - sql_print_error("Can't create thread-keys"); - if (unix_sock != INVALID_SOCKET) - unlink(mysql_unix_port); - exit(1); - } - start_signal_handler(); // Creates pidfile - if (acl_init((THD*) 0, opt_noacl)) - { - abort_loop=1; - select_thread_in_use=0; - (void) pthread_kill(signal_thread,MYSQL_KILL_SIGNAL); -#ifndef __WIN__ - if (!opt_bootstrap) - (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore -#endif - if (unix_sock != INVALID_SOCKET) - unlink(mysql_unix_port); - exit(1); - } - if (!opt_noacl) - (void) grant_init((THD*) 0); init_max_user_conn(); init_update_queries(); - DBUG_ASSERT(current_thd == 0); - -#ifdef HAVE_DLOPEN - if (!opt_noacl) - udf_init(); -#endif - /* init_slave() must be called after the thread keys are created */ - init_slave(); - DBUG_ASSERT(current_thd == 0); - if (opt_bin_log && !server_id) - { - server_id= !master_host ? 1 : 2; - switch (server_id) { -#ifdef EXTRA_DEBUG - case 1: - sql_print_error("\ -Warning: You have enabled the binary log, but you haven't set server-id:\n\ -Updates will be logged to the binary log, but connections to slaves will\n\ -not be accepted."); - break; -#endif - case 2: - sql_print_error("\ -Warning: You should set server-id to a non-0 value if master_host is set.\n\ -The server will not act as a slave."); - break; - } - } if (opt_bin_log) { open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin", @@ -2142,23 +2079,27 @@ The server will not act as a slave."); using_update_log=1; } + return 0; +} - if (opt_bootstrap) - { - int error=bootstrap(stdin); - end_thr_alarm(); // Don't allow alarms - unireg_abort(error ? 1 : 0); - } - if (opt_init_file) +static void create_maintenance_thread() +{ + if ( +#ifdef HAVE_BERKELEY_DB + !berkeley_skip || +#endif + (flush_time && flush_time != ~(ulong) 0L)) { - if (read_init_file(opt_init_file)) - { - end_thr_alarm(); // Don't allow alarms - unireg_abort(1); - } + pthread_t hThread; + if (pthread_create(&hThread,&connection_attrib,handle_manager,0)) + sql_print_error("Warning: Can't create thread to manage maintenance"); } - (void) thr_setconcurrency(concurrency); // 10 by default -#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) //IRENA +} + +static void create_shutdown_thread() +{ + +#ifdef __WIN__ { hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name); pthread_t hThread; @@ -2177,38 +2118,24 @@ The server will not act as a slave."); sql_print_error("Warning: Can't create thread to handle shutdown requests"); } #endif +} - if ( -#ifdef HAVE_BERKELEY_DB - !berkeley_skip || -#endif - (flush_time && flush_time != ~(ulong) 0L)) - { - pthread_t hThread; - if (pthread_create(&hThread,&connection_attrib,handle_manager,0)) - sql_print_error("Warning: Can't create thread to manage maintenance"); - } - - printf(ER(ER_READY),my_progname,server_version,""); - fflush(stdout); -#if defined(__NT__) || defined(HAVE_SMEM) #ifdef __NT__ +void create_named_pipe_thread() +{ if (hPipe == INVALID_HANDLE_VALUE && - (!have_tcpip || opt_disable_networking) && - !opt_enable_shared_memory) + (!have_tcpip || opt_disable_networking)) { - sql_print_error("TCP/IP,--shared-memory or --named-pipe should be configured on NT OS"); - unireg_abort(1); + sql_print_error("TCP/IP or --enable-named-pipe should be configured on NT OS"); + unireg_abort(1); } else -#endif { pthread_mutex_lock(&LOCK_thread_count); (void) pthread_cond_init(&COND_handler_count,NULL); { pthread_t hThread; handler_count=0; -#ifdef __NT__ if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe) { handler_count++; @@ -2219,36 +2146,169 @@ The server will not act as a slave."); handler_count--; } } -#endif -#ifdef HAVE_SMEM - if (opt_enable_shared_memory) - { - handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_shared_memory, 0)) - { - sql_print_error("Warning: Can't create thread to handle shared memory"); - handler_count--; - } - } -#endif if (have_tcpip && !opt_disable_networking) { handler_count++; if (pthread_create(&hThread,&connection_attrib, handle_connections_sockets, 0)) { - sql_print_error("Warning: Can't create thread to handle tcp/ip"); + sql_print_error("Warning: Can't create thread to handle named pipes"); handler_count--; } } while (handler_count > 0) - { pthread_cond_wait(&COND_handler_count,&LOCK_thread_count); - } } pthread_mutex_unlock(&LOCK_thread_count); } +} +#endif + +#ifndef EMBEDDED_LIBRARY +#ifdef __WIN__ +int win_main(int argc, char **argv) +#else +int main(int argc, char **argv) +#endif +{ + int init_error; + + DEBUGGER_OFF; + +#ifdef _CUSTOMSTARTUPCONFIG_ + if (_cust_check_startup()) + { + / * _cust_check_startup will report startup failure error * / + exit( 1 ); + } +#endif + + MY_INIT(argv[0]); // init my_sys library & pthreads + + if ((init_error=init_common_variables(MYSQL_CONFIG_NAME, + argc, argv, load_default_groups))) + if (init_error == 2) + unireg_abort(1); + else + exit(1); + + init_signals(); + if (init_thread_environement()) + exit(1); + select_thread=pthread_self(); + select_thread_in_use=1; + if (!(opt_specialflag & SPECIAL_NO_PRIOR)) + my_pthread_setprio(pthread_self(),CONNECT_PRIOR); + + if (!(opt_specialflag & SPECIAL_NO_PRIOR)) + my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); + + init_ssl(); + +#ifdef HAVE_LIBWRAP + libwrapName= my_progname+dirname_length(my_progname); + openlog(libwrapName, LOG_PID, LOG_AUTH); +#endif + + /* + We have enough space for fiddling with the argv, continue + */ + if (my_setwd(mysql_real_data_home,MYF(MY_WME))) + { + unireg_abort(1); /* purecov: inspected */ + } + mysql_data_home= mysql_data_home_buff; + mysql_data_home[0]=FN_CURLIB; // all paths are relative from here + mysql_data_home[1]=0; + server_init(); + + if (opt_bin_log && !server_id) + { + server_id= !master_host ? 1 : 2; + switch (server_id) { +#ifdef EXTRA_DEBUG + case 1: + sql_print_error("\ +Warning: You have enabled the binary log, but you haven't set server-id:\n\ +Updates will be logged to the binary log, but connections to slaves will\n\ +not be accepted."); + break; +#endif + case 2: + sql_print_error("\ +Warning: You should set server-id to a non-0 value if master_host is set.\n\ +The server will not act as a slave."); + break; + } + } + + if (init_server_components()) + exit(1); + +#ifdef __WIN__ +#define MYSQL_ERR_FILE "mysql.err" + if (!opt_console) + { + freopen(MYSQL_ERR_FILE,"a+",stdout); + freopen(MYSQL_ERR_FILE,"a+",stderr); + } +#endif + +#ifdef __WIN__ + if (!opt_console) + FreeConsole(); // Remove window +#endif + + /* + init signals & alarm + After this we can't quit by a simple unireg_abort + */ + error_handler_hook = my_message_sql; + start_signal_handler(); // Creates pidfile + if (acl_init((THD *)0, opt_noacl)) + { + abort_loop=1; + select_thread_in_use=0; + (void) pthread_kill(signal_thread,MYSQL_KILL_SIGNAL); +#ifndef __WIN__ + if (!opt_bootstrap) + (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore +#endif + exit(1); + } + if (!opt_noacl) + (void) grant_init((THD *)0); + +#ifdef HAVE_DLOPEN + if (!opt_noacl) + udf_init(); +#endif + /* init_slave() must be called after the thread keys are created */ + init_slave(); + + if (opt_bootstrap) + { + int error=bootstrap(stdin); + end_thr_alarm(); // Don't allow alarms + unireg_abort(error ? 1 : 0); + } + if (opt_init_file) + { + if (read_init_file(opt_init_file)) + { + end_thr_alarm(); // Don't allow alarms + unireg_abort(1); + } + } + + create_shutdown_thread(); + create_maintenance_thread(); + + printf(ER(ER_READY),my_progname,server_version,""); + fflush(stdout); + +#ifdef __NT__ + create_named_pipe_thread(); #else handle_connections_sockets(0); #ifdef EXTRA_DEBUG2 @@ -2295,6 +2355,8 @@ The server will not act as a slave."); return(0); /* purecov: deadcode */ } +#endif /* EMBEDDED_LIBRARY */ + /**************************************************************************** Main and thread entry function for Win32 @@ -2433,7 +2495,7 @@ int main(int argc, char **argv) Execute all commands from a file. Used by the mysql_install_db script to create MySQL privilege tables without having to start a full MySQL server. */ - +#ifndef EMBEDDED_LIBRARY static int bootstrap(FILE *file) { THD *thd= new THD; @@ -2470,6 +2532,8 @@ static int bootstrap(FILE *file) DBUG_RETURN(error); } +#endif + static bool read_init_file(char *file_name) { FILE *file; @@ -2477,11 +2541,14 @@ static bool read_init_file(char *file_name) DBUG_PRINT("enter",("name: %s",file_name)); if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME)))) return(1); +#ifndef EMBEDDED_LIBRARY bootstrap(file); /* Ignore errors from this */ +#endif (void) my_fclose(file,MYF(MY_WME)); return 0; } +#ifndef EMBEDDED_LIBRARY static void create_new_thread(THD *thd) { @@ -2563,6 +2630,7 @@ static void create_new_thread(THD *thd) DBUG_PRINT("info",("Thread created")); DBUG_VOID_RETURN; } +#endif #ifdef SIGNALS_DONT_BREAK_READ inline void kill_broken_server() @@ -2580,6 +2648,7 @@ inline void kill_broken_server() #define MAYBE_BROKEN_SYSCALL #endif +#ifndef EMBEDDED_LIBRARY /* Handle new connections and spawn new process to handle them */ extern "C" pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused))) @@ -3084,6 +3153,7 @@ error: } #endif /* HAVE_SMEM */ +#endif /* EMBEDDED_LIBRARY */ /****************************************************************************** ** handle start options @@ -3187,6 +3257,7 @@ enum options { OPT_INNODB_LOG_FILE_SIZE, OPT_INNODB_LOG_BUFFER_SIZE, OPT_INNODB_BUFFER_POOL_SIZE, + OPT_INNODB_BUFFER_POOL_AWE_MEM_MB, OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE, OPT_INNODB_FILE_IO_THREADS, OPT_INNODB_LOCK_WAIT_TIMEOUT, @@ -3448,6 +3519,7 @@ struct my_option my_long_options[] = GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"memlock", OPT_MEMLOCK, "Lock mysqld in memory", (gptr*) &locked_in_memory, (gptr*) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, +#ifdef HAVE_REPLICATION {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT, "Option used by mysql-test for debugging and testing of replication", (gptr*) &disconnect_slave_event_count, @@ -3466,6 +3538,7 @@ struct my_option my_long_options[] = (gptr*) &opt_sporadic_binlog_dump_fail, (gptr*) &opt_sporadic_binlog_dump_fail, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, +#endif /* HAVE_REPLICATION */ {"safemalloc-mem-limit", OPT_SAFEMALLOC_MEM_LIMIT, "Simulate memory shortage when compiled with the --with-debug=full option", 0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3541,7 +3614,7 @@ struct my_option my_long_options[] = GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"old-passwords", OPT_OLD_PASSWORDS, "Use old password encryption method (needed for old clients)", + {"old-passwords", OPT_OLD_PASSWORDS, "Use old password encryption method (needed for 4.0 and older clients)", (gptr*) &opt_old_passwords, (gptr*) &opt_old_passwords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef TO_BE_DELETED {"safe-show-database", OPT_SAFE_SHOW_DB, @@ -3608,12 +3681,14 @@ struct my_option my_long_options[] = {"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE, "Undocumented", (gptr*) &relay_log_info_file, (gptr*) &relay_log_info_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +#ifdef HAVE_REPLICATION {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR, "Undocumented", (gptr*) &slave_load_tmpdir, (gptr*) &slave_load_tmpdir, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"slave-skip-errors", OPT_SLAVE_SKIP_ERRORS, "Tells the slave thread to continue replication when a query returns an error from the provided list", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +#endif {"socket", OPT_SOCKET, "Socket file to use for connection", (gptr*) &mysql_unix_port, (gptr*) &mysql_unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3746,6 +3821,10 @@ struct my_option my_long_options[] = "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.", (gptr*) &innobase_buffer_pool_size, (gptr*) &innobase_buffer_pool_size, 0, GET_LONG, REQUIRED_ARG, 8*1024*1024L, 1024*1024L, ~0L, 0, 1024*1024L, 0}, + {"innodb_buffer_pool_awe_mem_mb", OPT_INNODB_BUFFER_POOL_AWE_MEM_MB, + "If Windows AWE is used, the size of InnoDB buffer pool allocated from the AWE memory.", + (gptr*) &innobase_buffer_pool_awe_mem_mb, (gptr*) &innobase_buffer_pool_awe_mem_mb, 0, + GET_LONG, REQUIRED_ARG, 0, 0, 63000, 0, 1, 0}, {"innodb_additional_mem_pool_size", OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE, "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.", (gptr*) &innobase_additional_mem_pool_size, @@ -3792,8 +3871,13 @@ struct my_option my_long_options[] = {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES, "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive.", (gptr*) &lower_case_table_names, - (gptr*) &lower_case_table_names, 0, - GET_BOOL, NO_ARG, IF_WIN(1,0), 0, 1, 0, 1, 0}, + (gptr*) &lower_case_table_names, 0, GET_BOOL, NO_ARG, +#ifdef FN_NO_CASE_SENCE + 1 +#else + 0 +#endif + , 0, 1, 0, 1, 0}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "Max packetlength to send/receive from to server.", (gptr*) &global_system_variables.max_allowed_packet, @@ -3832,7 +3916,7 @@ struct my_option my_long_options[] = {"max_join_size", OPT_MAX_JOIN_SIZE, "Joins that are probably going to read more than max_join_size records return an error.", (gptr*) &global_system_variables.max_join_size, - (gptr*) &max_system_variables.max_join_size, 0, GET_ULONG, REQUIRED_ARG, + (gptr*) &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG, ~0L, 1, ~0L, 0, 1, 0}, {"max_prepared_statements", OPT_MAX_PREP_STMT, "Max number of prepared_statements for a thread", @@ -3941,6 +4025,7 @@ struct my_option my_long_options[] = (gptr*) &global_system_variables.read_buff_size, (gptr*) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, +#ifdef HAVE_REPLICATION {"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT, "Max space to use for all relay logs", (gptr*) &relay_log_space_limit, @@ -3955,6 +4040,7 @@ struct my_option my_long_options[] = "Number of seconds to wait for more data from a master/slave connection before aborting the read.", (gptr*) &slave_net_timeout, (gptr*) &slave_net_timeout, 0, GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0}, +#endif {"slow_launch_time", OPT_SLOW_LAUNCH_TIME, "If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.", (gptr*) &slow_launch_time, (gptr*) &slow_launch_time, 0, GET_ULONG, @@ -4233,12 +4319,12 @@ static void set_options(void) sizeof(mysql_real_data_home)-1); /* Set default values for some variables */ - global_system_variables.table_type=DB_TYPE_MYISAM; - global_system_variables.tx_isolation=ISO_REPEATABLE_READ; + global_system_variables.table_type= DB_TYPE_MYISAM; + global_system_variables.tx_isolation= ISO_REPEATABLE_READ; global_system_variables.select_limit= (ulonglong) HA_POS_ERROR; - max_system_variables.select_limit= (ulong) HA_POS_ERROR; + max_system_variables.select_limit= (ulonglong) HA_POS_ERROR; global_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; - max_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; + max_system_variables.max_join_size= (ulonglong) HA_POS_ERROR; #ifdef __WIN__ /* Allow Win32 users to move MySQL anywhere */ @@ -4273,9 +4359,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_endinfo=1; /* unireg: memory allocation */ break; case 'a': - opt_sql_mode = (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT | - MODE_ANSI_QUOTES | MODE_IGNORE_SPACE | MODE_SERIALIZABLE | - MODE_ONLY_FULL_GROUP_BY); + global_system_variables.sql_mode= + (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT | + MODE_ANSI_QUOTES | MODE_IGNORE_SPACE | MODE_SERIALIZABLE | + MODE_ONLY_FULL_GROUP_BY); global_system_variables.tx_isolation= ISO_SERIALIZABLE; break; case 'b': @@ -4298,9 +4385,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'o': protocol_version=PROTOCOL_VERSION-1; break; +#ifdef HAVE_REPLICATION case OPT_SLAVE_SKIP_ERRORS: init_slave_skip_errors(argument); break; +#endif case OPT_SAFEMALLOC_MEM_LIMIT: #if !defined(DBUG_OFF) && defined(SAFEMALLOC) safemalloc_mem_limit = atoi(argument); @@ -4340,6 +4429,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case (int) OPT_BIN_LOG: opt_bin_log=1; break; +#ifdef HAVE_REPLICATION case (int) OPT_INIT_RPL_ROLE: { int role; @@ -4374,7 +4464,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), exit(1); } val= p--; - while (my_isspace(system_charset_info, *p) && p > argument) + while (my_isspace(mysqld_charset, *p) && p > argument) *p-- = 0; if (p == argument) { @@ -4384,7 +4474,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), } *val= 0; val+= 2; - while (*val && my_isspace(system_charset_info, *val)) + while (*val && my_isspace(mysqld_charset, *val)) *val++; if (!*val) { @@ -4460,13 +4550,14 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), table_rules_on = 1; break; } - case (int) OPT_SLOW_QUERY_LOG: - opt_slow_log=1; - break; case (int)OPT_RECKLESS_SLAVE: opt_reckless_slave = 1; init_slave_skip_errors("all"); break; +#endif /* HAVE_REPLICATION */ + case (int) OPT_SLOW_QUERY_LOG: + opt_slow_log=1; + break; case (int) OPT_SKIP_NEW: opt_specialflag|= SPECIAL_NO_NEW_FUNC; delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE; @@ -4526,7 +4617,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), have_symlink=SHOW_OPTION_DISABLED; break; case (int) OPT_BIND_ADDRESS: - if (argument && my_isdigit(system_charset_info, argument[0])) + if (argument && my_isdigit(mysqld_charset, argument[0])) { my_bind_addr = (ulong) inet_addr(argument); } @@ -4637,8 +4728,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), berkeley_lock_type=berkeley_lock_types[type-1]; else { - if (test_if_int(argument,(uint) strlen(argument))) - berkeley_lock_scan_time=atoi(argument); + int err; + char *end; + uint length= strlen(argument); + long value= my_strntol(my_charset_latin1, argument, length, 10, &end, &err); + if (test_if_int(argument,(uint) length, end, my_charset_latin1)) + berkeley_lock_scan_time= value; else { fprintf(stderr,"Unknown lock type: %s\n",argument); @@ -4699,16 +4794,17 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), } case OPT_SQL_MODE: { - sql_mode_str = argument; - if ((opt_sql_mode = - find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0) + sql_mode_str= argument; + if ((global_system_variables.sql_mode= + find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0) { fprintf(stderr, "Unknown option to sql-mode: %s\n", argument); exit(1); } - global_system_variables.tx_isolation= ((opt_sql_mode & MODE_SERIALIZABLE) ? - ISO_SERIALIZABLE : - ISO_REPEATABLE_READ); + global_system_variables.tx_isolation= + ((global_system_variables.sql_mode & MODE_SERIALIZABLE) ? + ISO_SERIALIZABLE : + ISO_REPEATABLE_READ); break; } case OPT_MASTER_PASSWORD: @@ -4840,11 +4936,13 @@ static void fix_paths(void) if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) exit(1); +#ifdef HAVE_REPLICATION if (!slave_load_tmpdir) { if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE)))) exit(1); } +#endif } @@ -4939,8 +5037,8 @@ static ulong find_bit_type(const char *x, TYPELIB *bit_lib) j=pos; while (j != end) { - if (my_toupper(system_charset_info,*i++) != - my_toupper(system_charset_info,*j++)) + if (my_toupper(mysqld_charset,*i++) != + my_toupper(mysqld_charset,*j++)) goto skipp; } found_int=bit; |