Más contenido relacionado
La actualidad más candente (19)
Similar a 20140518 JJUG MySQL Clsuter as NoSQL (20)
Más de Ryusuke Kajiyama (20)
20140518 JJUG MySQL Clsuter as NoSQL
- 1. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.1
Using MySQL Cluster
as NoSQL with Java
Ryusuke Kajiyama
MySQL Sales Consulting Manager
- 2. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.2
ORACLE DRIVES
MySQL INNOVATION
DELIVERING MORE AND
BETTER PRODUCTS FASTER
- 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3
MySQL Enterprise Monitor 2.2
MySQL Cluster 7.1
MySQL Cluster Manager 1.0
MySQL Workbench 5.2
MySQL Database 5.5
MySQL Enterprise Backup 3.5
MySQL Enterprise Monitor 2.3
MySQL Cluster Manager 1.1
MySQL Enterprise Backup 3.7
All GA!
Oracle VM Template for MySQL
Oracle Products Certifications
MySQL Windows Installer
MySQL Enterprise Security
MySQL Enterprise Scalability
MySQL Cluster 7.2
MySQL Cluster Manager 1.3
MySQL Utilities 1.0.6
MySQL Workbench 6.0
All GA!
MySQL Enterprise Backup 3.10
MySQL Enterprise Audit
MySQL Windows Tools
MySQL Database 5.6
MySQL Cluster 7.3
MySQL Workbench 6.1
MySQL Fabric 1.4 RC
MySQL Database 5.7 DMR
*Development Milestone Release
All GA!
Available Now!
MySQLのイノベーション: 2010 - 2014
- 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4
Oracle Database and MySQL
Complementary on the Web and in The Cloud
Web and Cloud computing is not a ‘one size fits all’ model
Together Servicing Broader User Needs
MySQL Well Suited for Web-based & Custom Departmental
apps
Users can Benefit by Running MySQL and Oracle Together
For both on-premise and Cloud computing
- 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5
MySQLサーバ開発の優先課題
Web、クラウドインフラ、組み込みでの利用への最適化
プラグインによるアーキテクチャの簡素化
– メンテナンス効率および拡張性の向上
– さらなるNoSQLオプションの追加 (HTTP, JSON, JavaScript など)
リファクタリング
– InnoDBのデータディクショナリ
– オプティマイザ/パーサー/プロトコル
InnoDB
– 主要な使い方の改良(参照専用、高速なリカバリ)、GIS
– 全文検索の日本語対応 (中国語、韓国語も)
高可用性構成の簡素化、レプリケーション強化、シャーディング
- 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6
MySQL Cluster
- 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7
MySQLの高可用性構成
MySQL
Cluster
MySQL
Cluster
アプリケーション/
APサーバ
負荷分散
双方向
同期複製
• MySQL Cluster
シェアードナッシング型高性能クラスタ
MySQL
Server
• MySQL+DRBD
Linux用のノード間データコピー
アプリケーション/
APサーバ
フェールオーバー
同期複製
MySQL
Server
アプリケーション/
APサーバ
共有ディスク
• HAソフト利用
共有ディスクにデータを格納
フェールオーバー
MySQL
Server
MySQL
Server
アプリケーション/
APサーバ
負荷分散
非同期複製
• レプリケーション(標準機能)
非同期&準同期データレプリケーション
MySQL
Server
MySQL
Server
- 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8
Who’s Using MySQL Cluster?
- 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9
MySQL Cluster
シェアードナッシング型Active-Active RDBMSクラスタ
& トランザクション対応NoSQL
MySQL Cluster Data Nodes
Data Layer
Clients
Management
Nodes
Management
Nodes
Application Layer
- 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10
複数拠点へのクラスタ構成の展開
ディザスタリカバリ構成
およびシステムの国際展開
クラスタ構成を複数拠点間で
レプリケーション
– 構成の全てがアクティブ
– 待機系リソース無し
個別のクラスタを
AZ(availability zones)に
– 同期レプリケーション & サ
イト間での自動フェール
オーバー
Geographic Replication
- 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11
SQL & NoSQL
どちらのアクセス方法でもACIDなトランザクション処理
MySQL Cluster Data Nodes
Data Layer
Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps
JPA
Cluster JPA
PHP Perl Python Ruby JDBC Cluster J JS Apache Memcache
d
MySQL JNI Node.JS mod_ndb ndb_eng
NDB API (C++)
- 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12
秒間12億UPDATE
• 30 x Intel E5-2600搭載
サーバ
• NoSQL C++ API,
flexaSynch benchmark
• ACID トランザクショ
ン、 同期レプリケー
ション 0
5
10
15
20
25
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
MillionsofUPDATEsperSecond
MySQL Cluster Data Nodes
- 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13
RDBMSの役割は?
NoSQL
シンプルなアクセスパ
ターン
一貫性や耐障害性は妥協
しているが高性能
柔軟なデータフォーマッ
ト
シンプルな運用
RDBMS
JOINを含む複雑な処理
ACID トランザクション
定義されたスキーマ
豊富なツール群
単一ソリューションで全てをカ
バーすることは簡単では無い
拡張性
性能
高可用性
運用容易性
SQL/Joins
ACID
トランザクショ
ン
- 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14
Cluster & Memcached – スキーマフリー
<town:maidenhead,SL6>
key value
<town:maidenhead,SL6>
key value
Key Value
town:maidenhead SL6
generic table
Application view
SQL view
- 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15
Cluster & Memcached – 定義済みスキーマ
<town:maidenhead,SL6>
prefix key value
<town:maidenhead,SL6>
key value
Prefix Table Key-col Val-col policy
town: address town code cluster
Config tables
town ... code ...
maidenhead ... SL6 ...
address Table
Application view
SQL view
- 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16
MySQLの高可用性ソリューション
MySQL 5.6
レプリケーショ
ン
Oracle VM
Template
Solaris
Cluster
Windows
Cluster
DRBD
MySQL
Cluster
自動フェールオー
バー
✔ ✔ ✔ ✔ ✔ ✔
データロス無し Semi-Sync ✔ ✔ ✔ ✔ ✔
サポートOS All Linux Solaris Windows Linux All
クラスタモード
Master +
Slaves
Active/
Passive
Active/
Passive
Active/
Passive
Active/
Passive
Multi-
Master
共有ディスク 不要 必要 必要 必要 不要 不要
可用性デザイン 99.9% 99.99% 99.99% 99.95% 99.99% 99.999%
単一ベンダサポート ✔ ✔ ✔ ✖ ✔ ✔
- 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17
“Connector/J”
JDBC Driver
of MySQL
- 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18
インストール
プラットフォーム独立
最新GAリリース
– http://www.mysql.com/downloads/connector/j/
tar.gz または zip ファイルを解凍
JARファイルを環境変数CLASSPATHに追加
例
export set CLASSPATH=/opt/java/mysql-connector-java-5.1.18-bin.jar:$CLASSPATH
- 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21
ロードバランス/フェールオーバー機能
jdbc:mysql://primary,failover - 3.0.2以降 (2002年!!)
jdbc:mysql:replication:// - 3.1.11以降 (2005年)
jdbc:mysql:loadbalance:// - 5.0.5以降 (2007年)
- 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.22
ロードバランス/フェールオーバー機能の利用方法
jdbc:mysql://primary,failover-1,failover-2...
– 通常利用するサーバが停止すると、他のサーバにフェールオーバーす
る
jdbc:mysql:replication://
– レプリケーション構成において、更新処理はマスタにて実行され、
参照処理はスレーブ間で分散する
jdbc:mysql:loadbalance://
– MySQL Cluster(NDB)やマルチマスタレプリケーションの構成の場合、
参照更新処理を全てのノードに分散する
- 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23
JMX経由での接続状況の監視および設定
ロードバランスおよびフェールオーバーを管理可能
– loadBalanceConnectionGroup=“グループ名”
– JMX – loadBalanceEnableJMX=true
– com.mysql.jdbc.ConnectionGroupManager 経由
– ホストの追加および削除 (gracefully or forcefully)
– アクティブおよびインアクティブなホストのリストの取得
– 接続数およびトランザクション数の取得
詳細: https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-
concepts-managing-load-balanced-connections.html
- 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24
ロードバランス/フェールオーバーの制御
標準のコンポーネント
– 通信関連のException
– SQLState が “08”で始まる
– ユーザ定義の SQLState リスト – ユーザ定義の Class リスト
カスタムコンポーネント
– LoadBalanceExceptionChecker インターフェスを実装
- 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25
StandardLoadBalanceExceptionChecker
プロパティ
loadBalanceSQLStateFailover
– フェールオーバーさせるSQLStateの値をカンマ区切りでリストにする
– 前方一致
“08” は “08000” や “08S01” などとマッチ
loadBalanceSQLExceptionSubclassFailover
– フェールオーバーさせるSQLExceptionのサブクラスのFCQNをカンマ
区切りでリストにする
– Class.isInstance(Exception)にて比較させる
- 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.26
Custom Exception Checker
LoadBalanceExceptionCheckerが必要
– shouldExceptionTriggerFailover(SQLException ex) メソッド
– 例:NDBLoadBalanceExceptionChecker
public class NdbLoadBalanceExceptionChecker extends
StandardLoadBalanceExceptionChecker {
public boolean shouldExceptionTriggerFailover(SQLException ex) {
return super.shouldExceptionTriggerFailover(ex) || checkNdbException(ex);
}
private boolean checkNdbException(SQLException ex) {
// Have to parse the message since most NDB errors are mapped to the same DEMC, sadly.
return (ex.getMessage().startsWith("Lock wait timeout exceeded") || (ex.getMessage().startsWith("Got
temporary error")
&& ex.getMessage().endsWith("from NDB")));
}
}
- 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.27
ClusterJ &
ClusterJPA
- 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.28
MySQL Cluster : ClusterJ/JPA
ドメインオブジェクトモデルの永続化API
(ClusterJ) :
– Java API
– 高性能、低レイテンシ
ClusterJの上位レイヤとしてJPAインター
フェース
– JPA準拠
OpenJPA のプラグインとして実装
– 可能な場合はClusterJを使用、
いくつかの処理はJDBC経由に迂回する
– 全体としてJDBC単独よりも高速化を狙う
– Javaアプリ開発者にとってより扱いやすく
– WebアプリでのMySQL Cluster利用を簡素化
MySQL Cluster Data Nodes
Data Layer
Apps Apps Apps Apps
JPA
Cluster JPA
JDBC Cluster J
MySQL JNI
NDB API (C++)
- 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.29
ClusterJ
高性能かつ使いやすい
Hibernate / JPA / JDOのスタイル
Domain Object Model DataMapper パターン
– データがドメインオブジェクトに相当
– ドメインオブジェクトとビジネスロジックは分離
– ドメインオブジェクトがデータベース上のテーブルにマッピングされる
ndbjtieライブラリをベースに開発
– JNI アダプタ
– MySQL Cluster API (通称NDB API)からJavaに直接マッピング
リレーションはサポートしていない
– 外部キーやJOINはサポートしていない
- 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.30
ClusterJからNoSQLとして利用
キーバリュー型データストア
– テキストデータ (String <=> CLOB)
– バイナリデータ (byte[ ] <=> BLOB)
ドキュメントを格納
– JSON, XML, etc.
セッション情報を格納
– key = セッションID
– value = シリアライズされたセッション情報
REST pluginやnode.js API
- 29. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.31
Domain Object Model Mapping
永続化インターフェスまたはクラス
アノテーションにてマッピングを定義
– テーブル名
– 列名
– インデックス
書き方は選択可能:
– ユーザインタフェース (ClusterJが実装クラスを生成)
– 永続化クラス (ClusterJがベース実装のクラスを提供)
- 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.32
ClusterJ に実装クラスを生成させる場合
@PersistenceCapable(table="employee")
public interface Employee {
long getId();
void setId(int id);
@Column(name="full_name")
String getName();
void setName(String value);
int getSalary();
void setSalary(int value);
Integer getAge();
void setAge(Integer value);
}
- 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.33
ClusterJ のクラスを利用する場合
public class Employee
extends DynamicObject {
public String table() {
return "employee";
long getId() {
return (Long)get(0);
}
void setId(long value) {
set(0, value);
}
...
// other fields and behavior
}
- 32. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.34
ClusterJ API
SessionFactory
– MySQL Clusterへの接続ごとにインスタンスを生成
– 接続プロパティを設定
– マルチスレッドセーフ
Session
– ユーザごとのインスタンス (単一スレッドごと)
Transaction
– セッションごとのインスタンス
Query
– セッション内に複数のインスタンス
- 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.35
ClusterJ Example
Session session;
void getSession() {
session = sessionFactory.getSession();
}
Employee createEmployee(long id, String name,
int salary, int age) {
Employee employee =
session.newInstance(Employee.class);
employee.setId(id);
employee.setName(name);
employee.setSalary(salary);
employee.setAge(age);
session.persist(employee);
return employee;
}
- 34. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.36
Cluster Example
Employee findEmployee(long id) {
Employee employee =
session.find(Employee.class, id);
return employee;
}
void updateSalary(long id, int salary) {
Employee employee = findEmployee(id);
employee.setSalary(salary);
session.updatePersistent(employee);
}
- 35. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.37
ClusterJ Query
Builder パターン
JPAのCriteria APIに類似
列の値とパラメタを比較:
– equal, lessEqual, greaterEqual, lessThan, greaterThan, in, between
– nullとの比較もサポート
論理演算子との組み合わせも可能:
– OR, AND, NOT
ソート、件数制限(limit)
インデックスを使って処理されるように最適化
– 主キーまたはユニークキーを使用しての参照
– インデックスを利用してソート済み結果をスキャン
– インデックスが利用できない場合はテーブルスキャン
- 36. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.38
ClusterJ Query Example
QueryDomainType qemp =
builder.createQueryDefinition(Employee.class) ;
Predicate geAge = qemp.get("age")
.greaterEqual(qemp.param("ageFloor"));
Predicate leSalary = qemp.get("salary")
.lessEqual(qemp.param("salaryCap"));
qemp.where(geAge.and(leSalary));
Query query = session.createQuery(qemp) ;
query.setOrdering(Query.DESCENDING, "age");
query.setParameter("ageFloor",33);
query.setParameter("salaryCap", 44000);
List<Employee> results = query.getResultList() ;
- 37. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.39
ClusterJ トランザクション
トランザクションを明示することも可能
– begin()
– commit()
– rollback()
トランザクションのロールバックを指示することも可能
– setRollbackOnly()
– getRollbackOnly()
これらの関数が使用されない場合、それぞれの処理が単一トランザク
ションとして扱われる
- 38. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.40
ClusterJPA
OpenJPAのプラグインとして実装
– 利用にはopenjpa-1.2.0.jarやConnector/Jなどが必要
– http://dev.mysql.com/doc/ndbapi/en/mccj-using-jpa.html
単純な参照更新処理はClusterJにて実行
JOINを含む処理などはJDBC経由
– SQLノードにてNDB APIに変換
1クラス1テーブルをサポート
一対多または多対一のリレーションをサポート
- 39. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.41
SQL and NoSQL
Best of both world with ACID Transactions
MySQL Cluster Data Nodes
Data Layer
Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps Apps
JPA
Cluster JPA
PHP Perl Python Ruby JDBC Cluster J JS Apache Memcache
d
MySQL JNI Node.JS mod_ndb ndb_eng
NDB API (C++)
- 40. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.42
5.6
MySQL Server – GA
InnoDBの改良やオプティマイザの刷新による性能&拡張性向上
レプリケーションの可用性向上 & NoSQLインタフェース追加
MySQL Cluster - GA
MySQL 5.6統合、外部キーサポート
Node.jp APIの追加、運用性能向上
7.3
5.7
MySQL Server – DMR
リファクタリング & 各機能のプラグイン化
さらなるNoSQLインタフェース追加
- 41. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.43
The world's most popular open source database
世界でもっとも普及している、オープンソース データベース