MySQL Cluster 7.5 inside and out
Mikael Ronstrőm February 9, 2018
Copyright iClaustron AB 2016, 2018, All rights reserved
February 2018: First edition Revision History for First edition: 2 feb 2018 First release
FĹ‘rlag: BoD - Books on Demand, Stockholm, Sverige Tryck: BoD - Books on Demand, Norderstedt, Tyskland ISBN: 978-91-7699-814-4
Contents
About MySQL Cluster 7.5 xvii 0.1 About the author Mikael Ronstrőm . . . . . . . . . . . . . . . . . . . . . . . . . xviii 0.2 Purpose of the book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
I
When to use MySQL Cluster
1
1 What is special with MySQL Cluster 1.1 AlwaysOn for reads and writes . . . . . . . . . . . . 1.2 Global solution for replication . . . . . . . . . . . . 1.3 Consistency of data in large clusters . . . . . . . . . 1.4 High read and write Scalability . . . . . . . . . . . . 1.5 Predictable response time . . . . . . . . . . . . . . . 1.6 Base platform for data storage . . . . . . . . . . . . 1.7 Multi-dimensional scaling . . . . . . . . . . . . . . . 1.8 Non-blocking 2PC transaction protocol . . . . . . . 1.9 Global checkpoints . . . . . . . . . . . . . . . . . . . 1.10 Automatically Parallelised and Distributed Queries .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
2 3 4 6 8 10 11 12 12 13 13
2 Rationale for MySQL Cluster 2.1 Separation of Data Server and Query Server 2.2 Predictable response time requirements . . . 2.3 MySQL Cluster and multi-core architectures 2.4 Shared nothing architecture . . . . . . . . . . 2.5 MySQL Cluster and the CAP theorem . . . . 2.6 OLTP, OLAP and relational models . . . . . 2.7 Data storage requirements . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
14 14 21 27 28 29 30 31
3 Use 3.1 3.2 3.3 3.4
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
33 34 36 41 43
cases for MySQL Cluster Networking applications . . . Telecom servers . . . . . . . . Gaming systems . . . . . . . Financial applications . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
ii
CONTENTS 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
44 44 45 45 46 49 51 51 52
4 NDB and InnoDB 4.1 Differences between NDB and InnoDB 4.2 Consistency Model differences . . . . 4.3 Foreign Key differences . . . . . . . . 4.4 Differences in Online Change . . . . . 4.5 Challenges in replacing InnoDB . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
53 53 57 58 58 58
5 MySQL Cluster and InnoDB Cluster 5.1 Comparison to Galera Cluster . . . . 5.2 Group Replication . . . . . . . . . . . 5.3 Differences between MySQL clustering 5.4 Differences in query execution . . . . 5.5 Differences in recovery . . . . . . . . . 5.6 Differences in handling node failures . 5.7 Sharding differences . . . . . . . . . . 5.8 Multi-master differences . . . . . . . . 5.9 Detailed differences . . . . . . . . . . 5.10 What clustering solution to select . .
. . . . . . . . . . . . solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
59 59 59 60 63 63 64 65 65 66 67
II
Fraud Detection . . . . . . Web applications . . . . . . Soft real-time applications . Oracle OpenStack . . . . . GE . . . . . . . . . . . . . Hadoop File Server . . . . . LDAP Server . . . . . . . . NoSQL Applications . . . . Conclusion . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
Introduction to database concepts
6 Relation Model 6.1 Basic concepts . . . . . . . . 6.2 Distributed Relational Model 6.3 Replicated Relational Model 6.4 Hashmaps . . . . . . . . . . . 6.5 Read backup replica tables . 6.6 Fully replicated tables . . . .
70 . . . . . .
71 71 73 74 75 76 76
7 Transactional Model 7.1 Basic transaction theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Locking theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77 77 79
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
CONTENTS 7.3
iii
Distributed transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 Computer Model 8.1 CPU Core . . . . . . . . . 8.2 CPU Socket . . . . . . . . 8.3 Computer . . . . . . . . . 8.4 Computer network . . . . 8.5 Distributed Data Centers
III
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Introduction to MySQL Cluster
IV
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
85 85 89 90 91 91
92
9 MySQL Cluster Architecture 9.1 Node group concept (Shards) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2 Program types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 MySQL Cluster APIs 10.1 MySQL APIs . . . 10.2 Direct NDB APIs 10.3 memcached . . . . 10.4 OpenLDAP . . . .
82
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Getting Started
93 95 96 100 102 102 103 103
104
11 Getting Started for Developers 106 11.1 Getting Started on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 11.2 Getting Started on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 11.3 Using MySQL Cluster ConďŹ gurator for development . . . . . . . . . . . . . . . . 121 12 Installing MySQL Cluster 12.1 Installing using yum . . . . . . . 12.2 Installing using apt . . . . . . . 12.3 Installing using Zypper on Suse . 12.4 MySQL Cluster packages . . . . 12.5 Install using an RPM package . 12.6 Installing on Debian . . . . . . . 12.7 Installing tarballs on Linux . . . 12.8 Installing on Solaris . . . . . . . 12.9 Preparing to run MySQL Cluster 12.10 Installing on FreeBSD . . . . . .
. . . . . . . . . . . . . . . . on . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linux . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
122 122 125 126 126 128 128 129 129 129 132
13 Starting programs 133 13.1 Order of starting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
iv
CONTENTS 13.2 13.3 13.4 13.5 13.6
. . . . .
135 138 141 142 143
14 MySQL Cluster configuration files 14.1 General rules for MySQL configuration files . . . . . . . . . . . . . . . . . . . . . 14.2 Cluster configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.3 MySQL configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
144 144 145 147
15 MySQL Cluster and Docker 15.1 Using Docker to avoid installation problems . . . . . . . 15.2 Using Docker on a single host . . . . . . . . . . . . . . . 15.3 Using Docker overlay network . . . . . . . . . . . . . . . 15.4 Using Docker Swarm . . . . . . . . . . . . . . . . . . . . 15.5 Setting the password on MySQL Server container . . . 15.6 Running the NDB management client . . . . . . . . . . 15.7 Using Docker to limit memory resources . . . . . . . . . 15.8 Using Docker to limit CPU resources . . . . . . . . . . 15.9 Using Docker and cgroups to control CPU and memory
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
149 150 152 152 153 153 153 153 154 155
16 Building MySQL Cluster 16.1 Linux . . . . . . . . . . 16.2 Solaris . . . . . . . . . . 16.3 FreeBSD . . . . . . . . 16.4 Mac OS X . . . . . . . 16.5 Windows . . . . . . . . 17 HW 17.1 17.2 17.3 17.4 17.5 17.6
V
Starting Starting Starting Starting Starting
ndb_mgmd . . . . . . . . ndbmtd . . . . . . . . . . a MySQL Server (mysqld) ndb_mgm . . . . . . . . . mcmd . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
156 157 158 158 158 158
setups for MySQL Cluster Single host setup . . . . . . . . . . . . . . . . . . . NDB as an In-memory storage engine for MySQL Minimum configuration for AlwaysOn . . . . . . . Setting up MySQL Cluster for secure operation . . Scaling out from the simple HA setup . . . . . . . Set up of MySQL Cluster for multi-cluster apps .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
159 159 160 160 162 163 166
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
MySQL Cluster as a SQL engine
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
168
18 Basic SQL statements 170 18.1 Create a table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 18.2 Altering a table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
CONTENTS
v
18.3 Querying a table . . . . . . . . . . 18.4 Writing to a table . . . . . . . . . 18.5 Transactions . . . . . . . . . . . . 18.6 Drop/Truncate Table . . . . . . . 18.7 Indexes . . . . . . . . . . . . . . . 18.8 Foreign Keys . . . . . . . . . . . . 18.9 Optimize/Analyze Table . . . . . . 18.10 BLOBs . . . . . . . . . . . . . . . 18.11 Row format of NDB tables . . . . 18.12 Disk Data Columns . . . . . . . . 18.13 MySQL Replication of NDB tables
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
174 176 176 176 176 180 180 180 180 180 180
19 NDB Row Data structure 181 19.1 Row format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 19.2 Fixed row format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 19.3 Dynamic row format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 20 Foreign Key handling 20.1 Foreign key considerations
187 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
21 BLOB handling 22 Disk 22.1 22.2 22.3 22.4 22.5 22.6
columns Row format for disk columns . . . Tablespaces . . . . . . . . . . . . . UNDO log . . . . . . . . . . . . . Syntax for disk data . . . . . . . . Page Manager . . . . . . . . . . . Considerations for disk data tables
191
. . . . . .
. . . . . .
23 Table options 23.1 Read Backup feature . . . . . . . . . . 23.2 Fully replicated tables . . . . . . . . . 23.3 Partitioning of tables . . . . . . . . . 23.4 Considerations for selecting number of 23.5 Partition Balance . . . . . . . . . . . 23.6 Setting explicit number of partitions . 23.7 No REDO logging . . . . . . . . . . . 23.8 Schema Considerations . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
193 194 194 195 195 197 198
. . . . . . . . . . . . . . . . . . partitions . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
200 200 201 202 204 205 207 207 208
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
24 MySQL Concepts in NDB storage engine 209 24.1 MySQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 24.2 MySQL Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
vi
CONTENTS 24.3 MySQL Triggers . . . . . . . 24.4 MySQL Views . . . . . . . . 24.5 MySQL Events . . . . . . . . 24.6 MySQL Stored Procedures . 24.7 MySQL Functions . . . . . . 24.8 MySQL User Management . 24.9 MySQL Transactions . . . . 24.10 Savepoints . . . . . . . . . . 24.11 MySQL Prepared Statements 24.12 MySQL Explain statements . 24.13 Table locks . . . . . . . . . . 24.14 XA support . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
209 210 210 210 211 211 211 211 211 211 212 212
25 Altering a Table 25.1 Online meta data operations 25.2 Online Add Column . . . . . 25.3 Online Create Tablespace . . 25.4 Online Create Logfile group . 25.5 Online Add Node . . . . . . . 25.6 Optimize Table . . . . . . . . 25.7 Reorganise Table . . . . . . . 25.8 Offline meta data operations
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
213 213 215 216 216 217 218 219 219
VI
Concepts in MySQL Cluster
26 Non-blocking 2PC 26.1 Idea behind new two-phase commit protocol 26.2 Achieving a non-blocking commit protocol . 26.3 Global checkpoint protocol . . . . . . . . . . 26.4 Handling cluster crash . . . . . . . . . . . . . 26.5 Impact of Read Backup feature . . . . . . . . 26.6 Conclusions . . . . . . . . . . . . . . . . . . .
221 . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
223 224 226 227 229 230 230
27 Routing of reads and writes 27.1 Choosing the MySQL Server . . . . . . . . . . . . 27.2 Choosing the node of the transaction coordinator . 27.3 Choosing the tc thread . . . . . . . . . . . . . . . 27.4 Choosing the data node for reading . . . . . . . . 27.5 Choosing the ldm thread . . . . . . . . . . . . . . 27.6 Choosing the data nodes for writing . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
231 231 232 233 233 233 233
28 Concurrency Control
. . . . . .
. . . . . .
234
CONTENTS 28.1 28.2 28.3 28.4 28.5
vii
Row locking . . . . . . . . . Consistency Models . . . . . Read Committed mode . . . Locking and Unique indexes Locking and BLOB tables . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
235 236 237 237 238
29 Parallel Query 29.1 Full table scan in NDB . . . 29.2 Range scan in NDB . . . . . 29.3 Partition pruned range scans 29.4 Pushdown joins . . . . . . . . 29.5 Condition pushdown . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
239 239 239 240 240 242
30 Specialised MySQL Servers
243
VII
244
Tools to import and export data
31 Import data 31.1 ndb_restore using Backups 31.2 Importing from mysqldump 31.3 Alter Table . . . . . . . . . 31.4 mysqlimport . . . . . . . .
. . . files . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
246 247 247 247 247
32 Export data 248 32.1 mysqldump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 32.2 SELECT INTO OUTFILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 33 Backup 33.1 Backup algorithm . . . . . . . . . . . . . 33.2 The START BACKUP command . . . . . 33.3 Aborting a backup . . . . . . . . . . . . . 33.4 Backup file placement . . . . . . . . . . . 33.5 Backup configuration . . . . . . . . . . . 33.6 Backup file management . . . . . . . . . . 33.7 Backing up metadata in MySQL Cluster
. . . . . . .
. . . . . . .
. . . . . . .
34 Restore 34.1 Restoring metadata . . . . . . . . . . . . . . . 34.2 Partial restore . . . . . . . . . . . . . . . . . . 34.3 Restore for upgrade . . . . . . . . . . . . . . . 34.4 Restore as part of MySQL Cluster Replication 34.5 Restoring Distributed Privileges . . . . . . . . 34.6 Various other use cases for ndb_restore . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . .
250 250 251 251 251 252 252 252
. . . . . .
254 256 256 257 258 259 259
viii
CONTENTS 34.7 Special parameters for ndb_restore . . . . . . . . . . . . . . . . . . . . . . . . . . 259
VIII
MySQL Cluster APIs
260
35 C++ NDB API 35.1 Meta data operations . . . . . . . . . . . . . . . . . . 35.2 Initialising the NDB API and MySQL client API . . . 35.3 Concurrency in the NDB API . . . . . . . . . . . . . . 35.4 Ndb cluster connection . . . . . . . . . . . . . . . . . 35.5 Ndb object . . . . . . . . . . . . . . . . . . . . . . . . 35.6 Setting up a row . . . . . . . . . . . . . . . . . . . . . 35.7 Transactions . . . . . . . . . . . . . . . . . . . . . . . 35.8 Key operations . . . . . . . . . . . . . . . . . . . . . . 35.9 Scan operations . . . . . . . . . . . . . . . . . . . . . 35.10 Options . . . . . . . . . . . . . . . . . . . . . . . . . . 35.11 Scan partitioning info . . . . . . . . . . . . . . . . . . 35.12 Interpreter commands as part of NDB API operations 35.13 Scan example . . . . . . . . . . . . . . . . . . . . . . . 35.14 NDB Event API . . . . . . . . . . . . . . . . . . . . . 35.15 Pushdown Join . . . . . . . . . . . . . . . . . . . . . . 35.16 Asynchronous API . . . . . . . . . . . . . . . . . . . . 35.17 flexAsynch Architecture . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
262 263 263 263 264 266 267 269 272 273 275 276 283 284 285 288 289 289
36 ClusterJ, API for Java and Scala 36.1 Installing ClusterJ . . . . . . . . . 36.2 Compiling ClusterJ applications . 36.3 Executing a ClusterJ application . 36.4 ClusterJ annotations . . . . . . . . 36.5 Startup example code . . . . . . . 36.6 Session Object . . . . . . . . . . . 36.7 Transactions . . . . . . . . . . . . 36.8 Creating a query . . . . . . . . . . 36.9 Column type mappings . . . . . . 36.10 ClusterJ reconnect . . . . . . . . . 36.11 Dynamic mapping of rows . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
290 290 291 291 295 297 298 301 302 305 306 306
37 Node.js API 37.1 Installing Database Jones . . . 37.2 Installing ndb adapter . . . . . 37.3 The Tweet sample application 37.4 ConnectionProperties . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
307 307 308 309 310
. . . .
. . . .
CONTENTS 37.5 37.6 37.7 37.8
IX
Cluster connection Startup example . Session operations Final comments .
ix object . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Global replication
38 Internals of MySQL Cluster Replication 38.1 Data node triggers . . . . . . . . . . . . . . 38.2 Epochs . . . . . . . . . . . . . . . . . . . . 38.3 Epoch Buffers . . . . . . . . . . . . . . . . 38.4 Send buffers . . . . . . . . . . . . . . . . . 38.5 MySQL replication server internals . . . . . 38.6 Limitations of MySQL Cluster Replication
312 314 315 319
320 . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
321 321 322 322 324 324 324
39 Multi-Site MySQL Cluster 39.1 MySQL Replication . . . . . . . . . . . . . . . . . . . 39.2 Architecture of MySQL Cluster Replication . . . . . . 39.3 Tables used by MySQL Cluster Replication . . . . . . 39.4 Epochs . . . . . . . . . . . . . . . . . . . . . . . . . . 39.5 Setting up a replication channel between two clusters 39.6 Point-in-Time backups . . . . . . . . . . . . . . . . . . 39.7 Read Slave Clusters . . . . . . . . . . . . . . . . . . . 39.8 Characteristics of slave applier for NDB . . . . . . . . 39.9 Purging MySQL Replication files . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
327 328 329 331 336 337 341 341 342 342
40 Global Fail-over Architecture 40.1 Setup for fail-over scenario . . . . . . . . . 40.2 Discovering failure of a replication channel 40.3 Discover failure of a cluster . . . . . . . . . 40.4 Cluster fail over . . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
344 344 344 348 350
41 Globally Distributed MySQL Cluster 41.1 NDB$MAX_DELETE_WIN(column_name) 41.2 NDB$OLD(column_name) . . . . . . . . . . 41.3 NDB$EPOCH2 . . . . . . . . . . . . . . . . 41.4 Conflict detection tables . . . . . . . . . . . . 41.5 Setup for circular replication . . . . . . . . . 41.6 ndb-log-update-as-minimal . . . . . . . . . . . 41.7 Insert-Insert conflicts . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
351 351 352 353 353 355 358 358
42 Extremely Available Solutions
359
x
CONTENTS 42.1 42.2 42.3 42.4
X
Setting up transaction-based conflict Characteristics of this solution . . . Conflict handling . . . . . . . . . . . More comments . . . . . . . . . . .
detection . . . . . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Management of MySQL Cluster
43 Ndbinfo Tables 43.1 Reasons to use ndbinfo . . . . . 43.2 How ndbinfo works . . . . . . . . 43.3 Metadata tables . . . . . . . . . 43.4 Connection information . . . . . 43.5 Configuration information . . . . 43.6 Transaction information . . . . . 43.7 Live transaction information . . 43.8 Memory information . . . . . . . 43.9 Thread statistics . . . . . . . . . 43.10 Node information . . . . . . . . 43.11 Restart information . . . . . . . 43.12 Local checkpoint information . . 43.13 Disk page cache information . . 43.14 Communication information . . 43.15 Status of REDO and UNDO logs 43.16 Fragment statistics . . . . . . . . 43.17 Error messages . . . . . . . . . . 43.18 Summary of ndbinfo information
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
364 . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
44 NDB management client ndb_mgm 44.1 SHOW command . . . . . . . . . . . . . . . 44.2 START/STOP commands . . . . . . . . . . 44.3 REPORT command . . . . . . . . . . . . . 44.4 STATUS command . . . . . . . . . . . . . . 44.5 PROMPT command . . . . . . . . . . . . . 44.6 ENTER SINGLE USER MODE command 44.7 CLUSTERLOG command . . . . . . . . . . 44.8 DUMP command . . . . . . . . . . . . . . . 44.9 EXIT/QUIT command . . . . . . . . . . . 44.10 CONNECT command . . . . . . . . . . . . 44.11 PURGE STALE SESSIONS . . . . . . . . . 45 Cluster log and node logs
360 362 362 363
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
366 366 367 369 370 371 371 373 374 376 378 379 381 382 383 383 384 385 385
. . . . . . . . . . .
386 386 387 389 389 390 390 391 391 391 391 392 393
CONTENTS 45.1 45.2 45.3 45.4
The Cluster log . . . . . . . . Management server node log Data node logs . . . . . . . . Summary of logs . . . . . . .
xi . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
393 397 397 404
46 Troubleshooting NDB 405 46.1 Data node crash output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 46.2 Debugging MySQL Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 47 Online changes of Configuration 47.1 Cluster configuration . . . . . . . . . . . . . . 47.2 Adding nodes to the cluster . . . . . . . . . . . 47.3 Managing the configuration database . . . . . 47.4 Procedure to perform online config changes . . 47.5 Online changes of MySQL Server configuration 47.6 Online add MySQL Server . . . . . . . . . . . 47.7 Online change of data node configuration . . . 47.8 Online add data node . . . . . . . . . . . . . .
XI
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
Recovery in MySQL Cluster
411 411 411 412 418 419 419 419 420
422
48 Crash handling 48.1 Replication inside a cluster . . . . . . . . . . . . 48.2 Failures supported from a fully functional cluster 48.3 Arbitrator . . . . . . . . . . . . . . . . . . . . . . 48.4 External Arbitrator . . . . . . . . . . . . . . . . 48.5 Handling startup and network partitioning . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
424 424 425 426 426 426
49 NDB Recovery Architecture 49.1 Transaction protocol . . . . . . . . . . . 49.2 Transaction coordinator failure protocol 49.3 Global Checkpoint protocol . . . . . . . 49.4 Local checkpoint protocol . . . . . . . . 49.5 Schema transaction protocol . . . . . . 49.6 Node registration protocol . . . . . . . . 49.7 Heartbeat protocol . . . . . . . . . . . . 49.8 Node failure protocol . . . . . . . . . . 49.9 Graceful shutdown protocol . . . . . . . 49.10 Watchdog handling . . . . . . . . . . . 49.11 Node restart activities . . . . . . . . . . 49.12 Initial node restart activities . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
428 430 432 432 434 436 436 437 437 437 438 438 439
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
xii
CONTENTS
50 Optimising restart times 50.1 Early phases . . . . . . . . . 50.2 Load data phase . . . . . . . 50.3 UNDO log execution . . . . . 50.4 REDO log execution . . . . . 50.5 Rebuild ordered indexes . . . 50.6 Rebuild unique indexes . . . 50.7 Copy fragment phase . . . . 50.8 Local checkpoint phase . . . 50.9 Initial node restart . . . . . . 50.10 Handling MySQL Replication 50.11 Final words . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Servers . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
440 440 441 441 442 442 442 442 443 443 444 444
51 NDB startup 51.1 Initial start . . . . 51.2 Node restart . . . 51.3 System restart . . 51.4 Initial node restart 51.5 NDB start phases
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
445 445 445 446 446 447
XII
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Internals of NDB Cluster
52 Data Node Architecture 52.1 Block and Signal Architecture 52.2 Receive handling in Data Node 52.3 Send handling in Data Node . 52.4 NDB connection setup protocol 52.5 NDB signal header deďŹ nition . 53 API 53.1 53.2 53.3 53.4 53.5 53.6
449 . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
451 451 454 454 455 456
Node Architecture Cluster connection . . . . . . . . . User threads . . . . . . . . . . . . NDB API send threads . . . . . . NDB API receive threads . . . . . NDB API cluster manager threads Blocks in API nodes . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
458 458 459 459 459 460 460
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
461 461 463 463 466
54 Blocks in a Data Node 54.1 LDM Blocks . . . . 54.2 TC blocks . . . . . . 54.3 Main thread blocks 54.4 Rep blocks . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . .
. . . .
. . . .