19. 本日の流れ
1. Yahoo JAPAN! のMySQL 利用事例
2. ストリーム処理の利点
3. Binlog Events を検証してみた
1. サンプルコード解説
2. 更新内容を取り出す方法
3. ありそうで、なかった機能
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
19
20. MySQL Binlog Events
• バイナリログを用いたストリーム処理ができる
• MySQL Labs で公開中(2015/12現在)
• 昔はBinlog APIっていうやつがあったらしい
• C++ libraries
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
20
25. CHANGE LOG
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
25
############################
ChangeLog for Binary Log API
############################
Release 0.1.0 (released April 20, 2013)
---------------------------------------
* BAPI-1: In the binlog-replication-listener library,
mysql::Binary_log::connect function does not abort when
non-existent file name or server is provided
29. basic-1 のソース - 接続方法
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
29
Binary_log_driver *drv= create_transport(argv[1]);
if (drv == NULL)
return 1;
Binary_log binlog(drv);
if (binlog.connect() != ERR_OK)
{
delete drv;
return 1;
}
URIを渡して接続URIを渡して接続
30. basic-1 を動かしてみる
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
30
$ ./basic-1 mysql://root:Password123_@localhost:3306
Found event of type 2
Found event of type 19
Found event of type 30
mysql> CREATE TABLE `mytable` ~
mysql> INSERT INTO mytable (v1) VALUES('abc');
31. イベントとは
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
31
QueryQuery BEGINBEGIN
Table_MapTable_Map 処理する対象テーブルの指定処理する対象テーブルの指定
Write_rowsWrite_rows INSERT INTO ~INSERT INTO ~
Update_rowsUpdate_rows UPDATE ~UPDATE ~
• 1つのトランザクションは複数イベントで構成
• 「Table_Map」や「Rotate」など特殊なイベン
トもある
イベントタイプ イベント内容(イメージ)
トランザクション
POS
POS
POS
POS
32. EVENT_TYPE 一覧
Unknown
Start_v3
Query
Stop
Rotate
Intvar
Load
Slave
Create_file
Append_block
Exec_load
Copyright (C) 2015 Yahoo Japan Corporation. All Rights Reserved. 無断引用・転載禁止
32
Delete_file
New_load
RAND
User var
Format_desc
Xid
Begin_load_query
Execute_load_query
Table_map
Write_rows_event_old
Update_rows_event_old
Delete_rows_event_old
Write_rows_v1
Update_rows_v1
Delete_rows_v1
Incident
Heartbeat
Ignorable
Rows_query
Write_rows
Update_rows
Delete_rows
Gtid
Anonymous_Gtid
Previous_gtids
User Defined