Mais conteĂșdo relacionado
Semelhante a The OSSCube MySQL High Availability Tutorial (20)
The OSSCube MySQL High Availability Tutorial
- 4. What is a Cluster?
MySQL Cluster Tutorial, © OSSCube
- 5. Single MySQL Server Architecture
SQL Request
MySQL Server
MySQL Client
MySQL Client
Response
MySQL Cluster Tutorial, © OSSCube
- 6. MySQL Cluster Architecture
NDB API Call
SQL Request
MySQL Client
Partitioning
Replication
Message
Response
Response
SQL Node (MySQL server)
MySQL Cluster Tutorial, © OSSCube
Data Nodes
- 15. Split Brain
I have full
responsibility
of the cluster
Servers can
not see
each other
I have full
responsibility
of the cluster
MySQL Cluster Tutorial,© OSSCube
- 25. Phase Two: Failure
(Abort Commit)
Transaction
Transaction
Failed
Successful
Rollback
Rollback
Transaction
Transaction
MySQL Cluster Tutorial, © OSSCube
- 27. Initiate MySQL Cluster
âą
âą
âą
âą
âą
âą
âą
âą
# file "config.ini" - 2 data nodes and 2 SQL nodes# This file
is placed in the startup directory of ndb_mgmd (the#
management server)
# The first MySQL Server can be started from any host. The
second# can be started only on the host MySQLd_5.MySQL.com
[NDBD DEFAULT]
NoOfReplicas= 2
DataDir= /var/lib/MySQL-cluster
[NDB_MGMD]
Hostname= ndb_mgmd.MySQL.com
DataDir= /var/lib/MySQL-cluster
[NDBD]
HostName= ndbd_2.MySQL.com
[NDBD]
HostName=ndbd_3.MySQL.com
[MySQLD]
[MySQLD]
HostName= MySQLd_5.MySQL.com
MySQL Cluster Tutorial, © OSSCube
- 29. Data Nodes
âą my.cnf# example additions to
my.cnf for MySQL Cluster
âą [ndbd]
connectstring=ndb_mgmd.MySQL.com
MySQL Cluster Tutorial, © OSSCube
- 31. SQL Nodes
âą my.cnf
âą # example additions to my.cnf for
MySQL Cluster
# (will work on all versions)
âą # enable ndbcluster storage engine,
and provide connectstring for
management
âą # server host to the default port
1186
âą [mysqld]
Ndbcluster
ndbconnectstring=ndb_mgmd.MySQL.com
MySQL Cluster Tutorial, © OSSCube
:1186
- 38. NDBâs Storage Method
âą In-Memory Storage
âą Disk-Based Storage
â New in MySQL 5.1
â Undo Logging
â Fixed-Width Columns
MySQL Cluster Tutorial, © OSSCube
- 41. Creating Indexes
âą
Each table in the cluster always has a hash index for a Primary Key
âą
Ordered indexes can be created with ALTER TABLE ADD INDEX ....
MySQL Cluster Tutorial, © OSSCube
- 42. First Node/First Fragment
âą
âą
Hidden field/table created that will handle the management of the
Unique Index on Name
Ordered Index (T-Tree) created for Continent field
Hidden
Field
Code_Hash
1351
1785
1943
2031
2345
Code
CHE
CHN
FIN
GOR
SKO
Name
Switzerland
China
Finland
United Kingdom
South Korea
Continent
Europe
Asia
Europe
Europe
Asia
Ordered
Index
Hidden
Table
MySQL Cluster Tutorial, © OSSCube
- 43. Second Node/Second Fragment
âą
âą
Same as First Node/Fragment setup
Contains the remaining data
Hidden
Field
Code Hash
1231
1853
2145
2197
Code
BRA
ESP
IND
MOR
Name
Brazil
Spain
India
Morocco
Continent
South America
Europe
Asia
Africa
Ordered
Index
Hidden
Table
MySQL Cluster Tutorial, © OSSCube
- 44. Unique Key Lookup
Primary Key Lookup may
UniqueKey Lookup network hop
require another
PK values
Function()
Hash
Look up row
Data node
Data node
Look up row
Data node
Data node
MySQL Server
MySQL Cluster Tutorial, © OSSCube
- 45. Parallel Ordered Index
Scan
Data node
Data node
TTTree
Tree
Index
Index
rows
MySQL
Server
Data node
Data node
MySQL Cluster Tutorial, © OSSCube
TTTree
Tree
Index
Index
- 46. Parallel full table scan
Data node
Data node
rows
MySQL
Server
Data node
Data node
MySQL Cluster Tutorial, OSSPAC 09
Singapore, © OSSCube
- 47. Parallel full table scan ( WHERE
condition processed in SQL
node)
SQL Query
Data node
Data node
Few Rows
Few Rows
Many Rows
rows Rows
Many
MySQL
Server
Where
Conditi
on
MySQL Cluster Tutorial, © OSSCube
Data node
Data node
- 48. Parallel full table scan
( WHERE condition
processed in data node)
SQL Query
Where
Conditi
Fewrows on
Rows
Few Rows
Few Rows
Few Rows
Data node
Data node
MySQL
Server
Where
Conditi
on
MySQL Cluster Tutorial, © OSSCube
Data node
Data node
- 52. Global Check Point
âą A GCP occurs every few seconds, when
transactions for all nodes are synchronized
and the REDO log is flushed to disk
MySQL Cluster Tutorial, © OSSCube
- 54. Memory - RAM
âą
Memory Allocation
Total Memory = N(data nodes)* Local Memory /
NoOfReplicas
-- or -Local Memory = Total Memory * NoOfReplicas / N(data
nodes)
âą
Sizing up the
Memory
â Fixed size in memory
â Variable sized in memory
â Fixed size on disk
MySQL Cluster Tutorial, © OSSCube
- 59. Creating the Log File Group
âą Create Log File Group
CREATE LOGFILE GROUP lg_1
ADD UNDOFILE 'undo_1.dat'
INITIAL_SIZE 16M
UNDO_BUFFER_SIZE 2M
ENGINE NDB;
âą Adding Undo Files to Log File Group
ALTER LOGFILE GROUP lg_1
ADD UNDOFILE 'undo_2.dat'
INITIAL_SIZE 12M
ENGINE NDB;
MySQL Cluster Tutorial, © OSSCube
- 60. Verifying UNDO Files are
Created
âą INFORMATION_SCHEMA Tables
SELECT LOGFILE_GROUP_NAME, LOGFILE_GROUP_NUMBER,
EXTRA
FROM INFORMATION_SCHEMA.FILES
WHERE FILE_NAME = 'undo_1.dat';
SELECT LOGFILE_GROUP_NAME, LOGFILE_GROUP_NUMBER,
EXTRA
FROM INFORMATION_SCHEMA.FILES
WHERE FILE_NAME = 'undo_2.dat';
MySQL Cluster Tutorial, © OSSCube
- 61. Creating the Tablespace
âą Create a Tablespace
CREATE TABLESPACE ts_1
ADD DATAFILE 'data_1.dat'
USE LOGFILE GROUP lg_1
INITIAL_SIZE 32M
ENGINE NDB;
âą Add an Additional Data File
ALTER TABLESPACE ts_1
ADD DATAFILE 'data_2.dat'
INITIAL_SIZE 48M
ENGINE NDB;
âą Verifying Data Files are Created
SELECT FILE_NAME, LOGFILE_GROUP_NAME, EXTRA
FROM INFORMATION_SCHEMA.FILES
WHERE TABLESPACE_NAME = 'ts_1' AND FILE_TYPE =
'DATAFILE';
MySQL Cluster Tutorial, © OSSCube
- 62. Create a Disk Data Table
âą Non-Indexed Columns Stored on Disk in Tablespace
CREATE TABLE dt_1 (
memberId INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
lName VARCHAR(50) NOT NULL, fName VARCHAR(50) NOT NULL,
dob DATE NOT NULL, joined DATE NOT NULL,
INDEX(lName, fName)
) TABLESPACE ts_1 STORAGE DISK ENGINE NDB;
âą Alter Existing Non-Cluster Tables
ALTER TABLE city TABLESPACE ts1 STORAGE DISK ENGINE=NDB;
âą View Table Status
SHOW TABLE STATUS LIKE 'city'G
MySQL Cluster Tutorial, © OSSCube
- 66. MySQL Clusterâs Native
Backup Tool
âą Backup Data
â .ctl
â .log
â .data
Data
Node
âą Abort Backup
Data
Node
Backup-1.2.ctl
Backup-1.2.log
Backup-1.0.2.Data
Backup-1.1.2.Data
Backup-1.3.ctl
Backup-1.3.log
Backup-1.0.3.Data
Backup-1.1.3.Data
Data
Data
ndb_mgm> ABORT BACKUP 6
Node
Node
Abort of backup 6 ordered
Node 2: Backup 10 started from 1 has
been aborted. Error: 1321
MySQL Cluster Tutorial, © OSSCube
- 68. Restoring Backups
âą Recovering MySQL Cluster's Native Backup Files (1/3)
â Verify Management Node is Running
shell> ndb_mgm -e "SHOW"
â Start and Empty the Data Nodes
âą Start each data node with the --initial option.
MySQL Cluster Tutorial, © OSSCube
- 74. Full Table Scan
âą Without Condition Pushdown
âą With Condition Pushdown
MySQL Cluster Tutorial, © OSSCube
- 75. Parallel full table scan
( WHERE condition
processed in SQL node)
SQL Query
Few Rows
Where
Condition
Data node
Many
rows Rows
MySQL
Server
MySQL Cluster Tutorial, © OSSCube
Data node
- 76. Parallel full table scan ( WHERE
condition processed in data
node)
SQL Query
Where
Condition
Data node
Few Rows
Few Rows
rows
MySQL
Server
MySQL Cluster Tutorial, © OSSCube
Where
Data
Condition node
- 84. NDB Injector Thread
âą A thread inside MySQL server
âą Responsible for injecting rows in binlog and
produces âSingle connical binlog for clusterâ
âą not just one MySQL Server
âą It contains everything written on all ndbApi
program including MySQLd connected to cluster
MySQL Cluster Tutorial, © OSSCube
- 87. Thank you for your time and attention
For more information, please feel free to drop in a line to
sales@osscube.com or visit http://www.osscube.com
Or call us at 1-888-9OSSCube (Toll Free for USA)
1-919-791-5472 (From outside USA)
MySQL Cluster Tutorial, © OSSCube