pro mysql ndb cluster · 233 spring street, 6th floor, new york, ny 10013. phone 1-800-springer,...
TRANSCRIPT
Pro MySQL NDB Cluster
Master the MySQL Cluster Lifecycle—Jesper Wisborg KroghMikiya Okuno
Pro MySQL NDB Cluster
Jesper Wisborg Krogh
Mikiya Okuno
Pro MySQL NDB Cluster
Jesper Wisborg Krogh Mikiya OkunoSydney, New South Wales, Australia Tochigi, Japan
ISBN-13 (pbk): 978-1-4842-2981-1 ISBN-13 (electronic): 978-1-4842-2982-8https://doi.org/10.1007/978-1-4842-2982-8
Library of Congress Control Number: 2017958958
Copyright © 2017 by Jesper Wisborg Krogh and Mikiya Okuno
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Managing Director: Welmoed SpahrEditorial Director: Todd GreenAcquisitions Editor: Jonathan GennickDevelopment Editor: Laura BerendsonTechnical Reviewer: Charles BellCoordinating Editor: Jill BalzanoCopy Editor: Kezia EndsleyCompositor: SPi GlobalIndexer: SPi GlobalArtist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484229811. For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Contents at a Glance
About the Authors ���������������������������������������������������������������������������������������������������xxi
About the Technical Reviewer ������������������������������������������������������������������������������xxiii
Acknowledgments �������������������������������������������������������������������������������������������������xxv
Introduction ���������������������������������������������������������������������������������������������������������xxvii
■Part I: The Basics �������������������������������������������������������������������������������� 1
■Chapter 1: Architecture and Core Concepts ���������������������������������������������������������� 3
■Chapter 2: The Data Nodes ���������������������������������������������������������������������������������� 23
■Part II: Installation and Configuration ���������������������������������������������� 65
■Chapter 3: System Planning �������������������������������������������������������������������������������� 67
■Chapter 4: Configuration ������������������������������������������������������������������������������������� 85
■Chapter 5: Installation ��������������������������������������������������������������������������������������� 141
■Chapter 6: Replication ��������������������������������������������������������������������������������������� 175
■Part III: Daily Tasks and Maintenance �������������������������������������������� 237
■Chapter 7: The NDB Management Client and Other NDB Utilities ���������������������� 239
■Chapter 8: Backups and Restores ��������������������������������������������������������������������� 251
■Chapter 9: Table Maintenance ��������������������������������������������������������������������������� 283
■Chapter 10: Restarts ������������������������������������������������������������������������������������������ 309
■Chapter 11: Upgrades and Downgrades ������������������������������������������������������������ 351
■Chapter 12: Security Considerations ����������������������������������������������������������������� 373
■Chapter 13: MySQL Cluster Manager ����������������������������������������������������������������� 395
iii
■ Contents at a GlanCe
iv
■Part IV: Monitoring and Troubleshooting ���������������������������������������� 439
■Chapter 14: Monitoring Solutions and the Operating System ��������������������������� 441
■Chapter 15: Sources for Monitoring Data ���������������������������������������������������������� 457
■Chapter 16: Monitoring MySQL NDB Cluster ������������������������������������������������������ 519
■Chapter 17: Typical Troubles and Solutions������������������������������������������������������� 551
■Part V: Development and Performance Tuning ������������������������������� 569
■Chapter 18: Developing Applications Using SQL with MySQL NDB Cluster�������� 571
■Chapter 19: MySQL NDB Cluster as a NoSQL Database ������������������������������������� 611
■Chapter 20: MySQL NDB Cluster and Application Performance Tuning ������������� 655
Index ��������������������������������������������������������������������������������������������������������������������� 681
Contents
About the Authors ���������������������������������������������������������������������������������������������������xxi
About the Technical Reviewer ������������������������������������������������������������������������������xxiii
Acknowledgments �������������������������������������������������������������������������������������������������xxv
Introduction ���������������������������������������������������������������������������������������������������������xxvii
■Part I: The Basics �������������������������������������������������������������������������������� 1
■Chapter 1: Architecture and Core Concepts ���������������������������������������������������������� 3
Terminology ���������������������������������������������������������������������������������������������������������������������� 3
Characteristics and Features ������������������������������������������������������������������������������������������� 6
Architecture �������������������������������������������������������������������������������������������������������������������������������������������� 6
Features �������������������������������������������������������������������������������������������������������������������������������������������������� 6
Limitations ���������������������������������������������������������������������������������������������������������������������������������������������� 8
Use Cases ��������������������������������������������������������������������������������������������������������������������������������������������� 10
Node Types ��������������������������������������������������������������������������������������������������������������������� 11
Management Nodes������������������������������������������������������������������������������������������������������������������������������ 12
Data Nodes ������������������������������������������������������������������������������������������������������������������������������������������� 14
API and SQL Nodes ������������������������������������������������������������������������������������������������������������������������������� 15
Built-In High Availability ������������������������������������������������������������������������������������������������� 16
Shared Nothing Architecture ���������������������������������������������������������������������������������������������������������������� 16
Heartbeats �������������������������������������������������������������������������������������������������������������������������������������������� 18
Data Node Failure Handling and Arbitration ����������������������������������������������������������������������������������������� 19
Summary ������������������������������������������������������������������������������������������������������������������������ 21
v
■ Contents
vi
■Chapter 2: The Data Nodes ���������������������������������������������������������������������������������� 23
Single-Threaded Versus Multi-Threaded Data Nodes ���������������������������������������������������� 23
Thread Types����������������������������������������������������������������������������������������������������������������������������������������� 23
Performance Considerations ���������������������������������������������������������������������������������������������������������������� 26
Replicas �������������������������������������������������������������������������������������������������������������������������� 26
Primary and Backup Replicas ��������������������������������������������������������������������������������������������������������������� 26
MySQL NDB Cluster 7�5: Read from Backup Replica ���������������������������������������������������������������������������� 27
Node Groups ������������������������������������������������������������������������������������������������������������������� 29
Partitions ������������������������������������������������������������������������������������������������������������������������ 30
Automatic Partitioning �������������������������������������������������������������������������������������������������������������������������� 31
User-Defined Partitioning ��������������������������������������������������������������������������������������������������������������������� 32
MySQL NDB Cluster 7�5: Partition Balancing ���������������������������������������������������������������������������������������� 32
MySQL NDB Cluster 7�5: Fully Replicated Tables ���������������������������������������������������������������������������������� 33
Case Study: Partition Distribution ��������������������������������������������������������������������������������������������������������� 33
D for Durability ��������������������������������������������������������������������������������������������������������������� 40
Duplication of Data ������������������������������������������������������������������������������������������������������������������������������� 41
Local Checkpoints (LCPs) ��������������������������������������������������������������������������������������������������������������������� 42
The Redo Logs �������������������������������������������������������������������������������������������������������������������������������������� 42
Global Checkpoints (GCPs)�������������������������������������������������������������������������������������������������������������������� 43
Restarts and Processes �������������������������������������������������������������������������������������������������� 43
Data Node Internals �������������������������������������������������������������������������������������������������������� 44
Memory Usage �������������������������������������������������������������������������������������������������������������������������������������� 44
Kernel Blocks ���������������������������������������������������������������������������������������������������������������������������������������� 45
Signals �������������������������������������������������������������������������������������������������������������������������������������������������� 49
Job Buffer ��������������������������������������������������������������������������������������������������������������������������������������������� 49
Send and Receive Buffers �������������������������������������������������������������������������������������������������������������������� 50
Triggers ������������������������������������������������������������������������������������������������������������������������������������������������� 51
Epochs �������������������������������������������������������������������������������������������������������������������������������������������������� 51
Master Node ����������������������������������������������������������������������������������������������������������������������������������������� 52
■ Contents
vii
Data and Indexes ������������������������������������������������������������������������������������������������������������ 52
Data Memory and Index Memory ��������������������������������������������������������������������������������������������������������� 52
On-Disk Data ���������������������������������������������������������������������������������������������������������������������������������������� 53
BLOB, TEXT, and JSON Columns ����������������������������������������������������������������������������������������������������������� 55
Cases Studies: Investigating the Schema Objects ��������������������������������������������������������� 56
The ndb_show_tables Utility ���������������������������������������������������������������������������������������������������������������� 57
The ndb_desc Utility ����������������������������������������������������������������������������������������������������������������������������� 58
The NDB File System ������������������������������������������������������������������������������������������������������ 62
Summary ������������������������������������������������������������������������������������������������������������������������ 64
■Part II: Installation and Configuration ���������������������������������������������� 65
■Chapter 3: System Planning �������������������������������������������������������������������������������� 67
Determine Your Priorities ����������������������������������������������������������������������������������������������� 67
High Availability Requirements ��������������������������������������������������������������������������������������� 67
Data Node ��������������������������������������������������������������������������������������������������������������������������������������������� 67
SQL Node ���������������������������������������������������������������������������������������������������������������������������������������������� 68
Management Node ������������������������������������������������������������������������������������������������������������������������������� 68
Prepare for Network Partitioning ������������������������������������������������������������������������������������ 69
Scalability ����������������������������������������������������������������������������������������������������������������������� 70
Disaster Recovery ���������������������������������������������������������������������������������������������������������� 71
Typical Topologies ���������������������������������������������������������������������������������������������������������� 71
Number of Replicas ������������������������������������������������������������������������������������������������������������������������������ 71
Maximum Number of Data Nodes ��������������������������������������������������������������������������������������������������������� 71
Maximum Number of Total Nodes �������������������������������������������������������������������������������������������������������� 71
Arbitration Rank ������������������������������������������������������������������������������������������������������������������������������������ 72
Placing the SQL Node and the Data Node on the Same Machine ��������������������������������������������������������� 72
Typical Topology Examples ������������������������������������������������������������������������������������������������������������������� 72
Platform Considerations ������������������������������������������������������������������������������������������������� 77
Processor Type and Operating System ������������������������������������������������������������������������������������������������� 77
CPU Performance and Characteristics �������������������������������������������������������������������������������������������������� 77
■ Contents
viii
Memory Consumption �������������������������������������������������������������������������������������������������������������������������� 79
Disk Performance ��������������������������������������������������������������������������������������������������������������������������������� 80
Virtual Machines ����������������������������������������������������������������������������������������������������������������������������������� 80
Network Design �������������������������������������������������������������������������������������������������������������� 80
Network Devices ����������������������������������������������������������������������������������������������������������������������������������� 80
Network Redundancy ��������������������������������������������������������������������������������������������������������������������������� 81
Direct Connection ��������������������������������������������������������������������������������������������������������������������������������� 81
Security Considerations ������������������������������������������������������������������������������������������������������������������������ 81
Extending Capacity Using Disk Objects �������������������������������������������������������������������������� 81
Performance Considerations ���������������������������������������������������������������������������������������������������������������� 82
Storage Requirements �������������������������������������������������������������������������������������������������������������������������� 82
Memory Consumption �������������������������������������������������������������������������������������������������������������������������� 82
Summary ������������������������������������������������������������������������������������������������������������������������ 82
■Chapter 4: Configuration ������������������������������������������������������������������������������������� 85
Configuration Overview �������������������������������������������������������������������������������������������������� 85
Formatting config�ini ���������������������������������������������������������������������������������������������������������������������������� 85
Restart Types ���������������������������������������������������������������������������������������������������������������������������������������� 87
Management Node Options �������������������������������������������������������������������������������������������� 88
Major Options for Management Node ��������������������������������������������������������������������������������������������������� 88
Vital Point for Management Node Configuration ���������������������������������������������������������������������������������� 91
Data Node Options ���������������������������������������������������������������������������������������������������������� 91
Basic Options ���������������������������������������������������������������������������������������������������������������������������������������� 91
Memory Data Storage Options �������������������������������������������������������������������������������������������������������������� 93
Schema Object Options ������������������������������������������������������������������������������������������������������������������������ 96
Transaction Options ������������������������������������������������������������������������������������������������������������������������������ 99
Estimate for Total Memory Consumption �������������������������������������������������������������������������������������������� 103
Checkpoint Options ����������������������������������������������������������������������������������������������������������������������������� 104
Estimating Redo Log Size ������������������������������������������������������������������������������������������������������������������� 111
Multi-Threading Options ��������������������������������������������������������������������������������������������������������������������� 112
Consideration for CPU Properties ������������������������������������������������������������������������������������������������������� 116
■ Contents
ix
Backup Options ���������������������������������������������������������������������������������������������������������������������������������� 117
Transporter Options ���������������������������������������������������������������������������������������������������������������������������� 120
Disk Object Options ���������������������������������������������������������������������������������������������������������������������������� 121
Heartbeat and Watchdog Options ������������������������������������������������������������������������������������������������������� 124
Logging Options ���������������������������������������������������������������������������������������������������������������������������������� 126
Recommended Configuration Strategy ����������������������������������������������������������������������������������������������� 127
SQL Node Options ��������������������������������������������������������������������������������������������������������� 127
Major Options for SQL Node ��������������������������������������������������������������������������������������������������������������� 128
Vital Point for SQL Node Configuration ����������������������������������������������������������������������������������������������� 130
TCP Transporter Options ����������������������������������������������������������������������������������������������� 130
Major Options for Transporter ������������������������������������������������������������������������������������������������������������� 131
Transporter via Separate Network Path ���������������������������������������������������������������������������������������������� 132
Program Startup Options (my�cnf) �������������������������������������������������������������������������������� 133
Common Options �������������������������������������������������������������������������������������������������������������������������������� 133
Major Options for ndb_mgmd ������������������������������������������������������������������������������������������������������������� 134
Options for ndbd/ndbmtd�������������������������������������������������������������������������������������������������������������������� 136
Options for mysqld ����������������������������������������������������������������������������������������������������������������������������� 137
Location of Option Files ���������������������������������������������������������������������������������������������������������������������� 139
Summary ���������������������������������������������������������������������������������������������������������������������� 140
■Chapter 5: Installation ��������������������������������������������������������������������������������������� 141
Package Installation ����������������������������������������������������������������������������������������������������� 141
Obtaining Packages ���������������������������������������������������������������������������������������������������������������������������� 141
Installation on Linux ��������������������������������������������������������������������������������������������������������������������������� 145
Installation on Windows ���������������������������������������������������������������������������������������������������������������������� 151
Installation on macOS ������������������������������������������������������������������������������������������������������������������������� 160
Installing MySQL NDB Cluster Instances Using Auto Installer �������������������������������������� 166
Verifying Installation ����������������������������������������������������������������������������������������������������� 171
Configuration Files ������������������������������������������������������������������������������������������������������������������������������ 171
Initial Startup �������������������������������������������������������������������������������������������������������������������������������������� 171
Checking the Status ��������������������������������������������������������������������������������������������������������������������������� 172
■ Contents
x
Uninstalling Packages �������������������������������������������������������������������������������������������������� 173
Tar�gz and Zip Archive Package ���������������������������������������������������������������������������������������������������������� 173
RPM Package �������������������������������������������������������������������������������������������������������������������������������������� 173
Windows Installer Package ���������������������������������������������������������������������������������������������������������������� 173
macOS Native Package ���������������������������������������������������������������������������������������������������������������������� 174
Summary ���������������������������������������������������������������������������������������������������������������������� 174
■Chapter 6: Replication ��������������������������������������������������������������������������������������� 175
NDB Cluster Replication Overview ������������������������������������������������������������������������������� 175
Replication Architecture Overview ����������������������������������������������������������������������������������������������������� 175
Replication Channel Failover �������������������������������������������������������������������������������������������������������������� 178
NDB Cluster Replication Tables ���������������������������������������������������������������������������������������������������������� 179
Use Cases and Advantages of NDB Cluster Replication���������������������������������������������������������������������� 179
Setting Up NDB Cluster Replication ������������������������������������������������������������������������������ 181
Setting Up NDB Cluster Replication with an Empty Database ������������������������������������������������������������ 182
Setting Up NDB Cluster Replication with an Existing Database (Offline) �������������������������������������������� 186
Setting Up NDB Cluster Replication with Existing Database (Online) ������������������������������������������������� 186
Failing Over NDB Cluster Replication Channel ������������������������������������������������������������������������������������ 188
NDB Cluster Replication Daily Maintenance ����������������������������������������������������������������� 191
Monitoring NDB Cluster Replication ��������������������������������������������������������������������������������������������������� 191
Restarting Master Cluster ������������������������������������������������������������������������������������������������������������������� 195
NDB Cluster Replication Performance Tuning������������������������������������������������������������������������������������� 196
Conflict Detection and Resolution �������������������������������������������������������������������������������� 198
Multi-Master Replication �������������������������������������������������������������������������������������������������������������������� 198
Conflicts Caused by Multi-Master Replication ������������������������������������������������������������������������������������ 201
Conflict Detection Methods ���������������������������������������������������������������������������������������������������������������� 203
Conflict Detection for Read Operations ���������������������������������������������������������������������������������������������� 212
Setting Up Conflict Detection and Resolution ������������������������������������������������������������������������������������� 213
Monitoring Conflict Detection ������������������������������������������������������������������������������������������������������������� 219
Conflict Detection Case Study ������������������������������������������������������������������������������������������������������������ 221
Application Modifications Required for Conflict Detection ����������������������������������������������������������������� 227
■ Contents
xi
Cautions and Limitations of Conflict Detection ����������������������������������������������������������������������������������� 228
Replication to InnoDB ��������������������������������������������������������������������������������������������������� 229
Requirements and Limitations ������������������������������������������������������������������������������������������������������������ 229
Setting Up Replication to InnoDB �������������������������������������������������������������������������������������������������������� 231
Tips When Using InnoDB as a Slave ��������������������������������������������������������������������������������������������������� 234
MySQL Server Options Related to Cluster Replication ������������������������������������������������� 234
Notes and Limitations of NDB Cluster Replication ������������������������������������������������������� 236
Summary ���������������������������������������������������������������������������������������������������������������������� 236
■Part III: Daily Tasks and Maintenance �������������������������������������������� 237
■Chapter 7: The NDB Management Client and Other NDB Utilities ���������������������� 239
The NDB Management Client ��������������������������������������������������������������������������������������� 239
Invoking the NDB Management Client ������������������������������������������������������������������������������������������������ 240
Getting Help from Inside the Client ����������������������������������������������������������������������������������������������������� 242
Setting the Prompt������������������������������������������������������������������������������������������������������������������������������ 243
Display the Cluster Status ������������������������������������������������������������������������������������������������������������������ 244
Single User Mode ������������������������������������������������������������������������������������������������������������������������������� 245
Create Reports ������������������������������������������������������������������������������������������������������������������������������������ 246
Purge Stale Sessions �������������������������������������������������������������������������������������������������������������������������� 247
Other NDB Utilities �������������������������������������������������������������������������������������������������������� 247
Summary ���������������������������������������������������������������������������������������������������������������������� 249
■Chapter 8: Backups and Restores ��������������������������������������������������������������������� 251
Backups and Backup Procedures ��������������������������������������������������������������������������������� 251
Native NDB Cluster Online Backups ����������������������������������������������������������������������������� 252
Overview ��������������������������������������������������������������������������������������������������������������������������������������������� 252
Implementation Details ����������������������������������������������������������������������������������������������������������������������� 253
Starting and Aborting Backups ����������������������������������������������������������������������������������������������������������� 255
Choosing the Backup ID ���������������������������������������������������������������������������������������������������������������������� 256
Backup Monitoring ����������������������������������������������������������������������������������������������������������������������������� 257
Backup Configuration ������������������������������������������������������������������������������������������������������������������������� 260
■ Contents
xii
Logical Backups and Binary Logs �������������������������������������������������������������������������������� 261
Consistency Considerations ���������������������������������������������������������������������������������������������������������������� 261
Creating Logical Backups ������������������������������������������������������������������������������������������������������������������� 262
Logical Backups from MySQL Workbench ������������������������������������������������������������������������������������������ 266
Backing Up Privileges ������������������������������������������������������������������������������������������������������������������������� 268
Binary Logs ����������������������������������������������������������������������������������������������������������������������������������������� 269
Restores ����������������������������������������������������������������������������������������������������������������������� 271
The ndb_restore Program ������������������������������������������������������������������������������������������������������������������� 271
Restore Schema ��������������������������������������������������������������������������������������������������������������������������������� 272
Full Data Restores ������������������������������������������������������������������������������������������������������������������������������ 273
Restore to a Different Number of Data Nodes ������������������������������������������������������������������������������������ 274
Partial Data Restores �������������������������������������������������������������������������������������������������������������������������� 274
Restores Using MySQL Workbench ����������������������������������������������������������������������������������������������������� 276
Point-In-Time Recovery (PITR) ������������������������������������������������������������������������������������������������������������ 277
Summary ���������������������������������������������������������������������������������������������������������������������� 281
■Chapter 9: Table Maintenance ��������������������������������������������������������������������������� 283
Schema Changes ��������������������������������������������������������������������������������������������������������� 283
Distributing Schema Changes and the Global Schema Lock �������������������������������������������������������������� 283
Online Versus Offline Schema Changes ���������������������������������������������������������������������������������������������� 285
Offline Schema Changes �������������������������������������������������������������������������������������������������������������������� 286
Online Schema Changes ��������������������������������������������������������������������������������������������������������������������� 287
ALTER TABLE Algorithm ����������������������������������������������������������������������������������������������������������������������� 288
ALTER TABLE Examples ������������������������������������������������������������������������������������������������ 290
Default Behavior ��������������������������������������������������������������������������������������������������������������������������������� 290
Adding a Column with the Explicit Column Format ���������������������������������������������������������������������������� 290
Specifying Algorithm and Lock Type ��������������������������������������������������������������������������������������������������� 291
Attempting Unsupported In-Place Changes ���������������������������������������������������������������������������������������� 291
Schema Changes in Version 7�2 and Earlier ��������������������������������������������������������������������������������������� 292
Reorganize Partitions ��������������������������������������������������������������������������������������������������� 292
■ Contents
xiii
Defragmentation ���������������������������������������������������������������������������������������������������������� 296
Index Statistics ������������������������������������������������������������������������������������������������������������� 297
Index Statistics Internals �������������������������������������������������������������������������������������������������������������������� 299
Maintaining Index Statistics ��������������������������������������������������������������������������������������������������������������� 300
Options and Status Variables �������������������������������������������������������������������������������������������������������������� 303
Summary ���������������������������������������������������������������������������������������������������������������������� 307
■Chapter 10: Restarts ������������������������������������������������������������������������������������������ 309
Restart Types ���������������������������������������������������������������������������������������������������������������� 310
Node Restart ��������������������������������������������������������������������������������������������������������������������������������������� 310
Initial Node Restart ����������������������������������������������������������������������������������������������������������������������������� 310
System Restart ����������������������������������������������������������������������������������������������������������������������������������� 311
Initial System Restart ������������������������������������������������������������������������������������������������������������������������� 311
Rolling Restart �������������������������������������������������������������������������������������������������������������� 312
Stopping and Starting Nodes ��������������������������������������������������������������������������������������� 314
Management Nodes���������������������������������������������������������������������������������������������������������������������������� 315
Data Nodes ����������������������������������������������������������������������������������������������������������������������������������������� 317
API/SQL Nodes ������������������������������������������������������������������������������������������������������������������������������������ 320
Restart Related Configuration �������������������������������������������������������������������������������������� 320
Startup Process ������������������������������������������������������������������������������������������������������������ 322
Monitoring Restarts ������������������������������������������������������������������������������������������������������ 325
The Management Client ���������������������������������������������������������������������������������������������������������������������� 325
The ndb_waiter Utility ������������������������������������������������������������������������������������������������������������������������ 325
The ndbinfo�restart_info Table ������������������������������������������������������������������������������������������������������������ 326
A Restart Seen in the Logs ����������������������������������������������������������������������������������������������������������������� 327
Example Restart Scenarios ������������������������������������������������������������������������������������������ 328
Configuration Change ������������������������������������������������������������������������������������������������������������������������� 330
Adding a Management Node �������������������������������������������������������������������������������������������������������������� 334
Adding Data Nodes ����������������������������������������������������������������������������������������������������������������������������� 336
Adding Data Nodes with Node Group Pre-Allocated ��������������������������������������������������������������������������� 342
Adding API/SQL Node �������������������������������������������������������������������������������������������������������������������������� 344
■ Contents
xiv
Recovering from a Corrupt NDB File System �������������������������������������������������������������������������������������� 345
Initial System Restart ������������������������������������������������������������������������������������������������������������������������� 346
Summary ���������������������������������������������������������������������������������������������������������������������� 349
■Chapter 11: Upgrades and Downgrades ������������������������������������������������������������ 351
Upgrades ���������������������������������������������������������������������������������������������������������������������� 351
Upgrade Types ������������������������������������������������������������������������������������������������������������������������������������ 351
Upgrade Considerations ��������������������������������������������������������������������������������������������������������������������� 352
Downgrades ����������������������������������������������������������������������������������������������������������������� 353
Performing Upgrades and Downgrades ����������������������������������������������������������������������� 354
Online Upgrades and Downgrades ����������������������������������������������������������������������������������������������������� 357
Offline Upgrades and Downgrades ����������������������������������������������������������������������������������������������������� 358
Case Studies ���������������������������������������������������������������������������������������������������������������� 358
Online Upgrade Using Generic Binaries ���������������������������������������������������������������������������������������������� 360
Upgrade from 7�4 to 7�5 Using RPM ��������������������������������������������������������������������������������������������������� 364
Online Downgrade ������������������������������������������������������������������������������������������������������������������������������ 367
Offline Upgrade ����������������������������������������������������������������������������������������������������������������������������������� 370
Summary ���������������������������������������������������������������������������������������������������������������������� 371
■Chapter 12: Security Considerations ����������������������������������������������������������������� 373
Network Security ���������������������������������������������������������������������������������������������������������� 373
Updates ������������������������������������������������������������������������������������������������������������������������ 375
Accounts and Privileges in the SQL Nodes ������������������������������������������������������������������� 376
Accounts and Password Management ����������������������������������������������������������������������������������������������� 377
SSL/TLS Certificates ��������������������������������������������������������������������������������������������������������������������������� 381
The Access Control and Privilege System ������������������������������������������������������������������������������������������ 382
Distributed Privileges ��������������������������������������������������������������������������������������������������� 384
Enabling Distributed Privileges ����������������������������������������������������������������������������������������������������������� 387
Disabling Distributed Privileges ���������������������������������������������������������������������������������������������������������� 389
Special Considerations ����������������������������������������������������������������������������������������������������������������������� 391
The Operating System and the Rest of the Infrastructure �������������������������������������������� 393
Summary ���������������������������������������������������������������������������������������������������������������������� 394
■ Contents
xv
■Chapter 13: MySQL Cluster Manager ����������������������������������������������������������������� 395
Background ������������������������������������������������������������������������������������������������������������������ 395
Terminology ���������������������������������������������������������������������������������������������������������������������������������������� 396
Architecture ���������������������������������������������������������������������������������������������������������������������������������������� 396
Commands ������������������������������������������������������������������������������������������������������������������������������������������ 398
Limitations ������������������������������������������������������������������������������������������������������������������������������������������ 400
Download, Installation, and Configuration �������������������������������������������������������������������� 401
Downloading ��������������������������������������������������������������������������������������������������������������������������������������� 402
Installation on Linux ��������������������������������������������������������������������������������������������������������������������������� 404
Installation on Microsoft Windows ������������������������������������������������������������������������������������������������������ 406
Upgrading ������������������������������������������������������������������������������������������������������������������������������������������� 409
Configuration �������������������������������������������������������������������������������������������������������������������������������������� 410
Starting and Stopping MySQL Cluster Manager ��������������������������������������������������������������������������������� 414
The MySQL Cluster Manager Client ���������������������������������������������������������������������������������������������������� 415
Managing a Cluster ������������������������������������������������������������������������������������������������������ 416
Installing the Cluster Binaries ������������������������������������������������������������������������������������������������������������� 416
Preparing the Cluster Through the mcm Client ���������������������������������������������������������������������������������� 417
Cluster Configuration: Auto Tuning ����������������������������������������������������������������������������������������������������� 420
Cluster Configuration: The set Command ������������������������������������������������������������������������������������������� 422
Cluster Configuration: The get Command ������������������������������������������������������������������������������������������� 423
Cluster Configuration: The reset Command ���������������������������������������������������������������������������������������� 424
Starting and Stopping Processes ������������������������������������������������������������������������������������������������������� 425
Configuration of an Online Cluster ������������������������������������������������������������������������������������������������������ 427
Backups ���������������������������������������������������������������������������������������������������������������������������������������������� 429
Restoring a Backup ���������������������������������������������������������������������������������������������������������������������������� 431
Upgrades �������������������������������������������������������������������������������������������������������������������������������������������� 432
Troubleshooting MySQL Cluster Manager �������������������������������������������������������������������� 433
Error Messages and the Log ��������������������������������������������������������������������������������������������������������������� 433
Self-Healing Agents ���������������������������������������������������������������������������������������������������������������������������� 435
Summary ���������������������������������������������������������������������������������������������������������������������� 437
■ Contents
xvi
■Part IV: Monitoring and Troubleshooting ���������������������������������������� 439
■Chapter 14: Monitoring Solutions and the Operating System ��������������������������� 441
Why Monitor? ��������������������������������������������������������������������������������������������������������������� 441
Establish a Baseline ��������������������������������������������������������������������������������������������������������������������������� 442
Perform a Root Cause Analysis ����������������������������������������������������������������������������������������������������������� 443
Perform Preventive Maintenance ������������������������������������������������������������������������������������������������������� 445
Monitoring Solutions ���������������������������������������������������������������������������������������������������� 445
MySQL Monitoring Solutions �������������������������������������������������������������������������������������������������������������� 446
MySQL Enterprise Monitor (MEM) �������������������������������������������������������������������������������� 446
Components ���������������������������������������������������������������������������������������������������������������������������������������� 447
Installation and Upgrades ������������������������������������������������������������������������������������������������������������������� 448
Features ���������������������������������������������������������������������������������������������������������������������������������������������� 450
The Operating System �������������������������������������������������������������������������������������������������� 453
CPU Usage ������������������������������������������������������������������������������������������������������������������������������������������ 453
Network Usage ����������������������������������������������������������������������������������������������������������������������������������� 453
Disk Usage ������������������������������������������������������������������������������������������������������������������������������������������ 454
Memory Usage ������������������������������������������������������������������������������������������������������������������������������������ 454
Logs ���������������������������������������������������������������������������������������������������������������������������������������������������� 455
Summary ���������������������������������������������������������������������������������������������������������������������� 455
■Chapter 15: Sources for Monitoring Data ���������������������������������������������������������� 457
The Information Schema ���������������������������������������������������������������������������������������������� 457
Information Schema Tables ���������������������������������������������������������������������������������������������������������������� 458
Using the Information Schema ����������������������������������������������������������������������������������������������������������� 460
The Information Schema and NDB Cluster ����������������������������������������������������������������������������������������� 461
The Performance Schema �������������������������������������������������������������������������������������������� 464
Performance Schema Threads ����������������������������������������������������������������������������������������������������������� 465
Performance Schema Tables Overview ���������������������������������������������������������������������������������������������� 467
Setup Tables and Configuration ���������������������������������������������������������������������������������������������������������� 467
Event Tables ���������������������������������������������������������������������������������������������������������������������������������������� 472
■ Contents
xvii
Summary Tables ��������������������������������������������������������������������������������������������������������������������������������� 482
Connection and Thread Tables ������������������������������������������������������������������������������������������������������������ 485
Variable and Status Tables������������������������������������������������������������������������������������������������������������������ 489
Replication Tables ������������������������������������������������������������������������������������������������������������������������������� 490
Instance Tables ����������������������������������������������������������������������������������������������������������������������������������� 491
Lock Tables ����������������������������������������������������������������������������������������������������������������������������������������� 493
The sys Schema ����������������������������������������������������������������������������������������������������������� 493
Installation ������������������������������������������������������������������������������������������������������������������������������������������ 494
sys Schema Objects ��������������������������������������������������������������������������������������������������������������������������� 495
sys Schema Configuration ������������������������������������������������������������������������������������������������������������������ 504
Command-Line Usage and Examples ������������������������������������������������������������������������������������������������� 506
MySQL Workbench Performance Reports ������������������������������������������������������������������������������������������� 510
SHOW Statements �������������������������������������������������������������������������������������������������������� 511
MySQL Logs ������������������������������������������������������������������������������������������������������������������ 514
SQL Node Error Logs��������������������������������������������������������������������������������������������������������������������������� 514
Audit Logs ������������������������������������������������������������������������������������������������������������������������������������������� 516
Summary ���������������������������������������������������������������������������������������������������������������������� 517
■Chapter 16: Monitoring MySQL NDB Cluster ������������������������������������������������������ 519
The NDB Cluster Information Database (ndbinfo) ��������������������������������������������������������� 519
Configuration �������������������������������������������������������������������������������������������������������������������������������������� 519
The ndbinfo Views ������������������������������������������������������������������������������������������������������������������������������ 523
NDB Cluster Reports ����������������������������������������������������������������������������������������������������� 527
Memory Usage Report ������������������������������������������������������������������������������������������������������������������������ 528
Disk Page Buffer Report ��������������������������������������������������������������������������������������������������������������������� 529
Transporters Report ���������������������������������������������������������������������������������������������������������������������������� 531
Disk Write Speed Report ��������������������������������������������������������������������������������������������������������������������� 532
Locks Report ��������������������������������������������������������������������������������������������������������������������������������������� 534
Log Buffers and Spaces Report ���������������������������������������������������������������������������������������������������������� 538
Configuration Report ��������������������������������������������������������������������������������������������������������������������������� 540
■ Contents
xviii
NDB Cluster Logs ��������������������������������������������������������������������������������������������������������� 544
Cluster Logs ���������������������������������������������������������������������������������������������������������������������������������������� 544
Data Node Logs ���������������������������������������������������������������������������������������������������������������������������������� 549
Summary ���������������������������������������������������������������������������������������������������������������������� 550
■Chapter 17: Typical Troubles and Solutions������������������������������������������������������� 551
Typical Problems on Data Nodes ���������������������������������������������������������������������������������� 551
General Information about Node Failures ������������������������������������������������������������������������������������������� 551
Cluster Log ����������������������������������������������������������������������������������������������������������������������������������������� 551
Node Log��������������������������������������������������������������������������������������������������������������������������������������������� 552
Error Log ��������������������������������������������������������������������������������������������������������������������������������������������� 553
Trace Files ������������������������������������������������������������������������������������������������������������������������������������������ 553
Core Files �������������������������������������������������������������������������������������������������������������������������������������������� 555
NDB Error Reporter Utility ������������������������������������������������������������������������������������������������������������������� 556
Watchdog Timeout ������������������������������������������������������������������������������������������������������������������������������ 556
LCP Watchdog Timeout ����������������������������������������������������������������������������������������������������������������������� 558
Swap Insanity ������������������������������������������������������������������������������������������������������������������������������������� 558
GCP Stop ��������������������������������������������������������������������������������������������������������������������������������������������� 560
Network Partitioning (Split Brain) ������������������������������������������������������������������������������������������������������� 561
Unplanned Shutdown of Entire System ���������������������������������������������������������������������������������������������� 562
Typical Problems on SQL Nodes ����������������������������������������������������������������������������������� 563
Errors While Executing Queries ���������������������������������������������������������������������������������������������������������� 563
Resource Temporary Errors ���������������������������������������������������������������������������������������������������������������� 563
Non-Temporary Errors ������������������������������������������������������������������������������������������������������������������������ 563
Connection to Data Node Is Lost ��������������������������������������������������������������������������������������������������������� 564
Errors Related to Transaction Handling ���������������������������������������������������������������������������������������������� 564
Crashes ����������������������������������������������������������������������������������������������������������������������������������������������� 565
Typical Problems on Management Nodes �������������������������������������������������������������������� 567
Summary ���������������������������������������������������������������������������������������������������������������������� 567
■ Contents
xix
■Part V: Development and Performance Tuning ������������������������������� 569
■Chapter 18: Developing Applications Using SQL with MySQL NDB Cluster�������� 571
Designing Tables ���������������������������������������������������������������������������������������������������������� 571
Creating NDB Cluster Tables ��������������������������������������������������������������������������������������������������������������� 571
Supported Data Types ������������������������������������������������������������������������������������������������������������������������� 572
Three Types of Indexes ����������������������������������������������������������������������������������������������������������������������� 573
Defining Indexes ��������������������������������������������������������������������������������������������������������������������������������� 577
The T-Tree Index ��������������������������������������������������������������������������������������������������������������������������������� 580
Estimating Table Size �������������������������������������������������������������������������������������������������������������������������� 581
Estimating Required Objects per Table ����������������������������������������������������������������������������������������������� 584
Defining Foreign Key Constraints ������������������������������������������������������������������������������������������������������� 584
Reviewing Table Definition ����������������������������������������������������������������������������������������������������������������� 585
Disk Data Tables ��������������������������������������������������������������������������������������������������������������������������������� 588
Consideration for Normalization ��������������������������������������������������������������������������������������������������������� 593
Major Limits Regarding Table Design ������������������������������������������������������������������������������������������������� 594
Accessing Data via SQL ������������������������������������������������������������������������������������������������ 595
Connecting to SQL Node ��������������������������������������������������������������������������������������������������������������������� 595
Transaction Handling for NDBCluster Tables �������������������������������������������������������������������������������������� 602
Error-Handling Techniques ����������������������������������������������������������������������������������������������������������������� 603
Summary ���������������������������������������������������������������������������������������������������������������������� 608
■Chapter 19: MySQL NDB Cluster as a NoSQL Database ������������������������������������� 611
Why NoSQL? ����������������������������������������������������������������������������������������������������������������� 611
Accessing Data via memcached ���������������������������������������������������������������������������������� 612
Why Use NDB-memcached ����������������������������������������������������������������������������������������������������������������� 612
Setting Up NDB-memcached �������������������������������������������������������������������������������������������������������������� 613
Defining Mapping to NDB Cluster Tables �������������������������������������������������������������������������������������������� 616
Accessing Data via the NDB API ����������������������������������������������������������������������������������� 622
Why Use the NDB API? ������������������������������������������������������������������������������������������������������������������������ 622
Installing Header Files and Libraries for the NDB API ������������������������������������������������������������������������� 623
Building an Application with the NDB API ������������������������������������������������������������������������������������������� 623
■ Contents
xx
References and Examples ������������������������������������������������������������������������������������������������������������������ 624
Typical Program Flow ������������������������������������������������������������������������������������������������������������������������� 624
Simple Read Example ������������������������������������������������������������������������������������������������������������������������� 626
Accessing Data Using NdbRecord ������������������������������������������������������������������������������������������������������ 632
Scan Example ������������������������������������������������������������������������������������������������������������������������������������� 635
Error-Handling Considerations ������������������������������������������������������������������������������������������������������������ 648
Accessing Data via ClusterJ ����������������������������������������������������������������������������������������� 650
Installing ClusterJ ������������������������������������������������������������������������������������������������������������������������������� 650
Writing a ClusterJ Application ������������������������������������������������������������������������������������������������������������ 651
ClusterJ Example �������������������������������������������������������������������������������������������������������������������������������� 651
Summary ���������������������������������������������������������������������������������������������������������������������� 654
■Chapter 20: MySQL NDB Cluster and Application Performance Tuning ������������� 655
MySQL NDB Cluster Tuning������������������������������������������������������������������������������������������� 655
Disabling Powersave and CPU Frequency Scaling ����������������������������������������������������������������������������� 655
CPU Binding Strategy �������������������������������������������������������������������������������������������������������������������������� 657
Disk Type and File System Block Size ������������������������������������������������������������������������������������������������ 665
SQL Tuning ������������������������������������������������������������������������������������������������������������������� 666
Commit Sizing ������������������������������������������������������������������������������������������������������������������������������������ 666
Non-Transactional Batch Processing �������������������������������������������������������������������������������������������������� 667
Engine Condition Pushdown Optimization ������������������������������������������������������������������������������������������ 667
Optimizing Joins ��������������������������������������������������������������������������������������������������������������������������������� 668
Optimizing Partitioning ����������������������������������������������������������������������������������������������������������������������� 672
Optimizing Access from SQL Node to Data Node �������������������������������������������������������������������������������� 677
Adding Nodes ������������������������������������������������������������������������������������������������������������������������������������� 679
Using NoSQL API in Conjunction with SQL ������������������������������������������������������������������������������������������ 680
Summary ���������������������������������������������������������������������������������������������������������������������� 680
Index ��������������������������������������������������������������������������������������������������������������������� 681
About the Authors
Jesper Wisborg Krogh is a member of the Oracle MySQL Support team and has spoken on several occasions at Oracle OpenWorld. He has a background with a Ph.D. in computational chemistry before changing to work with MySQL and other software development in 2006. Jesper lives in Sydney, Australia and enjoys spending time outdoors walking, traveling, and reading. His areas of expertise include MySQL Cluster, MySQL Enterprise Backup, and the Performance and sys schemas. He is an active author in the Oracle Knowledge Base and regularly blogs on MySQL topics.
Mikiya Okuno is a member of the Oracle MySQL Support team based in Japan and has written four database-related books in Japanese. He joined the MySQL support team in 2007 when MySQL AB was an independent company. Before joining MySQL, he worked at Sun Microsystems (which acquired MySQL AB, then was acquired by Oracle) as a technical support engineer. He has over 16 years of technical support experience in the computer industry. Mikiya is a self-confessed computer geek and loves Gentoo Linux OS and ErgoDox keyboard for his desktop. Emacs is his preference.
xxi
About the Technical Reviewer
Dr. Charles Bell conducts research in emerging technologies. He is a member of the Oracle MySQL Development team as a senior developer working on a variety of database administration and high availability projects. He lives in a small town in rural Virginia with his loving wife. He received his Ph.D. in engineering from Virginia Commonwealth University in 2005. His research interests include database systems, software engineering, sensor networks, and 3D printing. He spends his limited free time as a practicing Maker focusing on microcontroller and 3D printers and printing projects.
xxiii
Acknowledgments
We would like to thank all of the people who made this book possible. First of all, Jonathan Gennick, Jill Balzano, and Laura Berendson ensured its progress. Jonathan and Jill, your guidance has been invaluable. However, the rest of the team at Apress should not be forgotten either: thank you.
A special thanks to our technical reviewer, Charles Bell. It has been great to get your feedback and learn from your experience as an author. Our colleagues at Oracle also deserve credit for this book becoming a reality. The discussions with the MySQL NDB Cluster developers and our direct colleagues in the MySQL Support team were key to becoming an expert on MySQL NDB Cluster. It is hard to start mentioning names while not forgetting any, but a definite thanks to our manager Adam Dixon for the support. Thanks to the developers Frazer Clement and Mikael Ronström for, time and time again, explaining technical matters of MySQL NDB Cluster, as well as Pekka Nousiainen for his feedback on the index statistics implementation. Of course, Jon Stephens must not be forgotten for his work on the MySQL NDB Cluster chapter in the MySQL Reference Manual.
Last but not least, a warm-hearted thanks to our wives, Ann-Margrete and Junko, as well as Mikiya’s children, who put up with us while we were busy writing this book.
xxv
Introduction
MySQL NDB Cluster is part of the MySQL family of products. There are few databases matching as many buzzwords as MySQL NDB Cluster: high availability, SQL, NoSQL, in-memory database, automatic failure handling, sharding, etc. This book discusses how these properties are integrated into MySQL NDB Cluster and how they are not just buzzwords, but real features.
Whom This Book Is ForThe book has been written for database administrators who are looking into deploying MySQL NDB Cluster or already have a cluster in production and want to increase their knowledge to be able to handle routine administrative tasks and troubleshooting. While we have attempted to write the book assuming as little existing knowledge as possible, it is an advantage to have at least some SQL database background.
How This Book Is StructuredThe chapters have been divided into five parts, with each part covering related topics. The journey starts with some background knowledge of how MySQL NDB Cluster works, then moves on to installation and configuration, daily tasks and maintenance, monitoring and troubleshooting, and completes with development and performance tuning.
Part IThe first part consists of two chapters and discusses how MySQL NDB Cluster works from a technical point of view. There is not a lot of focus on practical tasks, but some of the theory is exemplified through case studies. The two chapters are:
• Chapter 1: Architecture and Core Concepts. The first chapter goes into how the cluster works at a high level as well as more specific details for two of the nodes types: management and API nodes.
• Chapter 2: The Data Nodes. The second chapter exclusively focuses on the data nodes, which are where the data is stored and queries are executed.
xxvii
■ IntroduCtIon
xxviii
Part IIThe second part explains how to deploy MySQL NDB Cluster, starting with system considerations, then discusses configuration, installation, and replication. The four chapters are:
• Chapter 3: System Planning. This chapter discusses what to consider when choosing hardware and how to plan for network partitioning and scalability. There are also several examples of typical topologies.
• Chapter 4: Configuration. This chapter shows how MySQL NDB Cluster is configured and goes through the most important configuration options.
• Chapter 5: Installation. It is finally time to install MySQL NDB Cluster. The chapter has installation instructions for Linux, Microsoft Windows, and MacOS.
• Chapter 6: Replication. Replication allows the data from one cluster to be replicated to another cluster, or an InnoDB database. MySQL NDB Cluster’s conflict resolution features for active-active replication between two clusters are also included.
Part IIIThe cluster is up and running, so this third part moves on to a series of practical focused chapters describing how day-to-day tasks and maintenance are performed. There are seven chapters in this part:
• Chapter 7: The NDB Management Client and Other NDB Utilities. This chapter discusses the utilities available in the MySQL NDB Cluster installation. Most of the focus is on the NDB management client, which can be used to perform a range of tasks such as starting, stopping, and restarting nodes as well as creating backups, getting the cluster status, etc.
• Chapter 8: Backups and Restores. The data is worth no more than its ability to be recovered in the event of a disaster. This chapter discusses the ins and outs of backups and restores.
• Chapter 9: Table Maintenance. This chapter goes through the online and offline schema change features, defragmentation, and index statistics.
• Chapter 10: Restarts. In a product that aims at making itself highly available, online restarts are important. This chapter goes through the concepts of rolling restarts and system restarts. There are also several detailed examples of tasks requiring a restart.
• Chapter 11: Upgrades and Downgrades. This chapter discusses and gives practical examples of how it is possible to perform upgrades and downgrades, both online and offline.
• Chapter 12: Security Considerations. Security must be a primary part of the design decisions, starting from the initial planning and continuing through the lifetime of the cluster. This chapter goes through the most important security aspects for MySQL NDB Cluster.
• Chapter 13: MySQL Cluster Manager. This chapter provides a tutorial for the MySQL Enterprise offering MySQL Cluster Manager (MCM), which provides an easier way to manage a cluster. The chapter includes the main steps, from the initial installation through an upgrade.
■ IntroduCtIon
xxix
Part IVA special part of a database’s daily routines is monitoring and troubleshooting. That is the topic of Part IV. There are four chapters in this part:
• Chapter 14: Monitoring Solutions and the Operating System. This chapter goes through how monitoring solutions, particularly MySQL Enterprise Monitor, can be used to prevent and solve issues, and ends with considerations of what to monitor at the operating system level.
• Chapter 15: Sources for Monitoring Data. This chapter goes through the traditional sources in MySQL for collecting and monitoring data, including the Information Schema, the Performance Schema, the sys schema, the SHOW statements, and the MySQL error log.
• Chapter 16: Monitoring MySQL NDB Cluster. MySQL NDB Cluster provides some additional monitoring sources: The ndbinfo schema and the logs on the management and data nodes.
• Chapter 17: Typical Troubles and Solutions. No matter how careful a database is managed, there will be times when something goes wrong. This chapter goes through some general troubleshooting techniques for MySQL NDB Cluster and some typical issues.
Part VThe last part moves on to the development part of MySQL NDB Cluster. Developing using SQL and NoSQL and performance tuning are all discussed. The three chapters in Part V are:
• Chapter 18: Developing Application Using SQL with MySQL NDB Cluster. This chapter goes through table and index creation and other considerations, such as error handling when using SQL statements in the development.
• Chapter 19: MySQL NDB Cluster as NoSQL Database. MySQL NDB Cluster supports several NoSQL APIs. This chapter discusses NDB-memcached, the C++ NDB API, and ClusterJ. The chapter also includes several code examples.
• Chapter 20: MySQL NDB Cluster and Application Performance Tuning. The final chapter of the book covers performance tuning at the system and SQL levels. The system level, for example, includes binding data node threads to CPUs and disk types. The SQL level includes optimizing joins and partitioning, mixing NoSQL and SQL, and more.
Downloading the CodeThe code for the examples shown in this book is available on the Apress web site, www.apress.com. A link can be found on the book’s information page.
PART I
The Basics
3© Jesper Wisborg Krogh and Mikiya Okuno 2017 J. W. Krogh and M. Okuno, Pro MySQL NDB Cluster, https://doi.org/10.1007/978-1-4842-2982-8_1
CHAPTER 1
Architecture and Core Concepts
MySQL NDB Cluster is a distributed real-time database management system using a shared nothing architecture. It excels at workloads with a high volume of small transactions, and it aims at providing high availability with no single point of failure and duplication of data through two-phase commits and synchronous replication. Part of the high availability implementation also includes a real-time promise; that is, MySQL NDB Cluster looks to provide consistent response times. To avoid problems on one node causing delays in the rest of the cluster, MySQL NDB Cluster employs a fail early strategy, which affects particularly the data nodes and is something that users should have in mind.
The communication within the cluster is performed using the NDB API (a NoSQL API), which was originally developed together with the rest of NDB Cluster in the 1990s. However, since NDB Cluster became part of MySQL in 2003, a storage engine that plugs into MySQL Server using the pluggable storage engine API has been developed. So nowadays the most commonly used method of interacting with NDB Cluster is through SQL statements similar to other storage engines in MySQL, such as InnoDB.
■ Note For MySQL NDB Cluster, the term NoSQL API means an application programming interface that allows communication with the backend storage engine while bypassing the SQL layer. The underlying storage is identical irrespective of the API used, and the same data can be accessed concurrently using different APIs, including the SQL API. Chapters 18 and 19 discuss the APIs in more detail.
With the ongoing development, MySQL NDB Cluster is today a general-purpose storage engine that supports a wide range of features, including features not supported by any other storage engine in MySQL.
This chapter provides the big picture of MySQL NDB Cluster by looking at the general characteristics and features of MySQL NDB Cluster, limitations, the various node types, and the built-in high availability. Chapter 2 continues the discussion by focusing on the backend storage, the data nodes. First up though, a quick overview of the terminology in MySQL NDB Cluster.
TerminologyOne of the aspects that can be difficult when studying a new subject is the terminology. Each product has its own way of naming and describing features. This section provides an overview of the most important terms used in MySQL NDB Cluster. More details of what these terms mean will become apparent as the features are discussed throughout this book.
Table 1-1 contains a list of several of the terms used in the description of MySQL NDB Cluster and all of its features. The list is ordered alphabetically.
ChAPTer 1 ■ ArChITeCTure AND Core CoNCePTS
4
Table 1-1. Terminology of MySQL NDB Cluster
Term Description
Angel The angel process monitors the actual ndbd/ndbmtd process (data node) and handles node failures.
Arbitration The process of determining which data nodes can continue after the failure of a data node.
API node A process communicating with the data nodes. This can, for example, be part of the application, an SQL node, or a utility program.
Asynchronous replication The replication used to replicate between two clusters or MySQL Server instances. The replication is asynchronous because it is performed after the control is returned to the application. Thus, only the master side is guaranteed to apply the change.
Binary log A log used to record all schema and data changes. Primarily used for replication and point-in-time recoveries (PITR).
Cluster In this book, used for a collection of data, management, and API nodes in MySQL NDB Cluster.
Data node The backend storage for MySQL NDB Cluster. Also known as ndbd or ndbmtd.
High availability The ability to provide the service with “very little downtime”. What “very little” is and what constitutes “downtime” depends on the system and product. For MySQL NDB Cluster being available means being able to execute transactions with consistent response times.
Kernel block The building blocks that make up the data nodes.
InnoDB The main storage engine in MySQL Server.
ndb_mgmd The binary used to start the management nodes.
ndbd The binary used to start the single threaded data nodes. See also data node.
ndbmtd The binary used to start the multi-threaded (mt) data nodes. See also data node.
OLAP Online analytical processing: A typical OLAP workload can be used to generate reports.
OLTP Online transaction processing: Mostly small, quick transactions.
Management node The MySQL NDB Cluster nodes handling, for example, configuration, connections, and arbitration.
mysqld The daemon process used for MySQL Server and the SQL nodes. See also SQL node and API node.
MySQL Server The standard MySQL database product not including data nodes and management nodes.
Node group A group of data nodes sharing the same data. Each node group has as many members as there are replicas of the data. When a cluster has more than one node group, the data is automatically sharded between the node groups, so each node group only stores a subset of the data.
(continued)