TokuDB調研文檔


另見連接:http://note.youdao.com/share/?id=77dd1e9cc139b57586665f702467c56a&type=note
 
安裝
安裝主要包括兩種方法:1)rpm安裝  2)源碼編譯
 
1. rpm安裝
此方式是比較簡單的方式,按照Percona安裝說明文檔指示的方法操做便可。
首先安裝 Percona yum repository  : 
sudo rpm -i percona-release-0.0-1.x86_64.rpm
接下來安裝Percona-Server-tokudb-56.x86_64
sudo yum install Percona-Server-tokudb-56.x86_64
在這一步安裝過程當中,安裝程序會向屏幕輸出不少信息,可根據具體信息查找問題或直接success。tokudb和mysqld存在衝突,強烈建議使用rpm包安裝時機器上不存在mysqld,不然會報錯。
 
安裝好後,就能夠啓動mysqld_safe,而後能夠正常訪問mysqld。
 
2.  源碼編譯
Percona的tokudb是以一個單獨的包進行發佈的,所以源碼編譯須要分別安裝Percona 5.6.19和tokudb 
5.6.19咱們已經在gitlab上放了一份代碼(內部地址,略去)
選擇其中的percona-server-5.6.17-66.0.tokudb.tar.gz,下載後解壓縮,將其中的storage/tokudb放到Mysql相關目錄。
 
編譯時cmake須要指定DWITH_TOKUDB_STORAGE_ENGINE=1,而後執行make /make install。
 
編譯tokudb須要gcc版本大於4.8,cmake版本大於2.8.9,請自行折騰。
 
 
使用TokuDB存儲引擎
tokuDB默認是使用Module方式編譯的,所以在使用前須要首先Install,具體方式以下:
INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';
後續經過
show engines/show plugins/ select @@tokudb_version 就能夠看到tokudb相關的內容。
 
 
建表
在install相關so以後,能夠直接建立tokudb類型的表,Percona給出了一個 例子,看起來和建立innodb的表沒有什麼區別。
mysql> CREATE TABLE `City` (
 `ID` int(11) NOT NULL AUTO_INCREMENT,
 `Name` char(35) NOT NULL DEFAULT '',
 `CountryCode` char(3) NOT NULL DEFAULT '',
 `District` char(20) NOT NULL DEFAULT '',
 `Population` int(11) NOT NULL DEFAULT '0',
 PRIMARY KEY (`ID`),
 KEY `CountryCode` (`CountryCode`)
) ENGINE=TokuDB
也能夠將其餘存儲引擎的表修改爲tokudb:
mysql> ALTER TABLE City ENGINE=TokuDB;
經確承認以在innodb和tokudb兩個存儲引擎之間相互轉換。
 
 
同一事務內對不一樣存儲引擎表進行操做
經測試,同一個事務內能夠對innodb/tokudb分別進行操做,以下:
mysql> insert into City_tokudb(ID) values(1);
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into City_innodb(ID) values(1);
Query OK, 1 row affected (0.00 sec)
 
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
 
mysql> insert into City_innodb(ID) values(2);
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into City_tokudb(ID) values(2);
Query OK, 1 row affected (0.00 sec)
 
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
 
mysql> select * from City_innodb;
+----+------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+------+-------------+----------+------------+
| 1 | | | | 0 |
| 2 | | | | 0 |
+----+------+-------------+----------+------------+
2 rows in set (0.00 sec)
 
mysql> select * from City_tokudb;
+----+------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+------+-------------+----------+------------+
| 1 | | | | 0 |
| 2 | | | | 0 |
+----+------+-------------+----------+------------+
2 rows in set (0.00 sec)
 
複製相關
因爲binlog和存儲引擎是相互獨立的,所以理論上覆制不該受到TokuDB的影響。此處,以常規的主備搭建爲基礎,在主庫上對TokuDB的表分別執行建表,增刪改查操做,並在備庫上確認複製數據無誤。
常規的主備搭建流程參見:
 
主庫執行的操做:
mysql> CREATE TABLE `City_repl` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`) ) ENGINE=TokuDB;
Query OK, 0 rows affected (0.01 sec)
 
mysql> insert into City_repl(ID) values(1);
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into City_repl(ID) values(2);
Query OK, 1 row affected (0.00 sec)
 
mysql> delete from City_repl where ID=1;
Query OK, 1 row affected (0.00 sec)
 
mysql> update City_repl set ID=3 where ID=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
相應的備庫同步執行查詢結果以下:
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| City_repl |
+----------------+
1 row in set (0.00 sec)
 
mysql> select * from City_repl;
+----+------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+------+-------------+----------+------------+
| 1 | | | | 0 |
| 2 | | | | 0 |
+----+------+-------------+----------+------------+
2 rows in set (0.00 sec)
 
mysql> select * from City_repl;
+----+------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+------+-------------+----------+------------+
| 2 | | | | 0 |
+----+------+-------------+----------+------------+
1 row in set (0.00 sec)
 
mysql> select * from City_repl;
+----+------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+------+-------------+----------+------------+
| 3 | | | | 0 |
+----+------+-------------+----------+------------+
 
可見簡單的針對TokuDB的增刪改查操做,備份是能夠正常工做的。
 
備份相關
Percona Xtrabackup當前並不支持TokuDB tables的備份,從Percona官方觀點來看,其在近期內也並無支持TokuDB的計劃。
TokuDB企業版提供Hot Backup的方案,其實現原理參見: TokuDB Hot Backup – Part 1   TokuDB Hot Backup – Part 2, 固然這不會是咱們考慮的方案。
Percona推薦使用LVM或是mysqldumper來備份TokuDB表,而網易在《程序員》上發表的一篇文章中提到其使用mysqldump對TokuDB進行備份。
 
參考連接
1)Percona版本安裝說明文檔:
2)Official TokuDB Documentation
3)TokuDB在網易生產環境中的應用實踐
4)TokuDB一些源碼分析(from @淘寶一工)
5)Percona Server 5.6.16-64.0 with TokuDB engine now available
http://www.mysqlperformanceblog.com/2014/03/03/percona-server-5-6-16-64-0-with-tokudb-engine-now-available/
相關文章
相關標籤/搜索