@RKajiyama
MySQL グ ループ レプリケーション
GR
レプリケーション
【名】 写し,模写,複写,複製 出典:ランダムハウス英和大辞典
MySQL レプリケーション
マスター スレーブ
参照処理 負荷分散
高可用性
ディザスタ リカバリ
アプリケーション マスター 接続スレッド データ バイナ リ ログ スレーブ データ リレー ログ コミッ ト データ 変更 バイナリロ グ 変更 レプリケーショ ン レスポン ス データ変更 トランザク ション履歴 トランザク ション履歴
3.23
非同期
5.5
準同期
5.6
マルチ スレッド
5.7
マルチ ソース
5.7.17
マルチ マスター
GR
非同期レプリケーション execute binlog relay log commit apply binlog commit relay log apply binlog commit
準同期レプリケーション execute binlog relay log commit apply binlog commit relay log apply binlog commit
グループレプリケーション execute binlog relay log commit apply binlog commit relay log apply binlog commit certify certify certify
マスター → スレーブ マルチソース マルチマスター マスター → 複数スレーブ マルチマスター 多段構成
MySQL グループ・レプリケー ション • MySQL 側でのフェイルオーバー処理が不 要 32 M M M M M レプリケーション グループ クライアント
障害検知 • サーバーがグループから外れると、 他のサーバーは自動的に検知 M M M M M メンテナンスや システムクラッシュが発生
自動復旧 • サーバーが再びグループに参加すると、 自動的に他のサーバーと同期 M M M M M グループに参加
自動復旧 • サーバーが再びグループに参加すると、 自動的に他のサーバーと同期 M M M M M リカバリー → オンライン
自動復旧 • サーバーが再びグループに参加すると、 自動的に他のサーバーと同期 M M M M M リカバリー → オンライン
読み取り専用モード • メンバー参加時の分散リカバリ中は、 自動的に読み取り専用モードに M M M M M 読み取り専用モード
モード
シングルプライマリー マルチマスター
シングルプライマリモード • デフォルトではシングルプライマリモー ド • 1 ノードが書き込み可能なマスター (PRIMARY) • 他はホットスタンバイ (SECONDARY) +---------------------------------------+-------+ | Variable_name | Value | +---------------------------------------+-------+ | group_replication_single_primary_mode | ON | +---------------------------------------+-------+ +----------------------------------------------------+-------+ | Variable_name | Value | +----------------------------------------------------+-------+ | group_replication_enforce_update_everywhere_checks | OFF | +----------------------------------------------------+-------+ ※ シングルプライマリモードの設定
シングルプライマリモード • Secondary ノードは参照のみ可能 – 書き込んだ場合は、 ERROR 1290 が発生する S S S S P S Primary ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statementERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement
[1]: http://mysqlhighavailability.com/mysql-group-replication-for-mysql-5-7-15/ シングルプライマリモード • プライマリサーバーのメンバー ID の確認 mysql> SELECT * FROM performance_schema.replication_group_members; +-------------------------+------------------------------------+-------------+-----------+------------+ |CHANNEL_NAME |MEMBER_ID |MEMBER_HOST |MEMBER_PORT|MEMBER_STATE| +-------------------------+------------------------------------+-------------+-----------+------------+ |group_replication_applier|919a7d77-9ff3-11e6-acb8-080027d65c57|replications | 3310|ONLINE | |group_replication_applier|9c8e6f77-9ff3-11e6-b1d1-080027d65c57|replications | 3320|ONLINE | |group_replication_applier|ac0ec52b-9ff3-11e6-b801-080027d65c57|replications | 3330|ONLINE | +-------------------------+------------------------------------+-------------+-----------+------------+ mysql> SELECT * FROM performance_schema.global_status WHERE VARIABLE_NAME='group_replication_primary_member'; +----------------------------------+--------------------------------------+ | VARIABLE_NAME | VARIABLE_VALUE | +----------------------------------+--------------------------------------+ | group_replication_primary_member | 919a7d77-9ff3-11e6-acb8-080027d65c57 | +----------------------------------+--------------------------------------+ mysql> SELECT * FROM performance_schema.replication_group_members; +-------------------------+------------------------------------+-------------+-----------+------------+ |CHANNEL_NAME |MEMBER_ID |MEMBER_HOST |MEMBER_PORT|MEMBER_STATE| +-------------------------+------------------------------------+-------------+-----------+------------+ |group_replication_applier|919a7d77-9ff3-11e6-acb8-080027d65c57|replications | 3310|ONLINE | |group_replication_applier|9c8e6f77-9ff3-11e6-b1d1-080027d65c57|replications | 3320|ONLINE | |group_replication_applier|ac0ec52b-9ff3-11e6-b801-080027d65c57|replications | 3330|ONLINE | +-------------------------+------------------------------------+-------------+-----------+------------+ mysql> SELECT * FROM performance_schema.global_status WHERE VARIABLE_NAME='group_replication_primary_member'; +----------------------------------+--------------------------------------+ | VARIABLE_NAME | VARIABLE_VALUE | +----------------------------------+--------------------------------------+ | group_replication_primary_member | 919a7d77-9ff3-11e6-acb8-080027d65c57 | +----------------------------------+--------------------------------------+
マルチマスターモード • 全てのノードでデータ更新可能 M M M M M UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1
マルチマスターモード • 異なるサーバー上で同じデータを更新し た場合、先にコミットしたトランザク ションが優先 44 M M M M M UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1 OKOK
マルチマスターモード • 後からコミットしたトランザクションは ロールバックされる 45 M M M M M UPDATE t1 SET a=4 WHERE a=1UPDATE t1 SET a=3 WHERE a=1
マルチマスターモード • 後からコミットしたトランザクションは ロールバックされる 46 M M M M M UPDATE t1 SET a=4 WHERE a=1UPDATE t1 SET a=3 WHERE a=1 OKERROR 1180 (HY000): Got error 149 during COMMIT ERROR 1180 (HY000): Got error 149 during COMMIT
アーキテクチャ概要 M M M M M Com. API Replication Plugin API MySQL Server Group Comm. System (Corosync) Group Com. Engine
API Replication Plugin API MySQL Server Performance Schema Tables: Monitoring MySQL APIs: Lifecycle / Capture / Applier InnoDB Replication Protocol Group Com. API Group Com. Engine Network Plugin Capture Applier Conflicts Handler Group Comm. System (Corosync) Group Com. Engine Group Com. Binding Recovery
MySQL Router: 2.1 • グループレプリケーション対 応ソフトウェアルータ – GR 構成を自動判別 – 各メンバーのメタデータを利 用 • 起動時の GR の設定を取得 • アプリケーションから接続 – バックエンド構成の考慮不要 App Servers with MySQL Router MySQL Group Replication MySQL Shell Setup, Manage, Orchestrate
MySQL Shell 開発と運用管理の作業と統合した新クライアントプログラム App Servers with MySQL Router MySQL Group Replication MySQL Shell Setup, Manage, Orchestrate •複数の言語利用可能 : JavaScript, Python, SQL •ドキュメントと リレーショナルモデル両対応 •開発用 API と管理用 API
MySQL Shell: Admin API • mysql-js> dba.help() • MySQL AdminAPI アクセス用 グローバル変数 'dba' • DBA 管理作業 – GR の構成作成および確認 – インスタンスの起動停止 データベース管理用 API App Servers with MySQL Router MySQL Group Replication MySQL Shell Setup, Manage, Orchestrate
InnoDB Cluster
MySQL Router + Group Replication + MySQL Shell
= InnoDB Cluster
@RKajiyama

第20回 中国地方DB勉強会 in 岡山 MySQLレプリケーション

Editor's Notes

  • #48 Group Replication is a plugin and uses a service interface to access the server such as a logging interface and a sql interface, etc. The execution flow is transfered to the plugin through extension points or callbacks. Underneath there is a group communication system which is responsible for propagating messages, for example transactions, to all members.
  • #49 MySQL Group Replication is tigthly integrated with the server which means that it will keep evolving. For example, several information on Group Replication is exposed through performance schema tables and more things will be eventually added. The interface between the sever and the plugin is very neat and clean. During transaction execution there is no interaction among remote members: changes are locally executed and captured. Upon commit control is transfered to the plugin which propagates the changes to remote members. Upon delivery, each replica verifies whether the changes conflict with any other concurrent change that was previously delivered. If there is no conflict, their are applied and the transaction is committed. Otherwise, the transaction is aborted and ignored on remote members.
  • #52 The MySQL Shell is intended as a general purpose scriptable management frontend for MySQL. The AdminAPI provides InnoDB clusters management functionality over the Shell. Within the context of MySQL HA, it can be used for: * Install the metadata schema * Update the metadata schema from the actual state of the replicaset * Perform remote provisioning of MySQL instances for GR via SSH, acting as a remote frontend for mysqlprovision (start a replicaset, add instances to a replicaset etc) In the future, it will also allow management of sharding related functionality.