標籤:mmap 返回 blog public 目的 字元 span ora 簡單
一直想分析下mysql的源碼,開始的時候不知道從哪下手,先從csv的檔案儲存體開始吧,這個還是比較簡單的。我是用的是mysql5.7.16版本的源碼。
csv源碼檔案在mysql源碼的mysql-5.7.16\storage\csv檔案夾下,這裡面除了一個make檔案,剩下的四個檔案就是csv的儲存讀取代碼。
transparent_file.h/cc檔案比較簡單,只定義了一個Transparent_file類,目的是從指定的檔案中讀取資料到緩衝中。
class Transparent_file{ File filedes; uchar *buff; /* in-memory window to the file or mmaped area */ /* current window sizes */ my_off_t lower_bound;//檔案位移開始位置 my_off_t upper_bound;//檔案位移結束位置 uint buff_size;//快取檔案的長度public: Transparent_file(); ~Transparent_file(); void init_buff(File filedes_arg);//從檔案中讀取資料到記憶體緩衝中 uchar *ptr();//返回記憶體緩衝指標 my_off_t start(); my_off_t end(); char get_value (my_off_t offset); my_off_t read_next();//讀取下一段};
1.Transparent_file建構函式,根據buff_size和字元的大小申請了指定長度的空間,只是申請,沒有初始設定檔案中的資料。
2.init_buff函數的作用是從指定檔案中負載檔案內容到緩衝中。
3.read_next從檔案中下一個buff_size長度的內容放到緩衝中,並重寫lower_bound和upper_bound的值。
4.get_value從檔案中讀取指定位置長度為buff_size的資料,放到緩衝中。
未完待續。。。
Mysql源碼分析--csv儲存引擎