MySQL Cluster

Craig Sylvester MySQL Sales Consultant

Monday, August 15, 2011 1 Safe Harbor Statement

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

© 2011 – Proprietary and Confidential

Monday, August 15, 2011 2 Agenda

• MySQL Cluster • MySQL Cluster Manager

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 3 MySQL Cluster Carrier Grade

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 4 MySQL Cluster Architecture

Clients

MySQL Cluster Application Nodes

MySQL MySQL Cluster Cluster Mgmt Mgmt

MySQL Cluster Data Nodes

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 5 MySQL Cluster - Components

• SQL Access SQL Node • STD API’s (JDBC, ODBC, PERL, (MySQL) Python, LDAP, C, .NET, etc)

NDB API • High Performance C/C++ API (Application) • Developer’s Guide

Data Node • Data Storage (Memory/Disk) (NDB Storage Engine) • Automatic & User-Defined Partitioning

Management • Administration & Configuration Node • Arbitration

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 6 MySQL Cluster – Black Box Concept

Clients (JDBC, ODBC, C, PHP, etc)

High Perf API

MySQL Server(s)

BLACK BOX

Mgm Node Data Nodes

NDB Storage Engine

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 7 MySQL Cluster – Distributed DB

Two Data Nodes (Physical) authid (PK) fname lname country * 100% of database on each node

1 Albert Camus France Two Replicas (Logical)

2 Ernest Hemingway USA * One copy of each

3 Johan Goethe Germany One Node Groups

4 Junichiro Tanizaki Japan * One set of identical Data Nodes

Node Group 1

Data Nodes

NDB Storage Engine

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 8 Auto data distribution and mirroring

Four Data Nodes (Physical) authid (PK) fname lname country * Half of database on each node

1 Albert Camus France Two Replicas (Logical) 2 Ernest Hemingway USA * Two copies of each partition

3 Johan Goethe Germany Two Node Groups 4 Junichiro Tanizaki Japan * Two sets of identical Data Nodes

Node Group 1 Node Group 2

authid (PK) fname lname country authid (PK) fname lname country

1 Albert Camus France 2 Ernest Hemingway USA

3 Johan Goethe Germany 4 Junichiro Tanizaki Japan

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 9 Synchronous Data Replication

Update: Two-phase UPDATE author commit SET country = ‘France’ WHERE authid = 1; protocol

Node Group 1 Node Group 2

authid (PK) fname lname country authid (PK) fname lname country

1 Albert Camus France 2 Ernest Hemingway USA

3 Johan Goethe Germany 4 Junichiro Tanizaki Japan

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 10 High Availability

Query: Result:

SELECT fname, lname Albert Camus FROM author Ernest Hemingway WHERE authid BETWEEN 1 AND 3; Johan Goethe

Node Group 1 Node Group 2 X X authid (PK) fname lname country authid (PK) fname lname country

1 Albert Camus France 2 Ernest Hemingway USA

3 Johan Goethe Germany 4 Junichiro Tanizaki Japan

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 11 Automatic Failure Detection - Heartbeats

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 12 Automatic resynchronization of failed node

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 13 Online Add Node

Application

Node Group 1 Dynamic scaling of a NG 1 NG 2 running Cluster – no interruption to service

authid (PK) fname lname country authid (PK) fname lname country 1 Albert Camus France

1 Albert Camus France 3 Johan Goethe Germany

2 Ernest Hemingway USA authid (PK) fname lname country 3 Johan Goethe Germany 2 Ernest Hemingway USA

4 Junichiro Tanizaki Japan 4 Junichiro Tanizaki Japan

http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster7_architecture.php

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 14 Geo Redundancy

• Asynchronous replication between Clusters • Supports Master-Master Replication with automatic conflict resolution

Asynchronous MySQL Replication

Cluster 1 Cluster 2

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 15 Replication Flexibility

• Synchronous replication within a Cluster node group for HA • Bi-Direction asynchronous Cluster 1 Cluster 2 replication to remote Cluster for geographic redundancy • Asynchronous replication to non-Cluster for specialized activities such as report generation

InnoDB MyISAM InnoDB • Mix and match replication types

Synchronous replication

Asynchronous replication

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 16 Backup & Restore

• Built-in Online Backup capability – Active transactions continue unaffected!!! – Non-locking/blocking • Backs up each data node – Stored on local disk on each data node • Restore – Restore one data node at-a-time • Point-In-Time Recovery – Need to enable Binary-Logging on MySQL Server • Logging used for Async Replication – Procedure • Restore cluster backup • Replay changes up-to a point using binary logs

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 17 Cluster Use Cases

• Subscriber Data Management Systems – Five 9’s or greater availability – Scalability: Cluster supports up to 255 total nodes (48 data nodes) – Multiple data access API’s (LDAP, SQL, C/C++, JDBC/ODBC, PERL, Python, PHP, Ruby) • Web Session Management – Manage persistent sessions requiring fast lookup and HA • AAA Session Management • In-Memory Cache / Persistent Cache – High speed access with guaranteed latencies – Disk-based storage • Applications requiring Automatic Sharding (or Partitioning) of data • Applications requiring High Insert/Update rates – In-memory nature enables high update rates – HLR/HSS

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 18 ndbinfo: Online Usage Metrics

mysql> use ndbinfo mysql> show tables; +------+ • ndbinfo database presents real- | Tables_in_ndbinfo | +------+ time metric data in the form of tables | blocks | • Examples include: | config_params | – Resource usage (memory, buffers) | counters | – Event counters (such as number of READ | logbuffers | operations since last restart) | logspaces | – Data node status and connection status | memoryusage | | nodes | | resources | | transporters | +------+

http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster7_architecture.php

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 19 ndbinfo examples 1. Check memory usage/availability

mysql> select * from ndbinfo.memoryusage; +------+------+------+------+------+------+ | node_id | memory_type | used | used_pages | total | total_pages | +------+------+------+------+------+------+ | 3 | Data memory | 917504 | 28 | 104857600 | 3200 | | 3 | Index memory | 221184 | 27 | 11010048 | 1344 | | 4 | Data memory | 917504 | 28 | 104857600 | 3200 | | 4 | Index memory | 221184 | 27 | 11010048 | 1344 | +------+------+------+------+------+------+

2. Check how many scans performed on each data node since the last restart

mysql> select node_id as 'data node', val as 'Table Scans' from ndbinfo.counters where counter_name='TABLE_SCANS'; +------+------+ | data node | Table Scans | +------+------+ | 3 | 3 | | 4 | 4 | +------+------+

http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster7_architecture.php

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 20 Enterprise Monitor Integration

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 21 MySQL Cluster Manager

Reducing database TCO and creating a more agile, highly available IT environment

Automated Management

Monitoring & High Availability Recovery Operation

http://www.mysql.com/products/database/cluster/mcm/

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 22 MySQL Cluster Manager 1.1 Features

http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster_manager.php

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 23 Cluster Manager example configuration

mysql client • One agent per physical host – no central manager 7. mysqld 8. mysqld each agent is responsible for its 1. ndb_mgmd 2. ndb_mgmd – local nodes agent agent – responsible for managing all 192.168.0.10 192.168.0.11 nodes in the cluster • Management responsibilities 3. ndbd 4. ndbd – Starting, stopping & restarting nodes 5. ndbd 6. ndbd – Configuration changes agent agent – Upgrades Host & Node status reporting 192.168.0.12 192.168.0.13 – – Recovering failed nodes n. mysqld MySQL Server (ID=n)

n. ndb_mgmd Management Node (ID=n)

n. ndbd Data Node (ID=n)

agent MySQL Cluster Manager agent

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 24 Creating & Starting a Cluster

mysql 1. Define the site: client Mysql> create site --hosts=192.168.0.10,192.168.0.11, -> 192.168.0.12,192.168.0.13 mysite; 2. Expand Cluster tar-ball(s) to known directory

7. mysqld 8. mysqld (basedir)

1. ndb_mgmd 2. ndb_mgmd 3. Define the package(s):

agent agent Mysql> add package --basedir=/usr/local/mysql_6_3_26 6.3; Mysql> add package --basedir=/usr/local/mysql_7_0_7 7.0;

192.168.0.10 192.168.0.11 4. Create the Cluster Mysql> create cluster --package=6.3 -> [email protected],[email protected], 3. ndbd 4. ndbd -> [email protected],[email protected], [email protected], -> [email protected],[email protected],[email protected] -> mycluster; 5. ndbd 6. ndbd

agent agent 5. Start the Cluster: Mysql> start cluster mycluster;

192.168.0.12 192.168.0.13 Note: Step 4 is where you define what nodes/processes make up the Cluster and where they should run

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 25 Check the status of the Cluster

mysql client • Request the status of the Cluster processes mysql> show status --process mycluster; +------+------+------+------+------+ | Id | Process | Host | Status | Nodegroup | +------+------+------+------+------+ 7. mysqld 8. mysqld | 1 | ndb_mgmd | 192.168.0.10 | running | | | 2 | ndb_mgmd | 192.168.0.11 | running | | 1. ndb_mgmd 2. ndb_mgmd | 3 | ndbd | 192.168.0.12 | running | 0 | | 4 | ndbd | 192.168.0.13 | running | 0 | | 5 | ndbd | 192.168.0.12 | running | 1 | agent agent | 6 | ndbd | 192.168.0.13 | running | 1 | | 7 | mysqld | 192.168.0.10 | running | | | 8 | mysqld | 192.168.0.11 | running | | +------+------+------+------+------+ 192.168.0.10 192.168.0.11 • Get the status of the hosts & agents

3. ndbd 4. ndbd mysql> list hosts mysite; +------+------+------+ 5. ndbd 6. ndbd | Host | Status | Version | +------+------+------+ | 192.168.0.10 | Available | 1.0.1 | agent agent | 192.168.0.11 | Available | 1.0.1 | | 192.168.0.12 | Available | 1.0.1 | | 192.168.0.13 | Available | 1.0.1 | 192.168.0.12 192.168.0.13 +------+------+------+

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 26 Upgrade Cluster

mysql client • Upgrade from MySQL Cluster 6.3.26 to 7.0.7:

mysql> upgrade cluster --package=7.0 mycluster; 7. mysqld 8. mysqld • Automatically upgrades each node and 1. ndb_mgmd 2. ndb_mgmd restarts the process, in the correct order, to agent agent avoid any loss of service • Without MySQL Cluster Manager, the 192.168.0.10 192.168.0.11 administrator must stop each process in turn, start the process with the new version 3. ndbd 4. ndbd and wait for the node to restart before

5. ndbd 6. ndbd moving onto the next one

agent agent

192.168.0.12 192.168.0.13

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 27 HA Provided by Cluster Manager

• Service is maintained for all Cluster processes (i.e., automatically restart process)

7. mysqld 8. mysqld • Without MySQL Cluster Manager, an angel process would recreate failed ndbd 1. ndb_mgmd 2. ndb_mgmd processes but not mysqld or ndb_mgmd agent agent processes • Cluster continues to function if one or more 192.168.0.10 192.168.0.11 agents fail or is stopped (e.g. To upgrade it) – To restore management functions, the agent should be 3. ndbd 4. ndbd restarted

5. ndbd 6. ndbd

agent agent

192.168.0.12 192.168.0.13

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 28 ClusterJ/JPA Plugin

Apps Apps Apps Apps Apps • Traditionally, Java applications have accessed

OpenJPA MySQL Cluster in one of two ways: ClusterJPA – JDBC Driver for MySQL (Connector/J) via MySQL Server JDBC ClusterJ – Written own JNI layer on top of NDB API MySQL JNI JNI • New Domain Object Model Persistence API NDB API (C++) (ClusterJ) : – Java API Network – High performance, low latency – Feature rich • JPA interface built upon this new Java layer: – Java Persistence API compliant • Implemented as an OpenJPA plugin – Uses ClusterJ where possible, reverts to JDBC for some operations – Higher performance than JDBC – More natural for most Java designers – Easier Cluster adoption for web applications Data Nodes

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 29 ClusterJ Application code example

// Create a session (connection to the database) SessionFactory factory = ClusterJHelper.getSessionFactory(props); Session session = factory.getSession();

// Create and initialise an Employee Employee newEmployee = session.newInstance(Employee.class); newEmployee.setId(988); newEmployee.setFirst("John"); newEmployee.setLast("Jones"); newEmployee.setStarted("1 February 2009"); newEmployee.setDepartment(666);

// Write the Employee to the database session.persist(newEmployee);

// Fetch the Employee from the database Employee theEmployee = session.find(Employee.class, 988);

// Make some changes to the Employee & write back to the database theEmployee.setDepartment(777); theEmployee.setCity("London"); session.updatePersistent(theEmployee);

// Retrieve the set all of Employees in department 777 QueryBuilder builder = session.getQueryBuilder(); QueryDomainType domain = builder.createQueryDefinition(Employee.class); domain.where(domain.get("department").equal(domain.param("department"))); Query query = session.createQuery(domain); query.setParameter("department",777); List results = query.getResultList();

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 30 ClusterJ Limitations

• Persistent Interfaces – no persistent classes • No Relationships – primitive types only • No Multi-table inheritance – single table per persistent interface • No joins in queries – column comparisons and boolean operators • No Table creation – user needs to create tables and indexes • No Lazy Loading – entire record is loaded at one time, including LOBs

http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster_connector_for_java.php

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 31 JPA (Java Persistence API)

• The Java standard for persistence – Works in server containers and outside (not CMP!) • Choice of implementations: OpenJPA, Hibernate, TopLink, or...... – Depends on application requirements – Select the implementation via configuration file (persistence.xml) • ClusterJPA optimized for OpenJPA today – Other implementations (Hibernate, TopLink, etc) access MySQL Cluster via JDBC

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 32 ClusterJPA Annotated class example

@Entity(name = "department") mysql> describe department;

public class Department { +------+------+------+-----+------+------+ private int Id; | Field | Type | Null | Key | Default | Extra | +------+------+------+-----+------+------+ private String Site; | id | int(11) | NO | PRI | NULL | | public Department(){} | location | varchar(255) | YES | | NULL | | +------+------+------+-----+------+------+ @Id public int getId() {return Id;} public void setId(int id) {Id=id;}

@Column(name="location") public String getSite() {return Site;} public void setSite(String site) Note that OpenJPA will create this table if it doesn’t already exist but {Site=site;} user needs to change the storage engine to NDB: mysql> ALTER TABLE department=ndb; }

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 33 ClusterJPA Application code example

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("clusterdb"); EntityManager em = entityManagerFactory.createEntityManager(); EntityTransaction userTransaction = em.getTransaction();

userTransaction.begin(); Department dept = new Department(); dept.setId(101); dept.setSite(“London”); em.persist(dept); userTransaction.commit();

userTransaction.begin(); Department theDepartment = em.find(Department.class, 101); theDepartment.setSite(“Edinburgh”); userTransaction.commit();

em.close(); entityManagerFactory.close();

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 34 Java Access Performance

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 35 MySQL Cluster 7.2 DM Download! • Queries 20x Faster – Adaptive Query Localization (aka Push Down JOINs, SPJ) – Ships the query to the data, reducing overhead • Schema Flexibility – 4x increase in column support, 128 to 512 columns – Can be added on-line to existing tables, no service interruption • User Data Consolidation – Centralizes user privileges to data nodes, accessible from all MySQL Servers – Radically simplifies provisioning and administration

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 36 MySQL Cluster 7.2: NotOnlySQL: Memcached API

• Build update-intensive, highly available services with MySQL Cluster back-end • Accessed via memcached API

• Consolidate caching and database tiers • Use existing memcached clients & avoid application changes • Support for update-intensive workloads, eliminate cache invalidation • Scalable, persistent, HA data store • Simpler re-use of data across services

• Implementation • NDB plug-in to memcached server • Direct access to NDB API

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 37 Resources to Get Started

• MySQL Cluster 7.1, Architecture and New Features – http://www.mysql.com/why-mysql/white-papers/ mysql_wp_cluster7_architecture.php • MySQL Cluster Manager – http://www.mysql.com/why-mysql/white-papers/ mysql_wp_cluster_manager.php • MySQL Cluster Connector for Java – http://www.mysql.com/why-mysql/white-papers/ mysql_wp_cluster_connector_for_java.php • MySQL Cluster 7.1 Evaluation Guide – http://www.mysql.com/why-mysql/white-papers/mysql_cluster_eval_guide.php • Getting Started with MySQL Cluster – http://www.mysql.com/products/database/cluster/get-started.html • MySQL Cluster on the Web – http://www.mysql.com/products/database/cluster/

© 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 38 © 2011 Oracle Corporation – Proprietary and Confidential

Monday, August 15, 2011 39