SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL RouterとMySQL Fabric
MySQL FabricによるSharding環境においてのMySQL Router連携
Created: 2016/01/23
MySQL Global Business Unit
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。
また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。
以下の事項は、マテリアルやコード、機能を提供することをコミットメントするものではない為、
購買決定を行う際の判断材料になさらないで下さい。
オラクル製品に関して記載されている機能の開発、リリースおよび時期については、
弊社の裁量により決定されます。
SAFE HARBOR STATEMENT
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL Fabricとは?
• MySQLサーバー群を管理する
統合型のフレームワーク
• 高可用性とデータ・シャーディング
による拡張性を実現する事が可能
• OpenStack Novaとの連携
• MySQL Utilitiesの一部として提供
(2014-05-27 ver.1.4.3~)
– GTIDモードによるレプリケーション
機能を活用している
(MySQL 5.6.5以降で使用可能)
MySQL Fabric
Connector
Application
Read-slaves
SQL
Master group
Read-slaves
Master group
参照:MySQL Fabric の特徴と利点
http://www-jp.mysql.com/products/enterprise/fabric/features.html
Master
Slave
コネクター
管理
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Connectorからデータベースへのアクセス
常に最新の状況をメンバー間で共有
MySQL Fabric
Connector
Application
Read-slaves
Master group
アプリケーションからデータベースへの接続
①
Fabric対応コネクターがfabric.cfgの設定をImportして、Fabricノードに
アクセスし、レプリケーションの構成やシャーディング情報等を取得。
②
①で取得した情報をベースにマスターサーバー(Read_Write),
スレーブサーバー(Read_Only)へアクセス
①
② MySQL Backing Store
管理ノード
Master/Slave
コネクター
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL
Backing
Store
MySQL Fabricと管理データベース
管理サーバーでは、XML-RPCとMySQL Protocol
にてノードと通信しFabricの状態を管理
管理ノード
管理用データベースには、
Fabricで構成されたデータ
ベースの最新状況を保管
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Sharding with Fabric
書き込みスケーラビリティ より多くの書き込みを処理することが可能
大規模なデータセット 大き過ぎるデータベース/単一サーバーに収まらないデータ
性能改善 小さなインデックスサイズ/ワーキングセットに分割
UID 1-299 UID 300-599
キー範囲分割
UID 600-899
UID 900-1199
UID 1200-1499
………………
Single Master in each HA Group.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
例) MySQL Fabric 書き込みSharding
1) Fabricグループ構成の確認
2) FabricにSharding Groupを追加
mysqlfabric group create shard#
mysqlfabric group add shard# サーバー
mysqlfabric sharding add_table 1 test.employees emp_no
mysqlfabric sharding add_shard 1 shard1/1,shard2/300
3) Fabricグループ構成の確認
# shard1 (Server:63304,63305,63306)
# shard2 (Server:63307,63308,63309) 300以上
mysqlfabric dump sharding_information
mysqlfabric group lookup_servers グループ名
1~299
300~
※Shardingを削除する場合は、定義をDisableしてからRemove
Fabric対応コネクターが自動的にDMLを適切なグループに割り振ります
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
例) Fabric対応コネクター (python)
import mysql.connector
from mysql.connector import fabric
import time
def add_employee(conn, emp_no, first_name, last_name):
try:
conn.set_property(tables=["test.employees"], key=str(emp_no), mode=fabric.MODE_READWRITE, scope=fabric.SCOPE_LOCAL)
cur = conn.cursor()
cur.execute("INSERT INTO employees VALUES (%s, %s, %s)", (emp_no, first_name, last_name))
except mysql.connector.Error:
print "add_employee: Database connection error, trying to reconnect ..."
conn=connect()
def find_employee(conn, emp_no):
try:
conn.set_property(tables=["test.employees"], key=str(emp_no), mode=fabric.MODE_READONLY, scope=fabric.SCOPE_LOCAL)
cur = conn.cursor()
cur.execute( “SELECT concat(‘Hostname:’,@@hostname),concat(‘: ’,@@port,‘ ; ’), first_name, last_name FROM employees WHERE emp_no = %s", (emp_no,) )
except mysql.connector.Error:
print "find_employee: Database connection error, trying to reconnect ..."
conn=connect()
for row in cur:
print row[0],row[1],row[2],row[3]
def connect():
try:
conn=mysql.connector.connect(
fabric={"host" : "localhost", "port" : 32274, "username": "admin", "password": "admin"}, user="app", database="test", password="app", autocommit=True
コネクターがSharding Ruleをベースとして、データを自動的にそれぞれのグループへ
振り分けると同時に読み込みに関しても自動的にデータを持つグループへ分散
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL RouterからShardingされた
Fabric Groupにアクセスする場合
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
説明用) Sharding定義
-bash-4.2$ mysqlfabric dump sharding_information
Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e
Time-To-Live: 1
schema_name table_name column_name lower_bound shard_id type_name group_id global_group
----------- ---------- ----------- ----------- -------- --------- -------- ------------
test employees emp_no 1 1 RANGE shard1 global
test employees emp_no 500 2 RANGE shard2 global
global
server_uuid address status mode weight
------------------------------------ --------------- --------- ---------- ------
6d950152-c1c5-11e5-8f6d-080027d65c57 127.0.0.1:63301 PRIMARY READ_WRITE 1.0
70d6ea75-c1c5-11e5-8fe0-080027d65c57 127.0.0.1:63302 SECONDARY READ_ONLY 1.0
shard1
server_uuid address status mode weight
------------------------------------ --------------- --------- ---------- ------
74f7973b-c1c5-11e5-930f-080027d65c57 127.0.0.1:63303 PRIMARY READ_WRITE 1.0
79516b62-c1c5-11e5-9412-080027d65c57 127.0.0.1:63304 SECONDARY READ_ONLY 1.0
7c69673a-c1c5-11e5-94da-080027d65c57 127.0.0.1:63305 SECONDARY READ_ONLY 1.0
shard2
server_uuid address status mode weight
------------------------------------ --------------- --------- ---------- ------
802efea1-c1c5-11e5-95fe-080027d65c57 127.0.0.1:63306 PRIMARY READ_WRITE 1.0
84e9c0e9-c1c5-11e5-9789-080027d65c57 127.0.0.1:63307 SECONDARY READ_ONLY 1.0
88fe54f6-c1c5-11e5-9a10-080027d65c57 127.0.0.1:63308 SECONDARY READ_ONLY 1.0
親グループのGlobalに対して、
DDL, DMLを実行するとShard1,
Shard2にも反映されます。
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL Router設定ファイルをSharding環境用に設定
[fabric_cache:ha1]
address = localhost:32275
user = admin
[routing:Read_Write_Global]
bind_port = 7001
destinations = fabric+cache://ha1/group/global
mode = read-write
[routing:Read_Only_Global]
bind_port = 7002
destinations = fabric+cache://ha1/group/global
mode = read-only
[routing:Read_Write_shard1]
bind_port = 7003
destinations = fabric+cache://ha1/group/shard1
mode = read-write
[routing:Read_Only_shard1]
bind_port = 7004
destinations = fabric+cache://ha1/group/shard1
mode = read-only
[routing:Read_Write_shard2]
bind_port = 7005
destinations = fabric+cache://ha1/group/shard2
mode = read-write
[routing:Read_Only_shard2]
bind_port = 7006
destinations = fabric+cache://ha1/group/shard2
mode = read-only
[keepalive]
interval = 60
それぞれのレプリケーショングループ (Sharding Group)毎にrouter経由の接続を作成
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
例) test.employeeにデータをINSERT (Fabric対応Connector経由)
-bash-4.2$ mysql -h 127.0.0.1 -P 7003 -u root --password=root -e "select count(*),@@port FROM test.employees"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 22 | 63303 |
+----------+--------+
-bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 22 | 63304 |
+----------+--------+
-bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 22 | 63305 |
+----------+--------+
schema_name table_name column_name lower_bound shard_id type_name group_id global_group
----------- ---------- ----------- ----------- -------- --------- -------- ------------
test employees emp_no 1 1 RANGE shard1 global
test employees emp_no 500 2 RANGE shard2 global
Shard1のみに22件
データがINSERTされて
いる事が確認出来る
参照はRouter経由で行っている為、
Round-Robinしている
メモ:
Fabric対応コネクター経由の処理は常に、
アプリケーションからの接続先がFabric管理サーバー
スライド P.8参照
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
例) test.employeeにデータをINSERT (MySQL Router経由)
-bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees"
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 22 | 63305 |
+----------+--------+
-bash-4.2$ mysql -h 127.0.0.1 -P 7003 -u root --password=root -e "insert into
test.employees(emp_no,first_name,last_name) values(23,'Shard1','Insert from P7003')"
-bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees"
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 23 | 63304 |
+----------+--------+
-bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees"
+----------+--------+
| count(*) | @@port |
+----------+--------+
| 23 | 63305 |
+----------+--------+
schema_name table_name column_name lower_bound shard_id type_name group_id global_group
----------- ---------- ----------- ----------- -------- --------- -------- ------------
test employees emp_no 1 1 RANGE shard1 global
test employees emp_no 500 2 RANGE shard2 global
Router経由でshard1に
データを1件INSERT
参照はRouter経由で行っている為、
Round-Robinしている
メモ:
MySQL Router2.0.2経由の処理は、アプリケーション内部で
それぞれのShardingグループ毎の接続に分ける必要あり。
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
参考)
MySQL Fabric
https://www.mysql.com/products/enterprise/fabric.html
MySQL Router
https://www.mysql.com/products/enterprise/router.html
https://dev.mysql.com/doc/mysql-router/en/
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
MySQL RouterとMySQL Fabric(sharding)環境との連携

Weitere ähnliche Inhalte

Andere mochten auch

Multi thread slave_performance_on_opc
Multi thread slave_performance_on_opcMulti thread slave_performance_on_opc
Multi thread slave_performance_on_opcShinya Sugiyama
 
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)Yuji Otani
 
Solaris vs Linux
Solaris vs LinuxSolaris vs Linux
Solaris vs LinuxGrigale LTD
 
Building Scalable High Availability Systems using MySQL Fabric
Building Scalable High Availability Systems using MySQL FabricBuilding Scalable High Availability Systems using MySQL Fabric
Building Scalable High Availability Systems using MySQL FabricMats Kindahl
 
Programación MySQL-Ejercicios
Programación MySQL-EjerciciosProgramación MySQL-Ejercicios
Programación MySQL-Ejerciciostestgrupocomex
 
MySQLerの7つ道具
MySQLerの7つ道具MySQLerの7つ道具
MySQLerの7つ道具yoku0825
 
MySQL 5.7の次のMySQLは
MySQL 5.7の次のMySQLはMySQL 5.7の次のMySQLは
MySQL 5.7の次のMySQLはyoku0825
 
Spiderストレージエンジンのご紹介
Spiderストレージエンジンのご紹介Spiderストレージエンジンのご紹介
Spiderストレージエンジンのご紹介Kentoku
 
DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤Kenshin Yamada
 

Andere mochten auch (9)

Multi thread slave_performance_on_opc
Multi thread slave_performance_on_opcMulti thread slave_performance_on_opc
Multi thread slave_performance_on_opc
 
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)
MariaDB+GaleraClusterの運用事例(MySQL勉強会2016-01-28)
 
Solaris vs Linux
Solaris vs LinuxSolaris vs Linux
Solaris vs Linux
 
Building Scalable High Availability Systems using MySQL Fabric
Building Scalable High Availability Systems using MySQL FabricBuilding Scalable High Availability Systems using MySQL Fabric
Building Scalable High Availability Systems using MySQL Fabric
 
Programación MySQL-Ejercicios
Programación MySQL-EjerciciosProgramación MySQL-Ejercicios
Programación MySQL-Ejercicios
 
MySQLerの7つ道具
MySQLerの7つ道具MySQLerの7つ道具
MySQLerの7つ道具
 
MySQL 5.7の次のMySQLは
MySQL 5.7の次のMySQLはMySQL 5.7の次のMySQLは
MySQL 5.7の次のMySQLは
 
Spiderストレージエンジンのご紹介
Spiderストレージエンジンのご紹介Spiderストレージエンジンのご紹介
Spiderストレージエンジンのご紹介
 
DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤
 

Mehr von Shinya Sugiyama

MySQLとPostgreSQLの基本的な実行プラン比較
MySQLとPostgreSQLの基本的な実行プラン比較MySQLとPostgreSQLの基本的な実行プラン比較
MySQLとPostgreSQLの基本的な実行プラン比較Shinya Sugiyama
 
MySQLとPostgreSQLの基本的なパラメータ比較
MySQLとPostgreSQLの基本的なパラメータ比較MySQLとPostgreSQLの基本的なパラメータ比較
MySQLとPostgreSQLの基本的なパラメータ比較Shinya Sugiyama
 
MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較Shinya Sugiyama
 
MySQLとPostgreSQLの基本的なバックアップ比較
MySQLとPostgreSQLの基本的なバックアップ比較MySQLとPostgreSQLの基本的なバックアップ比較
MySQLとPostgreSQLの基本的なバックアップ比較Shinya Sugiyama
 
MySQLとPostgreSQLにおける基本的なアカウント管理
MySQLとPostgreSQLにおける基本的なアカウント管理MySQLとPostgreSQLにおける基本的なアカウント管理
MySQLとPostgreSQLにおける基本的なアカウント管理Shinya Sugiyama
 
Locondo 20190703@inno db_cluster
Locondo 20190703@inno db_clusterLocondo 20190703@inno db_cluster
Locondo 20190703@inno db_clusterShinya Sugiyama
 
Locondo 20190215@ec tech_group
Locondo 20190215@ec tech_groupLocondo 20190215@ec tech_group
Locondo 20190215@ec tech_groupShinya Sugiyama
 
DB tech showcase_tokyo2018_LOCONDO
DB tech showcase_tokyo2018_LOCONDODB tech showcase_tokyo2018_LOCONDO
DB tech showcase_tokyo2018_LOCONDOShinya Sugiyama
 
MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要Shinya Sugiyama
 
MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介Shinya Sugiyama
 
Oracle Cloud MySQL Service
Oracle Cloud MySQL ServiceOracle Cloud MySQL Service
Oracle Cloud MySQL ServiceShinya Sugiyama
 
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)Shinya Sugiyama
 
MySQLデータ暗号化と暗号鍵のローテーション
MySQLデータ暗号化と暗号鍵のローテーションMySQLデータ暗号化と暗号鍵のローテーション
MySQLデータ暗号化と暗号鍵のローテーションShinya Sugiyama
 
Power of SQL and NoSQL with MySQL5.7
Power of SQL and NoSQL with MySQL5.7Power of SQL and NoSQL with MySQL5.7
Power of SQL and NoSQL with MySQL5.7Shinya Sugiyama
 
MySQL57 Update@OSC Fukuoka 20151003
MySQL57 Update@OSC Fukuoka 20151003MySQL57 Update@OSC Fukuoka 20151003
MySQL57 Update@OSC Fukuoka 20151003Shinya Sugiyama
 
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)No sql with mysql cluster (MyNA・JPUG合同DB勉強会)
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)Shinya Sugiyama
 
MySQL 5.7とレプリケーションにおける改良
MySQL 5.7とレプリケーションにおける改良MySQL 5.7とレプリケーションにおける改良
MySQL 5.7とレプリケーションにおける改良Shinya Sugiyama
 
MySQL 5.7 Technical Update (日本語)
MySQL 5.7 Technical Update (日本語)MySQL 5.7 Technical Update (日本語)
MySQL 5.7 Technical Update (日本語)Shinya Sugiyama
 

Mehr von Shinya Sugiyama (20)

MySQLとPostgreSQLの基本的な実行プラン比較
MySQLとPostgreSQLの基本的な実行プラン比較MySQLとPostgreSQLの基本的な実行プラン比較
MySQLとPostgreSQLの基本的な実行プラン比較
 
MySQLとPostgreSQLの基本的なパラメータ比較
MySQLとPostgreSQLの基本的なパラメータ比較MySQLとPostgreSQLの基本的なパラメータ比較
MySQLとPostgreSQLの基本的なパラメータ比較
 
MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較
 
MySQLとPostgreSQLの基本的なバックアップ比較
MySQLとPostgreSQLの基本的なバックアップ比較MySQLとPostgreSQLの基本的なバックアップ比較
MySQLとPostgreSQLの基本的なバックアップ比較
 
MySQLとPostgreSQLにおける基本的なアカウント管理
MySQLとPostgreSQLにおける基本的なアカウント管理MySQLとPostgreSQLにおける基本的なアカウント管理
MySQLとPostgreSQLにおける基本的なアカウント管理
 
Locondo 20190703@inno db_cluster
Locondo 20190703@inno db_clusterLocondo 20190703@inno db_cluster
Locondo 20190703@inno db_cluster
 
Locondo 20190215@ec tech_group
Locondo 20190215@ec tech_groupLocondo 20190215@ec tech_group
Locondo 20190215@ec tech_group
 
DB tech showcase_tokyo2018_LOCONDO
DB tech showcase_tokyo2018_LOCONDODB tech showcase_tokyo2018_LOCONDO
DB tech showcase_tokyo2018_LOCONDO
 
MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要MySQL8.0 SYS スキーマ概要
MySQL8.0 SYS スキーマ概要
 
MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介
 
MySQL Partition Engine
MySQL Partition EngineMySQL Partition Engine
MySQL Partition Engine
 
Oracle Cloud MySQL Service
Oracle Cloud MySQL ServiceOracle Cloud MySQL Service
Oracle Cloud MySQL Service
 
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
 
MySQL8.0 in COSCUP2017
MySQL8.0 in COSCUP2017MySQL8.0 in COSCUP2017
MySQL8.0 in COSCUP2017
 
MySQLデータ暗号化と暗号鍵のローテーション
MySQLデータ暗号化と暗号鍵のローテーションMySQLデータ暗号化と暗号鍵のローテーション
MySQLデータ暗号化と暗号鍵のローテーション
 
Power of SQL and NoSQL with MySQL5.7
Power of SQL and NoSQL with MySQL5.7Power of SQL and NoSQL with MySQL5.7
Power of SQL and NoSQL with MySQL5.7
 
MySQL57 Update@OSC Fukuoka 20151003
MySQL57 Update@OSC Fukuoka 20151003MySQL57 Update@OSC Fukuoka 20151003
MySQL57 Update@OSC Fukuoka 20151003
 
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)No sql with mysql cluster (MyNA・JPUG合同DB勉強会)
No sql with mysql cluster (MyNA・JPUG合同DB勉強会)
 
MySQL 5.7とレプリケーションにおける改良
MySQL 5.7とレプリケーションにおける改良MySQL 5.7とレプリケーションにおける改良
MySQL 5.7とレプリケーションにおける改良
 
MySQL 5.7 Technical Update (日本語)
MySQL 5.7 Technical Update (日本語)MySQL 5.7 Technical Update (日本語)
MySQL 5.7 Technical Update (日本語)
 

MySQL RouterとMySQL Fabric(sharding)環境との連携

  • 1.
  • 2. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL RouterとMySQL Fabric MySQL FabricによるSharding環境においてのMySQL Router連携 Created: 2016/01/23 MySQL Global Business Unit
  • 3. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。 また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。 以下の事項は、マテリアルやコード、機能を提供することをコミットメントするものではない為、 購買決定を行う際の判断材料になさらないで下さい。 オラクル製品に関して記載されている機能の開発、リリースおよび時期については、 弊社の裁量により決定されます。 SAFE HARBOR STATEMENT 3
  • 4. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL Fabricとは? • MySQLサーバー群を管理する 統合型のフレームワーク • 高可用性とデータ・シャーディング による拡張性を実現する事が可能 • OpenStack Novaとの連携 • MySQL Utilitiesの一部として提供 (2014-05-27 ver.1.4.3~) – GTIDモードによるレプリケーション 機能を活用している (MySQL 5.6.5以降で使用可能) MySQL Fabric Connector Application Read-slaves SQL Master group Read-slaves Master group 参照:MySQL Fabric の特徴と利点 http://www-jp.mysql.com/products/enterprise/fabric/features.html Master Slave コネクター 管理
  • 5. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Connectorからデータベースへのアクセス 常に最新の状況をメンバー間で共有 MySQL Fabric Connector Application Read-slaves Master group アプリケーションからデータベースへの接続 ① Fabric対応コネクターがfabric.cfgの設定をImportして、Fabricノードに アクセスし、レプリケーションの構成やシャーディング情報等を取得。 ② ①で取得した情報をベースにマスターサーバー(Read_Write), スレーブサーバー(Read_Only)へアクセス ① ② MySQL Backing Store 管理ノード Master/Slave コネクター
  • 6. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL Backing Store MySQL Fabricと管理データベース 管理サーバーでは、XML-RPCとMySQL Protocol にてノードと通信しFabricの状態を管理 管理ノード 管理用データベースには、 Fabricで構成されたデータ ベースの最新状況を保管
  • 7. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Sharding with Fabric 書き込みスケーラビリティ より多くの書き込みを処理することが可能 大規模なデータセット 大き過ぎるデータベース/単一サーバーに収まらないデータ 性能改善 小さなインデックスサイズ/ワーキングセットに分割 UID 1-299 UID 300-599 キー範囲分割 UID 600-899 UID 900-1199 UID 1200-1499 ……………… Single Master in each HA Group.
  • 8. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 例) MySQL Fabric 書き込みSharding 1) Fabricグループ構成の確認 2) FabricにSharding Groupを追加 mysqlfabric group create shard# mysqlfabric group add shard# サーバー mysqlfabric sharding add_table 1 test.employees emp_no mysqlfabric sharding add_shard 1 shard1/1,shard2/300 3) Fabricグループ構成の確認 # shard1 (Server:63304,63305,63306) # shard2 (Server:63307,63308,63309) 300以上 mysqlfabric dump sharding_information mysqlfabric group lookup_servers グループ名 1~299 300~ ※Shardingを削除する場合は、定義をDisableしてからRemove Fabric対応コネクターが自動的にDMLを適切なグループに割り振ります
  • 9. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 例) Fabric対応コネクター (python) import mysql.connector from mysql.connector import fabric import time def add_employee(conn, emp_no, first_name, last_name): try: conn.set_property(tables=["test.employees"], key=str(emp_no), mode=fabric.MODE_READWRITE, scope=fabric.SCOPE_LOCAL) cur = conn.cursor() cur.execute("INSERT INTO employees VALUES (%s, %s, %s)", (emp_no, first_name, last_name)) except mysql.connector.Error: print "add_employee: Database connection error, trying to reconnect ..." conn=connect() def find_employee(conn, emp_no): try: conn.set_property(tables=["test.employees"], key=str(emp_no), mode=fabric.MODE_READONLY, scope=fabric.SCOPE_LOCAL) cur = conn.cursor() cur.execute( “SELECT concat(‘Hostname:’,@@hostname),concat(‘: ’,@@port,‘ ; ’), first_name, last_name FROM employees WHERE emp_no = %s", (emp_no,) ) except mysql.connector.Error: print "find_employee: Database connection error, trying to reconnect ..." conn=connect() for row in cur: print row[0],row[1],row[2],row[3] def connect(): try: conn=mysql.connector.connect( fabric={"host" : "localhost", "port" : 32274, "username": "admin", "password": "admin"}, user="app", database="test", password="app", autocommit=True コネクターがSharding Ruleをベースとして、データを自動的にそれぞれのグループへ 振り分けると同時に読み込みに関しても自動的にデータを持つグループへ分散
  • 10. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL RouterからShardingされた Fabric Groupにアクセスする場合
  • 11. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 説明用) Sharding定義 -bash-4.2$ mysqlfabric dump sharding_information Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 schema_name table_name column_name lower_bound shard_id type_name group_id global_group ----------- ---------- ----------- ----------- -------- --------- -------- ------------ test employees emp_no 1 1 RANGE shard1 global test employees emp_no 500 2 RANGE shard2 global global server_uuid address status mode weight ------------------------------------ --------------- --------- ---------- ------ 6d950152-c1c5-11e5-8f6d-080027d65c57 127.0.0.1:63301 PRIMARY READ_WRITE 1.0 70d6ea75-c1c5-11e5-8fe0-080027d65c57 127.0.0.1:63302 SECONDARY READ_ONLY 1.0 shard1 server_uuid address status mode weight ------------------------------------ --------------- --------- ---------- ------ 74f7973b-c1c5-11e5-930f-080027d65c57 127.0.0.1:63303 PRIMARY READ_WRITE 1.0 79516b62-c1c5-11e5-9412-080027d65c57 127.0.0.1:63304 SECONDARY READ_ONLY 1.0 7c69673a-c1c5-11e5-94da-080027d65c57 127.0.0.1:63305 SECONDARY READ_ONLY 1.0 shard2 server_uuid address status mode weight ------------------------------------ --------------- --------- ---------- ------ 802efea1-c1c5-11e5-95fe-080027d65c57 127.0.0.1:63306 PRIMARY READ_WRITE 1.0 84e9c0e9-c1c5-11e5-9789-080027d65c57 127.0.0.1:63307 SECONDARY READ_ONLY 1.0 88fe54f6-c1c5-11e5-9a10-080027d65c57 127.0.0.1:63308 SECONDARY READ_ONLY 1.0 親グループのGlobalに対して、 DDL, DMLを実行するとShard1, Shard2にも反映されます。
  • 12. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL Router設定ファイルをSharding環境用に設定 [fabric_cache:ha1] address = localhost:32275 user = admin [routing:Read_Write_Global] bind_port = 7001 destinations = fabric+cache://ha1/group/global mode = read-write [routing:Read_Only_Global] bind_port = 7002 destinations = fabric+cache://ha1/group/global mode = read-only [routing:Read_Write_shard1] bind_port = 7003 destinations = fabric+cache://ha1/group/shard1 mode = read-write [routing:Read_Only_shard1] bind_port = 7004 destinations = fabric+cache://ha1/group/shard1 mode = read-only [routing:Read_Write_shard2] bind_port = 7005 destinations = fabric+cache://ha1/group/shard2 mode = read-write [routing:Read_Only_shard2] bind_port = 7006 destinations = fabric+cache://ha1/group/shard2 mode = read-only [keepalive] interval = 60 それぞれのレプリケーショングループ (Sharding Group)毎にrouter経由の接続を作成
  • 13. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 例) test.employeeにデータをINSERT (Fabric対応Connector経由) -bash-4.2$ mysql -h 127.0.0.1 -P 7003 -u root --password=root -e "select count(*),@@port FROM test.employees" mysql: [Warning] Using a password on the command line interface can be insecure. +----------+--------+ | count(*) | @@port | +----------+--------+ | 22 | 63303 | +----------+--------+ -bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees" mysql: [Warning] Using a password on the command line interface can be insecure. +----------+--------+ | count(*) | @@port | +----------+--------+ | 22 | 63304 | +----------+--------+ -bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees" mysql: [Warning] Using a password on the command line interface can be insecure. +----------+--------+ | count(*) | @@port | +----------+--------+ | 22 | 63305 | +----------+--------+ schema_name table_name column_name lower_bound shard_id type_name group_id global_group ----------- ---------- ----------- ----------- -------- --------- -------- ------------ test employees emp_no 1 1 RANGE shard1 global test employees emp_no 500 2 RANGE shard2 global Shard1のみに22件 データがINSERTされて いる事が確認出来る 参照はRouter経由で行っている為、 Round-Robinしている メモ: Fabric対応コネクター経由の処理は常に、 アプリケーションからの接続先がFabric管理サーバー スライド P.8参照
  • 14. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 例) test.employeeにデータをINSERT (MySQL Router経由) -bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees" +----------+--------+ | count(*) | @@port | +----------+--------+ | 22 | 63305 | +----------+--------+ -bash-4.2$ mysql -h 127.0.0.1 -P 7003 -u root --password=root -e "insert into test.employees(emp_no,first_name,last_name) values(23,'Shard1','Insert from P7003')" -bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees" +----------+--------+ | count(*) | @@port | +----------+--------+ | 23 | 63304 | +----------+--------+ -bash-4.2$ mysql -h 127.0.0.1 -P 7004 -u root --password=root -e "select count(*),@@port FROM test.employees" +----------+--------+ | count(*) | @@port | +----------+--------+ | 23 | 63305 | +----------+--------+ schema_name table_name column_name lower_bound shard_id type_name group_id global_group ----------- ---------- ----------- ----------- -------- --------- -------- ------------ test employees emp_no 1 1 RANGE shard1 global test employees emp_no 500 2 RANGE shard2 global Router経由でshard1に データを1件INSERT 参照はRouter経由で行っている為、 Round-Robinしている メモ: MySQL Router2.0.2経由の処理は、アプリケーション内部で それぞれのShardingグループ毎の接続に分ける必要あり。
  • 15. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 参考) MySQL Fabric https://www.mysql.com/products/enterprise/fabric.html MySQL Router https://www.mysql.com/products/enterprise/router.html https://dev.mysql.com/doc/mysql-router/en/
  • 16. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |