/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ #include #include #include #include #include #include "sql_priv.h" #include "unireg.h" #include #include "sql_parse.h" #include "sql_locale.h" // MY_LOCALES, my_locales, my_locale_by_name #include "sql_show.h" // free_status_vars, add_status_vars, // reset_status_vars #include "strfunc.h" // find_set_from_flags #include "parse_file.h" // File_parser_dummy_hook #include "sql_db.h" // my_dboptions_cache_free // my_dboptions_cache_init #include "sql_table.h" // release_ddl_log, execute_ddl_log_recovery #include "sql_time.h" // known_date_time_formats, // get_date_time_format_str, // date_time_format_make #include "sql_acl.h" // acl_free, grant_free, acl_init, // grant_init #include "sql_base.h" // table_def_free, table_def_init, // Table_cache, // cached_table_definitions #include "sql_test.h" // mysql_print_status #include "item_create.h" // item_create_cleanup, item_create_init #include "sql_servers.h" // servers_free, servers_init #include "init.h" // unireg_init #include "derror.h" // init_errmessage #include "derror.h" // init_errmessage #include #include #include #include #include #include "mysqld_suffix.h" #include "mysys_err.h" #include "probes_mysql.h" #include "sql_callback.h" #include "global_threads.h" #include "mysqld.h" #include "my_default.h" #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE #include "../storage/perfschema/pfs_server.h" #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ #include #include #include #include "mysql_com_server.h" #include "set_var.h" #include "sys_vars_shared.h" #ifdef HAVE_SYS_PRCTL_H #include #endif #include #include #include #include "sql_reload.h" // reload_acl_and_cache #include "my_timer.h" // my_os_timer_init_ext, my_os_timer_deinit #ifdef HAVE_POLL_H #include #endif #ifdef HAVE_FESETROUND #include #endif using std::min; using std::max; using std::vector; #define mysqld_charset &my_charset_latin1 /* We have HAVE_purify below as this speeds up the shutdown of MySQL */ #if defined(HAVE_DEC_3_2_THREADS) || defined(SIGNALS_DONT_BREAK_READ) || defined(HAVE_purify) && defined(__linux__) #define HAVE_CLOSE_SERVER_SOCK 1 #endif extern "C" { // Because of SCO 3.2V4.2 #include #include #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif #include #ifdef HAVE_SYSENT_H #include #endif #ifdef HAVE_PWD_H #include // For getpwent #endif #ifdef HAVE_GRP_H #include #endif #include #if !defined(__WIN__) #include #ifdef HAVE_SYS_UN_H #include #endif #ifdef HAVE_SELECT_H #include #endif #ifdef HAVE_SYS_SELECT_H #include #endif #include #endif /* __WIN__ */ #include #ifdef HAVE_SYS_MMAN_H #include #endif #ifdef __WIN__ #include #endif #ifdef HAVE_SOLARIS_LARGE_PAGES #include #if defined(__sun__) && defined(__GNUC__) && defined(__cplusplus) \ && defined(_XOPEN_SOURCE) extern int getpagesizes(size_t *, int); extern int getpagesizes2(size_t *, int); extern int memcntl(caddr_t, size_t, int, caddr_t, int, int); #endif /* __sun__ ... */ #endif /* HAVE_SOLARIS_LARGE_PAGES */ #ifdef _AIX41 int initgroups(const char *,unsigned int); #endif #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT) #include #ifdef HAVE_FP_EXCEPT // Fix type conflict typedef fp_except fp_except_t; #endif #endif /* __FreeBSD__ && HAVE_IEEEFP_H && !HAVE_FEDISABLEEXCEPT */ #ifdef HAVE_SYS_FPU_H /* for IRIX to use set_fpc_csr() */ #include #endif #ifdef HAVE_FPU_CONTROL_H #include #endif #if defined(__i386__) && !defined(HAVE_FPU_CONTROL_H) # define fpu_control_t unsigned int # define _FPU_EXTENDED 0x300 # define _FPU_DOUBLE 0x200 # if defined(__GNUC__) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590) # define _FPU_GETCW(cw) asm volatile ("fnstcw %0" : "=m" (*&cw)) # define _FPU_SETCW(cw) asm volatile ("fldcw %0" : : "m" (*&cw)) # else # define _FPU_GETCW(cw) (cw= 0) # define _FPU_SETCW(cw) # endif #endif inline void setup_fpu() { #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) && !defined(HAVE_FEDISABLEEXCEPT) /* We can't handle floating point exceptions with threads, so disable this on freebsd Don't fall for overflow, underflow,divide-by-zero or loss of precision. fpsetmask() is deprecated in favor of fedisableexcept() in C99. */ #if defined(FP_X_DNML) fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ | FP_X_IMP)); #else fpsetmask(~(FP_X_INV | FP_X_OFL | FP_X_UFL | FP_X_DZ | FP_X_IMP)); #endif /* FP_X_DNML */ #endif /* __FreeBSD__ && HAVE_IEEEFP_H && !HAVE_FEDISABLEEXCEPT */ #ifdef HAVE_FEDISABLEEXCEPT fedisableexcept(FE_ALL_EXCEPT); #endif #ifdef HAVE_FESETROUND /* Set FPU rounding mode to "round-to-nearest" */ fesetround(FE_TONEAREST); #endif /* HAVE_FESETROUND */ /* x86 (32-bit) requires FPU precision to be explicitly set to 64 bit (double precision) for portable results of floating point operations. However, there is no need to do so if compiler is using SSE2 for floating point, double values will be stored and processed in 64 bits anyway. */ #if defined(__i386__) && !defined(__SSE2_MATH__) #if defined(_WIN32) #if !defined(_WIN64) _control87(_PC_53, MCW_PC); #endif /* !_WIN64 */ #else /* !_WIN32 */ fpu_control_t cw; _FPU_GETCW(cw); cw= (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE; _FPU_SETCW(cw); #endif /* _WIN32 && */ #endif /* __i386__ */ #if defined(__sgi) && defined(HAVE_SYS_FPU_H) /* Enable denormalized DOUBLE values support for IRIX */ union fpc_csr n; n.fc_word = get_fpc_csr(); n.fc_struct.flush = 0; set_fpc_csr(n.fc_word); #endif } } /* cplusplus */ #define MYSQL_KILL_SIGNAL SIGTERM #include // For thr_setconcurency() #ifdef SOLARIS extern "C" int gethostname(char *name, int namelen); #endif extern "C" sig_handler handle_fatal_signal(int sig); #if defined(__linux__) #define ENABLE_TEMP_POOL 1 #else #define ENABLE_TEMP_POOL 0 #endif /* Constants */ #include // ORACLE_WELCOME_COPYRIGHT_NOTICE const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"}; static const char *tc_heuristic_recover_names[]= { "NONE", "COMMIT", "ROLLBACK", NullS }; static TYPELIB tc_heuristic_recover_typelib= { array_elements(tc_heuristic_recover_names)-1,"", tc_heuristic_recover_names, NULL }; const char *first_keyword= "first", *binary_keyword= "BINARY"; const char *my_localhost= "localhost", *delayed_user= "DELAYED"; bool opt_large_files= sizeof(my_off_t) > 4; static my_bool opt_autocommit; ///< for --autocommit command-line option /* Used with --help for detailed option */ static my_bool opt_help= 0, opt_verbose= 0; arg_cmp_func Arg_comparator::comparator_matrix[5][2] = {{&Arg_comparator::compare_string, &Arg_comparator::compare_e_string}, {&Arg_comparator::compare_real, &Arg_comparator::compare_e_real}, {&Arg_comparator::compare_int_signed, &Arg_comparator::compare_e_int}, {&Arg_comparator::compare_row, &Arg_comparator::compare_e_row}, {&Arg_comparator::compare_decimal, &Arg_comparator::compare_e_decimal}}; /* static variables */ #ifdef HAVE_PSI_INTERFACE #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) static PSI_thread_key key_thread_handle_con_namedpipes; static PSI_cond_key key_COND_handler_count; #endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ #if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) static PSI_thread_key key_thread_handle_con_sharedmem; #endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */ #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) static PSI_thread_key key_thread_handle_con_sockets; #endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ #ifdef __WIN__ static PSI_thread_key key_thread_handle_shutdown; #endif /* __WIN__ */ #if defined (HAVE_OPENSSL) && !defined(HAVE_YASSL) static PSI_rwlock_key key_rwlock_openssl; #endif #endif /* HAVE_PSI_INTERFACE */ /** Statement instrumentation key for replication. */ #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_statement_info stmt_info_rpl; #endif /* the default log output is log tables */ static bool lower_case_table_names_used= 0; /* See Bug#56666 and Bug#56760 */; volatile bool ready_to_exit; static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0; static my_bool opt_short_log_format= 0; static uint kill_blocked_pthreads_flag, wake_pthread; static char *mysqld_user, *mysqld_chroot; static char *default_character_set_name; static char *character_set_filesystem_name; static char *lc_messages; static char *lc_time_names_name; char *my_bind_addr_str; static char *default_collation_name; char *default_storage_engine; char *default_tmp_storage_engine; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; LEX_STRING opt_init_connect, opt_init_slave; static mysql_cond_t COND_thread_cache, COND_flush_thread_cache; /* Global variables */ bool opt_bin_log, opt_ignore_builtin_innodb= 0; my_bool opt_log, opt_log_raw; ulonglong log_output_options; my_bool opt_log_queries_not_using_indexes= 0; ulong opt_log_throttle_queries_not_using_indexes= 0; bool opt_error_log= IF_WIN(1,0); bool opt_disable_networking=0, opt_skip_show_db=0; bool opt_skip_name_resolve=0; my_bool opt_character_set_client_handshake= 1; bool server_id_supplied = 0; bool opt_endinfo, using_udf_functions; bool opt_using_transactions; bool volatile abort_loop; bool volatile shutdown_in_progress; ulong log_warnings; uint host_cache_size; #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) ulong slow_start_timeout; #endif /* True if the bootstrap thread is running. Protected by LOCK_thread_count. Used in bootstrap() function to determine if the bootstrap thread has completed. Note, that we can't use 'thread_count' instead, since in 5.1, in presence of the Event Scheduler, there may be event threads running in parallel, so it's impossible to know what value of 'thread_count' is a sign of completion of the bootstrap thread. At the same time, we can't start the event scheduler after bootstrap either, since we want to be able to process event-related SQL commands in the init file and in --bootstrap mode. */ bool in_bootstrap= FALSE; my_bool opt_bootstrap= 0; /** @brief 'grant_option' is used to indicate if privileges needs to be checked, in which case the lock, LOCK_grant, is used to protect access to the grant table. @note This flag is dropped in 5.1 @see grant_init() */ bool volatile grant_option; my_bool opt_skip_slave_start = 0; ///< If set, slave is not autostarted my_bool opt_reckless_slave = 0; my_bool opt_enable_named_pipe= 0; my_bool opt_local_infile, opt_slave_compressed_protocol; my_bool opt_safe_user_create = 0; my_bool opt_show_slave_auth_info; my_bool opt_log_slave_updates= 0; char *opt_slave_skip_errors; my_bool opt_slave_allow_batching= 0; /** compatibility option: - index usage hints (USE INDEX without a FOR clause) behave as in 5.0 */ my_bool old_mode; /* Legacy global handlerton. These will be removed (please do not add more). */ handlerton *heap_hton; handlerton *myisam_hton; handlerton *partition_hton; uint opt_server_id_bits= 0; ulong opt_server_id_mask= 0; my_bool read_only= 0, opt_readonly= 0; my_bool super_read_only= 0, opt_super_readonly= 0; my_bool use_temp_pool, relay_log_purge; my_bool relay_log_recovery; my_bool opt_sync_frm, opt_allow_suspicious_udfs; my_bool opt_secure_auth= 0; char* opt_secure_file_priv= NULL; my_bool opt_secure_file_priv_noarg= FALSE; my_bool lower_case_file_system= 1; my_bool opt_myisam_use_mmap= 0; uint opt_large_page_size= 0; #if defined(ENABLED_DEBUG_SYNC) MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout= 0; #endif /* defined(ENABLED_DEBUG_SYNC) */ my_bool opt_userstat= 0, opt_thread_statistics= 0; /* True if there is at least one per-hour limit for some user, so we should check them before each query (and possibly reset counters when hour is changed). False otherwise. */ volatile bool mqh_used = 0; my_bool opt_noacl= 0; #ifdef HAVE_INITGROUPS volatile sig_atomic_t calling_initgroups= 0; /**< Used in SIGSEGV handler. */ #endif uint mysqld_port, test_flags, select_errors, ha_open_options; uint mysqld_extra_port; uint mysqld_port_timeout; ulong delay_key_write_options; uint lower_case_table_names; ulong tc_heuristic_recover= 0; int32 num_thread_running; ulong what_to_log; ulong slow_launch_time; ulong open_files_limit; ulonglong opt_mts_pending_jobs_size_max; ulong refresh_version; /* Increments on each reload */ ulong specialflag=0; ulonglong denied_connections= 0; Error_log_throttle err_log_throttle(Log_throttle::LOG_THROTTLE_WINDOW_SIZE, sql_print_error, "Error log throttle: %10lu 'Can't create" " thread to handle new connection'" " error(s) suppressed"); /** Limit of the total number of prepared statements in the server. Is necessary to protect the server against out-of-memory attacks. */ ulong max_prepared_stmt_count; /** Current total number of prepared statements in the server. This number is exact, and therefore may not be equal to the difference between `com_stmt_prepare' and `com_stmt_close' (global status variables), as the latter ones account for all registered attempts to prepare a statement (including unsuccessful ones). Prepared statements are currently connection-local: if the same SQL query text is prepared in two different connections, this counts as two distinct prepared statements. */ ulong prepared_stmt_count=0; ulong thread_id=1L,current_pid; ulong slow_launch_threads = 0; uint opt_mts_checkpoint_period, opt_mts_checkpoint_group; ulong expire_logs_days = 0; /** Soft upper limit for number of sp_head objects that can be stored in the sp_cache for one connection. */ ulong stored_program_cache_size= 0; const double log_10[] = { 1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009, 1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019, 1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029, 1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039, 1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049, 1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059, 1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069, 1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079, 1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089, 1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099, 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109, 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119, 1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129, 1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139, 1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169, 1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199, 1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209, 1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219, 1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229, 1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239, 1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249, 1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259, 1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, 1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279, 1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308 }; time_t server_start_time, flush_status_time; char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30]; char default_logfile_name[FN_REFLEN]; char *default_tz_name; char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN]; char mysql_real_data_home[FN_REFLEN], lc_messages_dir[FN_REFLEN], reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN], *opt_init_file, *opt_tc_log_file; char *lc_messages_dir_ptr; char mysql_unpacked_real_data_home[FN_REFLEN]; int mysql_unpacked_real_data_home_len; uint mysql_real_data_home_len, mysql_data_home_len= 1; uint reg_ext_length; char logname_path[FN_REFLEN]; char secure_file_real_path[FN_REFLEN]; DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format; Time_zone *default_tz; char *mysql_data_home= const_cast("."); const char *mysql_real_data_home_ptr= mysql_real_data_home; char server_version[SERVER_VERSION_LENGTH]; char *mysqld_unix_port, *opt_mysql_tmpdir; ulong thread_handling; /** name of reference on left expression in rewritten IN subquery */ const char *in_left_expr_name= ""; /** name of additional condition */ const char *in_additional_cond= ""; const char *in_having_cond= ""; my_decimal decimal_zero; /** Number of connection errors when selecting on the listening port */ ulong connection_errors_select= 0; /** Number of connection errors when accepting sockets in the listening port. */ ulong connection_errors_accept= 0; /** Number of connection errors from TCP wrappers. */ ulong connection_errors_tcpwrap= 0; /** Number of connection errors from internal server errors. */ ulong connection_errors_internal= 0; /** Number of connection errors from the server max_connection limit. */ ulong connection_errors_max_connection= 0; /** Number of errors when reading the peer address. */ ulong connection_errors_peer_addr= 0; /* classes for comparation parsing/processing */ Eq_creator eq_creator; Ne_creator ne_creator; Gt_creator gt_creator; Lt_creator lt_creator; Ge_creator ge_creator; Le_creator le_creator; MYSQL_FILE *bootstrap_file; int bootstrap_error; struct system_variables global_system_variables; struct system_variables max_system_variables; MY_TMPDIR mysql_tmpdir_list; MY_BITMAP temp_pool; CHARSET_INFO *system_charset_info, *files_charset_info ; CHARSET_INFO *national_charset_info, *table_alias_charset; CHARSET_INFO *character_set_filesystem; CHARSET_INFO *error_message_charset_info; MY_LOCALE *my_default_lc_messages; MY_LOCALE *my_default_lc_time_names; SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen, have_query_cache; SHOW_COMP_OPTION have_geometry, have_rtree_keys; SHOW_COMP_OPTION have_crypt, have_compress; SHOW_COMP_OPTION have_profiling; SHOW_COMP_OPTION have_backup_locks; SHOW_COMP_OPTION have_snapshot_cloning; ulonglong opt_log_warnings_suppress= 0; char* enforce_storage_engine= NULL; char* utility_user= NULL; char* utility_user_password= NULL; char* utility_user_schema_access= NULL; /* Plucking this from sql/sql_acl.cc for an array of privilege names */ extern TYPELIB utility_user_privileges_typelib; ulonglong utility_user_privileges= 0; SHOW_COMP_OPTION have_statement_timeout= SHOW_OPTION_DISABLED; /* Thread specific variables */ pthread_key(MEM_ROOT**,THR_MALLOC); pthread_key(THD*, THR_THD); mysql_mutex_t LOCK_thread_created; mysql_mutex_t LOCK_thread_count, LOCK_thd_remove; mysql_mutex_t LOCK_status, LOCK_error_log, LOCK_uuid_generator, LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_global_system_variables, LOCK_user_conn, LOCK_slave_list, LOCK_active_mi, LOCK_connection_count, LOCK_error_messages; mysql_mutex_t LOCK_sql_rand; mysql_mutex_t LOCK_stats, LOCK_global_user_client_stats, LOCK_global_table_stats, LOCK_global_index_stats; /** The below lock protects access to two global server variables: max_prepared_stmt_count and prepared_stmt_count. These variables set the limit and hold the current total number of prepared statements in the server, respectively. As PREPARE/DEALLOCATE rate in a loaded server may be fairly high, we need a dedicated lock. */ mysql_mutex_t LOCK_prepared_stmt_count; /* The below two locks are introudced as guards (second mutex) for the global variables sql_slave_skip_counter and slave_net_timeout respectively. See fix_slave_skip_counter/fix_slave_net_timeout for more details */ mysql_mutex_t LOCK_sql_slave_skip_counter; mysql_mutex_t LOCK_slave_net_timeout; mysql_mutex_t LOCK_log_throttle_qni; #ifdef HAVE_OPENSSL mysql_mutex_t LOCK_des_key_file; #endif mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; mysql_rwlock_t LOCK_system_variables_hash; mysql_cond_t COND_thread_count; pthread_t signal_thread; pthread_attr_t connection_attrib; mysql_mutex_t LOCK_server_started; mysql_rwlock_t LOCK_consistent_snapshot; int mysqld_server_started= 0; File_parser_dummy_hook file_parser_dummy_hook; /* replication parameters, if master_host is not NULL, we are a slave */ uint report_port= 0; ulong master_retry_count=0; char *master_info_file; char *relay_log_info_file, *report_user, *report_password, *report_host; char *opt_relay_logname = 0, *opt_relaylog_index_name=0; char *opt_logname, *opt_slow_logname, *opt_bin_logname; /* Static variables */ static volatile sig_atomic_t kill_in_progress; static my_bool opt_myisam_log; static int cleanup_done; static ulong opt_specialflag; static char *opt_update_logname; char *opt_binlog_index_name; char *mysql_home_ptr, *pidfile_name_ptr; /** Initial command line arguments (arguments), after load_defaults(). This memory is allocated by @c load_defaults() and should be freed using @c free_defaults(). Do not modify defaults_argc / defaults_argv, use remaining_argc / remaining_argv instead to parse the command line arguments in multiple steps. */ static char **defaults_argv; /** Remaining command line arguments (count), filtered by handle_options().*/ static int remaining_argc; /** Remaining command line arguments (arguments), filtered by handle_options().*/ static char **remaining_argv; int orig_argc; char **orig_argv; THD *thd; #if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL) bool init_rsa_keys(void); void deinit_rsa_keys(void); int show_rsa_public_key(THD *thd, SHOW_VAR *var, char *buff); #endif static volatile sig_atomic_t global_thread_count= 0; static std::set *global_thread_list= NULL; static ulong blocked_pthread_count= 0; static std::list *waiting_thd_list= NULL; /* global_thread_list and waiting_thd_list are both pointers to objects on the heap, to avoid potential problems with running destructors atexit(). */ static void delete_global_thread_list() { delete global_thread_list; delete waiting_thd_list; global_thread_list= NULL; waiting_thd_list= NULL; } Thread_iterator global_thread_list_begin() { mysql_mutex_assert_owner(&LOCK_thread_count); return global_thread_list->begin(); } Thread_iterator global_thread_list_end() { mysql_mutex_assert_owner(&LOCK_thread_count); return global_thread_list->end(); } void copy_global_thread_list(std::set *new_copy) { mysql_mutex_assert_owner(&LOCK_thd_remove); mysql_mutex_lock(&LOCK_thread_count); *new_copy= *global_thread_list; mysql_mutex_unlock(&LOCK_thread_count); } void add_global_thread(THD *thd) { DBUG_PRINT("info", ("add_global_thread %p", thd)); mysql_mutex_assert_owner(&LOCK_thread_count); const bool have_thread= global_thread_list->find(thd) != global_thread_list->end(); if (!have_thread) { ++global_thread_count; global_thread_list->insert(thd); } // Adding the same THD twice is an error. DBUG_ASSERT(!have_thread); } void remove_global_thread(THD *thd) { DBUG_PRINT("info", ("remove_global_thread %p", thd)); mysql_mutex_lock(&LOCK_thd_remove); mysql_mutex_lock(&LOCK_thread_count); DBUG_ASSERT(thd->release_resources_done()); /* Used by binlog_reset_master. It would be cleaner to use DEBUG_SYNC here, but that's not possible because the THD's debug sync feature has been shut down at this point. */ DBUG_EXECUTE_IF("sleep_after_lock_thread_count_before_delete_thd", sleep(5);); const size_t num_erased= global_thread_list->erase(thd); if (num_erased == 1) --global_thread_count; // Removing a THD that was never added is an error. DBUG_ASSERT(1 == num_erased); mysql_mutex_unlock(&LOCK_thd_remove); mysql_cond_broadcast(&COND_thread_count); mysql_mutex_unlock(&LOCK_thread_count); } uint get_thread_count() { return (uint) global_thread_count; } /* Multiple threads of execution use the random state maintained in global sql_rand to generate random numbers. sql_rnd_with_mutex use mutex LOCK_sql_rand to protect sql_rand across multiple instantiations that use sql_rand to generate random numbers. */ ulong sql_rnd_with_mutex() { mysql_mutex_lock(&LOCK_sql_rand); ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */ mysql_mutex_unlock(&LOCK_sql_rand); return tmp; } #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_statement_info stmt_info_new_packet; #endif /** A log message for the error log, buffered in memory. Log messages are temporarily buffered when generated before the error log is initialized, and then printed once the error log is ready. */ class Buffered_log : public Sql_alloc { public: Buffered_log(enum loglevel level, const char *message); ~Buffered_log() {} void print(void); private: /** Log message level. */ enum loglevel m_level; /** Log message text. */ String m_message; }; /** Constructor. @param level the message log level @param message the message text */ Buffered_log::Buffered_log(enum loglevel level, const char *message) : m_level(level), m_message() { m_message.copy(message, strlen(message), &my_charset_latin1); } /** Print a buffered log to the real log file. */ void Buffered_log::print() { /* Since messages are buffered, they can be printed out of order with other entries in the log. Add "Buffered xxx" to the message text to prevent confusion. */ switch(m_level) { case ERROR_LEVEL: sql_print_error("Buffered error: %s\n", m_message.c_ptr_safe()); break; case WARNING_LEVEL: sql_print_warning("Buffered warning: %s\n", m_message.c_ptr_safe()); break; case INFORMATION_LEVEL: /* Messages printed as "information" still end up in the mysqld *error* log, but with a [Note] tag instead of an [ERROR] tag. While this is probably fine for a human reading the log, it is upsetting existing automated scripts used to parse logs, because such scripts are likely to not already handle [Note] properly. INFORMATION_LEVEL messages are simply silenced, on purpose, to avoid un needed verbosity. */ break; } } /** Collection of all the buffered log messages. */ class Buffered_logs { public: Buffered_logs() {} ~Buffered_logs() {} void init(); void cleanup(); void buffer(enum loglevel m_level, const char *msg); void print(); private: /** Memory root to use to store buffered logs. This memory root lifespan is between init and cleanup. Once the buffered logs are printed, they are not needed anymore, and all the memory used is reclaimed. */ MEM_ROOT m_root; /** List of buffered log messages. */ List m_list; }; void Buffered_logs::init() { init_alloc_root(&m_root, 1024, 0); } void Buffered_logs::cleanup() { m_list.delete_elements(); free_root(&m_root, MYF(0)); } /** Add a log message to the buffer. */ void Buffered_logs::buffer(enum loglevel level, const char *msg) { /* Do not let Sql_alloc::operator new(size_t) allocate memory, there is no memory root associated with the main() thread. Give explicitly the proper memory root to use to Sql_alloc::operator new(size_t, MEM_ROOT *) instead. */ Buffered_log *log= new (&m_root) Buffered_log(level, msg); if (log) m_list.push_back(log, &m_root); } /** Print buffered log messages. */ void Buffered_logs::print() { Buffered_log *log; List_iterator_fast it(m_list); while ((log= it++)) log->print(); } /** Logs reported before a logger is available. */ static Buffered_logs buffered_logs; /** Error reporter that buffer log messages. @param level log message level @param format log message format string */ C_MODE_START static void buffered_option_error_reporter(enum loglevel level, const char *format, ...) { va_list args; char buffer[1024]; va_start(args, format); my_vsnprintf(buffer, sizeof(buffer), format, args); va_end(args); buffered_logs.buffer(level, buffer); } /** Character set and collation error reporter that prints to sql error log. @param level log message level @param format log message format string This routine is used to print character set and collation warnings and errors inside an already running mysqld server, e.g. when a character set or collation is requested for the very first time and its initialization does not go well for some reasons. Note: At early mysqld initialization stage, when error log is not yet available, we use buffered_option_error_reporter() instead, to print general character set subsystem initialization errors, such as Index.xml syntax problems, bad XML tag hierarchy, etc. */ static void charset_error_reporter(enum loglevel level, const char *format, ...) { va_list args; va_start(args, format); vprint_msg_to_log(level, format, args); va_end(args); } C_MODE_END static MYSQL_SOCKET unix_sock, base_ip_sock, extra_ip_sock; struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD() /* OS specific variables */ #ifdef __WIN__ #undef getpid #include static mysql_cond_t COND_handler_count; static uint handler_count; static bool start_mode=0, use_opt_args; static int opt_argc; static char **opt_argv; #if !defined(EMBEDDED_LIBRARY) static HANDLE hEventShutdown; static char shutdown_event_name[40]; #include "nt_servc.h" static NTService Service; ///< Service object for WinNT #endif /* EMBEDDED_LIBRARY */ #endif /* __WIN__ */ #ifdef _WIN32 static char pipe_name[512]; static SECURITY_ATTRIBUTES saPipeSecurity; static SECURITY_DESCRIPTOR sdPipeDescriptor; static HANDLE hPipe = INVALID_HANDLE_VALUE; #endif #ifndef EMBEDDED_LIBRARY bool mysqld_embedded=0; #else bool mysqld_embedded=1; #endif static my_bool plugins_are_initialized= FALSE; #ifndef DBUG_OFF static const char* default_dbug_option; #endif #ifdef HAVE_SMEM char *shared_memory_base_name= default_shared_memory_base_name; my_bool opt_enable_shared_memory; HANDLE smem_event_connect_request= 0; #endif my_bool opt_use_ssl = 0; char *opt_ssl_ca= NULL, *opt_ssl_capath= NULL, *opt_ssl_cert= NULL, *opt_ssl_cipher= NULL, *opt_ssl_key= NULL, *opt_ssl_crl= NULL, *opt_ssl_crlpath= NULL; #ifdef HAVE_OPENSSL #include #ifndef HAVE_YASSL typedef struct CRYPTO_dynlock_value { mysql_rwlock_t lock; } openssl_lock_t; static openssl_lock_t *openssl_stdlocks; static openssl_lock_t *openssl_dynlock_create(const char *, int); static void openssl_dynlock_destroy(openssl_lock_t *, const char *, int); static void openssl_lock_function(int, int, const char *, int); static void openssl_lock(int, openssl_lock_t *, const char *, int); static unsigned long openssl_id_function(); #endif char *des_key_file; #ifndef EMBEDDED_LIBRARY struct st_VioSSLFd *ssl_acceptor_fd; #endif #endif /* HAVE_OPENSSL */ /** Number of currently active user connections. The variable is protected by LOCK_connection_count. */ uint connection_count= 0, extra_connection_count= 0; /* Function declarations */ pthread_handler_t signal_hand(void *arg); static int mysql_init_variables(char *arg_mysql_home); static void set_server_version(void); static int init_thread_environment(); static char *get_relative_path(const char *path); static int fix_paths(void); #ifdef _WIN32 pthread_handler_t handle_connections_sockets_thread(void *arg); #endif pthread_handler_t kill_server_thread(void *arg); #ifdef _WIN32 pthread_handler_t handle_connections_namedpipes(void *arg); #endif #ifdef HAVE_SMEM pthread_handler_t handle_connections_shared_memory(void *arg); #endif pthread_handler_t handle_slave(void *arg); static void clean_up(bool print_message); static int test_if_case_insensitive(const char *dir_name); #ifndef EMBEDDED_LIBRARY static void usage(void); static void clean_up_mutexes(void); static void wait_for_signal_thread_to_end(void); static void mysqld_exit(int exit_code) __attribute__((noreturn)); #endif extern "C" sig_handler print_signal_warning(int sig) { if (log_warnings) sql_print_warning("Got signal %d from thread %ld", sig,my_thread_id()); #ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY my_sigset(sig,print_signal_warning); /* int. thread system calls */ #endif #if !defined(__WIN__) if (sig == SIGALRM) alarm(2); /* reschedule alarm */ #endif } #ifndef EMBEDDED_LIBRARY static void init_error_log_mutex() { mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log, MY_MUTEX_INIT_FAST); } static void clean_up_error_log_mutex() { mysql_mutex_destroy(&LOCK_error_log); } /** cleanup all memory and end program nicely. If SIGNALS_DONT_BREAK_READ is defined, this function is called by the main thread. To get MySQL to shut down nicely in this case (Mac OS X) we have to call exit() instead if pthread_exit(). @note This function never returns. */ void unireg_end(void) { clean_up(1); my_thread_end(); #if defined(SIGNALS_DONT_BREAK_READ) exit(0); #else pthread_exit(0); // Exit is in main thread #endif } extern "C" void unireg_abort(int exit_code) { DBUG_ENTER("unireg_abort"); if (exit_code) sql_print_error("Aborting\n"); clean_up((exit_code || !opt_bootstrap)); /* purecov: inspected */ DBUG_PRINT("quit",("done with cleanup in unireg_abort")); mysqld_exit(exit_code); } static void mysqld_exit(int exit_code) { clean_up_mutexes(); clean_up_error_log_mutex(); #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE shutdown_performance_schema(); #endif my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); exit(exit_code); /* purecov: inspected */ } #endif /* !EMBEDDED_LIBRARY */ void clean_up(bool print_message) { DBUG_PRINT("exit",("clean_up")); if (cleanup_done++) return; /* purecov: inspected */ logger.cleanup_base(); my_dboptions_cache_free(); ignore_db_dirs_free(); item_func_sleep_free(); lex_free(); /* Free some memory */ item_create_cleanup(); end_thr_alarm(1); /* Free allocated memory */ my_free_open_file_info(); if (defaults_argv) free_defaults(defaults_argv); free_tmpdir(&mysql_tmpdir_list); my_free(opt_bin_logname); bitmap_free(&temp_pool); my_regex_end(); cleanup_errmsgs(); (void) my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST); // finish server errs DBUG_PRINT("quit", ("Error messages freed")); /* Tell main we are ready */ logger.cleanup_end(); my_atomic_rwlock_destroy(&opt_binlog_max_flush_queue_time_lock); my_atomic_rwlock_destroy(&global_query_id_lock); my_atomic_rwlock_destroy(&thread_running_lock); free_charsets(); mysql_mutex_lock(&LOCK_thread_count); DBUG_PRINT("quit", ("got thread count lock")); ready_to_exit=1; /* do the broadcast inside the lock to ensure that my_end() is not called */ mysql_cond_broadcast(&COND_thread_count); mysql_mutex_unlock(&LOCK_thread_count); delete_global_thread_list(); if (THR_THD) (void) pthread_key_delete(THR_THD); if (THR_MALLOC) (void) pthread_key_delete(THR_MALLOC); my_handle_options_end(); /* The following lines may never be executed as the main thread may have killed us */ DBUG_PRINT("quit", ("done with cleanup")); } /* clean_up */ #ifndef EMBEDDED_LIBRARY static void clean_up_mutexes() { mysql_rwlock_destroy(&LOCK_grant); mysql_mutex_destroy(&LOCK_thread_created); mysql_mutex_destroy(&LOCK_thread_count); mysql_mutex_destroy(&LOCK_log_throttle_qni); mysql_mutex_destroy(&LOCK_status); mysql_mutex_destroy(&LOCK_delayed_insert); mysql_mutex_destroy(&LOCK_delayed_status); mysql_mutex_destroy(&LOCK_delayed_create); mysql_mutex_destroy(&LOCK_crypt); mysql_mutex_destroy(&LOCK_user_conn); mysql_mutex_destroy(&LOCK_connection_count); #ifdef HAVE_OPENSSL mysql_mutex_destroy(&LOCK_des_key_file); #ifndef HAVE_YASSL for (int i= 0; i < CRYPTO_num_locks(); ++i) mysql_rwlock_destroy(&openssl_stdlocks[i].lock); OPENSSL_free(openssl_stdlocks); #endif #endif mysql_mutex_destroy(&LOCK_active_mi); mysql_rwlock_destroy(&LOCK_sys_init_connect); mysql_rwlock_destroy(&LOCK_sys_init_slave); mysql_mutex_destroy(&LOCK_global_system_variables); mysql_rwlock_destroy(&LOCK_system_variables_hash); mysql_mutex_destroy(&LOCK_uuid_generator); mysql_mutex_destroy(&LOCK_sql_rand); mysql_mutex_destroy(&LOCK_prepared_stmt_count); mysql_mutex_destroy(&LOCK_sql_slave_skip_counter); mysql_mutex_destroy(&LOCK_slave_net_timeout); mysql_mutex_destroy(&LOCK_error_messages); mysql_cond_destroy(&COND_thread_count); mysql_mutex_destroy(&LOCK_thd_remove); mysql_cond_destroy(&COND_thread_cache); mysql_cond_destroy(&COND_flush_thread_cache); mysql_mutex_destroy(&LOCK_stats); mysql_mutex_destroy(&LOCK_global_user_client_stats); mysql_mutex_destroy(&LOCK_global_table_stats); mysql_mutex_destroy(&LOCK_global_index_stats); mysql_rwlock_destroy(&LOCK_consistent_snapshot); } #endif /*EMBEDDED_LIBRARY*/ /**************************************************************************** ** Init IP and UNIX socket ****************************************************************************/ /** MY_BIND_ALL_ADDRESSES defines a special value for the bind-address option, which means that the server should listen to all available network addresses, both IPv6 (if available) and IPv4. Basically, this value instructs the server to make an attempt to bind the server socket to '::' address, and rollback to '0.0.0.0' if the attempt fails. */ const char *MY_BIND_ALL_ADDRESSES= "*"; #ifndef EMBEDDED_LIBRARY /** Change root user if started with @c --chroot . */ static void set_root(const char *path) { #if !defined(__WIN__) if (chroot(path) == -1) { sql_perror("chroot"); unireg_abort(1); } my_setwd("/", MYF(0)); #endif } #endif /*!EMBEDDED_LIBRARY*/ /** All global error messages are sent here where the first one is stored for the client. */ /* ARGSUSED */ extern "C" void my_message_sql(uint error, const char *str, myf MyFlags); void my_message_sql(uint error, const char *str, myf MyFlags) { THD *thd= current_thd; DBUG_ENTER("my_message_sql"); DBUG_PRINT("error", ("error: %u message: '%s'", error, str)); DBUG_ASSERT(str != NULL); /* An error should have a valid error number (!= 0), so it can be caught in stored procedures by SQL exception handlers. Calling my_error() with error == 0 is a bug. Remaining known places to fix: - storage/myisam/mi_create.c, my_printf_error() TODO: DBUG_ASSERT(error != 0); */ if (error == 0) { /* At least, prevent new abuse ... */ DBUG_ASSERT(strncmp(str, "MyISAM table", 12) == 0); error= ER_UNKNOWN_ERROR; } if (thd) { if (MyFlags & ME_FATALERROR) thd->is_fatal_error= 1; (void) thd->raise_condition(error, NULL, Sql_condition::WARN_LEVEL_ERROR, str); } /* When simulating OOM, skip writing to error log to avoid mtr errors */ DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_VOID_RETURN;); if (!thd || MyFlags & ME_NOREFRESH) sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */ DBUG_VOID_RETURN; } #ifndef EMBEDDED_LIBRARY extern "C" void *my_str_malloc_mysqld(size_t size); extern "C" void my_str_free_mysqld(void *ptr); extern "C" void *my_str_realloc_mysqld(void *ptr, size_t size); void *my_str_malloc_mysqld(size_t size) { return my_malloc(size, MYF(MY_FAE)); } void my_str_free_mysqld(void *ptr) { my_free(ptr); } void *my_str_realloc_mysqld(void *ptr, size_t size) { return my_realloc(ptr, size, MYF(MY_FAE)); } #endif /* EMBEDDED_LIBRARY */ #ifdef __WIN__ pthread_handler_t handle_shutdown(void *arg) { MSG msg; my_thread_init(); /* this call should create the message queue for this thread */ PeekMessage(&msg, NULL, 1, 65534,PM_NOREMOVE); #if !defined(EMBEDDED_LIBRARY) if (WaitForSingleObject(hEventShutdown,INFINITE)==WAIT_OBJECT_0) #endif /* EMBEDDED_LIBRARY */ kill_server(MYSQL_KILL_SIGNAL); return 0; } #endif const char *load_default_groups[]= { #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE "mysql_cluster", #endif "mysqld","server", MYSQL_BASE_VERSION, 0, 0}; #if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) static const int load_default_groups_sz= sizeof(load_default_groups)/sizeof(load_default_groups[0]); #endif #ifndef EMBEDDED_LIBRARY /** This function is used to check for stack overrun for pathological cases of regular expressions and 'like' expressions. The call to current_thd is quite expensive, so we try to avoid it for the normal cases. The size of each stack frame for the wildcmp() routines is ~128 bytes, so checking *every* recursive call is not necessary. */ extern "C" int check_enough_stack_size(int recurse_level) { uchar stack_top; if (recurse_level % 16 != 0) return 0; THD *my_thd= current_thd; if (my_thd != NULL) return check_stack_overrun(my_thd, STACK_MIN_SIZE * 2, &stack_top); return 0; } #endif /** Initialize one of the global date/time format variables. @param format_type What kind of format should be supported @param var_ptr Pointer to variable that should be updated @retval 0 ok @retval 1 error */ static bool init_global_datetime_format(timestamp_type format_type, DATE_TIME_FORMAT *format) { /* Get command line option format->format.str is already set by my_getopt */ format->format.length= strlen(format->format.str); if (parse_date_time_format(format_type, format)) { fprintf(stderr, "Wrong date/time format specifier: %s\n", format->format.str); return true; } return false; } #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1]; PSI_statement_info com_statement_info[(uint) COM_END + 1]; /** Initialize the command names array. Since we do not want to maintain a separate array, this is populated from data mined in com_status_vars, which already has one name for each command. */ void init_sql_statement_info() { uint i; for (i= 0; i < ((uint) SQLCOM_END + 1); i++) { sql_statement_info[i].m_name= sql_statement_names[i].str; sql_statement_info[i].m_flags= 0; } /* "statement/sql/error" represents broken queries (syntax error). */ sql_statement_info[(uint) SQLCOM_END].m_name= "error"; sql_statement_info[(uint) SQLCOM_END].m_flags= 0; } void init_com_statement_info() { uint index; for (index= 0; index < (uint) COM_END + 1; index++) { com_statement_info[index].m_name= command_name[index].str; com_statement_info[index].m_flags= 0; } /* "statement/abstract/query" can mutate into "statement/sql/..." */ com_statement_info[(uint) COM_QUERY].m_flags= PSI_FLAG_MUTABLE; } #endif /** Create the name of the default general log file @param[IN] buff Location for building new string. @param[IN] log_ext The extension for the file (e.g .log) @returns Pointer to a new string containing the name */ static inline char *make_default_log_name(char *buff,const char* log_ext) { return make_log_name(buff, default_logfile_name, log_ext); } int init_common_variables(char *arg_mysql_home) { umask(((~my_umask) & 0666)); connection_errors_select= 0; connection_errors_accept= 0; connection_errors_tcpwrap= 0; connection_errors_internal= 0; connection_errors_max_connection= 0; connection_errors_peer_addr= 0; my_decimal_set_zero(&decimal_zero); // set decimal_zero constant; tzset(); // Set tzname max_system_variables.pseudo_thread_id= (ulong)~0; server_start_time= flush_status_time= my_time(0); if (init_thread_environment() || mysql_init_variables(arg_mysql_home)) return 1; if (ignore_db_dirs_init()) return 1; #ifdef HAVE_TZNAME { struct tm tm_tmp; localtime_r(&server_start_time,&tm_tmp); strmake(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0], sizeof(system_time_zone)-1); } #endif /* TODO: remove this when my_time_t is 64 bit compatible */ if (!IS_TIME_T_VALID_FOR_TIMESTAMP(server_start_time)) { sql_print_error("This MySQL server doesn't support dates later then 2038"); return 1; } if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0) { strmake(glob_hostname, STRING_WITH_LEN("localhost")); sql_print_warning("gethostname failed, using '%s' as hostname", glob_hostname); strmake(default_logfile_name, STRING_WITH_LEN("mysql")); } else strmake(default_logfile_name, glob_hostname, sizeof(default_logfile_name)-5); strmake(pidfile_name, default_logfile_name, sizeof(pidfile_name)-5); strmov(fn_ext(pidfile_name),".pid"); // Add proper extension if (fix_paths()) return 1; set_server_version(); DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, server_version, SYSTEM_TYPE,MACHINE_TYPE)); unireg_init(opt_specialflag); /* Set up extern variabels */ if (!(my_default_lc_messages= my_locale_by_name(lc_messages))) { sql_print_error("Unknown locale: '%s'", lc_messages); return 1; } global_system_variables.lc_messages= my_default_lc_messages; if (init_errmessage()) /* Read error messages from file */ return 1; lex_init(); if (item_create_init()) return 1; item_init(); #ifndef EMBEDDED_LIBRARY my_regex_init(&my_charset_latin1, check_enough_stack_size); my_string_stack_guard= check_enough_stack_size; #else my_regex_init(&my_charset_latin1, NULL); #endif /* Process a comma-separated character set list and choose the first available character set. This is mostly for test purposes, to be able to start "mysqld" even if the requested character set is not available (see bug#18743). */ for (;;) { char *next_character_set_name= strchr(default_character_set_name, ','); if (next_character_set_name) *next_character_set_name++= '\0'; if (!(default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY, MYF(MY_WME)))) { if (next_character_set_name) { default_character_set_name= next_character_set_name; default_collation_name= 0; // Ignore collation } else return 1; // Eof of the list } else break; } if (default_collation_name) { CHARSET_INFO *default_collation; default_collation= get_charset_by_name(default_collation_name, MYF(0)); if (!default_collation) { #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE buffered_logs.print(); buffered_logs.cleanup(); #endif sql_print_error(ER_DEFAULT(ER_UNKNOWN_COLLATION), default_collation_name); return 1; } if (!my_charset_same(default_charset_info, default_collation)) { sql_print_error(ER_DEFAULT(ER_COLLATION_CHARSET_MISMATCH), default_collation_name, default_charset_info->csname); return 1; } default_charset_info= default_collation; } /* Set collactions that depends on the default collation */ global_system_variables.collation_server= default_charset_info; global_system_variables.collation_database= default_charset_info; if (is_supported_parser_charset(default_charset_info)) { global_system_variables.collation_connection= default_charset_info; global_system_variables.character_set_results= default_charset_info; global_system_variables.character_set_client= default_charset_info; } else { sql_print_information("'%s' can not be used as client character set. " "'%s' will be used as default client character set.", default_charset_info->csname, my_charset_latin1.csname); global_system_variables.collation_connection= &my_charset_latin1; global_system_variables.character_set_results= &my_charset_latin1; global_system_variables.character_set_client= &my_charset_latin1; } if (!(character_set_filesystem= get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY, MYF(MY_WME)))) return 1; global_system_variables.character_set_filesystem= character_set_filesystem; if (!(my_default_lc_time_names= my_locale_by_name(lc_time_names_name))) { sql_print_error("Unknown locale: '%s'", lc_time_names_name); return 1; } global_system_variables.lc_time_names= my_default_lc_time_names; /* check log options and issue warnings if needed */ if (opt_log && opt_logname && !(log_output_options & LOG_FILE) && !(log_output_options & LOG_NONE)) sql_print_warning("Although a path was specified for the " "--general-log-file option, log tables are used. " "To enable logging to files use the --log-output=file option."); #define FIX_LOG_VAR(VAR, ALT) \ if (!VAR || !*VAR) \ { \ my_free(VAR); /* it could be an allocated empty string "" */ \ VAR= ALT; \ } FIX_LOG_VAR(opt_logname, make_default_log_name(logname_path, ".log")); #if (ENABLE_TEMP_POOL) if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1)) return 1; #else use_temp_pool= 0; #endif if (my_dboptions_cache_init()) return 1; /* Reset table_alias_charset, now that lower_case_table_names is set. */ table_alias_charset= (lower_case_table_names ? &my_charset_utf8_tolower_ci : &my_charset_bin); if (ignore_db_dirs_process_additions()) { sql_print_error("An error occurred while storing ignore_db_dirs to a hash."); return 1; } return 0; } static int init_thread_environment() { mysql_mutex_init(key_LOCK_thread_created, &LOCK_thread_created, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_thread_count, &LOCK_thread_count, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_thd_remove, &LOCK_thd_remove, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_delayed_insert, &LOCK_delayed_insert, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_delayed_status, &LOCK_delayed_status, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_delayed_create, &LOCK_delayed_create, MY_MUTEX_INIT_SLOW); mysql_mutex_init(key_LOCK_crypt, &LOCK_crypt, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_user_conn, &LOCK_user_conn, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_active_mi, &LOCK_active_mi, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_global_system_variables, &LOCK_global_system_variables, MY_MUTEX_INIT_FAST); mysql_rwlock_init(key_rwlock_LOCK_system_variables_hash, &LOCK_system_variables_hash); mysql_mutex_init(key_LOCK_prepared_stmt_count, &LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_sql_slave_skip_counter, &LOCK_sql_slave_skip_counter, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_slave_net_timeout, &LOCK_slave_net_timeout, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_error_messages, &LOCK_error_messages, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_uuid_generator, &LOCK_uuid_generator, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_sql_rand, &LOCK_sql_rand, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_connection_count, &LOCK_connection_count, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_log_throttle_qni, &LOCK_log_throttle_qni, MY_MUTEX_INIT_FAST); #ifdef HAVE_OPENSSL mysql_mutex_init(key_LOCK_des_key_file, &LOCK_des_key_file, MY_MUTEX_INIT_FAST); #ifndef HAVE_YASSL openssl_stdlocks= (openssl_lock_t*) OPENSSL_malloc(CRYPTO_num_locks() * sizeof(openssl_lock_t)); for (int i= 0; i < CRYPTO_num_locks(); ++i) mysql_rwlock_init(key_rwlock_openssl, &openssl_stdlocks[i].lock); CRYPTO_set_dynlock_create_callback(openssl_dynlock_create); CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy); CRYPTO_set_dynlock_lock_callback(openssl_lock); CRYPTO_set_locking_callback(openssl_lock_function); CRYPTO_set_id_callback(openssl_id_function); #endif #endif mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect); mysql_rwlock_init(key_rwlock_LOCK_sys_init_slave, &LOCK_sys_init_slave); mysql_rwlock_init(key_rwlock_LOCK_grant, &LOCK_grant); mysql_rwlock_init(key_rwlock_LOCK_consistent_snapshot, &LOCK_consistent_snapshot); mysql_cond_init(key_COND_thread_count, &COND_thread_count, NULL); mysql_cond_init(key_COND_thread_cache, &COND_thread_cache, NULL); mysql_cond_init(key_COND_flush_thread_cache, &COND_flush_thread_cache, NULL); mysql_mutex_init(key_LOCK_server_started, &LOCK_server_started, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_stats, &LOCK_stats, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_global_user_client_stats, &LOCK_global_user_client_stats, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_global_table_stats, &LOCK_global_table_stats, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_global_index_stats, &LOCK_global_index_stats, MY_MUTEX_INIT_FAST); /* Parameter for threads created for connections */ (void) pthread_attr_init(&connection_attrib); (void) pthread_attr_setdetachstate(&connection_attrib, PTHREAD_CREATE_DETACHED); pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM); if (pthread_key_create(&THR_THD,NULL) || pthread_key_create(&THR_MALLOC,NULL)) { sql_print_error("Can't create thread-keys"); return 1; } return 0; } #if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL) static unsigned long openssl_id_function() { return (unsigned long) pthread_self(); } static openssl_lock_t *openssl_dynlock_create(const char *file, int line) { openssl_lock_t *lock= new openssl_lock_t; mysql_rwlock_init(key_rwlock_openssl, &lock->lock); return lock; } static void openssl_dynlock_destroy(openssl_lock_t *lock, const char *file, int line) { mysql_rwlock_destroy(&lock->lock); delete lock; } static void openssl_lock_function(int mode, int n, const char *file, int line) { if (n < 0 || n > CRYPTO_num_locks()) { /* Lock number out of bounds. */ sql_print_error("Fatal: OpenSSL interface problem (n = %d)", n); abort(); } openssl_lock(mode, &openssl_stdlocks[n], file, line); } static void openssl_lock(int mode, openssl_lock_t *lock, const char *file, int line) { int err; char const *what; switch (mode) { case CRYPTO_LOCK|CRYPTO_READ: what = "read lock"; err= mysql_rwlock_rdlock(&lock->lock); break; case CRYPTO_LOCK|CRYPTO_WRITE: what = "write lock"; err= mysql_rwlock_wrlock(&lock->lock); break; case CRYPTO_UNLOCK|CRYPTO_READ: case CRYPTO_UNLOCK|CRYPTO_WRITE: what = "unlock"; err= mysql_rwlock_unlock(&lock->lock); break; default: /* Unknown locking mode. */ sql_print_error("Fatal: OpenSSL interface problem (mode=0x%x)", mode); abort(); } if (err) { sql_print_error("Fatal: can't %s OpenSSL lock", what); abort(); } } #endif /* HAVE_OPENSSL */ static int init_server_components() { DBUG_ENTER("init_server_components"); #ifdef HAVE_MY_TIMER if (my_os_timer_init_ext()) sql_print_error("Failed to initialize timer component (errno %d).", errno); #else have_statement_timeout= SHOW_OPTION_NO; #endif randominit(&sql_rand,(ulong) server_start_time,(ulong) server_start_time/2); setup_fpu(); init_thr_lock(); proc_info_hook= set_thd_stage_info; /* Now that the logger is available, redirect character set errors directly to the logger (instead of the buffered_logs used at the server startup time). */ my_charset_error_reporter= charset_error_reporter; opt_server_id_mask = ~ulong(0); /* if the errmsg.sys is not loaded, terminate to maintain behaviour */ // if (!DEFAULT_ERRMSGS[0][0]) // unireg_abort(1); logger.set_handlers(LOG_FILE, opt_log ? LOG_FILE:LOG_NONE); init_update_queries(); DBUG_RETURN(0); } #ifdef __WIN__ int win_init(int argc, char **argv) #else int mysqld_init(char *arg_mysql_home) #endif { #ifndef _WIN32 // For windows, my_init() is called from the win specific mysqld_main if (my_init()) // init my_sys library & pthreads { fprintf(stderr, "my_init() failed.\n"); return 1; } #endif /* Must be initialized early for comparison of options name */ system_charset_info= &my_charset_utf8_general_ci; sys_var_init(); #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE /* Initialize the array of performance schema instrument configurations. */ init_pfs_instrument_array(); #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ init_error_log_mutex(); /* Perform basic logger initialization logger. Should be called after MY_INIT, as it initializes mutexes. Log tables are inited later. */ logger.init_base(); #ifdef _CUSTOMSTARTUPCONFIG_ if (_cust_check_startup()) { / * _cust_check_startup will report startup failure error * / exit(1); } #endif if (init_common_variables(arg_mysql_home)) { printf("init_common_variables failed.\n"); unireg_abort(1); // Will do exit } #ifndef DBUG_OFF srand(time(NULL)); #endif if (init_server_components()) { printf("init_server_components failed.\n"); unireg_abort(1); } /* Initialize my_str_malloc(), my_str_realloc() and my_str_free() */ my_str_malloc= &my_str_malloc_mysqld; my_str_free= &my_str_free_mysqld; my_str_realloc= &my_str_realloc_mysqld; /* init signals & alarm After this we can't quit by a simple unireg_abort */ error_handler_hook= my_message_sql; sql_print_warning_hook = sql_print_warning; if (!(thd= new THD)) { return -1; } thd->start_utime= my_micro_time(); thd->thr_create_utime= my_micro_time(); thd->thread_stack= (char *)&thd; if (thd->store_globals()) { return -1; } return 0; } LEX * sql_parser(char *query, char *default_db) { thd->reset_db(default_db, strlen(default_db)); if (dispatch_command(COM_QUERY, thd, query, (uint) strlen(query))) { return NULL; } return thd->lex; } int sql_parser_cleanup() { thd->end_statement(); thd->cleanup_after_query(); free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); DBUG_ASSERT(thd->change_list.is_empty()); return 0; } int mysqld_cleanup() { clean_up(1); return 0; } /**************************************************************************** Handle start options ******************************************************************************/ #ifndef EMBEDDED_LIBRARY static void print_version(void) { set_server_version(); printf("%s Ver %s for %s on %s (%s)\n",my_progname, server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT); } #endif /*!EMBEDDED_LIBRARY*/ /** Initialize MySQL global variables to default values. @note The reason to set a lot of global variables to zero is to allow one to restart the embedded server with a clean environment It's also needed on some exotic platforms where global variables are not set to 0 when a program starts. We don't need to set variables refered to in my_long_options as these are initialized by my_getopt. */ static int mysql_init_variables(char *arg_mysql_home) { /* Things reset to zero */ opt_skip_slave_start= opt_reckless_slave = 0; mysql_home[0]= pidfile_name[0]= 0; opt_log= 0; opt_logname= opt_update_logname= opt_binlog_index_name= 0; opt_tc_log_file= (char *)"tc.log"; // no hostname in tc_log file name ! opt_myisam_log= 0; mqh_used= 0; kill_in_progress= 0; cleanup_done= 0; server_id_supplied= 0; test_flags= select_errors= ha_open_options=0; global_thread_count= num_thread_running= kill_blocked_pthreads_flag= wake_pthread=0; blocked_pthread_count= 0; opt_endinfo= using_udf_functions= 0; opt_using_transactions= 0; abort_loop= 0; ready_to_exit= shutdown_in_progress= grant_option= 0; specialflag= 0; mysqld_user= mysqld_chroot = 0; prepared_stmt_count= 0; mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS; memset(&mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list)); /* Character sets */ system_charset_info= &my_charset_utf8_general_ci; files_charset_info= &my_charset_utf8_general_ci; national_charset_info= &my_charset_utf8_general_ci; table_alias_charset= &my_charset_bin; character_set_filesystem= &my_charset_bin; opt_specialflag= SPECIAL_ENGLISH; unix_sock= MYSQL_INVALID_SOCKET; base_ip_sock= extra_ip_sock= MYSQL_INVALID_SOCKET; mysql_home_ptr= mysql_home; pidfile_name_ptr= pidfile_name; lc_messages_dir_ptr= lc_messages_dir; what_to_log= ~ (1L << (uint) COM_TIME); strmov(server_version, MYSQL_SERVER_VERSION); /* Variables in libraries */ charsets_dir= 0; default_character_set_name= (char*) MYSQL_DEFAULT_CHARSET_NAME; default_collation_name= compiled_default_collation_name; character_set_filesystem_name= (char*) "binary"; lc_messages= (char*) "en_US"; lc_time_names_name= (char*) "en_US"; /* Variables that depends on compile options */ #ifndef DBUG_OFF default_dbug_option=IF_WIN("d:t:i:O,\\mysqld.trace", "d:t:i:o,/tmp/mysqld.trace"); #endif (void) strmake(mysql_home, arg_mysql_home, sizeof(mysql_home)-1); return 0; } /* Create version name for running mysqld version We automaticly add suffixes -debug, -embedded and -log to the version name to make the version more descriptive. (MYSQL_SERVER_SUFFIX is set by the compilation environment) */ static void set_server_version(void) { char *end= strxmov(server_version, MYSQL_SERVER_VERSION, MYSQL_SERVER_SUFFIX_STR, NullS); #ifdef EMBEDDED_LIBRARY end= strmov(end, "-embedded"); #endif #ifndef DBUG_OFF if (!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug")) end= strmov(end, "-debug"); #endif if (opt_log) strmov(end, "-log"); // This may slow down system } static char *get_relative_path(const char *path) { if (test_if_hard_path(path) && is_prefix(path,DEFAULT_MYSQL_HOME) && strcmp(DEFAULT_MYSQL_HOME,FN_ROOTDIR)) { path+=(uint) strlen(DEFAULT_MYSQL_HOME); while (*path == FN_LIBCHAR || *path == FN_LIBCHAR2) path++; } return (char*) path; } /** Fix filename and replace extension where 'dir' is relative to mysql_real_data_home. @return 1 if len(path) > FN_REFLEN */ bool fn_format_relative_to_data_home(char * to, const char *name, const char *dir, const char *extension) { char tmp_path[FN_REFLEN]; if (!test_if_hard_path(dir)) { strxnmov(tmp_path,sizeof(tmp_path)-1, mysql_real_data_home, dir, NullS); dir=tmp_path; } return !fn_format(to, name, dir, extension, MY_APPEND_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH); } /** Test a file path to determine if the path is compatible with the secure file path restriction. @param path null terminated character string @return @retval TRUE The path is secure @retval FALSE The path isn't secure */ bool is_secure_file_path(char *path) { char buff1[FN_REFLEN], buff2[FN_REFLEN]; size_t opt_secure_file_priv_len; /* --secure-file-priv without argument means disable SELECT INTO OUTFILE/LOAD DATA INFILE */ if (opt_secure_file_priv_noarg) return FALSE; /* All paths are secure if opt_secure_file_path is 0 */ if (!opt_secure_file_priv) return TRUE; opt_secure_file_priv_len= strlen(opt_secure_file_priv); if (strlen(path) >= FN_REFLEN) return FALSE; if (my_realpath(buff1, path, 0)) { /* The supplied file path might have been a file and not a directory. */ int length= (int)dirname_length(path); if (length >= FN_REFLEN) return FALSE; memcpy(buff2, path, length); buff2[length]= '\0'; if (length == 0 || my_realpath(buff1, buff2, 0)) return FALSE; } convert_dirname(buff2, buff1, NullS); if (!lower_case_file_system) { if (strncmp(opt_secure_file_priv, buff2, opt_secure_file_priv_len)) return FALSE; } else { if (files_charset_info->coll->strnncoll(files_charset_info, (uchar *) buff2, strlen(buff2), (uchar *) opt_secure_file_priv, opt_secure_file_priv_len, TRUE)) return FALSE; } return TRUE; } static int fix_paths(void) { char buff[FN_REFLEN],*pos; convert_dirname(mysql_home,mysql_home,NullS); /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */ my_realpath(mysql_home,mysql_home,MYF(0)); /* Ensure that mysql_home ends in FN_LIBCHAR */ pos=strend(mysql_home); if (pos[-1] != FN_LIBCHAR) { pos[0]= FN_LIBCHAR; pos[1]= 0; } convert_dirname(lc_messages_dir, lc_messages_dir, NullS); convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS); (void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home); (void) my_load_path(pidfile_name, pidfile_name_ptr, mysql_real_data_home); my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0)); mysql_unpacked_real_data_home_len= (int) strlen(mysql_unpacked_real_data_home); if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len-1] == FN_LIBCHAR) --mysql_unpacked_real_data_home_len; char *sharedir=get_relative_path(SHAREDIR); if (test_if_hard_path(sharedir)) strmake(buff,sharedir,sizeof(buff)-1); /* purecov: tested */ else strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS); convert_dirname(buff,buff,NullS); (void) my_load_path(lc_messages_dir, lc_messages_dir, buff); /* If --character-sets-dir isn't given, use shared library dir */ if (charsets_dir) strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir)-1); else strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff, CHARSET_DIR, NullS); (void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff); convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS); charsets_dir=mysql_charsets_dir; if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) return 1; if (!opt_mysql_tmpdir) opt_mysql_tmpdir= mysql_tmpdir; /* Convert the secure-file-priv option to system format, allowing a quick strcmp to check if read or write is in an allowed dir */ if (opt_secure_file_priv && !opt_secure_file_priv_noarg) { if (*opt_secure_file_priv == 0) opt_secure_file_priv= NULL; else { if (strlen(opt_secure_file_priv) >= FN_REFLEN) opt_secure_file_priv[FN_REFLEN-1]= '\0'; if (my_realpath(buff, opt_secure_file_priv, 0)) { sql_print_warning("Failed to normalize the argument for --secure-file-priv."); return 1; } convert_dirname(secure_file_real_path, buff, NullS); opt_secure_file_priv= secure_file_real_path; } } return 0; } /** Check if file system used for databases is case insensitive. @param dir_name Directory to test @retval -1 Don't know (Test failed) @retval 0 File system is case sensitive @retval 1 File system is case insensitive */ static int test_if_case_insensitive(const char *dir_name) { int result= 0; File file; char buff[FN_REFLEN], buff2[FN_REFLEN]; MY_STAT stat_info; DBUG_ENTER("test_if_case_insensitive"); fn_format(buff, glob_hostname, dir_name, ".lower-test", MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR); fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST", MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR); mysql_file_delete(key_file_casetest, buff2, MYF(0)); if ((file= mysql_file_create(key_file_casetest, buff, 0666, O_RDWR, MYF(0))) < 0) { sql_print_warning("Can't create test file %s", buff); DBUG_RETURN(-1); } mysql_file_close(file, MYF(0)); if (mysql_file_stat(key_file_casetest, buff2, &stat_info, MYF(0))) result= 1; // Can access file mysql_file_delete(key_file_casetest, buff, MYF(MY_WME)); DBUG_PRINT("exit", ("result: %d", result)); DBUG_RETURN(result); } /***************************************************************************** Instantiate variables for missing storage engines This section should go away soon *****************************************************************************/ #ifdef HAVE_PSI_INTERFACE #ifdef HAVE_MMAP PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active, key_LOCK_pool; #endif /* HAVE_MMAP */ #ifdef HAVE_OPENSSL PSI_mutex_key key_LOCK_des_key_file; #endif /* HAVE_OPENSSL */ PSI_mutex_key key_LOCK_temporary_tables; PSI_mutex_key key_BINLOG_LOCK_commit; PSI_mutex_key key_BINLOG_LOCK_commit_queue; PSI_mutex_key key_BINLOG_LOCK_done; PSI_mutex_key key_BINLOG_LOCK_flush_queue; PSI_mutex_key key_BINLOG_LOCK_index; PSI_mutex_key key_BINLOG_LOCK_log; PSI_mutex_key key_BINLOG_LOCK_sync; PSI_mutex_key key_BINLOG_LOCK_sync_queue; PSI_mutex_key key_BINLOG_LOCK_xids; PSI_mutex_key key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi, key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create, key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log, key_LOCK_stats, key_LOCK_global_user_client_stats, key_LOCK_global_table_stats, key_LOCK_global_index_stats, key_LOCK_gdl, key_LOCK_global_system_variables, key_LOCK_manager, key_LOCK_prepared_stmt_count, key_LOCK_sql_slave_skip_counter, key_LOCK_slave_net_timeout, key_LOCK_server_started, key_LOCK_status, key_LOCK_system_variables_hash, key_LOCK_table_share, key_LOCK_thd_data, key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log, key_master_info_data_lock, key_master_info_run_lock, key_master_info_sleep_lock, key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock, key_relay_log_info_sleep_lock, key_relay_log_info_log_space_lock, key_relay_log_info_run_lock, key_mutex_slave_parallel_pend_jobs, key_mutex_mts_temp_tables_lock, key_mutex_slave_parallel_worker, key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data, key_LOCK_error_messages, key_LOG_INFO_lock, key_LOCK_thread_count, key_LOCK_log_throttle_qni; PSI_mutex_key key_LOCK_thd_remove; PSI_mutex_key key_RELAYLOG_LOCK_commit; PSI_mutex_key key_RELAYLOG_LOCK_commit_queue; PSI_mutex_key key_RELAYLOG_LOCK_done; PSI_mutex_key key_RELAYLOG_LOCK_flush_queue; PSI_mutex_key key_RELAYLOG_LOCK_index; PSI_mutex_key key_RELAYLOG_LOCK_log; PSI_mutex_key key_RELAYLOG_LOCK_sync; PSI_mutex_key key_RELAYLOG_LOCK_sync_queue; PSI_mutex_key key_RELAYLOG_LOCK_xids; PSI_mutex_key key_LOCK_sql_rand; PSI_mutex_key key_gtid_ensure_index_mutex; PSI_mutex_key key_LOCK_thread_created; static PSI_mutex_info all_server_mutexes[]= { #ifdef HAVE_OPENSSL { &key_LOCK_des_key_file, "LOCK_des_key_file", PSI_FLAG_GLOBAL}, #endif /* HAVE_OPENSSL */ { &key_BINLOG_LOCK_commit, "MYSQL_BIN_LOG::LOCK_commit", 0 }, { &key_BINLOG_LOCK_commit_queue, "MYSQL_BIN_LOG::LOCK_commit_queue", 0 }, { &key_BINLOG_LOCK_done, "MYSQL_BIN_LOG::LOCK_done", 0 }, { &key_BINLOG_LOCK_flush_queue, "MYSQL_BIN_LOG::LOCK_flush_queue", 0 }, { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0}, { &key_BINLOG_LOCK_log, "MYSQL_BIN_LOG::LOCK_log", 0}, { &key_BINLOG_LOCK_sync, "MYSQL_BIN_LOG::LOCK_sync", 0}, { &key_BINLOG_LOCK_sync_queue, "MYSQL_BIN_LOG::LOCK_sync_queue", 0 }, { &key_BINLOG_LOCK_xids, "MYSQL_BIN_LOG::LOCK_xids", 0 }, { &key_RELAYLOG_LOCK_commit, "MYSQL_RELAY_LOG::LOCK_commit", 0}, { &key_RELAYLOG_LOCK_commit_queue, "MYSQL_RELAY_LOG::LOCK_commit_queue", 0 }, { &key_RELAYLOG_LOCK_done, "MYSQL_RELAY_LOG::LOCK_done", 0 }, { &key_RELAYLOG_LOCK_flush_queue, "MYSQL_RELAY_LOG::LOCK_flush_queue", 0 }, { &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0}, { &key_RELAYLOG_LOCK_log, "MYSQL_RELAY_LOG::LOCK_log", 0}, { &key_RELAYLOG_LOCK_sync, "MYSQL_RELAY_LOG::LOCK_sync", 0}, { &key_RELAYLOG_LOCK_sync_queue, "MYSQL_RELAY_LOG::LOCK_sync_queue", 0 }, { &key_RELAYLOG_LOCK_xids, "MYSQL_RELAY_LOG::LOCK_xids", 0}, { &key_delayed_insert_mutex, "Delayed_insert::mutex", 0}, { &key_hash_filo_lock, "hash_filo::lock", 0}, { &key_LOCK_active_mi, "LOCK_active_mi", PSI_FLAG_GLOBAL}, { &key_LOCK_connection_count, "LOCK_connection_count", PSI_FLAG_GLOBAL}, { &key_LOCK_crypt, "LOCK_crypt", PSI_FLAG_GLOBAL}, { &key_LOCK_delayed_create, "LOCK_delayed_create", PSI_FLAG_GLOBAL}, { &key_LOCK_delayed_insert, "LOCK_delayed_insert", PSI_FLAG_GLOBAL}, { &key_LOCK_delayed_status, "LOCK_delayed_status", PSI_FLAG_GLOBAL}, { &key_LOCK_error_log, "LOCK_error_log", PSI_FLAG_GLOBAL}, { &key_LOCK_stats, "LOCK_stats", PSI_FLAG_GLOBAL}, { &key_LOCK_global_user_client_stats, "LOCK_global_user_client_stats", PSI_FLAG_GLOBAL}, { &key_LOCK_global_table_stats, "LOCK_global_table_stats", PSI_FLAG_GLOBAL}, { &key_LOCK_global_index_stats, "LOCK_global_index_stats", PSI_FLAG_GLOBAL}, { &key_LOCK_gdl, "LOCK_gdl", PSI_FLAG_GLOBAL}, { &key_LOCK_global_system_variables, "LOCK_global_system_variables", PSI_FLAG_GLOBAL}, { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_GLOBAL}, { &key_LOCK_sql_slave_skip_counter, "LOCK_sql_slave_skip_counter", PSI_FLAG_GLOBAL}, { &key_LOCK_slave_net_timeout, "LOCK_slave_net_timeout", PSI_FLAG_GLOBAL}, { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_GLOBAL}, { &key_LOCK_status, "LOCK_status", PSI_FLAG_GLOBAL}, { &key_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, { &key_LOCK_table_share, "LOCK_table_share", PSI_FLAG_GLOBAL}, { &key_LOCK_thd_data, "THD::LOCK_thd_data", 0}, { &key_LOCK_temporary_tables, "THD::LOCK_temporary_tables", 0}, { &key_LOCK_user_conn, "LOCK_user_conn", PSI_FLAG_GLOBAL}, { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL}, { &key_LOCK_sql_rand, "LOCK_sql_rand", PSI_FLAG_GLOBAL}, { &key_LOG_LOCK_log, "LOG::LOCK_log", 0}, { &key_master_info_data_lock, "Master_info::data_lock", 0}, { &key_master_info_run_lock, "Master_info::run_lock", 0}, { &key_master_info_sleep_lock, "Master_info::sleep_lock", 0}, { &key_mutex_slave_reporting_capability_err_lock, "Slave_reporting_capability::err_lock", 0}, { &key_relay_log_info_data_lock, "Relay_log_info::data_lock", 0}, { &key_relay_log_info_sleep_lock, "Relay_log_info::sleep_lock", 0}, { &key_relay_log_info_log_space_lock, "Relay_log_info::log_space_lock", 0}, { &key_relay_log_info_run_lock, "Relay_log_info::run_lock", 0}, { &key_mutex_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_lock", 0}, { &key_mutex_mts_temp_tables_lock, "Relay_log_info::temp_tables_lock", 0}, { &key_mutex_slave_parallel_worker, "Worker_info::jobs_lock", 0}, { &key_TABLE_SHARE_LOCK_ha_data, "TABLE_SHARE::LOCK_ha_data", 0}, { &key_LOCK_error_messages, "LOCK_error_messages", PSI_FLAG_GLOBAL}, { &key_LOG_INFO_lock, "LOG_INFO::lock", 0}, { &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL}, { &key_LOCK_thd_remove, "LOCK_thd_remove", PSI_FLAG_GLOBAL}, { &key_LOCK_log_throttle_qni, "LOCK_log_throttle_qni", PSI_FLAG_GLOBAL}, { &key_gtid_ensure_index_mutex, "Gtid_state", PSI_FLAG_GLOBAL}, { &key_LOCK_thread_created, "LOCK_thread_created", PSI_FLAG_GLOBAL } }; PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock, key_rwlock_global_sid_lock, key_rwlock_LOCK_consistent_snapshot; PSI_rwlock_key key_rwlock_Trans_delegate_lock; PSI_rwlock_key key_rwlock_Binlog_storage_delegate_lock; #ifdef HAVE_REPLICATION PSI_rwlock_key key_rwlock_Binlog_transmit_delegate_lock; PSI_rwlock_key key_rwlock_Binlog_relay_IO_delegate_lock; #endif static PSI_rwlock_info all_server_rwlocks[]= { #if defined (HAVE_OPENSSL) && !defined(HAVE_YASSL) { &key_rwlock_openssl, "CRYPTO_dynlock_value::lock", 0}, #endif #ifdef HAVE_REPLICATION { &key_rwlock_Binlog_transmit_delegate_lock, "Binlog_transmit_delegate::lock", PSI_FLAG_GLOBAL}, { &key_rwlock_Binlog_relay_IO_delegate_lock, "Binlog_relay_IO_delegate::lock", PSI_FLAG_GLOBAL}, #endif { &key_rwlock_LOCK_grant, "LOCK_grant", PSI_FLAG_GLOBAL}, { &key_rwlock_LOCK_logger, "LOGGER::LOCK_logger", 0}, { &key_rwlock_LOCK_sys_init_connect, "LOCK_sys_init_connect", PSI_FLAG_GLOBAL}, { &key_rwlock_LOCK_sys_init_slave, "LOCK_sys_init_slave", PSI_FLAG_GLOBAL}, { &key_rwlock_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_GLOBAL}, { &key_rwlock_query_cache_query_lock, "Query_cache_query::lock", 0}, { &key_rwlock_global_sid_lock, "gtid_commit_rollback", PSI_FLAG_GLOBAL}, { &key_rwlock_Trans_delegate_lock, "Trans_delegate::lock", PSI_FLAG_GLOBAL}, { &key_rwlock_Binlog_storage_delegate_lock, "Binlog_storage_delegate::lock", PSI_FLAG_GLOBAL}, { &key_rwlock_LOCK_consistent_snapshot, "LOCK_consistent_snapshot", PSI_FLAG_GLOBAL} }; #ifdef HAVE_MMAP PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; #endif /* HAVE_MMAP */ PSI_cond_key key_BINLOG_update_cond, key_COND_cache_status_changed, key_COND_server_started, key_delayed_insert_cond, key_delayed_insert_cond_client, key_item_func_sleep_cond, key_master_info_data_cond, key_master_info_start_cond, key_master_info_stop_cond, key_master_info_sleep_cond, key_relay_log_info_data_cond, key_relay_log_info_log_space_cond, key_relay_log_info_start_cond, key_relay_log_info_stop_cond, key_relay_log_info_sleep_cond, key_cond_slave_parallel_pend_jobs, key_cond_slave_parallel_worker, key_TABLE_SHARE_cond, key_user_level_lock_cond, key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache; PSI_cond_key key_RELAYLOG_update_cond; PSI_cond_key key_BINLOG_COND_done; PSI_cond_key key_RELAYLOG_COND_done; PSI_cond_key key_BINLOG_prep_xids_cond; PSI_cond_key key_RELAYLOG_prep_xids_cond; PSI_cond_key key_gtid_ensure_index_cond; static PSI_cond_info all_server_conds[]= { #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) { &key_COND_handler_count, "COND_handler_count", PSI_FLAG_GLOBAL}, #endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ #ifdef HAVE_MMAP { &key_PAGE_cond, "PAGE::cond", 0}, { &key_COND_active, "TC_LOG_MMAP::COND_active", 0}, { &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0}, #endif /* HAVE_MMAP */ { &key_BINLOG_COND_done, "MYSQL_BIN_LOG::COND_done", 0}, { &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0}, { &key_BINLOG_prep_xids_cond, "MYSQL_BIN_LOG::prep_xids_cond", 0}, { &key_RELAYLOG_COND_done, "MYSQL_RELAY_LOG::COND_done", 0}, { &key_RELAYLOG_update_cond, "MYSQL_RELAY_LOG::update_cond", 0}, { &key_RELAYLOG_prep_xids_cond, "MYSQL_RELAY_LOG::prep_xids_cond", 0}, { &key_COND_server_started, "COND_server_started", PSI_FLAG_GLOBAL}, { &key_delayed_insert_cond, "Delayed_insert::cond", 0}, { &key_delayed_insert_cond_client, "Delayed_insert::cond_client", 0}, { &key_item_func_sleep_cond, "Item_func_sleep::cond", 0}, { &key_master_info_data_cond, "Master_info::data_cond", 0}, { &key_master_info_start_cond, "Master_info::start_cond", 0}, { &key_master_info_stop_cond, "Master_info::stop_cond", 0}, { &key_master_info_sleep_cond, "Master_info::sleep_cond", 0}, { &key_relay_log_info_data_cond, "Relay_log_info::data_cond", 0}, { &key_relay_log_info_log_space_cond, "Relay_log_info::log_space_cond", 0}, { &key_relay_log_info_start_cond, "Relay_log_info::start_cond", 0}, { &key_relay_log_info_stop_cond, "Relay_log_info::stop_cond", 0}, { &key_relay_log_info_sleep_cond, "Relay_log_info::sleep_cond", 0}, { &key_cond_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_cond", 0}, { &key_cond_slave_parallel_worker, "Worker_info::jobs_cond", 0}, { &key_TABLE_SHARE_cond, "TABLE_SHARE::cond", 0}, { &key_user_level_lock_cond, "User_level_lock::cond", 0}, { &key_COND_thread_count, "COND_thread_count", PSI_FLAG_GLOBAL}, { &key_COND_thread_cache, "COND_thread_cache", PSI_FLAG_GLOBAL}, { &key_COND_flush_thread_cache, "COND_flush_thread_cache", PSI_FLAG_GLOBAL}, { &key_gtid_ensure_index_cond, "Gtid_state", PSI_FLAG_GLOBAL} }; PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, key_thread_handle_manager, key_thread_main, key_thread_one_connection, key_thread_signal_hand; static PSI_thread_info all_server_threads[]= { #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) { &key_thread_handle_con_namedpipes, "con_named_pipes", PSI_FLAG_GLOBAL}, #endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ #if defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY) { &key_thread_handle_con_sharedmem, "con_shared_mem", PSI_FLAG_GLOBAL}, #endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */ #if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY) { &key_thread_handle_con_sockets, "con_sockets", PSI_FLAG_GLOBAL}, #endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */ #ifdef __WIN__ { &key_thread_handle_shutdown, "shutdown", PSI_FLAG_GLOBAL}, #endif /* __WIN__ */ { &key_thread_bootstrap, "bootstrap", PSI_FLAG_GLOBAL}, { &key_thread_delayed_insert, "delayed_insert", 0}, { &key_thread_handle_manager, "manager", PSI_FLAG_GLOBAL}, { &key_thread_main, "main", PSI_FLAG_GLOBAL}, { &key_thread_one_connection, "one_connection", 0}, { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL} }; #ifdef HAVE_MMAP PSI_file_key key_file_map; #endif /* HAVE_MMAP */ PSI_file_key key_file_casetest, key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load, key_file_loadfile, key_file_log_event_data, key_file_log_event_info, key_file_master_info, key_file_misc, key_file_partition, key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog, key_file_trg, key_file_trn, key_file_init; PSI_file_key key_file_query_log; PSI_file_key key_file_relaylog, key_file_relaylog_index; static PSI_file_info all_server_files[]= { #ifdef HAVE_MMAP { &key_file_map, "map", 0}, #endif /* HAVE_MMAP */ { &key_file_binlog, "binlog", 0}, { &key_file_binlog_index, "binlog_index", 0}, { &key_file_relaylog, "relaylog", 0}, { &key_file_relaylog_index, "relaylog_index", 0}, { &key_file_casetest, "casetest", 0}, { &key_file_dbopt, "dbopt", 0}, { &key_file_des_key_file, "des_key_file", 0}, { &key_file_ERRMSG, "ERRMSG", 0}, { &key_select_to_file, "select_to_file", 0}, { &key_file_fileparser, "file_parser", 0}, { &key_file_frm, "FRM", 0}, { &key_file_global_ddl_log, "global_ddl_log", 0}, { &key_file_load, "load", 0}, { &key_file_loadfile, "LOAD_FILE", 0}, { &key_file_log_event_data, "log_event_data", 0}, { &key_file_log_event_info, "log_event_info", 0}, { &key_file_master_info, "master_info", 0}, { &key_file_misc, "misc", 0}, { &key_file_partition, "partition", 0}, { &key_file_pid, "pid", 0}, { &key_file_query_log, "query_log", 0}, { &key_file_relay_log_info, "relay_log_info", 0}, { &key_file_send_file, "send_file", 0}, { &key_file_trg, "trigger_name", 0}, { &key_file_trn, "trigger", 0}, { &key_file_init, "init", 0} }; #endif /* HAVE_PSI_INTERFACE */ PSI_stage_info stage_after_create= { 0, "After create", 0}; PSI_stage_info stage_allocating_local_table= { 0, "allocating local table", 0}; PSI_stage_info stage_alter_inplace_prepare= { 0, "preparing for alter table", 0}; PSI_stage_info stage_alter_inplace= { 0, "altering table", 0}; PSI_stage_info stage_alter_inplace_commit= { 0, "committing alter table to storage engine", 0}; PSI_stage_info stage_changing_master= { 0, "Changing master", 0}; PSI_stage_info stage_checking_master_version= { 0, "Checking master version", 0}; PSI_stage_info stage_checking_permissions= { 0, "checking permissions", 0}; PSI_stage_info stage_checking_privileges_on_cached_query= { 0, "checking privileges on cached query", 0}; PSI_stage_info stage_checking_query_cache_for_query= { 0, "checking query cache for query", 0}; PSI_stage_info stage_cleaning_up= { 0, "cleaning up", 0}; PSI_stage_info stage_closing_tables= { 0, "closing tables", 0}; PSI_stage_info stage_connecting_to_master= { 0, "Connecting to master", 0}; PSI_stage_info stage_converting_heap_to_myisam= { 0, "converting HEAP to MyISAM", 0}; PSI_stage_info stage_copying_to_group_table= { 0, "Copying to group table", 0}; PSI_stage_info stage_copying_to_tmp_table= { 0, "Copying to tmp table", 0}; PSI_stage_info stage_copy_to_tmp_table= { 0, "copy to tmp table", 0}; PSI_stage_info stage_creating_delayed_handler= { 0, "Creating delayed handler", 0}; PSI_stage_info stage_creating_sort_index= { 0, "Creating sort index", 0}; PSI_stage_info stage_creating_table= { 0, "creating table", 0}; PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0}; PSI_stage_info stage_deleting_from_main_table= { 0, "deleting from main table", 0}; PSI_stage_info stage_deleting_from_reference_tables= { 0, "deleting from reference tables", 0}; PSI_stage_info stage_discard_or_import_tablespace= { 0, "discard_or_import_tablespace", 0}; PSI_stage_info stage_end= { 0, "end", 0}; PSI_stage_info stage_executing= { 0, "executing", 0}; PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0}; PSI_stage_info stage_explaining= { 0, "explaining", 0}; PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, "Finished reading one binlog; switching to next binlog", 0}; PSI_stage_info stage_flushing_relay_log_and_master_info_repository= { 0, "Flushing relay log and master info repository.", 0}; PSI_stage_info stage_flushing_relay_log_info_file= { 0, "Flushing relay-log info file.", 0}; PSI_stage_info stage_freeing_items= { 0, "freeing items", 0}; PSI_stage_info stage_fulltext_initialization= { 0, "FULLTEXT initialization", 0}; PSI_stage_info stage_got_handler_lock= { 0, "got handler lock", 0}; PSI_stage_info stage_got_old_table= { 0, "got old table", 0}; PSI_stage_info stage_init= { 0, "init", 0}; PSI_stage_info stage_insert= { 0, "insert", 0}; PSI_stage_info stage_invalidating_query_cache_entries_table= { 0, "invalidating query cache entries (table)", 0}; PSI_stage_info stage_invalidating_query_cache_entries_table_list= { 0, "invalidating query cache entries (table list)", 0}; PSI_stage_info stage_killing_slave= { 0, "Killing slave", 0}; PSI_stage_info stage_logging_slow_query= { 0, "logging slow query", 0}; PSI_stage_info stage_making_temp_file_append_before_load_data= { 0, "Making temporary file (append) before replaying LOAD DATA INFILE.", 0}; PSI_stage_info stage_making_temp_file_create_before_load_data= { 0, "Making temporary file (create) before replaying LOAD DATA INFILE.", 0}; PSI_stage_info stage_manage_keys= { 0, "manage keys", 0}; PSI_stage_info stage_master_has_sent_all_binlog_to_slave= { 0, "Master has sent all binlog to slave; waiting for binlog to be updated", 0}; PSI_stage_info stage_opening_tables= { 0, "Opening tables", 0}; PSI_stage_info stage_optimizing= { 0, "optimizing", 0}; PSI_stage_info stage_preparing= { 0, "preparing", 0}; PSI_stage_info stage_purging_old_relay_logs= { 0, "Purging old relay logs", 0}; PSI_stage_info stage_query_end= { 0, "query end", 0}; PSI_stage_info stage_queueing_master_event_to_the_relay_log= { 0, "Queueing master event to the relay log", 0}; PSI_stage_info stage_reading_event_from_the_relay_log= { 0, "Reading event from the relay log", 0}; PSI_stage_info stage_registering_slave_on_master= { 0, "Registering slave on master", 0}; PSI_stage_info stage_removing_duplicates= { 0, "Removing duplicates", 0}; PSI_stage_info stage_removing_tmp_table= { 0, "removing tmp table", 0}; PSI_stage_info stage_rename= { 0, "rename", 0}; PSI_stage_info stage_rename_result_table= { 0, "rename result table", 0}; PSI_stage_info stage_requesting_binlog_dump= { 0, "Requesting binlog dump", 0}; PSI_stage_info stage_reschedule= { 0, "reschedule", 0}; PSI_stage_info stage_searching_rows_for_update= { 0, "Searching rows for update", 0}; PSI_stage_info stage_sending_binlog_event_to_slave= { 0, "Sending binlog event to slave", 0}; PSI_stage_info stage_sending_cached_result_to_client= { 0, "sending cached result to client", 0}; PSI_stage_info stage_sending_data= { 0, "Sending data", 0}; PSI_stage_info stage_setup= { 0, "setup", 0}; PSI_stage_info stage_slave_has_read_all_relay_log= { 0, "Slave has read all relay log; waiting for the slave I/O thread to update it", 0}; PSI_stage_info stage_sorting_for_group= { 0, "Sorting for group", 0}; PSI_stage_info stage_sorting_for_order= { 0, "Sorting for order", 0}; PSI_stage_info stage_sorting_result= { 0, "Sorting result", 0}; PSI_stage_info stage_statistics= { 0, "statistics", 0}; PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until MASTER_DELAY seconds after master executed event", 0 }; PSI_stage_info stage_storing_result_in_query_cache= { 0, "storing result in query cache", 0}; PSI_stage_info stage_storing_row_into_queue= { 0, "storing row into queue", 0}; PSI_stage_info stage_system_lock= { 0, "System lock", 0}; PSI_stage_info stage_update= { 0, "update", 0}; PSI_stage_info stage_updating= { 0, "updating", 0}; PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0}; PSI_stage_info stage_updating_reference_tables= { 0, "updating reference tables", 0}; PSI_stage_info stage_upgrading_lock= { 0, "upgrading lock", 0}; PSI_stage_info stage_user_lock= { 0, "User lock", 0}; PSI_stage_info stage_user_sleep= { 0, "User sleep", 0}; PSI_stage_info stage_verifying_table= { 0, "verifying table", 0}; PSI_stage_info stage_waiting_for_delay_list= { 0, "waiting for delay_list", 0}; PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log= { 0, "waiting for GTID to be written to binary log", 0}; PSI_stage_info stage_waiting_for_handler_insert= { 0, "waiting for handler insert", 0}; PSI_stage_info stage_waiting_for_handler_lock= { 0, "waiting for handler lock", 0}; PSI_stage_info stage_waiting_for_handler_open= { 0, "waiting for handler open", 0}; PSI_stage_info stage_waiting_for_insert= { 0, "Waiting for INSERT", 0}; PSI_stage_info stage_waiting_for_master_to_send_event= { 0, "Waiting for master to send event", 0}; PSI_stage_info stage_waiting_for_master_update= { 0, "Waiting for master update", 0}; PSI_stage_info stage_waiting_for_relay_log_space= { 0, "Waiting for the slave SQL thread to free enough relay log space", 0}; PSI_stage_info stage_waiting_for_slave_mutex_on_exit= { 0, "Waiting for slave mutex on exit", 0}; PSI_stage_info stage_waiting_for_slave_thread_to_start= { 0, "Waiting for slave thread to start", 0}; PSI_stage_info stage_waiting_for_table_flush= { 0, "Waiting for table flush", 0}; PSI_stage_info stage_waiting_for_query_cache_lock= { 0, "Waiting for query cache lock", 0}; PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, "Waiting for the next event in relay log", 0}; PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position= { 0, "Waiting for the slave SQL thread to advance position", 0}; PSI_stage_info stage_waiting_to_finalize_termination= { 0, "Waiting to finalize termination", 0}; PSI_stage_info stage_waiting_to_get_readlock= { 0, "Waiting to get readlock", 0}; PSI_stage_info stage_slave_waiting_workers_to_exit= { 0, "Waiting for workers to exit", 0}; PSI_stage_info stage_slave_waiting_worker_to_release_partition= { 0, "Waiting for Slave Worker to release partition", 0}; PSI_stage_info stage_slave_waiting_worker_to_free_events= { 0, "Waiting for Slave Workers to free pending events", 0}; PSI_stage_info stage_slave_waiting_worker_queue= { 0, "Waiting for Slave Worker queue", 0}; PSI_stage_info stage_slave_waiting_event_from_coordinator= { 0, "Waiting for an event from Coordinator", 0}; PSI_stage_info stage_restoring_secondary_keys= { 0, "restoring secondary keys", 0}; #ifdef HAVE_PSI_INTERFACE PSI_stage_info *all_server_stages[]= { & stage_after_create, & stage_allocating_local_table, & stage_alter_inplace_prepare, & stage_alter_inplace, & stage_alter_inplace_commit, & stage_changing_master, & stage_checking_master_version, & stage_checking_permissions, & stage_checking_privileges_on_cached_query, & stage_checking_query_cache_for_query, & stage_cleaning_up, & stage_closing_tables, & stage_connecting_to_master, & stage_converting_heap_to_myisam, & stage_copying_to_group_table, & stage_copying_to_tmp_table, & stage_copy_to_tmp_table, & stage_creating_delayed_handler, & stage_creating_sort_index, & stage_creating_table, & stage_creating_tmp_table, & stage_deleting_from_main_table, & stage_deleting_from_reference_tables, & stage_discard_or_import_tablespace, & stage_end, & stage_executing, & stage_execution_of_init_command, & stage_explaining, & stage_finished_reading_one_binlog_switching_to_next_binlog, & stage_flushing_relay_log_and_master_info_repository, & stage_flushing_relay_log_info_file, & stage_freeing_items, & stage_fulltext_initialization, & stage_got_handler_lock, & stage_got_old_table, & stage_init, & stage_insert, & stage_invalidating_query_cache_entries_table, & stage_invalidating_query_cache_entries_table_list, & stage_killing_slave, & stage_logging_slow_query, & stage_making_temp_file_append_before_load_data, & stage_making_temp_file_create_before_load_data, & stage_manage_keys, & stage_master_has_sent_all_binlog_to_slave, & stage_opening_tables, & stage_optimizing, & stage_preparing, & stage_purging_old_relay_logs, & stage_query_end, & stage_queueing_master_event_to_the_relay_log, & stage_reading_event_from_the_relay_log, & stage_registering_slave_on_master, & stage_removing_duplicates, & stage_removing_tmp_table, & stage_rename, & stage_rename_result_table, & stage_requesting_binlog_dump, & stage_reschedule, & stage_searching_rows_for_update, & stage_sending_binlog_event_to_slave, & stage_sending_cached_result_to_client, & stage_sending_data, & stage_setup, & stage_slave_has_read_all_relay_log, & stage_sorting_for_group, & stage_sorting_for_order, & stage_sorting_result, & stage_sql_thd_waiting_until_delay, & stage_statistics, & stage_storing_result_in_query_cache, & stage_storing_row_into_queue, & stage_system_lock, & stage_update, & stage_updating, & stage_updating_main_table, & stage_updating_reference_tables, & stage_upgrading_lock, & stage_user_lock, & stage_user_sleep, & stage_verifying_table, & stage_waiting_for_delay_list, & stage_waiting_for_handler_insert, & stage_waiting_for_handler_lock, & stage_waiting_for_handler_open, & stage_waiting_for_insert, & stage_waiting_for_master_to_send_event, & stage_waiting_for_master_update, & stage_waiting_for_slave_mutex_on_exit, & stage_waiting_for_slave_thread_to_start, & stage_waiting_for_table_flush, & stage_waiting_for_query_cache_lock, & stage_waiting_for_the_next_event_in_relay_log, & stage_waiting_for_the_slave_thread_to_advance_position, & stage_waiting_to_finalize_termination, & stage_waiting_to_get_readlock, & stage_restoring_secondary_keys }; PSI_socket_key key_socket_tcpip, key_socket_unix, key_socket_client_connection; static PSI_socket_info all_server_sockets[]= { { &key_socket_tcpip, "server_tcpip_socket", PSI_FLAG_GLOBAL}, { &key_socket_unix, "server_unix_socket", PSI_FLAG_GLOBAL}, { &key_socket_client_connection, "client_connection", 0} }; /** Initialise all the performance schema instrumentation points used by the server. */ void init_server_psi_keys(void) { const char* category= "sql"; int count; count= array_elements(all_server_mutexes); mysql_mutex_register(category, all_server_mutexes, count); count= array_elements(all_server_rwlocks); mysql_rwlock_register(category, all_server_rwlocks, count); count= array_elements(all_server_conds); mysql_cond_register(category, all_server_conds, count); count= array_elements(all_server_threads); mysql_thread_register(category, all_server_threads, count); count= array_elements(all_server_files); mysql_file_register(category, all_server_files, count); count= array_elements(all_server_stages); mysql_stage_register(category, all_server_stages, count); count= array_elements(all_server_sockets); mysql_socket_register(category, all_server_sockets, count); #ifdef HAVE_PSI_STATEMENT_INTERFACE init_sql_statement_info(); count= array_elements(sql_statement_info); mysql_statement_register(category, sql_statement_info, count); category= "com"; init_com_statement_info(); /* Register [0 .. COM_QUERY - 1] as "statement/com/..." */ count= (int) COM_QUERY; mysql_statement_register(category, com_statement_info, count); /* Register [COM_QUERY + 1 .. COM_END] as "statement/com/..." */ count= (int) COM_END - (int) COM_QUERY; mysql_statement_register(category, & com_statement_info[(int) COM_QUERY + 1], count); category= "abstract"; /* Register [COM_QUERY] as "statement/abstract/com_query" */ mysql_statement_register(category, & com_statement_info[(int) COM_QUERY], 1); /* When a new packet is received, it is instrumented as "statement/abstract/new_packet". Based on the packet type found, it later mutates to the proper narrow type, for example "statement/abstract/query" or "statement/com/ping". In cases of "statement/abstract/query", SQL queries are given to the parser, which mutates the statement type to an even more narrow classification, for example "statement/sql/select". */ stmt_info_new_packet.m_key= 0; stmt_info_new_packet.m_name= "new_packet"; stmt_info_new_packet.m_flags= PSI_FLAG_MUTABLE; mysql_statement_register(category, &stmt_info_new_packet, 1); /* Statements processed from the relay log are initially instrumented as "statement/abstract/relay_log". The parser will mutate the statement type to a more specific classification, for example "statement/sql/insert". */ stmt_info_rpl.m_key= 0; stmt_info_rpl.m_name= "relay_log"; stmt_info_rpl.m_flags= PSI_FLAG_MUTABLE; mysql_statement_register(category, &stmt_info_rpl, 1); #endif } #endif /* HAVE_PSI_INTERFACE */