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/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM