代碼分析基于最新的5.5.21
Mysql服務(wù)器的main()在/sql/main.cc,實(shí)際的入口點(diǎn)在/sql/mysqld.cc。
我們直接從mysqld_main()開(kāi)始閱讀。
先理解一些比較重要的宏定義:
(1)宏HAVE_NPTL:
這個(gè)宏如果打開(kāi)了會(huì)去讀一個(gè)系統(tǒng)變量LD_ASSUME_KERNEL,并把他賦給一個(gè)全局變量ld_assume_kernel_is_set,這個(gè)系統(tǒng)變量設(shè)置了系統(tǒng)線(xiàn)程的實(shí)現(xiàn)模型。linux內(nèi)核在2.6版本后,缺省的線(xiàn)程模型是NPTL。-
http://www.linuxidc.com/Linux/2012-03/56277.htm 詳細(xì)情況請(qǐng)閱讀我博客里的這篇文章。
對(duì)于以HAVE_前綴的的宏,另有如下文章闡述:
http://www.linuxidc.com/Linux/2012-03/56278.htm 這里介紹了CMake的相關(guān)知識(shí),通過(guò)CMake在影子編譯目錄的include目錄里面生成了my_config.h文件。
my_config.h文件通過(guò)my_global.h文件包含到具體的需要使用HAVE_前綴的宏的源文件中。
(2)EMBEDDED_LIBRARY
該宏用于控制 嵌入式庫(kù)和客戶(hù)端/服務(wù)器版本不同的那部分代碼。
Mysql 可以編譯為一個(gè)libmysqld庫(kù)(嵌入式服務(wù)器),使用嵌入式MySQL服務(wù)器庫(kù),能夠在客戶(hù)端應(yīng)用程序中使用具備全部特性的MySQL服務(wù)器。
主要優(yōu)點(diǎn)在于,增加了速度,并使得嵌入式應(yīng)用程序的管理更簡(jiǎn)單。嵌入式服務(wù)器庫(kù)是以MySQL的客戶(hù)端/服務(wù)器版本為基礎(chǔ)的,采用C/C++語(yǔ)言編寫(xiě)。 其結(jié)果是嵌入式服務(wù)器也是用C/C++語(yǔ)言編寫(xiě)的。 在其他語(yǔ)言中,嵌入式服務(wù)器不可用。
這個(gè)宏可以通過(guò)CMake配置,
-DWITH_EMBEDDED_SERVER=1 打開(kāi)這個(gè)宏
在plug.cmake函數(shù)里有它的定義:
PROPERTIES COMPILE_DEFINITIONS "MYSQL_SERVER;EMBEDDED_LIBRARY")
整個(gè)代碼的流程如下:我們講分更細(xì)的文章詳細(xì)介紹每部分:
Mysql服務(wù)器監(jiān)聽(tīng):
Mysql 源代碼的目錄結(jié)構(gòu) :(以下來(lái)自官方文檔)
/BUILD The compilation configuration and make files for all platforms supported.
Use this folder for compilation and linking.
/client The MySQL command-line client tool.
/dbug Utilities for use in debugging (see Chapter 5 for more details).
/Docs Documentation for the current release. Linux users should usegenerate-text-files.pl in the support subfolder to generate the documentation. Windows users are provided with a manual.chm file.
/include The base system include files and headers.
/libmysql The C client API used for creating embedded systems. (See Chapter 6 formore details.)
/libmysqld The core server API files. Also used in creating embedded systems.(See Chapter 6 for more details.)
/mysql-test The MySQL system test suite. (See Chapter 4 for more details.)
/mysys The majority of the core operating system API wrappers and helper functions.
/regex A regular expression library. Used in the query optimizer and execution to resolve expressions.
/scripts A set of shell script-based utilities.
/sql The main system code. You should start your exploration from this folder.
/sql-bench A set of benchmarking utilities.
/SSL A set of Secure Socket Layer utilities and definitions.
/storage The MySQL pluggable storage engine source code is located inside this folder. Also included is the storage engine example code. (See Chapter 7 for more details.)
/strings The core string handling wrappers. Use these for all of your string handling needs.
/support-files A set of preconfigured configuration files for compiling with different options.
/tests A set of test programs and test files.
/vio The network and socket layer code.
/zlib Data compression tools.
本文出自:億恩科技【www.riomediacenter.com】
服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|