MySQL Cluster
MySQL Cluster, also known as MySQL NDB Cluster, is a technology providing shared-nothing clustering and auto-sharding for the MySQL database management system. It is designed to provide high availability and high throughput with low latency, while allowing for near linear scalability. MySQL Cluster is implemented through the NDB or NDBCLUSTER storage engine for MySQL.
Architecture
MySQL Cluster is designed around a distributed, multi-master ACID compliant architecture with no single point of failure. MySQL Cluster uses automatic sharding to scale out read and write operations on commodity hardware and can be accessed via SQL and Non-SQL APIs.Replication
Internally MySQL Cluster uses synchronous replication through a two-phase commit mechanism in order to guarantee that data is written to multiple nodes upon committing the data. Two copies of the data are required to guarantee availability. MySQL Cluster automatically creates “node groups” from the number of replicas and data nodes specified by the user. Updates are synchronously replicated between members of the node group to protect against data loss and support fast failover between nodes. Cluster replication differs from "MySQL Replication", which is instead.It is also possible to replicate asynchronously between clusters; this is sometimes referred to as "MySQL Cluster Replication" or "geographical replication". This is typically used to replicate clusters between data centers for IT disaster recovery or to reduce the effects of network latency by locating data physically closer to a set of users. Unlike standard MySQL replication, MySQL Cluster's geographic replication uses optimistic concurrency control and the concept of Epochs to provide a mechanism for conflict detection and resolution, enabling active/active clustering between data centers.
Starting with MySQL Cluster 7.2, support for synchronous replication between data centers was supported with the Multi-Site Clustering feature.
Horizontal data partitioning (auto-sharding)
MySQL Cluster is implemented as a fully distributed multi-master database ensuring updates made by any application or SQL node are instantly available to all of the other nodes accessing the cluster, and each data node can accept write operations.Data within MySQL Cluster tables is automatically partitioned across all of the data nodes in the system. This is done based on a hashing algorithm based on the primary key on the table, and is transparent to the end application. Clients can connect to any node in the cluster and have queries automatically access the correct shards needed to satisfy a query or commit a transaction. MySQL Cluster is able to support cross-shard queries and transactions.
Users can define their own partitioning schemes. This allows developers to add “distribution awareness” to applications by partitioning based on a sub-key that is common to all rows being accessed by high running transactions. This ensures that data used to complete transactions is localized on the same shard, thereby reducing network hops.
Hybrid storage
MySQL Cluster allows datasets larger than the capacity of a single machine to be stored and accessed across multiple machines.MySQL Cluster maintains all indexed columns in distributed memory. Non-indexed columns can also be maintained in distributed memory or can be maintained on disk with an in-memory page cache. Storing non-indexed columns on disk allows MySQL Cluster to store datasets larger than the aggregate memory of the clustered machines.
MySQL Cluster writes Redo logs to disk for all data changes as well as check pointing data to disk regularly. This allows the cluster to consistently recover from disk after a full cluster outage. As the Redo logs are written asynchronously with respect to transaction commit, some small number of transactions can be lost if the full cluster fails, however this can be mitigated by using geographic replication or multi-site cluster discussed above. The current default asynchronous write delay is 2 seconds, and is configurable. Normal single point of failure scenarios do not result in any data loss due to the synchronous data replication within the cluster.
When a MySQL Cluster table is maintained in memory, the cluster will only access disk storage to write Redo records and checkpoints. As these writes are sequential and limited random access patterns are involved, MySQL Cluster can achieve higher write throughput rates with limited disk hardware compared to a traditional disk-based caching RDBMS. This checkpointing to disk of in-memory table data can be disabled if disk-based persistence isn't needed.
Shared nothing
MySQL Cluster is designed to have no single point of failure. Provided that the cluster is set up correctly, any single node, system, or piece of hardware can fail without the entire cluster failing. Shared disk is not required. The interconnects between nodes can be standard Ethernet, Gigabit Ethernet, InfiniBand, or SCI interconnects.SQL and NoSQL APIs
As MySQL Cluster stores tables in data nodes, rather than in the MySQL Server, there are multiple interfaces available to access the database:- SQL access via the MySQL Server
- NoSQL APIs where MySQL Cluster libraries can be embedded into an application to provide direct access to the data nodes without passing through a SQL layer. These include:
- *
- *
- *
- *
- *
MySQL Cluster Manager
MySQL Ndb Operator
The open source simplifies the deployment and operation of MySQL Cluster on a Kubernetes cluster. Ndb Operator deploys containerized MySQL Cluster Data, Management and SQL nodes in a number of StatefulSets with data stored in Persistent Volumes.Kubernetes mechanisms extend the high availability features of MySQL Cluster, for example automatically restoring HA redundancy after hardware failures by migrating pods to new hardware.
Operating MySQL Cluster on Kubernetes allows a full stack of cloud native software to be operated in the same way on private or public clouds.
NDB Cluster
NDB Cluster is the distributed database system underlying MySQL Cluster. It can be used independently of a MySQL Server with users accessing the Cluster via the NDB API. "NDB" stands for Network Database.From the MySQL Server perspective the NDB Cluster is a Storage engine for storing tables of rows.
From the NDB Cluster perspective, a MySQL Server instance is an API process connected to the Cluster. NDB Cluster can concurrently support access from other types of API processes including Memcached, JavaScript/Node.JS, Java, JPA and HTTP/REST. All API processes can operate on the same tables and data stored in the NDB Cluster.
MySQL Cluster uses the MySQL Server to provide the following capabilities on top of Ndb Cluster:
- SQL parsing / optimising / execution capability
- * Connectors to applications via JDBC, ODBC etc.
- Cross-table join mechanism
- User authentication and authorisation
- Asynchronous data replication to other systems
Implementation
MySQL Cluster uses three different types of nodes :- Data node : These nodes store the data. Tables are automatically sharded across the data nodes which also transparently handle load balancing, replication, failover and self-healing.
- Management node : Used for configuration and monitoring of the cluster. They are required only to start or restart a cluster node. They can also be configured as arbitrators, but this is not mandatory.
- Application node or SQL node : A MySQL server that connects to all of the data nodes in order to perform data storage and retrieval. This node type is optional; it is possible to query data nodes directly via the NDB API, either natively using the C++ API or one of the additional NoSQL APIs described above.
Versions
From the 8.0 release onwards, MySQL Cluster is based directly on the corresponding releases of the MySQL Server. Previously, MySQL Cluster version numbers were decoupled from those of MySQL Server - for example MySQL Cluster 7.6 was based on/contained the server component from MySQL 5.7.Higher versions of MySQL Cluster include all of the features of lower versions, plus some new features.
Currently available versions:
- MySQL Cluster 9.X Innovation Release series
- MySQL Cluster 8.4 LTS based on MySQL 8.4 LTS release
- MySQL Cluster 8.0 based on MySQL 8.0
- MySQL Cluster 7.6 based on MySQL 5.7
- MySQL Cluster 8.1 based on MySQL 8.1 Innovation release
- MySQL Cluster 8.2 based on MySQL 8.2 Innovation release
- MySQL Cluster 8.3 based on MySQL 8.3 Innovation release
- MySQL Cluster 7.5 based on MySQL 5.7
- MySQL Cluster 7.4 based on MySQL 5.6
- MySQL Cluster 7.3 based on MySQL 5.6
- MySQL Cluster 7.2 based on MySQL 5.5
- MySQL Cluster 7.1 based on MySQL 5.1.D
- MySQL Cluster 7.0 based on MySQL 5.1.C
- MySQL Cluster 6.3 based on MySQL 5.1.B
- MySQL Cluster 6.2 based on MySQL 5.1.A
- Ndb included in MySQL 5.1.X source tree