Mysql 体系结构系列之七

本文深入探讨MySQL的核心模块,包括初始化参数模块、连接管理器和线程管理器。初始化参数模块主要在sql/mysqld.cc中,如init_common_variables()等。连接管理器通过handle_connections_sockets()监听并处理客户端连接。线程管理器使用THD类跟踪线程,确保每个连接都有相应处理线程。随着版本更新,如3.23引入线程缓存,4.1和5.0对THD类进行重大改造以支持新特性。
摘要由CSDN通过智能技术生成

前言:参考Mysql体系结构系列之六:核心模块之间的交互

http://blog.csdn.net/nature_ann/article/details/9792561

 

1. 细看核心模块 Detailed Look at the Core Modules

1.1 Server Initialization Module 初始化参数模块

<<------第一,初始化参数模块:负责服务器初始化--sql/mysqld.cc—main() ------>>

The Server Initialization Module is responsible for the server initialization on startup.

Most of the code is found in the filesql/mysqld.cc.

服务器初始化模块负责在启动时完成服务器的初始化。大部分的代码可在sql/mysqld.cc文件中找到。

 

The entry point is what a C/C++ programmer would expect:main( ).Some other functions of interest follow.

入口点是C/C++程序员所预期的主函数:main().还有其他一些相关的函数。

 

If the file is not mentioned, the location issql/mysqld.cc:

>>init_common_variables( )

>>init_thread_environment( )

>> init_server_components( )

>>grant_init( ) insql/sql_acl.cc

>>init_slave( ) insql/slave.cc

>>get_options( )

如何没有到文件,则位置是sql/mysqld.cc: (

init_common_variables( ), init_thread_environment( ), init_server_components( ), grant_init( ) insql/sql_acl.cc, init_slave( ) in sql/slave.cc, get_options( )

)

 

Although the code found in version 3.22 wasnever rewritten from scratch, it has

been significantly refactored as new features were added to MySQL.

虽然3.22中的代码从没有被彻底重写过,但是在Mysql添加新的功能时,却被大幅度重构。

 

One big chunk of initialization code that used to be under main( ) got reorganized gradually into a number of helper functionsover the lifetime of the code.

在代码的生命周期内,曾经属于main()函数的一大段初始化代码经过重新组织,逐渐的成为各种辅助函数。

 

Additionally, the command line and configuration file option parsing got switched from theGNU getopt( ) to theMySQL Core API option parser once it became available in version 4.0.

此外,自从4.0版本中出现mysql核心API选项解析器后,命令行和配置文件选项解析发生了转换,即从GNU getopt()切换到Mysql核心API选项解析器。

 

In version 5.1, a significant portion was added toinit_server_components( ) forplugin initialization.

在5.1的版本中,init_server_components()增加了一个重要的部分,用于进行插件初始化。

 

Overall, this area of the code is fairly stable. Based on the past history, we should  anticipate possibleincremental additions in the future as new features that require  special initialization on startup are added.

总体上来讲,这部分代码相当稳定。根据以往的历史,一些启动时需要执行特殊初始化的新功能的添加,我们可以期待以后添加更多的插件。

 

However, a rewrite of this code isunlikely.

不过,重写这部分代码是不可能的。

1.2 Connection Manager 连接管理器模块

<<---第二,连接管理模块:派发给线程管理器—handle_connections_scockets()----->>

The Connection Manager listens for incoming connections fromclients, and dispatches the requests to the Thread Manager.

连接管理器侦听来自客户端的连接,然后将请求派发给线程管理器。

 

This module is really just one function in sql/mysqld.cc: handle_connections_sockets().

这个模块只有一个函数handle_connections_sockets().

 

However, it deserves to be classified as a separate module due to its critical role in the operation of the server.

不过,由于在服务器运行中发挥了重要的作用,值得将它作为一个独立的模块归类。

 

The abundance of#ifdef directives speaks to the challenge of porting networking code to a variety of operating systems.

但是由于大量的#ifdef指令的存在,对于把网络代码移植到不同操作系统时会带来困难。

 

Over time, the code evolved somewhat to accommodate quirks in the network system calls of different operating systems.

随着时间的推移,代码逐渐演变,逐步的开始可以实现不同操作系统的网络系统调用的功能。

 

Further changes might be necessary in the future as new ports are attempted, or as the differentoperating system vendors introduce new quirks into new versions of their products.

人们不断尝试进行新的移植,未来可能有必要进行新的修改。不同的操作系统供应商将新特性引入到产品的新版本中来。

1.3  Thread  Manager线程管理器模块

<<---第三,线程管理模块:负责跟踪线程,处理客户端连接--sql/mysqld.cc-THD----->>

The Thread Manager is responsible for keeping track of threadsand for making sure

a thread is allocated to handle the connection from aclient.

线程管理器负责跟踪线程,确保分配线程处理来自客户端的连接。

 

This is another verysmall module. Most of the code is found in sql/mysqld.cc.

这是另一种非常小的模块,大部分代码都位于sql/mysqld.cc中。

 

The entry point iscreate_new_thread( ). Another function of interest isstart_cached_thread( ), defined in the same file.

入口点是create_new_thread().另一个有关函数是start_cached_thread(),在同一个文件中定义。

 

One could perhaps consider the THD class defined in sql/sql_class.h and implemented insql/sql_class.cc as a part of this module.

有人可能认为THD类是在sql/sql_class.h中定义,在sql/sql_class.cc中实现,是本模块的组成部分。

 

Objects of the THD type are thread descriptors,and are critical in the operation of most of the server modules.

THD类型的对象是线程描述符,对于大多数的服务器模块的运行是不可忽视的。

 

Many functions take aTHD pointer as their first argument.

许多函数都将THD指针作为他们的第一个参数。

 

The thread management code was significantly reworked in version 3.23 when the  thread cachewas added.

3.23版中增加线程高速缓存时,对线程管理代码进行了重大改写。

 

Since then it has not beenchanged significantly. It is reasonable to expect that it will not receive any significantchanges in the future.

从那以后就没有大幅度的改变过,基于此,有理由相信以后也不会发生很大的改变。

 

However, if we, in our abstraction, consider theTHD class itself as part of this module,we have a different story as far as changes are concerned.

然而,如果按照我们的抽象思维,讲THD类本身看做是该模块的组成部分,则就改变而言将会有不同的说法。

 

The addition of new featuressuch as prepared statements, server-side cursors, and stored procedures led to a significant rework of THD in versions 4.1 and 5.0.

新功能的增加,诸如预处理语句、服务器端光标以及存储过程,这些导致4.1版和5.0版对THD进行了大量修改。

 

It is now a super-class of theQuery_arena, Statement,Security_context, and Open_tables_state classes, which are also defined in sql/sql_class.h.

现在它是Query_arena, Statement, Security_context以及Open_tables_state等类的超类,也在sql/sql_class.h中定义。

 

 

待续。。。。。。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值