Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL Cluster Basics


Published on

This presentation was written by Wagner Bianchi for the presentation on the Oracle Consulting Team/Professional Services meeting that took place in San Francisco/CA.

Published in: Technology
  • Be the first to comment

MySQL Cluster Basics

  1. 1. MySQL Cluster Wagner Bianchi – LAD Senior Principal Consulting [email_address]
  2. 2. Disclaimer The preceding 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 decisions. The development, release, and timing of any features or functionality described for Oracle ’s products remains at the sole discretion of Oracle.
  3. 3. Technology Specifications <ul><li>Virtualization with Oracle VM VirtualBox; </li></ul><ul><li>MySQL Cluster 7.1.13. </li></ul>NodeType MachineName IP Management node1 Management node2 Data/Storage node3 Data/Storage node4 Data/Storage node5 Data/Storage node6 SQL/API node7 SQL/API node8 SQL/API node9 SQL/API node10
  4. 4. Agenda <ul><li>Cluster’s components; </li></ul><ul><ul><li>Management Node </li></ul></ul><ul><ul><li>SQL/API Node </li></ul></ul><ul><ul><li>Data/Storage Node </li></ul></ul><ul><li>Configurations File; </li></ul><ul><ul><li>Local </li></ul></ul><ul><ul><li>Global </li></ul></ul><ul><ul><li>Connect String </li></ul></ul><ul><li>Cluster Partitioning </li></ul><ul><ul><li>Partitions </li></ul></ul><ul><ul><li>Fragments </li></ul></ul><ul><li>Disk Tables </li></ul><ul><li>In-Memory Tables </li></ul><ul><li>Replication </li></ul><ul><ul><li>Synchronous </li></ul></ul><ul><ul><li>Assynchronous </li></ul></ul><ul><ul><li>Replication Channels; </li></ul></ul><ul><li>Backup & Restore </li></ul><ul><ul><li>Native Backup </li></ul></ul><ul><ul><li>Native Restore </li></ul></ul><ul><ul><li>mysqldump </li></ul></ul><ul><li>Performance Tuning </li></ul><ul><ul><li>Condition Pushdown </li></ul></ul><ul><ul><li>Iptraf </li></ul></ul>- Part I - Part II
  5. 5. Management Node <ul><li>Management Node have processes that make possible to manager the entire cluster at a high-level ; </li></ul><ul><li>There are two programs involved in the management of the MySQL Cluster: </li></ul><ul><ul><li>ndb_mgm: this is a command-line tool or client used for interacting with the cluster management daemon; </li></ul></ul><ul><ul><li>ndb_mgmd: this is the daemon responsible for exchanging status and other messages with cluster; </li></ul></ul>
  6. 6. Management Node <ul><li>Management Node is used by a client to make possible online interactions with all cluster nodes such as starts, restarts, check consumed resources, check cluster logs and et cetera; </li></ul><ul><li>Operations of native and online backup is done via management client, issuing the command START BACKUP, e.g.: </li></ul># executing na online native backup shell> ndb_mgm –e “START BACKUP”
  7. 7. Management Node <ul><li>We can check a data node's used or consumed resources: </li></ul><ul><li>Command ALL is used to report the actual node’s status and consumed resources. To check ALL STATUS , issue: </li></ul># executing na online native backup shell> ndb_mgm –e “ALL REPORT memoryusage” # checking data node’s status shell> ndb_mgm –e “ALL STATUS”
  8. 8. Management Node <ul><li>When a local data node's files are used and the option “ nostart ” is mentioned in these files, you’ll be required to start data nodes manually, using ndb_mgm as: </li></ul><ul><li>You can START or RESTART a node, issuing mentioned statement, preceding by the node ID. Observing that it will work only for data nodes, not for SQL/API nodes; </li></ul># start or restarting data nodes after its execution shell> ndb_mgm –e “4 [ START | RESTART ]”
  9. 9. Management Node <ul><li>Important to note that at the first ndb_mgmd start, it will create a directory to store all cluster’s configuration cache files at /usr/mysql-cluster; </li></ul><ul><li>To restart ndb_mgmd overwriting cache files, the following options can be used on command line ( ./ndb_mgmd ): </li></ul><ul><ul><li>--initial </li></ul></ul><ul><ul><li>--skip-config-cache </li></ul></ul><ul><ul><li>or removing cache files with: </li></ul></ul><ul><ul><ul><ul><li>rm –f /usr/mysql-cluster/* </li></ul></ul></ul></ul>
  10. 10. Management Node <ul><li>Downloading and installing mgm node packages: </li></ul># creating directories -> BASEDIR and DATADIR [ root@node1 ~ ] mkdir -p /usr/local/mysql-cluster [ root@node1 ~ ] mkdir -p /var/lib/mysql-cluster [ root@node1 ~ ] cd /usr/local/mysql-cluster # downloading management node necessary packages [ root@node1 ~ ] wget [ root@node1 ~ ] wget # installing necessary packages [ root@node1 mysql-cluster ] rpm -ivh MySQL-* Preparing... ############################################ [100%] 1:MySQL-Cluster-gpl-management ########################### [100%] 2:MySQL-Cluster-gpl-tools ################################ [100%]
  11. 11. Management Node <ul><li>Before to start ndb_mgmd , be sure that a configuration file, normally named config.ini has been created – you will be required to point this file using one of these options below: </li></ul><ul><li>Or the short form: </li></ul># command-line management daemon execution shell> ndb_mgmd --config-file=/path/to/file # using short form to state cluster’s config file shell> ndb_mgmd –f /path/to/file
  12. 12. Management Node <ul><li>You can verify that the management server process is running by viewing the output of a system command such this one: </li></ul><ul><li>Now we can use ndb_mgm, the management client to retrieve information about the cluster using SHOW command: </li></ul>[ root@node1 ]# ps aux | grep ndb_mgmd root 103467 17.3 0.7 8398 2564 ? Ssl 3:20 3:55 ndb_mgmd –f /usr/local/mysql-cluster/config.ini # SHOW command retrieves information about cluster [ root@node1 ]# ndb_mgm –e “ SHOW”
  13. 13. Data/Storage Node <ul><li>The Data or Storage Node, which is implemented as ndbd or ndbmtd , handles data storage and retrieval for a specific subset of the cluster’s data; </li></ul><ul><li>Usually a Data Node is part of a larger group of data nodes in a cluster that work together to handle data; </li></ul><ul><li>The specific purpose of Data or Storage Nodes is simply to process and retrieve information, being the storage for the whole cluster; </li></ul>
  14. 14. Data/Storage Node <ul><li>The data node’s tasks include, but are not limited to, the following: </li></ul><ul><ul><li>Storing and retrieving index and records data from memory and disk (whenever uses disk storage tables); </li></ul></ul><ul><ul><li>Injecting data into the binary logs for external replication; </li></ul></ul><ul><ul><li>Participating in distributed transactions; </li></ul></ul><ul><ul><li>Monitoring other nodes in the cluster and notifying the management server of any node failures; </li></ul></ul><ul><ul><li>Writing tables data to disk at checkpoints and performing recovery on restart; </li></ul></ul><ul><ul><li>Sending information to and processing requests from the management server; </li></ul></ul>
  15. 15. Data/Storage Node
  16. 16. Data/Storage Node <ul><li>Data nodes store database tables and indexes in memory and conduct a significant portion of the SQL query processing of a working cluster; </li></ul><ul><li>The single-threaded storage node process is called ndbd and either this or the multi-threaded version, ndbmtd must be installed and executed on each storage node; </li></ul><ul><li>Necessary packages: </li></ul><ul><ul><li>MySQL-Cluster-gpl-tools.rhel5.rpm </li></ul></ul><ul><ul><li>MySQL-Cluster-gpl-storage.rhel5.rpm </li></ul></ul>This is the same idea of multi-threaded replication applied on slave server when using MySQL 5.6 (milestone yet!!)
  17. 17. SQL/API Node <ul><li>The SQL Node, which runs as the mysqld program, provides application access to the cluster, receives all external interactions as queries and mysqldump backups; </li></ul><ul><li>Necessary packages to install: </li></ul><ul><ul><li>MySQL-Cluster-gpl-server-7.1.13.rhel5.i386.rpm </li></ul></ul><ul><ul><li>MySQL-Cluster-client-7.1.13.rhel5.i386.rpm </li></ul></ul><ul><ul><li>MySQL-Cluster-shared-7.1.13.rhel5.i386.rpm </li></ul></ul>
  18. 18. A good strategy for packages… <ul><li>Download all of the necessary installation pacakages for Cluster onto the Management Node and then later send them to the appropriate nodes: </li></ul>
  19. 19. Configuration Files
  20. 20. Configuration File <ul><li>To operate, the nodes that make up a MySQL Cluster, information about the cluster environment is needed and cluster's configuration file provides this; </li></ul><ul><li>Configuration files can be used to set nearly all of parameters available, although a set of these parameters even can be used on the command line; </li></ul><ul><li>A MySQL Cluster relies on two types of configuration files: </li></ul><ul><ul><li>Local configuration file, residing on each node; </li></ul></ul><ul><ul><li>Global configuration file, kept on Management Node; </li></ul></ul>
  21. 21. Local Configuration File <ul><li>Each data or API Node in a particular cluster needs to know how to connect to the cluster Management Node(s) – another way to provide necessary information is to use local configuration file; </li></ul><ul><li>These types of files follow similar conventions to my.cnf, are located in the same place and have the same structure; </li></ul>[ndbd] # local ndbd’s configuration file - /etc/my.cnf ndb-connectstring=, NoStart # ndbd do not start after be invoked
  22. 22. Global Configuration File <ul><li>The global configuration file is a central one that resides on one or more Management Node servers, and which provides information about the cluster as a whole </li></ul><ul><li>Specific types of nodes can be configured globally within the sections of this file, e.g., [ndbd default] ; </li></ul><ul><li>This file, commonly created as config.ini , is used by the Management Node to start cluster, receive nodes’ connections and start cluster’s operations; </li></ul>
  23. 23. Global Configuration File [ndb_mgmd] NodeId=1 HostName= [ndbd default] NoOfReplicas=2 DataDir=/var/lib/mysql-cluster StopOnError=false # angel will restart failed nodes [ndbd] NodeId=2 HostName= [ndbd] NodeId=3 HostName= [mysqld] NodeIde=4 HostName= [mysqld] # free reserved slot – e.g. ndb_restore, the native cli for database restore
  24. 24. The Cluster Connectstring <ul><li>One of the most important settings in the local configuration file is the cluster connectstring the provides connections between nodes; </li></ul><ul><li>This parameter is referenced in any of the three ways, depending on the node that is using it: </li></ul><ul><ul><li>ndb-connectstring : Data Nodes & SQL Nodes; </li></ul></ul><ul><ul><li>connect-string : Data Nodes only; </li></ul></ul><ul><ul><li>connectstring : SQL Node only; </li></ul></ul>
  25. 25. Cluster Partitioning
  26. 26. Cluster Partitioning <ul><li>A partition in simples terms is a portion or a set of table rows divided as a horizontal partition – in contrast we are familiar with the concept of vertical partition that divides tables by columns (this isn't supported by MySQL at this time); </li></ul><ul><li>MySQL Cluster has an internal algorithm that will automatically implement a partitioning that will roughly have the same amount of table rows; </li></ul><ul><li>This is done evenly balance the memory requirements that the ndbd/ndbmtd process make across all data nodes. </li></ul>
  27. 27. Cluster Partitioning <ul><li>It is also possible to specify the partitioning manually for NDB tables using PARTITION BY KEY and PARTITION BY LINEAR in a CREATE TABLE or ALTER TABLE ; </li></ul><ul><li>The number of cluster partitions is always equal to the number of data nodes in each of the cluster’s node groups – each node group must have the same number of nodes! </li></ul><ul><li>The cluster can also, and usually does) store multiple copies of each partition among the data nodes – these copies are referred to as fragments ; </li></ul>
  28. 28. Cluster Partitioning
  29. 29. Cluster Partitioning <ul><li>Partition P1 is stored on node group 0 – a primary replica (fragment) is stored on data node 1, and a secondary replica (backup of the fragment) is stored on data node 2; </li></ul><ul><li>Partition P2 is stored on the cluster’s other node group (node group 1). This partition’s primary replica is on data node 3, and its backup is on the data node 4; </li></ul><ul><li>Partition P3 is stored on node group 0. However, the placing of its two replicas is reserved from that of P1; for P3, the primary replica is stored on data node 2, and the backup on data node 3; </li></ul><ul><li>Partition P4 is stored on node group 1, and the place of its two replicas is reserved from that of P2 – that is, this partition’s primary replica is located on data node 4, with the backup replica on data node 3. </li></ul>
  30. 30. Cluster Partitioning
  31. 31. Cluster Partitioning <ul><li>Even trusting in MySQL Cluster’s algorithms, it is a good practice to review automatically created partitions in order to improve databases’ responses; </li></ul><ul><li>If MySQL Cluster package &quot;tools&quot; is installed, ndb_desc will be available and can be used with the “ -p &quot; flag: </li></ul>#some columns were omitted from the final result to better accommodate it -- Per partition info – Partition Row count Commit count Frag fixed memory Frag varsized memory 2 2 2 65536 327680 1 2 2 65536 327680 3 NDBT_ProgramExit: 0 - OK
  32. 32. Cluster Partitioning <ul><li>It is good practice following recovery from a MySQL Cluster backup to REORGANIZE PARTITIONS in order to force the algorithm to review what was done: </li></ul><ul><li>In the case that a database has too many tables, use to combine INFORMATION_SCHEMA.TABLES columns and CONCAT() function in order to produce a ALTER TABLE for each database table; </li></ul># alter partitions in order to adjust and better accommodate data # among all partitions, fragments and data nodes mysql> ALTER ONLINE TABLE world.City -> REORGANIZE PARTITION; Query OK, 0 rows affected (1.52 sec)
  33. 33. Disk-based and In-memory Tables
  34. 34. Disk-based Tables <ul><li>To configure disk-based tables, data nodes should have spare space on a high-performance block device, e.g. 15k storage disks, SSD based disks, SCSI and et cetera; </li></ul><ul><li>A set of two file types must be created on data nodes in order to accommodate data and logs on disk in manner that NDB Storage Engine can understand; </li></ul><ul><ul><li>TABLESPACES : disk-based tables stores their data in structures like this which made up of one or more files; </li></ul></ul><ul><ul><li>LOGFILE GROUP : disk-based tables stores their “ndb” data in a logfile group made up of one or more UNDO logfiles. (TC) </li></ul></ul>
  35. 35. Disk-based Tables <ul><li>First of all, create LOGFILE GROUP and an UNDOFILE ; </li></ul><ul><li>After that, create the TABLESPACE file that will use LOGFILE GROUP previously created; </li></ul>
  36. 36. Disk-based Tables <ul><li>A good test is to download world test database from the MySQL website, create database world into MySQL Cluster through the SQL, a LOGFILE GROUP , a TABLESPACE and finally, restore database from bkp file; </li></ul><ul><li>You must remember that, even a table that has been set up on disk will have its indexes kept in memory… </li></ul>
  37. 37. Disk-based Tables # creating database world mysql> CREATE DATABASE world; Query OK, 0 rows affected (1.52 sec) # creating logfile group world_log mysql> CREATE LOGFILE GROUP world_log ADD UNDOFILE ‘world_log.dat’ -> UNDO_BUFFER_SIZE=16M INITIAL_SIZE=200M ENGINE=NDB; Query OK, 0 rows affected (2.23 sec) # creating tablespace world_tbs, where will reside table`s data mysql> CREATE TABLESPACE world_tbs ADD DATAFILE ‘world_tbs.dat’ -> USE LOGFILE GROUP world_log INITIAL_SIZE=500M ENGINE=NDB; Query OK, 0 rows affected (1.09 sec) # restoring world database from world.sql file shell> cat world.sql | sed –e ‘s/ENGINE=MyISAM/STORAGE DISK TABLESPACE world_tbs ENGINE = NDB/g’ | mysql world
  38. 38. Disk-based Tables <ul><li>After those processes, it will be easier to check or confirm if tables are residing on right tablespace, using the right logfile group and they are controlled by NDB Cluster Storage Engine; </li></ul><ul><li>By completing these tests and using the other client programs it will then be possible to build the entire MySQL Cluster; </li></ul># on data node (node3) I used ndb_show_tables filtering results shell> ndb_show_tables –c –d world | grep Tablespace 9 Tablespace Online - world_tbs
  39. 39. Disk-based Tables <ul><li>As you saw on the last command list we created LOGFILE GROUP with world_log name, TABLESPACE file with world_tbs name and used STORAGE DISK statement on CREATE TABLE ; </li></ul><ul><li>Linux command sed with flag “ -e ” was used to replace the string “ ENGINE=MyISAM ” by “ STORAGE DISK ENGINE=NDB ”; </li></ul>
  40. 40. Disk Storage Metadata <ul><li>The FILES table in INFORMATION_SCHEMA database contains information about files related to disk based storage – this is an extension of defaults metadata dictionary; </li></ul><ul><li>Each row in the INFORMATION_SCHEMA.FILES table corresponds either to a data file or to an undo file, with exception of an additional row for log file groups, since free space is reported per group, not per undofile ; </li></ul>
  41. 41. Disk Storage Metadata <ul><li>Am I running out of space? </li></ul># creating a simple view to check that main question CREATE VIEW check_space AS SELECT FILE_NAME, ((TOTAL_EXTENTS * EXTENT_SIZE)/(1024 * 1024)) AS ‘Total MB’, ((FREE_EXTENTS * EXTENT_SIZE)/(1024*1024)) AS ‘Free MB’, ( ((FREE_EXTENTS * EXTENT_SIZE)*100) /(TOTAL_EXTENTS * EXTENT_SIZE) ) AS ‘% Free’, EXTRA FROM INFORMATION_SCHEMA.FILES WHERE ENGINE = ‘NDBCLUSTER’ AND FILE_TYPE = ‘DATAFILE’;
  42. 42. Disk Storage Metadata <ul><li>Now, I just need analyze results below and add more datafiles or resize those that already exist; </li></ul># results returned after the query’s execution mysql> select * from check_space; +---------------+----------+----------+---------+----------------+ | FILE_NAME | Total MB | Free MB | % Free | EXTRA | +---------------+----------+----------+---------+----------------+ | world_tbs.dat | 500.0000 | 494.0000 | 98.8000 | CLUSTER_NODE=3 | | world_tbs.dat | 500.0000 | 494.0000 | 98.8000 | CLUSTER_NODE=4 | | world_tbs.dat | 500.0000 | 494.0000 | 98.8000 | CLUSTER_NODE=5 | | world_tbs.dat | 500.0000 | 494.0000 | 98.8000 | CLUSTER_NODE=6 | +---------------+----------+----------+---------+----------------+ 4 rows in set (0.11 sec)
  43. 43. Disk Storage Metadata <ul><li>Adding new datafile to TABLESPACE world_tbs : </li></ul><ul><li>Executing our created view again: </li></ul># results returned after the query’s execution mysql> ALTER TABLESPACE world_tbs -> ADD DATAFILE ‘world_tbs-1.dat’ ENGINE=NDB; Query OK, 0 rows affected (4.11 sec) # results returned after the query’s execution mysql> select * from check_space; +-----------------+----------+----------+----------+-----------------+ | FILE_NAME       | Total MB | Free MB  | % Free   | EXTRA          | +-----------------+----------+----------+----------+----------------+ | world_tbs.dat   | 500.0000 | 494.0000 |  98.8000 | CLUSTER_NODE=3 | | world_tbs.dat   | 500.0000 | 494.0000 |  98.8000 | CLUSTER_NODE=4 | | world_tbs.dat   | 500.0000 | 494.0000 |  98.8000 | CLUSTER_NODE=5 | | world_tbs.dat   | 500.0000 | 494.0000 |  98.8000 | CLUSTER_NODE=6 | | world_tbs-1.dat | 100.0000 | 100.0000 | 100.0000 | CLUSTER_NODE=3 | | world_tbs-1.dat | 100.0000 | 100.0000 | 100.0000 | CLUSTER_NODE=4 | | world_tbs-1.dat | 100.0000 | 100.0000 | 100.0000 | CLUSTER_NODE=5 | | world_tbs-1.dat | 100.0000 | 100.0000 | 100.0000 | CLUSTER_NODE=6 | +-----------------+----------+----------+----------+----------------+ 8 rows in set (0.08 sec)
  44. 44. Disk Storage Metadata <ul><li>To DROP TABLESPACE world_tbs , you must drop LOGFILE GROUP world_log first, so that no errors are thrown by MySQL: </li></ul># trying to remove a tbs without remove logfile group used mysql> DROP TABLESPACE world_tbs ENGINE=NDB; ERROR 1529 (HY000): Failed to drop TABLESPACE mysql> SHOW WARNINGS; +-----------------------------------------------------------------+ Error | 1296 | Got error 768 'Cant drop filegroup, filegroup is used' from NDB | Error | 1529 | Failed to drop TABLESPACE +-----------------------------------------------------------------+ 2 rows in set (0.01 sec)
  45. 45. Disk Storage Metadata <ul><li>It is possible to run out of space or get close to that with undofiles in LOGFILE GROUP and this simple query will show if this is happening: </li></ul># checking if logs are reach its max file size mysql> SELECT CONCAT('CLUSTER NODE: ', node_id) AS NodeId,     ->        FORMAT(total/1024/1024,0) AS 'Total Space (MB)',     ->        FORMAT(used/1024/1024,0) AS 'Used Space (MB)'     -> FROM logspaces     -> GROUP BY NodeId; +-----------------+------------------+-----------------+ | NodeId          | Total Space (MB) | Used Space (MB) | +-----------------+------------------+-----------------+ | CLUSTER NODE: 3 | 256              | 0               | | CLUSTER NODE: 4 | 256              | 0               | | CLUSTER NODE: 5 | 256              | 0               | | CLUSTER NODE: 6 | 256              | 0               | +-----------------+------------------+-----------------+ 4 rows in set (0.26 sec)
  46. 46. In-memory Tables <ul><li>In order to store table data in-memory, no additional statements are required, instead some parameters must be configured to get the required data in main memory; </li></ul><ul><li>Those parameters must be configured in the global configuration file (located on mgm node),l generally use the [ndbd default] section; </li></ul><ul><li>it is not good to set up parameters individually for each Data Node; </li></ul>
  47. 47. In-memory Tables <ul><li>Most commonly used parameters in [ndbd] and [ndbd default]: </li></ul><ul><ul><li>DataMemory : amount of memory space for storing database records; </li></ul></ul><ul><ul><li>IndexMemory : amount of memory space to store hash indexes (primary key and unique indexes); </li></ul></ul><ul><ul><ul><li>MaxNoOfTables; </li></ul></ul></ul><ul><ul><ul><li>MaNoOfAttributes; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfOrderedIndexes; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfTriggers; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfConcurrentOperations; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfConcurrentIndexOperations; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfConcurrentScans; </li></ul></ul></ul><ul><ul><ul><li>MaxNoOfConcurrentTransactions “ …” </li></ul></ul></ul>
  48. 48. Good strategy to place’s tables <ul><li>Normally, a good strategy is to define together with the customer those data and tables that are critical to the customer's business and those that are not; </li></ul><ul><ul><li>Critical data will reside in-memory; </li></ul></ul><ul><ul><li>Non-critical data will reside on disk structures; </li></ul></ul><ul><li>In-memory tables require good parameter tuning in order to accommodate all data in memory: DataMemory , IndexMemory and MaxNoOf* ; </li></ul><ul><li>Disk-based tables will require structures to be created as LOGFILE GROUP and TABLESPACES, and will need faster disks such as SSD, SCSI or 15K disk storages; </li></ul>
  49. 49. Calculating DataMemory and IndexMemory <ul><li>MySQL Cluster comes with a set of utility programs that run on the command line with lots of helpful options for configuring your server; </li></ul><ul><li>To calculate the amount of required memory that a specific database will need to work in a MySQL Cluster, the Perl script named may be used; </li></ul><ul><li>Before you can use it, you will need the following Perl packages: </li></ul><ul><ul><li>perl-DBI*; </li></ul></ul><ul><ul><li>perl-DBD; </li></ul></ul><ul><ul><li>perl-Class-MethodMaker; </li></ul></ul>Install epel repository and use “ yum install ”
  50. 50. Calculating DataMemory and IndexMemory <ul><li> has more conservative options with only long flags, as seeing below: </li></ul><ul><ul><li>--username </li></ul></ul><ul><ul><li>--password – can`t be empty one; </li></ul></ul><ul><ul><li>--hostname; </li></ul></ul><ul><ul><li>--database; </li></ul></ul><ul><ul><li>--format – it can be text or HTML </li></ul></ul><ul><ul><li>--excludetables; </li></ul></ul><ul><ul><li>--excludedbs; </li></ul></ul><ul><ul><li>--savequeries (file); </li></ul></ul><ul><ul><li>--loadqueries (previously recorded with --savequeries); </li></ul></ul>
  51. 51. Calculating DataMemory and IndexMemory <ul><li>Executing against world database running into a non-cluster MySQL Server </li></ul># executing on command-line shell> --user=wb --password=“123” --hostname= --database=world --format=text # checking how much memory is required to put world database into a “MC” Parameter Minimum Requirements (world database) ----------------------------------------------- * indicates greater than default Parameter Default 4.1 5.0 5.1 DataMemory (KB) 81920 480 480 512 NoOfOrderedIndexes 128 3 3 3 NoOfTables 128 3 3 3 IndexMemory (KB) 18432 192 88 88 NoOfUniqueHashIndexes 64 0 0 0 NoOfAttributes 1000 24 24 24 NoOfTriggers 768 15 15 15
  52. 52. Agenda <ul><li>Cluster’s components; </li></ul><ul><ul><li>Management Node </li></ul></ul><ul><ul><li>SQL/API Node </li></ul></ul><ul><ul><li>Data/Storage Node </li></ul></ul><ul><li>Configurations File; </li></ul><ul><ul><li>Local </li></ul></ul><ul><ul><li>Global </li></ul></ul><ul><ul><li>Connect String </li></ul></ul><ul><li>Cluster Partitioning </li></ul><ul><ul><li>Partitions </li></ul></ul><ul><ul><li>Fragments </li></ul></ul><ul><li>Disk Tables </li></ul><ul><li>In-Memory Tables </li></ul><ul><li>Replication </li></ul><ul><ul><li>Synchronous </li></ul></ul><ul><ul><li>Assynchronous </li></ul></ul><ul><ul><li>Replication Channels; </li></ul></ul><ul><li>Backup & Restore </li></ul><ul><ul><li>Native Backup </li></ul></ul><ul><ul><li>Native Restore </li></ul></ul><ul><ul><li>mysqldump </li></ul></ul><ul><li>Performance Tuning </li></ul><ul><ul><li>Condition Pushdown </li></ul></ul><ul><ul><li>Iptraf </li></ul></ul>- Part I - Part II
  53. 53. Replication
  54. 54. MySQL Cluster Replication <ul><li>MySQL Replication is a feature of the MySQL Server that allows you to replicate data from one database server, called MASTER , to one or more, called SLAVE ; </li></ul><ul><li>Using MySQL Cluster has three replication modes: </li></ul><ul><ul><li>Synchronous replication happens only between Data Nodes and uses the Two Phase Commit Protocol that enables transactions to commit on all data nodes at the same time ; </li></ul></ul><ul><ul><li>Semi-synchronous and Asynchronous replication, to set up replication channels between two or more clusters ; </li></ul></ul>
  55. 55. MySQL Cluster Replication <ul><li>MySQL Cluster can be used across many sites for geographical replication - two sites connected as Active / Passive; </li></ul><ul><li>This kind of configuration is done via MASTER/MASTER implementation with the application accessing; </li></ul>
  56. 56. MySQL Cluster Replication <ul><li>In our actual scenario, where we are using ten nodes, 4 sql, 4 ndbd, and 2 mgm, it can be easily divided into two cluster’s sites, connected by a MASTER/MASTER replication; </li></ul><ul><li>Remember that a passive channel must be configured with a “write barrier”: </li></ul># read only will avoid write query execution from any user # apart from root -- root will continue be able to do writes mysql> SET GLOBAL read_only = 1; Query OK, 0 rows affected (0.00 sec)
  57. 57. MySQL Cluster Replication <ul><li>Step-by-step to replication channel configuration: </li></ul><ul><ul><li>Config.ini file on Node1 and Node2 must be recreated; </li></ul></ul><ul><ul><li>Unique server-id for each SQL Node inside the schema; </li></ul></ul><ul><ul><li>A common user must be create individually on each server; </li></ul></ul><ul><ul><ul><li>GRANT REPLICATION SLAVE …; </li></ul></ul></ul><ul><ul><li>Check if binary log is enabled – it must be enable; </li></ul></ul><ul><ul><li>CHANGE MASTER TO on servers involved, in order to create two: </li></ul></ul><ul><ul><ul><li>The first server from group A will MASTER/MASTER with first server from group B; </li></ul></ul></ul><ul><ul><ul><li>The second server from group A will MASTER/MASTER with second server from group B; </li></ul></ul></ul>
  58. 58. MySQL Cluster Replication
  59. 59. Backup & Restore
  60. 60. Backup & Restore <ul><li>Considering which method and tools will be used is a good way to begin the strategic planning for backup and recovery; </li></ul><ul><li>MySQL Cluster has its own native tools that can be used to design better backup and restore plans for existing databases; </li></ul><ul><li>Native backup is done by the START BACKUP command and the restored by the ndb_restore client program; </li></ul>
  61. 61. Backup – SINGLE USER MODE <ul><li>Single User Mode is a way to tell the cluster to process queries from a specific SQL/API Node only – It is good for situations when you need to avoid updates in the middle of a backup process: </li></ul># entering single user mode – other SQL/API will be ignored ndb_mgm> ENTER SINGLE USER MODE 4 Single user mode entered Access is granted for API node 4 only ndb_mgm> START BACKUP NOWAIT ndb_mgm> ndb_mgm> EXIT SINGLE USER MODE Exiting single user mode in progress Use ALL STATUS or SHOW to see when single user mode has been exited
  62. 62. Backup – START BACKUP <ul><li>A MySQL Cluster backup is a snapshot of all NDB databases stored by the cluster at a given time, and consists of three main parts: </li></ul><ul><ul><li>Metadata: the names and definitions of all MySQL Cluster databases and tables : </li></ul></ul><ul><ul><ul><li>BACKUP-backup_id.node_id.ctl </li></ul></ul></ul><ul><ul><li>Table records: the data actually stored in the tables at the time that the backup was made: </li></ul></ul><ul><ul><ul><li>BACKUP-backup_id.node_id.Data </li></ul></ul></ul><ul><ul><li>Transaction Log: a sequential record telling how and when data was stored in the database: </li></ul></ul><ul><ul><ul><li>BACKUP-backup_id.node_id.log </li></ul></ul></ul>
  63. 63. Backup – START BACKUP <ul><li>The START BACKUP command execution is done through the ndb_mgm or Management Node Client and it has three interesting options: </li></ul><ul><ul><li>NOWAIT : present the prompt immediately to the user; </li></ul></ul><ul><ul><li>WAIT STARTED : wait until the backup process starts; </li></ul></ul><ul><ul><li>WAIT COMPLETE : wait until the backup process is finished; </li></ul></ul><ul><li>It is good practice to set up a new physical partition on Data Nodes to store all backups – this behavior can be configured using BackupDataDir variable under [ndbd default] </li></ul>
  64. 64. Backup – START BACKUP <ul><li>When using START BACKUP with NOWAIT option, monitor the backup with ALL REPORT : </li></ul># using START BACKUP with NOWAIT and monitoring its process ndb_mgm> START BACKUP NOWAIT ndb_mgm> ALL REPORT BACKUPSTATUS Node 3: Local backup status: backup 3 started from node 1  #Records: 0 #LogRecords: 0  Data: 0 bytes Log: 0 bytes Node 4: Local backup status: backup 3 started from node 1  #Records: 0 #LogRecords: 0  Data: 0 bytes Log: 0 bytes ndb_mgm> Node 3: Backup 3 started from node 1 Node 3: Backup 3 started from node 1 completed  StartGCP: 5444 StopGCP: 5447  #Records: 7370 #LogRecords: 0  Data: 497788 bytes Log: 0 bytes
  65. 65. Backup – START BACKUP <ul><li>Cluster backups are created by default in the BACKUP subdirectory of the DataDir on each Data Node as showed below: </li></ul><ul><li>Listing files inside BACKUP-1: </li></ul># listing DataDir/BACKUP subdirectories [root@node3]# ls –l BACKUP-1 # listing files from BACKUP-1 directory [root@node3 BACKUP]# ls -l BACKUP-1/ total 276 -rw-r--r-- 1 root root 253388 Jun  7 17:57 BACKUP-1-0.3.Data -rw-r--r-- 1 root root  17660 Jun  7 17:57 BACKUP-1.3.ctl -rw-r--r-- 1 root root     52 Jun  7 17:57 BACKUP-1.3.log
  66. 66. Restore - ndb_restore <ul><li>The cluster’s restoration program is implemented as a separate command-line utility – ndb_restore and there are a lot of options that can be used with it; </li></ul><ul><ul><li>-c is a connect string; </li></ul></ul><ul><ul><li>-b is a backup id; </li></ul></ul><ul><ul><li>-n is the node’s id; </li></ul></ul><ul><ul><li>-r is the path where backup is located </li></ul></ul><ul><li>ndb_restore acts as a node in the cluster and requires a configuration section in the global cluster configuration – a free slot to use every execution; </li></ul>
  67. 67. Restore - ndb_restore <ul><li>[root@node3 ~]# ndb_restore -c -b 1 -n 3 -r /backup-cluster/BACKUP/BACKUP-1 Backup Id = 1 Nodeid = 3 backup path = /backup-cluster/BACKUP/BACKUP-1 Opening file '/backup-cluster/BACKUP/BACKUP-1/BACKUP-1.3.ctl' File size 17660 bytes Backup version in files: ndb-6.3.11 ndb version: mysql-5.1.56 ndb-7.1.13 Stop GCP of Backup: 4747 Connected to ndb!! Opening file '/backup-cluster/BACKUP/BACKUP-1/BACKUP-1-0.3.Data' File size 253388 bytes _____________________________________________________ Processing data in table: world/def/CountryLanguage(15) fragment 0 _____________________________________________________ Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 0 _____________________________________________________ Processing data in table: mysql/def/ndb_apply_status(6) fragment 0 _____________________________________________________ Processing data in table: world/def/City(11) fragment 0 _____________________________________________________ Processing data in table: mysql/def/NDB$BLOB_4_3(5) fragment 0 _____________________________________________________ Processing data in table: sys/def/SYSTAB_0(2) fragment 0 _____________________________________________________ Processing data in table: mysql/def/ndb_schema(4) fragment 0 _____________________________________________________ Processing data in table: world/def/Country(13) fragment 0 Opening file '/backup-cluster/BACKUP/BACKUP-1/BACKUP-1.3.log' File size 52 bytes Restored 2697 tuples and 0 log entries NDBT_ProgramExit: 0 - OK </li></ul>
  68. 68. Performance Tuning
  69. 69. Engine Condition Pushdown <ul><li>This optimization improves the efficiency of direct comparison between a no indexed column and a constant. In such cases, the condition is “pushed down” to the storage engine for evaluation; </li></ul><ul><li>For MySQL Cluster, this optimization can eliminate the need to send no matching rows over the network between the cluster's data nodes and the MySQL Server that issued the query, and can speed up queries where it is used by a factor of 5 to 10 times over cases where condition pushdown could be but is not used; </li></ul>
  70. 70. <ul><li>WHERE condition processed in the SQL Node: </li></ul>Engine Condition Pushdown Data Nodes Many Rows MySQL Few Rows SQL Query engine_condition_pushdown=0
  71. 71. Engine Condition Pushdown <ul><li>mysql> EXPLAIN SELECT a,b FROM t1 WHERE b = 10G </li></ul><ul><li>************** 1. row ************************** </li></ul><ul><li>id: 1 </li></ul><ul><li>select_type: SIMPLE </li></ul><ul><li>table: t1 </li></ul><ul><li>type: ALL </li></ul><ul><li>possible_keys: NULL </li></ul><ul><li>key: NULL </li></ul><ul><li>key_len: NULL </li></ul><ul><li>ref: NULL </li></ul><ul><li>rows: 10 </li></ul><ul><li>Extra: Using where </li></ul>
  72. 72. Engine Condition Pushdown <ul><li>WHERE condition “ pushed down ” to the Data Nodes: </li></ul>engine_condition_pushdown=1 Few Rows MySQL Few Rows SQL Query
  73. 73. Engine Condition Pushdown <ul><li>mysql> EXPLAIN SELECT a,b FROM t1 WHERE b = 10G </li></ul><ul><li>************** 1. row ************************** </li></ul><ul><li>id: 1 </li></ul><ul><li>select_type: SIMPLE </li></ul><ul><li>table: t1 </li></ul><ul><li>type: ALL </li></ul><ul><li>possible_keys: NULL </li></ul><ul><li>key: NULL </li></ul><ul><li>key_len: NULL </li></ul><ul><li>ref: NULL </li></ul><ul><li>rows: 10 </li></ul><ul><li>Extra: Using where with pushed condition </li></ul>
  74. 74. Iptraf <ul><li>IPTraf is a network monitoring utility for IP networks. It intercepts packets on the network and gives out various pieces of information about the current IP traffic over it; </li></ul><ul><li>It is simple to install after the epel repository is installed: </li></ul><ul><ul><li>shell> yum –y install iptraf </li></ul></ul><ul><li>To monitor the interface used by the cluster: </li></ul><ul><ul><li>shell> iptraf –i eth0 </li></ul></ul>
  75. 75. Iptraf
  76. 76. MySQL Cluster’s Architecture
  77. 77. Thanks! <ul><li>Wagner Bianchi is: </li></ul><ul><li>CMA 5.0/5.1/5.5; </li></ul><ul><li>CMDEV 5.0; </li></ul><ul><li>CMDBA 5.0; </li></ul><ul><li>CMCDBA 5.1; </li></ul><ul><li>@wagnerbianchijr </li></ul>