31.07.2013 Views

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>MySQL</strong> <strong>Cluster</strong> in short<br />

• <strong>MySQL</strong> <strong>Cluster</strong> is a tool to help you keep your data available<br />

• It consists of various processes called Nodes which should be setup in a shared-nothing<br />

environment.<br />

• Data Nodes: where data, table and index information is stored in-memory and<br />

optionally on disk (for non indexed data)<br />

During the tutorial you will notice NoOfReplicas=2 in the cluster configuration. This<br />

means that data is stored 2 times with cluster. If you have 2 data nodes, the data is<br />

partitioned in two parts. Each partitions has a replica on another data node. This way, in<br />

a 2 data node setup, each data node has a copy of all the data.<br />

• SQL Nodes or <strong>MySQL</strong> servers: using the NDB<strong>Cluster</strong> engine, you can use SQL to update<br />

data and retrieve information from the Data Nodes through your network (using TCP/IP)<br />

• Management Nodes: used for management and monitoring<br />

• API Nodes: application written using NDB API (SQL Nodes are an example)<br />

• The NDB<strong>Cluster</strong> engine is transaction-safe, ACID. Durability through checkpointing.<br />

Transactions<br />

Lets have a look how data is stored inside <strong>MySQL</strong> <strong>Cluster</strong>. We’ll use a table which was<br />

created using the ENGINE table option set to NDB<strong>Cluster</strong>:<br />

CREATE TABLE attendees (<br />

id INT UNSIGNED NOT NULL AUTO_INCREMENT,<br />

email VARCHAR(200) NOT NULL,<br />

PRIMARY KEY (id)<br />

) ENGINE=NDB<strong>Cluster</strong><br />

The Request<br />

Your web, Java or Python application talks to a <strong>MySQL</strong> server and asks to store a new<br />

attendee. It does this by first starting a transaction:<br />

START TRANSACTION<br />

The Transaction<br />

The <strong>MySQL</strong> server, or SQL Node, is opening a transaction on behave of the application and<br />

gets a Transaction Coordinator assigned. This coordinator is actually a Data Node which is<br />

chosen in a Round-Robin way.<br />

The Commit<br />

The application is done with sending the data and issues the COMMIT <strong>com</strong>mand. The <strong>MySQL</strong><br />

server passes on the request to the transaction coordinator and waits for the result.<br />

The Storage<br />

The Data Node acting as coordinator starts the 2-Phase Protocol. It first the other nodes<br />

whether they are ready to get the changes. When it gets an OK from all (and from itself), it<br />

says all to actually do the <strong>com</strong>mit.<br />

Copyright © 2010, Oracle and/or its affiliates. All rights reserved. 7/81

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!