MySQL原始碼閱讀筆記:代碼流程

來源:互聯網
上載者:User

程式碼分析基於最新的5.5.21

Mysql伺服器的main()在/sql/main.cc,實際的進入點在/sql/mysqld.cc。

我們直接從mysqld_main()開始閱讀。

先理解一些比較重要的宏定義:

(1)宏HAVE_NPTL:

這個宏如果開啟了會去讀一個系統變數LD_ASSUME_KERNEL,並把他賦給一個全域變數ld_assume_kernel_is_set,這個系統變數設定了系統線程的實現模型。linux核心在2.6版本後,預設的執行緒模式是NPTL。

    詳細情況請閱讀我部落格裡的這篇文章。

對於以HAVE_首碼的的宏,另有如下文章闡述:

  這裡介紹了CMake的相關知識,通過CMake在影子編譯目錄的include目錄裡面產生了my_config.h檔案。

my_config.h檔案通過my_global.h檔案包含到具體的需要使用HAVE_首碼的宏的源檔案中。

(2)EMBEDDED_LIBRARY

該宏用於控制  嵌入式庫和用戶端/伺服器版本不同的那部分代碼。

Mysql 可以編譯為一個libmysqld庫(嵌入式伺服器),使用嵌入式MySQL伺服器庫,能夠在用戶端應用程式中使用具備全部特性的MySQL伺服器。

主要優點在於,增加了速度,並使得嵌入式應用程式的管理更簡單。嵌入式伺服器庫是以MySQL的用戶端/伺服器版本為基礎的,採用C/C++語言編寫。 其結果是嵌入式伺服器也是用C/C++語言編寫的。 在其他語言中,嵌入式伺服器不可用。

這個宏可以通過CMake配置,

-DWITH_EMBEDDED_SERVER=1 開啟這個宏

在plug.cmake函數裡有它的定義:

PROPERTIES COMPILE_DEFINITIONS "MYSQL_SERVER;EMBEDDED_LIBRARY")

整個代碼的流程如下:我們講分更細的文章詳細介紹每部分:

Mysql伺服器監聽:

Mysql 原始碼的目錄結構 :(以下來自官方文檔)

/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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.