SlideShare ist ein Scribd-Unternehmen logo
1 von 85
Downloaden Sie, um offline zu lesen
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |
進化を続けるMySQLのド定番機能
MySQLレプリケーション最新機能
日付:2016/07/14
日本オラクル株式会社
MySQL Global Business Unit
Yoshiaki Yamasaki / 山﨑 由章
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。
また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはでき
ません。以下の事項は、マテリアルやコード、機能を提供することをコミットメントするも
のではない為、購買決定を行う際の判断材料になさらないで下さい。
オラクル製品に関して記載されている機能の開発、リリースおよび時期については、
弊社の裁量により決定されます。
2
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQLのレプリケーション機能
3
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションとは?
• データの複製(レプリカ)を別のサーバーに持てる機能
• MySQLの標準機能で、多数のWebサイト等で利用されている
– シンプルな設定で利用可能
– マスター→スレーブ 構成
4
M S
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションとは?
• マスターサーバー
– データを変更
– 変更内容をスレーブに転送
• スレーブサーバー
– マスターでの変更内容を受け取る
– 変更内容をデーターベースに反映
5
M S
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6
レプリケーション構成
M M/S S
S
S
S
M
S
M
M
サーバはマスター、スレーブまたは両方になれる
マスターは複数のスレーブを持てる
スレーブは複数のマスターを持てる ※MySQL 5.7以降
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションの利点:参照性能の向上
• 参照処理の負荷が高い場合は、スレーブサーバーを追加することで、
負荷分散による性能向上が実現できる
7
M S S
S
S
M
更新処理 参照処理
参照処理
更新処理
参照処理
の増加→
スレーブ
追加
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションの利点:高可用性構成の実現
• マスターの障害時に、スレーブをマスターに昇格することで
高可用性を実現可能
8
C
B
A
C
B
ACrash
C
B
A
Bが新しい
マスターに
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションの利点:地理的冗長性の実現
• 地理的に離れた場所に、災害対策サイトを構築可能
9
CA
BCAB
Image from
www.ginkgomaps.com
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
M
S
更新処理
BI(ビジネスインテリジェンス)や
レポート生成アプリ、データ分析アプリ、
バックアップ取得、など
10
レプリケーションの利点:レポート生成やバックアップ取得
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションの仕組み
• スレーブからレプリケーション開始
• バイナリログの内容をスレーブに転送し、実行
11
create …
insert …B
binary log
create …
insert …A
binary log
Client 1. スレーブがレプリケーションの
開始をマスターにリクエスト
2. マスターがレプリケーション
データをスレーブに転送
create …
insert …
relay log
3. リレーログの内容を
スレーブに適用
※log-slave-updatesを設定している場合、
スレーブでもバイナリログを出力
(多段構成のレプリケーション時必須)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
スレーブ上に存在するファイル、スレッド
• ファイル
– リレーログファイル:マスターから受信した変更点を記録したファイル
– バイナリログファイル:スレーブで実行した変更点を記録したファイル
(log-slave-updatesを有効にしている場合のみ出力)
– master.info:マスターへの接続に必要な情報や、読み取りを開始する
バイナリログの位置情報(バイナリログファイル名とポジション)が
記録されているOS上のファイル。(MySQL 5.6からテーブル内に格納可能)
– relay-log.info:リレーログをどこまで適用したかを記録しているOS上のファイル
(MySQL 5.6からテーブル内に格納可能)
• スレッド
– I/Oスレッド:マスターから受信したバイナリログをリレーログファイルとして保存
– SQLスレッド:リレーログファイル内の更新内容をDBへ反映する
12
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13
イメージ図
B
binary log
Position 100 create …
Position 200 insert
Position 300 insert
A
binary log 001
Client
I/Oスレッド
relay log 001
SQLスレッド
master.info
Position 100 create …
Position 200 insert …
Position 100 create
・マスターはA
・001のPosition 200
まで受信した
Position 100 insert …
Position 200 insert
binary log 002
relay-log.info
・001のPosition 100
まで適用した
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL 5.7 でのレプリケーション強化点
14
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTID(Global Transaction Identifiers)のオンラインでの設定
• GTIDの設定変更がオンラインに
– GTIDの設定変更(onまたはoff)の変更中も参照更新可能
• サーバ間でのデータ同期不要
• サーバ再起動不要
• レプリケーション構成の変更不要
– 任意のレプリケーション構成で利用可能
• 運用中にGITDの利用開始または停止が可能
15
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーションのフィルタをオンラインで変更
• スレーブのレプリケーションフィルタを動的に変更
– スレーブサーバの再起動不要
– 全てのスレーブでのフィルタをサポート
– 各種の文字コードによる値の設定が可能
16
mysql> CHANGE REPLICATION FILTER REPLICATE_DO_DB= (db1, db2)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17
マスターをAからBへの切り替える際にSQLスレッドの停止不要
新マスターへの切り替え/フェールオーバーをオンラインで
C
B
A
C
B
A障害発生
C
B
A
障害発生 構成変更
マスターをAからBに切り替えるために
DBAはCのリレーログの内容をデータに
反映する処理を停止する必要はない
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
レプリケーション監視の改善
• SQL文にて監視
• 意味の異なる情報は別々の場所に格納
• 拡張可能, 新しい機能との連携
• より正確で一貫性のある識別子の名称
• マスター/スレーブ、マルチソース、グループレプリケーション対応
18
Performance SchemaのReplication関連テーブル
※一部の情報は、Performance Schemaに追加できていません。詳細はこちらを参照下さい。
SHOW SLAVE STATUS Information Not In the Replication Tables
http://dev.mysql.com/doc/refman/5.7/en/performance-schema-replication-tables.html#idm140061595817488
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19
SQLスレッドの性能向上 – ロックベースの並列処理
Single Threaded Apply 8 Threads Applier 24 Threads Applier 48 Threads Applier 96 Threads Applier
0%
50%
100%
150%
200%
250%
Fast and Scalable Multi-threaded Replication Applier
(statement-based replication, durable settings, SSD storage)
Slaveapplytime
(SysbenchRWonthemasterwith96threads=100%)
10X
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
SQLスレッドの性能向上 – ロックベースの並列処理
• 文(STATEMENT)ベースおよび行(ROW)ベースの両フォーマット対応
• スケジュールのポリシーは下記コマンドで制御:
– logical_clock – ロックのタイムスタンプを通じてスケジューリング
– database – 5.6と同様のスケジューリング (データベースが異なれば並列実行)
• スレーブの性能拡張性は引き続き改良!
20
mysql> SET slave_parallel_type= [logical_clock|database]
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
ユーザスレッドとSenderスレッドの同期の改善
• バイナリログに対するユーザスレッドでの書き込みと
Senderスレッドでの読み込みを並列化
– Senderスレッドによるユーザセッション処理のブロックを最小化
– ユーザセッションとSenderスレッドのスループットを向上
21
Sender Thread Reads Binary Log User Thread Writes to Binary Log
Sender Thread Reads Binary Log
User Thread Writes to Binary Log
5.7.2以前
5.7.2+
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Senderスレッドの高速化
• アロケートされた送信バッファを毎回解放しないように変更
• より大きな送信バッファが必要な場合は、その際に拡張
• 拡張された送信バッファが使われなくなると動的に縮小
• MySQL 5.7.2でのSenderスレッドの改良:
– マスターの性能拡張性の向上;
– リソース消費の削減 (CPU);
– 負荷のピーク時のマスター特にDumpスレッドの処理負荷の軽減
22
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
準同期レプリケーションの高速化 – ACK Receiverスレッド
• 連続したトランザクションがスレーブからのACKをお互いに待たない
– トランザクションt1とt2を同時にSenderスレッドがスレーブに送る
– それぞれのACKを別のスレッドが受け取る
– t2の準同期のレイテンシにはt1の処理によるレイテンシは含まれない
• 準同期レプリケーション有効時にスレッドが開始される
• 準同期レプリケーション無効時にスレッドが停止される
23
mysql> SET GLOBAL rpl_semi_master_enabled= ON
mysql> SET GLOBAL rpl_semi_master_enabled= OFF
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Loss-less準同期レプリケーション
• マスターはスレーブからのACKを受け取ってからコミット
(5.6まではコミット後にスレーブに処理を転送)
– 他のトランザクションはACK待ちの間は該当トランザクションによる変更は見えない
• マスターに障害が発生した際でも、スレーブに転送されたトランザクション
のみが他のトランザクションから見える状態
• MySQL 5.6までの挙動か新しいLoss-lessを選択可能
24
mysql> SET rpl_semi_sync_master_wait_point= [AFTER_SYNC|AFTER_COMMIT]
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
準同期レプリケーション – 複数ACKを待つ
• 指定したN台のスレーブからACKを受信するまでコミットを行わない
• 動的に設定可能:
25
mysql> SET GLOBAL rpl_semi_sync_master_wait_for_slave_count= N
Master
Slave 2
T1: COMMIT
ACK
Slave 1
ACK
T1: COMMIT
succeeds
mysql> SET GLOBAL rpl_semi_sync_master_wait_for_slave_count= 2
Slave 3
Time
relay log
relay log
relay log
ACK
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTIDをテーブルに格納
• バイナリログを有効にしていないスレーブでもGTIDを利用可能
– マスターに昇格する予定のないスレーブでもGTIDを利用した
auto positioning(自動的にトランザクションの進捗を見つける仕組み)を利用可能
26
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 27
マルチソースレプリケーション
S
M M 1台のスレーブが複数のマスターを持つ構成M M
1台のサーバにデータを集約する構成:
• バックアップを1台で実行;
• 分析用途の複雑なクエリの実行;
• クラスタ間レプリケーションのデータハブ
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
その他の改良点
• マルチスレッドのApplierスレッドで、失敗したトランザクションの再試行が可能
• マルチスレッドのApplierスレッドのコミット順を維持するオプション
• mysqlbinlogツールにSSLオプション
• mysqlbinlogにデータベース名のリライトルール適用可能
• 指定されたGTIDになるまでApplierスレッドの処理を一時的に停止する関数
– WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(gtid_set[, timeout][,channel])
– WAIT_FOR_EXECUTED_GTID_SET(gtid_set[, timeout])
• MySQLのクライアントサーバ間プロトコルにGITDの情報を返す
• バイナリログ利用時にもXAトランザクションをサポート
• デフォルト値の変更 例) binlog_format=ROW, sync_binlog=1
28
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Appendix
• MySQL 5.7でのレプリケーション強化点に関するより詳細な資料
– MySQL 5.7 レプリケーション最新機能とロードマップ
http://downloads.mysql.com/presentations/20151030_03_MySQL5.7_Replication_jp.pdf
29
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL グループ・レプリケーション
30
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
概要1
31
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32
MySQL グループ・レプリケーション
M M M M M
Replication Group
Clients
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL グループ・レプリケーション
• MySQL グループ・レプリケーションとは?
– どのノードでもデータ更新可能なレプリケーションプラグイン
– 自動的な競合処理、リカバリ、グループ・メンバーシップ
• MySQL グループ・レプリケーションの利点
– 障害発生時にフェイルオーバー不要
– フォールトトレラント
– どのノードでもデータ更新可能
– 自動的なグループ再構成(障害発生時、再接続時)
– レプリケートされた高可用性データベースを提供.
– 自動分散強調(スプリットブレインとメッセージの損失から保護)
– 少ない管理コスト
33
※2016年7月現在、GAになっていません。
今後Pluginとして追加リリースする予定です。
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
マルチマスター
MySQL グループ・レプリケーション2
2.1
34
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
マルチマスター、どこでも更新可能!
• 異なるサーバー上での2つのトランザクションは、同じデータを更新可能
• 競合が検出され、対処される
– 先にコミットしたトランザクションが優先される
35
M M M M M
UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
マルチマスター、どこでも更新可能!
• 異なるサーバー上での2つのトランザクションは、同じデータを更新可能
• 競合が検出され、対処される
– 先にコミットしたトランザクションが優先される
36
M M M M M
UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1
OKOK
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
マルチマスター、どこでも更新可能!
• 異なるサーバー上での2つのトランザクションは、同じデータを更新可能
• 競合が検出され、対処される
– 先にコミットしたトランザクションが優先される
37
M M M M M
UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
マルチマスター、どこでも更新可能!
• 異なるサーバー上での2つのトランザクションは、同じデータを更新可能
• 競合が検出され、対処される
– 先にコミットしたトランザクションが優先される
38
M M M M M
UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1
OK
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
グループレプリケーションでのコミット時の動作
• トランザクションコミット時は、グループ内の全サーバーと通信し、
データ競合が発生しているか否かを確認する
• 競合が発生していなければ、そのトランザクションはコミットされる
– 更新処理が実行され、バイナリログにGTIDと共に更新内容が記録される
※GTIDは、グループレプリケーションの全メンバーで共通
• 競合が発生していた場合は、そのトランザクションは取り消される
– 更新処理は実行されないため、バイナリログにも記録されない
39
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
グループレプリケーション使用時のバイナリログの内容
• test.t1テーブルに対して、server_id=1のサーバーからデータを更新した後、
server_id=2のサーバーからデータを更新した時のバイナリログ例
40
mysql> show binlog events in 'yyamasaki-bin.000004' from 2580;
+----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+
| yyamasaki-bin.000004 | 2580 | Gtid | 1 | 2641 | SET @@SESSION.GTID_NEXT= '0a06e216-1bdb-11e6-b1e0-080027ff56de:7' |
| yyamasaki-bin.000004 | 2641 | Query | 1 | 2700 | BEGIN |
| yyamasaki-bin.000004 | 2700 | Table_map | 1 | 2741 | table_id: 108 (test.t1) |
| yyamasaki-bin.000004 | 2741 | Write_rows | 1 | 2777 | table_id: 108 flags: STMT_END_F |
| yyamasaki-bin.000004 | 2777 | Xid | 1 | 2804 | COMMIT /* xid=42 */ |
| yyamasaki-bin.000004 | 2804 | Gtid | 2 | 2865 | SET @@SESSION.GTID_NEXT= '0a06e216-1bdb-11e6-b1e0-080027ff56de:8' |
| yyamasaki-bin.000004 | 2865 | Query | 2 | 2929 | BEGIN |
| yyamasaki-bin.000004 | 2929 | Table_map | 2 | 2970 | table_id: 108 (test.t1) |
| yyamasaki-bin.000004 | 2970 | Write_rows | 2 | 3006 | table_id: 108 flags: STMT_END_F |
| yyamasaki-bin.000004 | 3006 | Xid | 2 | 3033 | COMMIT /* xid=49 */ |
+----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+
10 rows in set (0.00 sec)
GTIDが増えているどのサーバーから実行された
トランザクションか判断可能
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
マルチマスター
MySQL グループ・レプリケーション2
2.1
2.2
41
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーがグループに参加すると自動的に他のサーバーと同期する
42
M M M M M N
グループに参加
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーがグループに参加すると自動的に他のサーバーと同期する
43
M M M M M N
オンライン
同期
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーがグループに参加すると自動的に他のサーバーと同期する
44
M M M M M N
オンライン
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーがグループから外れると、他のサーバーは自動的に検知する
45
M M M M M M
メンテナンスや
システムクラッシュが発生
各メンバーシップの設定は論理的な
タイムスタンプ(view_id)によって識別される
view_id: 4
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーがグループから外れると、他のサーバーは自動的に検知する
46
M M M M M
view_id: 5
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
自動分散型サーバー復旧
• サーバーが再びグループに参加すると、自動的に他のサーバーと同期する
47
M M M M M M
view_id: 6
同期 -> オンライン
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
データを同期する仕組み
• GTIDレプリケーションの仕組みでデータを同期する
– グループ内のメンバーのバイナリログから更新内容の差分を受取ってデータを
同期する為、同期に必要なバイナリログが欠損している場合は、リカバリ処理が
完了せずに、グループに参加できない
48
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
新しいサーバーをグループに追加した時のエラーログの例
• グループ参加後、view_idが増加している(1928434991:1 ⇒ 1928434991:2)
– 最初からグループに存在したサーバー:127.0.0.1:10301
– 後からグループに参加したサーバー:127.0.0.1:10302
49
2016-07-20T10:12:58.547649Z 0 [Note] Plugin group_replication reported: 'Starting group replication recovery with
view_id 1928434991:1'
[XCOM_BINDING_DEBUG] ::install_view():: View delivered to client handler= 1302998040
2016-07-20T10:12:58.549672Z 8 [Note] Plugin group_replication reported: 'Only one server alive. Declaring this
server as online within the replication group'
<中略>
[XCOM_BINDING_DEBUG] ::process_possible_control_message():: Received a control message
[XCOM_BINDING_DEBUG] ::process_possible_control_message():: From: 127.0.0.1:10302 regarding view_id:0:0
[XCOM_BINDING_DEBUG] ::process_possible_control_message()::Still waiting for more State Exchange messages
[XCOM_BINDING_DEBUG] ::xcom_receive_data_internal():: xcom_receive_data message_id.group= 2530263840
message_id.msgno= 20 message_id.node= 0
[XCOM_BINDING_DEBUG] ::process_possible_control_message():: Received a control message
[XCOM_BINDING_DEBUG] ::process_possible_control_message():: From: 127.0.0.1:10301 regarding view_id:1928434991:1
[XCOM_BINDING_DEBUG] ::process_possible_control_message()::Install new view
[XCOM_BINDING_DEBUG] ::install_view():: Processing exchanged data
[XCOM_BINDING_DEBUG] ::install_view():: Processing exchanged data
2016-07-20T10:13:42.438996Z 0 [Note] Plugin group_replication reported: 'Marking group replication view change with
view_id 1928434991:2'
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
MySQL グループ・レプリケーション2
2.1
2.2
2.3
50
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL/InnoDB look & feel
• プラグインをロードし、レプリケーションをスタート
• グループ・レプリケーションの状態をパフォーマンス・スキーマから確認
51
mysql> SET GLOBAL group_replication_group_name= "35e59895-4985-11e6-a684-080027ff56de";
mysql> START GROUP_REPLICATION;
mysql> SELECT * FROM performance_schema.replication_group_members¥G
*************************** 1. row ***************************
CHANNEL_NAME: group_replication_applier
MEMBER_ID: 35e59895-4985-11e6-a684-080027ff56de
MEMBER_HOST: yyamasaki
MEMBER_PORT: 3306
MEMBER_STATE: ONLINE
*************************** 2. row ***************************
CHANNEL_NAME: group_replication_applier
MEMBER_ID: 773452b2-498b-11e6-9915-080027ff56de
MEMBER_HOST: yyamasaki
MEMBER_PORT: 3307
MEMBER_STATE: ONLINE
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL/InnoDB look & feel
• プラグインをロードし、レプリケーションをスタート
• グループ・レプリケーションの状態をパフォーマンス・スキーマから確認
52
mysql> SELECT * FROM performance_schema.replication_group_member_stats¥G
*************************** 1. row ***************************
CHANNEL_NAME: group_replication_applier
VIEW_ID: 1928434991:2
MEMBER_ID: 35e59895-4985-11e6-a684-080027ff56de
COUNT_TRANSACTIONS_IN_QUEUE: 0
COUNT_TRANSACTIONS_CHECKED: 0
COUNT_CONFLICTS_DETECTED: 0
COUNT_TRANSACTIONS_VALIDATING: 0
TRANSACTIONS_COMMITTED_ALL_MEMBERS: 35e59895-4985-11e6-a684-080027ff56de:1-35
LAST_CONFLICT_FREE_TRANSACTION: 35e59895-4985-11e6-a684-080027ff56de:35
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL/InnoDB look & feel
• プラグインをロードし、レプリケーションをスタート
• グループ・レプリケーションの状態をパフォーマンス・スキーマから確認
53
mysql> SELECT * FROM performance_schema.replication_connection_status¥G
*************************** 1. row ***************************
CHANNEL_NAME: group_replication_applier
GROUP_NAME: 35e59895-4985-11e6-a684-080027ff56de
SOURCE_UUID: 35e59895-4985-11e6-a684-080027ff56de
THREAD_ID: NULL
SERVICE_STATE: ON
COUNT_RECEIVED_HEARTBEATS: 0
LAST_HEARTBEAT_TIMESTAMP: 0000-00-00 00:00:00
RECEIVED_TRANSACTION_SET: 35e59895-4985-11e6-a684-080027ff56de:3-9:13-14:16:30:33-35
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTIDサポート
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
MySQL グループ・レプリケーション2
2.1
2.2
2.3
2.4
54
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTIDサポート
• 全グループメンバーは同じUUID、グループ名を持つ
55
M M M M M
INSERT y;
Will have GTID: group_name:2
INSERT x;
Will have GTID: group_name:1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTIDサポート
• 全グループメンバーは同じUUID、グループ名を持つ
56
M M M M M
INSERT y;
Will have GTID: group_name:1
SET GTID_NEXT= “UUID:50”
INSERT x;
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
GTIDサポート
• グループ外のサーバーからグループにレプリケート可能
• GTIDは保たれる
57
M M M M M
競合も検出される
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
GTIDサポート
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
MySQL グループ・レプリケーション2
2.1
2.2
2.3
2.4
2.5
58
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
• オートインクリメント値は、グループ内のメンバーと同じ値を生成しないよう
に構成されている
59
M M M M M
INSERT y;
y: 4
INSERT z;
z: 11
INSERT x;
x: 1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
• デフォルトではオフセットはserver_idによって提供され、増分値は7
60
M M M M M
INSERT y;
y: 4
INSERT z;
z: 11
INSERT x;
x: 1
[1]: http://mysqlhighavailability.com/mysql-group-replication-auto-increment-configuration-handling/
server_id: 1
server_id: 4
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
• GROUP_REPLICATION_AUTO_INCREMENT_INCREMENTオプションで、
増分値を変更可能
61
M M M M M
INSERT y;
y: 4
INSERT z;
z: 11
INSERT x;
x: 1
server_id: 1
server_id: 4
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
GTIDサポート
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
新しい分散コミュニケーションエンジン
MySQL グループ・レプリケーション2
2.1
2.2
2.3
2.4
2.5
2.6
62
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
新しい分散コミュニケーションエンジン
• マルチOSサポート
– Linux, Windows, OSX, Solaris, FreeBSD…
• サードパーティソフトウェア不要
• ネットワークのマルチキャストサポート不要
– MySQL グループ・レプリケーションは、マルチキャストが使用できないクラウド環境で
も使用可能
• メッセージサイズの制限なし
• 追加プロセス無し
– MySQL グループ・レプリケーションは同じソフトウェアスタックに含まれる
63
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
GTIDサポート
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
新しい分散コミュニケーションエンジン
MySQL グループ・レプリケーション2
2.1
2.2
2.3
2.4
2.5
2.6
設計上の要件2.7
64
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
設計上の要件
• InnoDBのみをサポート
• 全テーブルに主キーが必要
• GTID有効
• 楽観実行
– 競合によって、トランザクションはabortされるかもしれないし、COMMITされるかも
しれない
– データ競合発生時は、先にCOMMITしたトランザクションが優先して確定される。
後からCOMMITしたトランザクションはabortされる。
⇒データ競合の発生は、トランザクションCOMMIT時に検知される
65
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
オートインクリメント値の設定/処理
GTIDサポート
MySQL/InnoDB look & feel
自動分散型サーバー復旧
マルチマスター
新しい分散コミュニケーションエンジン
MySQL グループ・レプリケーション2
2.1
2.2
2.3
2.4
2.5
2.6
設計上の要件
制限事項
2.7
2.8
66
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
制限事項
• オンラインでのスキーマ変更(オンラインDDL)はサポートされない
※スキーマ変更手順:以下の手順を全ノードに対して順番に実行する
1.グループから離脱
2.バイナリログの出力を停止して、DDLを実行
3.グループに参加
67
※(他の部分での説明内容も含め)あくまで2016年7月14日時点のLab版(実験版)での挙動です。
今後のリリースにおいて予告なく挙動が変更になる可能性があります。特にオンラインDDLついては、
開発チーム内でも、どのように対処すべきかディスカッションが継続されています。
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 68
アーキテクチャ
Introduction
3
3.1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
MySQL Group Replication is
• Built on top of proven technology!
– Shares much of MySQL Replication infrastructure – thence does not feel alien!
– Multi-Master approach to replication.
• Built on reusable components!
– Layered implementation approach.
– Interface driven development.
– Decoupled from the server core.
– The plugin registers as listener to server events.
– Reuses the capture procedure from regular replication.
– Provides further decoupling from the communication infrasctructure.
69
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 70
Major Building Blocks
アーキテクチャ
Introduction
3
3.1
3.2
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 71
Major Building Blocks (1)
M M M M M
Com. API
Replication
Plugin
API
MySQL
Server
Group Comm.
System (Corosync)
Group Com. Engine
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 72
Major Building Blocks (2)
• Server calls into the plugin through a generic
interface
– (Most of server) internals are hidden from the plugin.
– Some of the semi-sync interfaces were reused. Others
were deployed.
• Plugin interacts with the server through a
generic interface
– Replication plugin determines the fate of the commit
operation through a well defined server interface.
– The plugin makes use of the relay log infrastructure to
inject changes in the receiving server.
Com. API
Replication
Plugin
API
MySQL
Server
Group Comm.
System (Corosync)
Group Com. Engine
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 73
Major Building Blocks (3)
• The plugin is responsible for
– Maintaining distributed execution context.
– Detecting conflicts.
– Handling distributed recovery:
• Detect membership changes;
• Donate state if needed;
• Collect state if needed.
– Receiving and handling transactions from other
members.
– Deciding the fate of on-going transactions.
Com. API
Replication
Plugin
API
MySQL
Server
Group Comm.
System (Corosync)
Group Com. Engine
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 74
Major Building Blocks (4)
• The communication API (and bindings) is
responsible for:
– Abstracting the underlaying communication engine
from the plugin itself.
– Maping the interface to a specific communication
engine.
Com. API
Replication
Plugin
API
MySQL
Server
Group Comm.
System (Corosync)
Group Com. Engine
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 75
Major Building Blocks (5)
• The communication engine:
– Variant of Paxos developed at MySQL.
– Building block to provide distributed agreement
between servers.
Com. API
Replication
Plugin
API
MySQL
Server
Group Comm.
System (Corosync)
Group Com. Engine
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 76
Major Building Blocks
アーキテクチャ
Introduction
3
3.1
3.2
The Complete Stack3.3
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 77
The Complete Stack
API
Replication
Plugin
API
MySQL
Server
Performance Schema Tables: Monitoring
MySQL
APIs: Lifecycle / Capture / Applier
InnoDB
Replication Protocol
Group Com. API
XCom
Network
Plugin
Capture Applier
Conflicts
Handler
Group Comm.
System (Corosync)
Group Com. Engine
Group Com. Binding
Recovery
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 78
ユースケース
ユースケース
4
4.1
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
ユースケース
• エラスティック・レプリケーション
– サーバー数を増やしたり減らしたり、非常に流動的なレプリケーション環境を必要と
する場合
• 高可用性シャード
– シャーディングは書き込み処理の拡張性を実現する一般的な方法
– ユーザーは高可用性シャードを実現するために、MySQL グループ・レプリケーションを
使用可能
– それぞれのシャード毎にレプリケーション・グループを作成
• マスター/スレーブレプリケーションの代替
– 単一のマスターサーバーがボトルネックになる場合がある
– グループ全体への書き込みは、特定の状況下でよりスケーラブルになる場合がある
79
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 80
ユースケース
ユースケース
4
4.1
4.2 全体像
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 81
拡張性、信頼性が高いMySQL環境
M
App
M M
Orchestrate & Manage
MApp M M
Simple Shard
Mapping, State and
Extra metadata.
Control, Coordinate, Provision
...
Monitoring (MEM)
MySQL Router Group Replication – Shard 1
Group Replication – Shard N
C, PHP, Perl, ...
MySQL Router
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 82
結論5
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
まとめ
• クラウドフレンドリー
– クラウドベースのインフラのようなエラスティック性が求められる環境と相性がいい技術
• MySQLサーバーとの統合
– よく知られたMySQLサーバーのAPIとの統合
– GTID、行ベースレプリケーション、パフォーマンス・スキーマとの統合
• 自己回復、管理負荷の軽減
– 自己回復:サーバーのフェイルオーバーを処理するための管理負荷無し
– マルチマスター、フォールトトレラントで信頼性の高いMySQLサービスを提供
83
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Appendix
• モジュールのダウンロード
– http://labs.mysql.com
※2016年7月14日時点で公開されているモジュールは
「MySQL Group Replication for MySQL Server 5.7.10」となっています。
試すためにはMySQL 5.7.10をご用意ください。
• エンジニアブログ (news, technical information, and much more)
– http://mysqlhighavailability.com
※チュートリアル記事
Getting started with MySQL Group Replication
http://mysqlhighavailability.com/getting-started-with-mysql-group-replication/
84
進化を続けるMySQLのド定番機能 MySQLレプリケーション最新機能

Weitere ähnliche Inhalte

Mehr von yoyamasaki

MySQLの公式GUIツール MySQL Workbench
MySQLの公式GUIツール MySQL WorkbenchMySQLの公式GUIツール MySQL Workbench
MySQLの公式GUIツール MySQL Workbenchyoyamasaki
 
MySQL 開発最新動向
MySQL 開発最新動向MySQL 開発最新動向
MySQL 開発最新動向yoyamasaki
 
MySQL最新情報  ※2016年12月
MySQL最新情報  ※2016年12月MySQL最新情報  ※2016年12月
MySQL最新情報  ※2016年12月yoyamasaki
 
20160929 inno db_fts_jp
20160929 inno db_fts_jp20160929 inno db_fts_jp
20160929 inno db_fts_jpyoyamasaki
 
MySQL 5.7 InnoDB 日本語全文検索(その2)
MySQL 5.7 InnoDB 日本語全文検索(その2)MySQL 5.7 InnoDB 日本語全文検索(その2)
MySQL 5.7 InnoDB 日本語全文検索(その2)yoyamasaki
 
Windows環境でのMySQL
Windows環境でのMySQLWindows環境でのMySQL
Windows環境でのMySQLyoyamasaki
 
MySQL 5.7 InnoDB 日本語全文検索
MySQL 5.7 InnoDB 日本語全文検索MySQL 5.7 InnoDB 日本語全文検索
MySQL 5.7 InnoDB 日本語全文検索yoyamasaki
 
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料yoyamasaki
 
20150920 中国地方db勉強会
20150920 中国地方db勉強会20150920 中国地方db勉強会
20150920 中国地方db勉強会yoyamasaki
 
DrupalとMySQL
DrupalとMySQLDrupalとMySQL
DrupalとMySQLyoyamasaki
 
Mysql+Mroongaで全文検索
Mysql+Mroongaで全文検索Mysql+Mroongaで全文検索
Mysql+Mroongaで全文検索yoyamasaki
 
MySQL Workbench 6.1 の紹介
MySQL Workbench 6.1 の紹介MySQL Workbench 6.1 の紹介
MySQL Workbench 6.1 の紹介yoyamasaki
 
MySQL製品概要
MySQL製品概要MySQL製品概要
MySQL製品概要yoyamasaki
 
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyoyoyamasaki
 
早くなったのか? MySQL5.5から5.6へのアップグレード事例
早くなったのか? MySQL5.5から5.6へのアップグレード事例早くなったのか? MySQL5.5から5.6へのアップグレード事例
早くなったのか? MySQL5.5から5.6へのアップグレード事例yoyamasaki
 
SQL+NoSQL!? それならMySQL Clusterでしょ。
SQL+NoSQL!? それならMySQL Clusterでしょ。SQL+NoSQL!? それならMySQL Clusterでしょ。
SQL+NoSQL!? それならMySQL Clusterでしょ。yoyamasaki
 
States of Dolphin - MySQL最新技術情報2013秋 -
States of Dolphin - MySQL最新技術情報2013秋 -States of Dolphin - MySQL最新技術情報2013秋 -
States of Dolphin - MySQL最新技術情報2013秋 -yoyamasaki
 
MySQL最新動向と便利ツールMySQL Workbench
MySQL最新動向と便利ツールMySQL WorkbenchMySQL最新動向と便利ツールMySQL Workbench
MySQL最新動向と便利ツールMySQL Workbenchyoyamasaki
 
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報yoyamasaki
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~yoyamasaki
 

Mehr von yoyamasaki (20)

MySQLの公式GUIツール MySQL Workbench
MySQLの公式GUIツール MySQL WorkbenchMySQLの公式GUIツール MySQL Workbench
MySQLの公式GUIツール MySQL Workbench
 
MySQL 開発最新動向
MySQL 開発最新動向MySQL 開発最新動向
MySQL 開発最新動向
 
MySQL最新情報  ※2016年12月
MySQL最新情報  ※2016年12月MySQL最新情報  ※2016年12月
MySQL最新情報  ※2016年12月
 
20160929 inno db_fts_jp
20160929 inno db_fts_jp20160929 inno db_fts_jp
20160929 inno db_fts_jp
 
MySQL 5.7 InnoDB 日本語全文検索(その2)
MySQL 5.7 InnoDB 日本語全文検索(その2)MySQL 5.7 InnoDB 日本語全文検索(その2)
MySQL 5.7 InnoDB 日本語全文検索(その2)
 
Windows環境でのMySQL
Windows環境でのMySQLWindows環境でのMySQL
Windows環境でのMySQL
 
MySQL 5.7 InnoDB 日本語全文検索
MySQL 5.7 InnoDB 日本語全文検索MySQL 5.7 InnoDB 日本語全文検索
MySQL 5.7 InnoDB 日本語全文検索
 
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料
MySQL最新情報 ※2015年9月5日「第1回 関西DB勉強会」での発表資料
 
20150920 中国地方db勉強会
20150920 中国地方db勉強会20150920 中国地方db勉強会
20150920 中国地方db勉強会
 
DrupalとMySQL
DrupalとMySQLDrupalとMySQL
DrupalとMySQL
 
Mysql+Mroongaで全文検索
Mysql+Mroongaで全文検索Mysql+Mroongaで全文検索
Mysql+Mroongaで全文検索
 
MySQL Workbench 6.1 の紹介
MySQL Workbench 6.1 の紹介MySQL Workbench 6.1 の紹介
MySQL Workbench 6.1 の紹介
 
MySQL製品概要
MySQL製品概要MySQL製品概要
MySQL製品概要
 
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo
[D14] MySQL 5.6時代のパフォーマンスチューニング *db tech showcase 2013 Tokyo
 
早くなったのか? MySQL5.5から5.6へのアップグレード事例
早くなったのか? MySQL5.5から5.6へのアップグレード事例早くなったのか? MySQL5.5から5.6へのアップグレード事例
早くなったのか? MySQL5.5から5.6へのアップグレード事例
 
SQL+NoSQL!? それならMySQL Clusterでしょ。
SQL+NoSQL!? それならMySQL Clusterでしょ。SQL+NoSQL!? それならMySQL Clusterでしょ。
SQL+NoSQL!? それならMySQL Clusterでしょ。
 
States of Dolphin - MySQL最新技術情報2013秋 -
States of Dolphin - MySQL最新技術情報2013秋 -States of Dolphin - MySQL最新技術情報2013秋 -
States of Dolphin - MySQL最新技術情報2013秋 -
 
MySQL最新動向と便利ツールMySQL Workbench
MySQL最新動向と便利ツールMySQL WorkbenchMySQL最新動向と便利ツールMySQL Workbench
MySQL最新動向と便利ツールMySQL Workbench
 
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報
MySQL Cluster 解説 & MySQL Cluster 7.3 最新情報
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
 

Kürzlich hochgeladen

モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 

Kürzlich hochgeladen (9)

モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 

進化を続けるMySQLのド定番機能 MySQLレプリケーション最新機能

  • 1. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 進化を続けるMySQLのド定番機能 MySQLレプリケーション最新機能 日付:2016/07/14 日本オラクル株式会社 MySQL Global Business Unit Yoshiaki Yamasaki / 山﨑 由章
  • 2. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。 また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはでき ません。以下の事項は、マテリアルやコード、機能を提供することをコミットメントするも のではない為、購買決定を行う際の判断材料になさらないで下さい。 オラクル製品に関して記載されている機能の開発、リリースおよび時期については、 弊社の裁量により決定されます。 2
  • 3. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQLのレプリケーション機能 3
  • 4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションとは? • データの複製(レプリカ)を別のサーバーに持てる機能 • MySQLの標準機能で、多数のWebサイト等で利用されている – シンプルな設定で利用可能 – マスター→スレーブ 構成 4 M S
  • 5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションとは? • マスターサーバー – データを変更 – 変更内容をスレーブに転送 • スレーブサーバー – マスターでの変更内容を受け取る – 変更内容をデーターベースに反映 5 M S
  • 6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6 レプリケーション構成 M M/S S S S S M S M M サーバはマスター、スレーブまたは両方になれる マスターは複数のスレーブを持てる スレーブは複数のマスターを持てる ※MySQL 5.7以降
  • 7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションの利点:参照性能の向上 • 参照処理の負荷が高い場合は、スレーブサーバーを追加することで、 負荷分散による性能向上が実現できる 7 M S S S S M 更新処理 参照処理 参照処理 更新処理 参照処理 の増加→ スレーブ 追加
  • 8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションの利点:高可用性構成の実現 • マスターの障害時に、スレーブをマスターに昇格することで 高可用性を実現可能 8 C B A C B ACrash C B A Bが新しい マスターに
  • 9. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションの利点:地理的冗長性の実現 • 地理的に離れた場所に、災害対策サイトを構築可能 9 CA BCAB Image from www.ginkgomaps.com
  • 10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. M S 更新処理 BI(ビジネスインテリジェンス)や レポート生成アプリ、データ分析アプリ、 バックアップ取得、など 10 レプリケーションの利点:レポート生成やバックアップ取得
  • 11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションの仕組み • スレーブからレプリケーション開始 • バイナリログの内容をスレーブに転送し、実行 11 create … insert …B binary log create … insert …A binary log Client 1. スレーブがレプリケーションの 開始をマスターにリクエスト 2. マスターがレプリケーション データをスレーブに転送 create … insert … relay log 3. リレーログの内容を スレーブに適用 ※log-slave-updatesを設定している場合、 スレーブでもバイナリログを出力 (多段構成のレプリケーション時必須)
  • 12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. スレーブ上に存在するファイル、スレッド • ファイル – リレーログファイル:マスターから受信した変更点を記録したファイル – バイナリログファイル:スレーブで実行した変更点を記録したファイル (log-slave-updatesを有効にしている場合のみ出力) – master.info:マスターへの接続に必要な情報や、読み取りを開始する バイナリログの位置情報(バイナリログファイル名とポジション)が 記録されているOS上のファイル。(MySQL 5.6からテーブル内に格納可能) – relay-log.info:リレーログをどこまで適用したかを記録しているOS上のファイル (MySQL 5.6からテーブル内に格納可能) • スレッド – I/Oスレッド:マスターから受信したバイナリログをリレーログファイルとして保存 – SQLスレッド:リレーログファイル内の更新内容をDBへ反映する 12
  • 13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13 イメージ図 B binary log Position 100 create … Position 200 insert Position 300 insert A binary log 001 Client I/Oスレッド relay log 001 SQLスレッド master.info Position 100 create … Position 200 insert … Position 100 create ・マスターはA ・001のPosition 200 まで受信した Position 100 insert … Position 200 insert binary log 002 relay-log.info ・001のPosition 100 まで適用した
  • 14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL 5.7 でのレプリケーション強化点 14
  • 15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTID(Global Transaction Identifiers)のオンラインでの設定 • GTIDの設定変更がオンラインに – GTIDの設定変更(onまたはoff)の変更中も参照更新可能 • サーバ間でのデータ同期不要 • サーバ再起動不要 • レプリケーション構成の変更不要 – 任意のレプリケーション構成で利用可能 • 運用中にGITDの利用開始または停止が可能 15
  • 16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーションのフィルタをオンラインで変更 • スレーブのレプリケーションフィルタを動的に変更 – スレーブサーバの再起動不要 – 全てのスレーブでのフィルタをサポート – 各種の文字コードによる値の設定が可能 16 mysql> CHANGE REPLICATION FILTER REPLICATE_DO_DB= (db1, db2)
  • 17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17 マスターをAからBへの切り替える際にSQLスレッドの停止不要 新マスターへの切り替え/フェールオーバーをオンラインで C B A C B A障害発生 C B A 障害発生 構成変更 マスターをAからBに切り替えるために DBAはCのリレーログの内容をデータに 反映する処理を停止する必要はない
  • 18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. レプリケーション監視の改善 • SQL文にて監視 • 意味の異なる情報は別々の場所に格納 • 拡張可能, 新しい機能との連携 • より正確で一貫性のある識別子の名称 • マスター/スレーブ、マルチソース、グループレプリケーション対応 18 Performance SchemaのReplication関連テーブル ※一部の情報は、Performance Schemaに追加できていません。詳細はこちらを参照下さい。 SHOW SLAVE STATUS Information Not In the Replication Tables http://dev.mysql.com/doc/refman/5.7/en/performance-schema-replication-tables.html#idm140061595817488
  • 19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19 SQLスレッドの性能向上 – ロックベースの並列処理 Single Threaded Apply 8 Threads Applier 24 Threads Applier 48 Threads Applier 96 Threads Applier 0% 50% 100% 150% 200% 250% Fast and Scalable Multi-threaded Replication Applier (statement-based replication, durable settings, SSD storage) Slaveapplytime (SysbenchRWonthemasterwith96threads=100%) 10X
  • 20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. SQLスレッドの性能向上 – ロックベースの並列処理 • 文(STATEMENT)ベースおよび行(ROW)ベースの両フォーマット対応 • スケジュールのポリシーは下記コマンドで制御: – logical_clock – ロックのタイムスタンプを通じてスケジューリング – database – 5.6と同様のスケジューリング (データベースが異なれば並列実行) • スレーブの性能拡張性は引き続き改良! 20 mysql> SET slave_parallel_type= [logical_clock|database]
  • 21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. ユーザスレッドとSenderスレッドの同期の改善 • バイナリログに対するユーザスレッドでの書き込みと Senderスレッドでの読み込みを並列化 – Senderスレッドによるユーザセッション処理のブロックを最小化 – ユーザセッションとSenderスレッドのスループットを向上 21 Sender Thread Reads Binary Log User Thread Writes to Binary Log Sender Thread Reads Binary Log User Thread Writes to Binary Log 5.7.2以前 5.7.2+
  • 22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Senderスレッドの高速化 • アロケートされた送信バッファを毎回解放しないように変更 • より大きな送信バッファが必要な場合は、その際に拡張 • 拡張された送信バッファが使われなくなると動的に縮小 • MySQL 5.7.2でのSenderスレッドの改良: – マスターの性能拡張性の向上; – リソース消費の削減 (CPU); – 負荷のピーク時のマスター特にDumpスレッドの処理負荷の軽減 22
  • 23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 準同期レプリケーションの高速化 – ACK Receiverスレッド • 連続したトランザクションがスレーブからのACKをお互いに待たない – トランザクションt1とt2を同時にSenderスレッドがスレーブに送る – それぞれのACKを別のスレッドが受け取る – t2の準同期のレイテンシにはt1の処理によるレイテンシは含まれない • 準同期レプリケーション有効時にスレッドが開始される • 準同期レプリケーション無効時にスレッドが停止される 23 mysql> SET GLOBAL rpl_semi_master_enabled= ON mysql> SET GLOBAL rpl_semi_master_enabled= OFF
  • 24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Loss-less準同期レプリケーション • マスターはスレーブからのACKを受け取ってからコミット (5.6まではコミット後にスレーブに処理を転送) – 他のトランザクションはACK待ちの間は該当トランザクションによる変更は見えない • マスターに障害が発生した際でも、スレーブに転送されたトランザクション のみが他のトランザクションから見える状態 • MySQL 5.6までの挙動か新しいLoss-lessを選択可能 24 mysql> SET rpl_semi_sync_master_wait_point= [AFTER_SYNC|AFTER_COMMIT]
  • 25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 準同期レプリケーション – 複数ACKを待つ • 指定したN台のスレーブからACKを受信するまでコミットを行わない • 動的に設定可能: 25 mysql> SET GLOBAL rpl_semi_sync_master_wait_for_slave_count= N Master Slave 2 T1: COMMIT ACK Slave 1 ACK T1: COMMIT succeeds mysql> SET GLOBAL rpl_semi_sync_master_wait_for_slave_count= 2 Slave 3 Time relay log relay log relay log ACK
  • 26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTIDをテーブルに格納 • バイナリログを有効にしていないスレーブでもGTIDを利用可能 – マスターに昇格する予定のないスレーブでもGTIDを利用した auto positioning(自動的にトランザクションの進捗を見つける仕組み)を利用可能 26
  • 27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 27 マルチソースレプリケーション S M M 1台のスレーブが複数のマスターを持つ構成M M 1台のサーバにデータを集約する構成: • バックアップを1台で実行; • 分析用途の複雑なクエリの実行; • クラスタ間レプリケーションのデータハブ
  • 28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. その他の改良点 • マルチスレッドのApplierスレッドで、失敗したトランザクションの再試行が可能 • マルチスレッドのApplierスレッドのコミット順を維持するオプション • mysqlbinlogツールにSSLオプション • mysqlbinlogにデータベース名のリライトルール適用可能 • 指定されたGTIDになるまでApplierスレッドの処理を一時的に停止する関数 – WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(gtid_set[, timeout][,channel]) – WAIT_FOR_EXECUTED_GTID_SET(gtid_set[, timeout]) • MySQLのクライアントサーバ間プロトコルにGITDの情報を返す • バイナリログ利用時にもXAトランザクションをサポート • デフォルト値の変更 例) binlog_format=ROW, sync_binlog=1 28
  • 29. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Appendix • MySQL 5.7でのレプリケーション強化点に関するより詳細な資料 – MySQL 5.7 レプリケーション最新機能とロードマップ http://downloads.mysql.com/presentations/20151030_03_MySQL5.7_Replication_jp.pdf 29
  • 30. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL グループ・レプリケーション 30
  • 31. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 概要1 31
  • 32. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32 MySQL グループ・レプリケーション M M M M M Replication Group Clients
  • 33. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL グループ・レプリケーション • MySQL グループ・レプリケーションとは? – どのノードでもデータ更新可能なレプリケーションプラグイン – 自動的な競合処理、リカバリ、グループ・メンバーシップ • MySQL グループ・レプリケーションの利点 – 障害発生時にフェイルオーバー不要 – フォールトトレラント – どのノードでもデータ更新可能 – 自動的なグループ再構成(障害発生時、再接続時) – レプリケートされた高可用性データベースを提供. – 自動分散強調(スプリットブレインとメッセージの損失から保護) – 少ない管理コスト 33 ※2016年7月現在、GAになっていません。 今後Pluginとして追加リリースする予定です。
  • 34. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. マルチマスター MySQL グループ・レプリケーション2 2.1 34
  • 35. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. マルチマスター、どこでも更新可能! • 異なるサーバー上での2つのトランザクションは、同じデータを更新可能 • 競合が検出され、対処される – 先にコミットしたトランザクションが優先される 35 M M M M M UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1
  • 36. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. マルチマスター、どこでも更新可能! • 異なるサーバー上での2つのトランザクションは、同じデータを更新可能 • 競合が検出され、対処される – 先にコミットしたトランザクションが優先される 36 M M M M M UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1 OKOK
  • 37. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. マルチマスター、どこでも更新可能! • 異なるサーバー上での2つのトランザクションは、同じデータを更新可能 • 競合が検出され、対処される – 先にコミットしたトランザクションが優先される 37 M M M M M UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1
  • 38. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. マルチマスター、どこでも更新可能! • 異なるサーバー上での2つのトランザクションは、同じデータを更新可能 • 競合が検出され、対処される – 先にコミットしたトランザクションが優先される 38 M M M M M UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1 OK
  • 39. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. グループレプリケーションでのコミット時の動作 • トランザクションコミット時は、グループ内の全サーバーと通信し、 データ競合が発生しているか否かを確認する • 競合が発生していなければ、そのトランザクションはコミットされる – 更新処理が実行され、バイナリログにGTIDと共に更新内容が記録される ※GTIDは、グループレプリケーションの全メンバーで共通 • 競合が発生していた場合は、そのトランザクションは取り消される – 更新処理は実行されないため、バイナリログにも記録されない 39
  • 40. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. グループレプリケーション使用時のバイナリログの内容 • test.t1テーブルに対して、server_id=1のサーバーからデータを更新した後、 server_id=2のサーバーからデータを更新した時のバイナリログ例 40 mysql> show binlog events in 'yyamasaki-bin.000004' from 2580; +----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+ | yyamasaki-bin.000004 | 2580 | Gtid | 1 | 2641 | SET @@SESSION.GTID_NEXT= '0a06e216-1bdb-11e6-b1e0-080027ff56de:7' | | yyamasaki-bin.000004 | 2641 | Query | 1 | 2700 | BEGIN | | yyamasaki-bin.000004 | 2700 | Table_map | 1 | 2741 | table_id: 108 (test.t1) | | yyamasaki-bin.000004 | 2741 | Write_rows | 1 | 2777 | table_id: 108 flags: STMT_END_F | | yyamasaki-bin.000004 | 2777 | Xid | 1 | 2804 | COMMIT /* xid=42 */ | | yyamasaki-bin.000004 | 2804 | Gtid | 2 | 2865 | SET @@SESSION.GTID_NEXT= '0a06e216-1bdb-11e6-b1e0-080027ff56de:8' | | yyamasaki-bin.000004 | 2865 | Query | 2 | 2929 | BEGIN | | yyamasaki-bin.000004 | 2929 | Table_map | 2 | 2970 | table_id: 108 (test.t1) | | yyamasaki-bin.000004 | 2970 | Write_rows | 2 | 3006 | table_id: 108 flags: STMT_END_F | | yyamasaki-bin.000004 | 3006 | Xid | 2 | 3033 | COMMIT /* xid=49 */ | +----------------------+------+------------+-----------+-------------+-------------------------------------------------------------------+ 10 rows in set (0.00 sec) GTIDが増えているどのサーバーから実行された トランザクションか判断可能
  • 41. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 マルチマスター MySQL グループ・レプリケーション2 2.1 2.2 41
  • 42. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーがグループに参加すると自動的に他のサーバーと同期する 42 M M M M M N グループに参加
  • 43. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーがグループに参加すると自動的に他のサーバーと同期する 43 M M M M M N オンライン 同期
  • 44. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーがグループに参加すると自動的に他のサーバーと同期する 44 M M M M M N オンライン
  • 45. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーがグループから外れると、他のサーバーは自動的に検知する 45 M M M M M M メンテナンスや システムクラッシュが発生 各メンバーシップの設定は論理的な タイムスタンプ(view_id)によって識別される view_id: 4
  • 46. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーがグループから外れると、他のサーバーは自動的に検知する 46 M M M M M view_id: 5
  • 47. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 自動分散型サーバー復旧 • サーバーが再びグループに参加すると、自動的に他のサーバーと同期する 47 M M M M M M view_id: 6 同期 -> オンライン
  • 48. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. データを同期する仕組み • GTIDレプリケーションの仕組みでデータを同期する – グループ内のメンバーのバイナリログから更新内容の差分を受取ってデータを 同期する為、同期に必要なバイナリログが欠損している場合は、リカバリ処理が 完了せずに、グループに参加できない 48
  • 49. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 新しいサーバーをグループに追加した時のエラーログの例 • グループ参加後、view_idが増加している(1928434991:1 ⇒ 1928434991:2) – 最初からグループに存在したサーバー:127.0.0.1:10301 – 後からグループに参加したサーバー:127.0.0.1:10302 49 2016-07-20T10:12:58.547649Z 0 [Note] Plugin group_replication reported: 'Starting group replication recovery with view_id 1928434991:1' [XCOM_BINDING_DEBUG] ::install_view():: View delivered to client handler= 1302998040 2016-07-20T10:12:58.549672Z 8 [Note] Plugin group_replication reported: 'Only one server alive. Declaring this server as online within the replication group' <中略> [XCOM_BINDING_DEBUG] ::process_possible_control_message():: Received a control message [XCOM_BINDING_DEBUG] ::process_possible_control_message():: From: 127.0.0.1:10302 regarding view_id:0:0 [XCOM_BINDING_DEBUG] ::process_possible_control_message()::Still waiting for more State Exchange messages [XCOM_BINDING_DEBUG] ::xcom_receive_data_internal():: xcom_receive_data message_id.group= 2530263840 message_id.msgno= 20 message_id.node= 0 [XCOM_BINDING_DEBUG] ::process_possible_control_message():: Received a control message [XCOM_BINDING_DEBUG] ::process_possible_control_message():: From: 127.0.0.1:10301 regarding view_id:1928434991:1 [XCOM_BINDING_DEBUG] ::process_possible_control_message()::Install new view [XCOM_BINDING_DEBUG] ::install_view():: Processing exchanged data [XCOM_BINDING_DEBUG] ::install_view():: Processing exchanged data 2016-07-20T10:13:42.438996Z 0 [Note] Plugin group_replication reported: 'Marking group replication view change with view_id 1928434991:2'
  • 50. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター MySQL グループ・レプリケーション2 2.1 2.2 2.3 50
  • 51. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL/InnoDB look & feel • プラグインをロードし、レプリケーションをスタート • グループ・レプリケーションの状態をパフォーマンス・スキーマから確認 51 mysql> SET GLOBAL group_replication_group_name= "35e59895-4985-11e6-a684-080027ff56de"; mysql> START GROUP_REPLICATION; mysql> SELECT * FROM performance_schema.replication_group_members¥G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 35e59895-4985-11e6-a684-080027ff56de MEMBER_HOST: yyamasaki MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 773452b2-498b-11e6-9915-080027ff56de MEMBER_HOST: yyamasaki MEMBER_PORT: 3307 MEMBER_STATE: ONLINE
  • 52. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL/InnoDB look & feel • プラグインをロードし、レプリケーションをスタート • グループ・レプリケーションの状態をパフォーマンス・スキーマから確認 52 mysql> SELECT * FROM performance_schema.replication_group_member_stats¥G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier VIEW_ID: 1928434991:2 MEMBER_ID: 35e59895-4985-11e6-a684-080027ff56de COUNT_TRANSACTIONS_IN_QUEUE: 0 COUNT_TRANSACTIONS_CHECKED: 0 COUNT_CONFLICTS_DETECTED: 0 COUNT_TRANSACTIONS_VALIDATING: 0 TRANSACTIONS_COMMITTED_ALL_MEMBERS: 35e59895-4985-11e6-a684-080027ff56de:1-35 LAST_CONFLICT_FREE_TRANSACTION: 35e59895-4985-11e6-a684-080027ff56de:35
  • 53. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL/InnoDB look & feel • プラグインをロードし、レプリケーションをスタート • グループ・レプリケーションの状態をパフォーマンス・スキーマから確認 53 mysql> SELECT * FROM performance_schema.replication_connection_status¥G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier GROUP_NAME: 35e59895-4985-11e6-a684-080027ff56de SOURCE_UUID: 35e59895-4985-11e6-a684-080027ff56de THREAD_ID: NULL SERVICE_STATE: ON COUNT_RECEIVED_HEARTBEATS: 0 LAST_HEARTBEAT_TIMESTAMP: 0000-00-00 00:00:00 RECEIVED_TRANSACTION_SET: 35e59895-4985-11e6-a684-080027ff56de:3-9:13-14:16:30:33-35 LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
  • 54. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTIDサポート MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター MySQL グループ・レプリケーション2 2.1 2.2 2.3 2.4 54
  • 55. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTIDサポート • 全グループメンバーは同じUUID、グループ名を持つ 55 M M M M M INSERT y; Will have GTID: group_name:2 INSERT x; Will have GTID: group_name:1
  • 56. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTIDサポート • 全グループメンバーは同じUUID、グループ名を持つ 56 M M M M M INSERT y; Will have GTID: group_name:1 SET GTID_NEXT= “UUID:50” INSERT x;
  • 57. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. GTIDサポート • グループ外のサーバーからグループにレプリケート可能 • GTIDは保たれる 57 M M M M M 競合も検出される
  • 58. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 GTIDサポート MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター MySQL グループ・レプリケーション2 2.1 2.2 2.3 2.4 2.5 58
  • 59. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 • オートインクリメント値は、グループ内のメンバーと同じ値を生成しないよう に構成されている 59 M M M M M INSERT y; y: 4 INSERT z; z: 11 INSERT x; x: 1
  • 60. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 • デフォルトではオフセットはserver_idによって提供され、増分値は7 60 M M M M M INSERT y; y: 4 INSERT z; z: 11 INSERT x; x: 1 [1]: http://mysqlhighavailability.com/mysql-group-replication-auto-increment-configuration-handling/ server_id: 1 server_id: 4
  • 61. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 • GROUP_REPLICATION_AUTO_INCREMENT_INCREMENTオプションで、 増分値を変更可能 61 M M M M M INSERT y; y: 4 INSERT z; z: 11 INSERT x; x: 1 server_id: 1 server_id: 4
  • 62. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 GTIDサポート MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター 新しい分散コミュニケーションエンジン MySQL グループ・レプリケーション2 2.1 2.2 2.3 2.4 2.5 2.6 62
  • 63. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 新しい分散コミュニケーションエンジン • マルチOSサポート – Linux, Windows, OSX, Solaris, FreeBSD… • サードパーティソフトウェア不要 • ネットワークのマルチキャストサポート不要 – MySQL グループ・レプリケーションは、マルチキャストが使用できないクラウド環境で も使用可能 • メッセージサイズの制限なし • 追加プロセス無し – MySQL グループ・レプリケーションは同じソフトウェアスタックに含まれる 63
  • 64. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 GTIDサポート MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター 新しい分散コミュニケーションエンジン MySQL グループ・レプリケーション2 2.1 2.2 2.3 2.4 2.5 2.6 設計上の要件2.7 64
  • 65. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 設計上の要件 • InnoDBのみをサポート • 全テーブルに主キーが必要 • GTID有効 • 楽観実行 – 競合によって、トランザクションはabortされるかもしれないし、COMMITされるかも しれない – データ競合発生時は、先にCOMMITしたトランザクションが優先して確定される。 後からCOMMITしたトランザクションはabortされる。 ⇒データ競合の発生は、トランザクションCOMMIT時に検知される 65
  • 66. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. オートインクリメント値の設定/処理 GTIDサポート MySQL/InnoDB look & feel 自動分散型サーバー復旧 マルチマスター 新しい分散コミュニケーションエンジン MySQL グループ・レプリケーション2 2.1 2.2 2.3 2.4 2.5 2.6 設計上の要件 制限事項 2.7 2.8 66
  • 67. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 制限事項 • オンラインでのスキーマ変更(オンラインDDL)はサポートされない ※スキーマ変更手順:以下の手順を全ノードに対して順番に実行する 1.グループから離脱 2.バイナリログの出力を停止して、DDLを実行 3.グループに参加 67 ※(他の部分での説明内容も含め)あくまで2016年7月14日時点のLab版(実験版)での挙動です。 今後のリリースにおいて予告なく挙動が変更になる可能性があります。特にオンラインDDLついては、 開発チーム内でも、どのように対処すべきかディスカッションが継続されています。
  • 68. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 68 アーキテクチャ Introduction 3 3.1
  • 69. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. MySQL Group Replication is • Built on top of proven technology! – Shares much of MySQL Replication infrastructure – thence does not feel alien! – Multi-Master approach to replication. • Built on reusable components! – Layered implementation approach. – Interface driven development. – Decoupled from the server core. – The plugin registers as listener to server events. – Reuses the capture procedure from regular replication. – Provides further decoupling from the communication infrasctructure. 69
  • 70. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 70 Major Building Blocks アーキテクチャ Introduction 3 3.1 3.2
  • 71. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 71 Major Building Blocks (1) M M M M M Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
  • 72. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 72 Major Building Blocks (2) • Server calls into the plugin through a generic interface – (Most of server) internals are hidden from the plugin. – Some of the semi-sync interfaces were reused. Others were deployed. • Plugin interacts with the server through a generic interface – Replication plugin determines the fate of the commit operation through a well defined server interface. – The plugin makes use of the relay log infrastructure to inject changes in the receiving server. Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
  • 73. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 73 Major Building Blocks (3) • The plugin is responsible for – Maintaining distributed execution context. – Detecting conflicts. – Handling distributed recovery: • Detect membership changes; • Donate state if needed; • Collect state if needed. – Receiving and handling transactions from other members. – Deciding the fate of on-going transactions. Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
  • 74. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 74 Major Building Blocks (4) • The communication API (and bindings) is responsible for: – Abstracting the underlaying communication engine from the plugin itself. – Maping the interface to a specific communication engine. Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
  • 75. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 75 Major Building Blocks (5) • The communication engine: – Variant of Paxos developed at MySQL. – Building block to provide distributed agreement between servers. Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
  • 76. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 76 Major Building Blocks アーキテクチャ Introduction 3 3.1 3.2 The Complete Stack3.3
  • 77. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 77 The Complete Stack API Replication Plugin API MySQL Server Performance Schema Tables: Monitoring MySQL APIs: Lifecycle / Capture / Applier InnoDB Replication Protocol Group Com. API XCom Network Plugin Capture Applier Conflicts Handler Group Comm. System (Corosync) Group Com. Engine Group Com. Binding Recovery
  • 78. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 78 ユースケース ユースケース 4 4.1
  • 79. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. ユースケース • エラスティック・レプリケーション – サーバー数を増やしたり減らしたり、非常に流動的なレプリケーション環境を必要と する場合 • 高可用性シャード – シャーディングは書き込み処理の拡張性を実現する一般的な方法 – ユーザーは高可用性シャードを実現するために、MySQL グループ・レプリケーションを 使用可能 – それぞれのシャード毎にレプリケーション・グループを作成 • マスター/スレーブレプリケーションの代替 – 単一のマスターサーバーがボトルネックになる場合がある – グループ全体への書き込みは、特定の状況下でよりスケーラブルになる場合がある 79
  • 80. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 80 ユースケース ユースケース 4 4.1 4.2 全体像
  • 81. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 81 拡張性、信頼性が高いMySQL環境 M App M M Orchestrate & Manage MApp M M Simple Shard Mapping, State and Extra metadata. Control, Coordinate, Provision ... Monitoring (MEM) MySQL Router Group Replication – Shard 1 Group Replication – Shard N C, PHP, Perl, ... MySQL Router
  • 82. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 82 結論5
  • 83. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. まとめ • クラウドフレンドリー – クラウドベースのインフラのようなエラスティック性が求められる環境と相性がいい技術 • MySQLサーバーとの統合 – よく知られたMySQLサーバーのAPIとの統合 – GTID、行ベースレプリケーション、パフォーマンス・スキーマとの統合 • 自己回復、管理負荷の軽減 – 自己回復:サーバーのフェイルオーバーを処理するための管理負荷無し – マルチマスター、フォールトトレラントで信頼性の高いMySQLサービスを提供 83
  • 84. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Appendix • モジュールのダウンロード – http://labs.mysql.com ※2016年7月14日時点で公開されているモジュールは 「MySQL Group Replication for MySQL Server 5.7.10」となっています。 試すためにはMySQL 5.7.10をご用意ください。 • エンジニアブログ (news, technical information, and much more) – http://mysqlhighavailability.com ※チュートリアル記事 Getting started with MySQL Group Replication http://mysqlhighavailability.com/getting-started-with-mysql-group-replication/ 84