mysql源码main_51ak带你看MYSQL源码1:main入口函数

#ifdef _WIN32

int win_main(int argc, char **argv)

#else

int mysqld_main(int argc, char **argv)

#endif

{

#zs#

Perform basic thread library and malloc initialization,

to be able to read defaults files and parse options.

#fzs#

my_progname= argv[0]; #zs#注: 记下mysql进程名#fzs#

#ifndef _WIN32

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE

pre_initialize_performance_schema();

#endif #zs#WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#

// For windows, my_init() is called from the win specific mysqld_main

if (my_init()) // init my_sys library & pthreads

{

sql_print_error("my_init() failed.");

flush_error_log_messages();

return 1;

}

#endif #zs# _WIN32 #fzs#

orig_argc= argc;

orig_argv= argv;

my_getopt_use_args_separator= TRUE;

my_defaults_read_login_file= FALSE;

#zs#注: 这里是去读配置文件里的启动项,读的时候还带入了argv ,应该是argv优行,#fzs#

if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))

{

flush_error_log_messages();

return 1;

}

my_getopt_use_args_separator= FALSE;

defaults_argc= argc;

defaults_argv= argv;

remaining_argc= argc;

remaining_argv= argv;

#zs# Must be initialized early for comparison of options name #fzs#

system_charset_info= &my_charset_utf8_general_ci;

#zs# Write mysys error messages to the error log. #fzs#

local_message_hook= error_log_print;

int ho_error;

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE

#zs#

Initialize the array of performance schema instrument configurations.

#fzs#

init_pfs_instrument_array();

#endif #zs# WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#

#zs#注: 这里跟过去发现还是在处理启动变量#fzs#

ho_error= handle_early_options();

#if !defined(_WIN32) && !defined(EMBEDDED_LIBRARY)

if (opt_bootstrap && opt_daemonize)

{

fprintf(stderr, "Bootstrap and daemon options are incompatible.n");

exit(MYSQLD_ABORT_EXIT);

}

if (opt_daemonize && log_error_dest == disabled_my_option &&

(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)))

{

fprintf(stderr, "Please enable --log-error option or set appropriate "

"redirections for standard output and/or standard error "

"in daemon mode.n");

exit(MYSQLD_ABORT_EXIT);

}

if (opt_daemonize)

{

if (chdir("/") < 0)

{

fprintf(stderr, "Cannot change to root director: %sn",

strerror(errno));

exit(MYSQLD_ABORT_EXIT);

}

if ((pipe_write_fd= mysqld::runtime::mysqld_daemonize()) < 0)

{

fprintf(stderr, "mysqld_daemonize failed n");

exit(MYSQLD_ABORT_EXIT);

}

}

#endif

#zs#注: 还是在处理启动变量。。。#fzs#

init_sql_statement_names();

sys_var_init();

ulong requested_open_files;

adjust_related_options(&requested_open_files);

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE

if (ho_error == 0)

{

if (!opt_help && !opt_bootstrap)

{

#zs# Add sizing hints from the server sizing parameters. #fzs#

pfs_param.m_hints.m_table_definition_cache= table_def_size;

pfs_param.m_hints.m_table_open_cache= table_cache_size;

pfs_param.m_hints.m_max_connections= max_connections;

pfs_param.m_hints.m_open_files_limit= requested_open_files;

pfs_param.m_hints.m_max_prepared_stmt_count= max_prepared_stmt_count;

PSI_hook= initialize_performance_schema(&pfs_param);

if (PSI_hook == NULL && pfs_param.m_enabled)

{

pfs_param.m_enabled= false;

sql_print_warning("Performance schema disabled (reason: init failed).");

}

}

}

#else

#zs#

Other provider of the instrumentation interface should

initialize PSI_hook here:

- HAVE_PSI_INTERFACE is for the instrumentation interface

- WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation

of the interface,

but there could be alternate implementations, which is why

these two defines are kept separate.

#fzs#

#endif #zs# WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#

#ifdef HAVE_PSI_INTERFACE

#zs#

Obtain the current performance schema instrumentation interface,

if available.

#fzs#

if (PSI_hook)

{

PSI *psi_server= (PSI*) PSI_hook->get_interface(PSI_CURRENT_VERSION);

if (likely(psi_server != NULL))

{

set_psi_server(psi_server);

#zs#

Now that we have parsed the command line arguments, and have initialized

the performance schema itself, the next step is to register all the

server instruments.

#fzs#

init_server_psi_keys();

#zs# Instrument the main thread #fzs#

PSI_thread *psi= PSI_THREAD_CALL(new_thread)(key_thread_main, NULL, 0);

PSI_THREAD_CALL(set_thread_os_id)(psi);

PSI_THREAD_CALL(set_thread)(psi);

#zs#

Now that some instrumentation is in place,

recreate objects which were initialised early,

so that they

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值