Galera Cluster Best Practices: Seppo Jaakola Codership
Galera Cluster Best Practices: Seppo Jaakola Codership
Galera Cluster Best Practices: Seppo Jaakola Codership
Seppo Jaakola
Codership
Agenda
read & write read & write read & write Read & write access to any node
Client can connect to any node
www.codership.com
5
Multi-Master Replication
a MySQL
www.codership.com
6
Galera Cluster
www.codership.com
7
Synchronous Replication
Transaction is
Read & write processed locally up
to commit time
a
Galera Replication
www.codership.com
10
Synchronous Replication
Transaction is
commit replicated to whole
cluster
a
Galera Replication
www.codership.com
11
Synchronous Replication
Client gets OK
OK status
a
Galera Replication
www.codership.com
12
Synchronous Replication
Transaction is
applied in slaves
a
Galera Replication
www.codership.com
13
Consistent Reads
Consistent reads
Transaction is
commit replicated to whole
cluster
Galera Replication
www.codership.com
15
Consistent reads
Galera Replication
www.codership.com
16
Consistent Reads
www.codership.com
17
Consistent Reads
● Use: wsrep_causal_reads=ON
➔ Every read (select, show) will wait until slave
queue has been fully applied
● There is timeout for max causal read wait:
● replicator.causal_read_keepalive
www.codership.com
18
Consistent Reads
● Use: wsrep_causal_reads=ON
➔ Every read (select, show) will wait until slave
queue has been fully applied
● There is timeout for max causal read wait:
● replicator.causal_read_keepalive
www.codership.com
19
Consistent reads
MySQL MySQL
Galera Replication
www.codership.com
20
Consistent Reads
www.codership.com
21
The Thing with wsrep_cluster_address
The Thing with wsrep_cluster_address
wsrep_cluster_address=gcomm://10.0.0.1,10.
0.0.2,10.0.0.3
Joiner
a Galera Replication
www.codership.com
25
wsrep_cluster_address
a Galera Replication
www.codership.com
26
wsrep_cluster_address
Replication relay
a Galera Replication
www.codership.com
27
wsrep_cluster_address
wsrep_cluster_address=gcomm://
Joiner
a Cluster 1
www.codership.com
28
wsrep_cluster_address
a Cluster 1 Cluster 2
www.codership.com
29
Dealing with Multi-Master Conflicts
Multi-master Conflicts
write write
a
Galera Replication
www.codership.com
31
Multi-master Conflicts
write write
Conflict detected
MySQL MySQL MySQL
a
Galera Replication
www.codership.com
32
Multi-master Conflicts
Deadlock
OK write error
a
Galera Replication
www.codership.com
33
Multi-Master Conflicts
www.codership.com
34
Database Hot-Spots
www.codership.com
35
Hot-Spots
write write
write
Hot row
www.codership.com
36
Diagnosing Multi-Master Conflicts
1. conflict
Write detected
write
2. retrying
a
Galera Replication
www.codership.com
39
Multi-Master Conflicts
www.codership.com
42
State Snapshot Transfer
➢ mysqldump
➢ rsync
➢ xtrabackup
www.codership.com
43
SST Request
www.codership.com
44
SST Method
wsrep_sst_mysqldump
Galera Replication
wsrep_sst_xtrabackup
www.codership.com
45
SST API
● Backups
www.codership.com
46
wsrep_sst_mysqldump
● Logical backup
● Slowest method
● Configure authentication
➢ wsrep_sst_auth=”root:rootpass”
www.codership.com
47
wsrep_sst_rsync
● Physical backup
● Fast method
www.codership.com
48
wsrep_sst_xtrabackup
● Contributed by Percona
● Probably the fastest method
● Uses xtrabackup
www.codership.com
49
SST Donor
Request to join
GTID: seqno-n
Donor Joiner
seqno-n
gcache
gcache
www.codership.com
51
Incremental State Transfer
Donor Joiner
gcache seqno-n
gcache
www.codership.com
52
Incremental State Transfer
● Very effective
● gcache.size parameter defines how big
www.codership.com
53
Incremental State Transfer
stored in cache
www.codership.com
54
Incremental State Transfer
www.codership.com
55
Backups Backups Backups
Backups
➢ Possible methods:
1.Disconnecting a node for backup
2.Using SST script interface
3.xtrabackup
www.codership.com
57
Backups with global Trx ID
www.codership.com
58
Backup by Disconnecting a Node
Galera Replication
www.codership.com
59
Backup by Disconnecting a Node
Load Balancing
Galera Replication
www.codership.com
60
Backup by Disconnecting a Node
Load Balancing
Galera Replication
www.codership.com
61
Backup by Disconnecting a Node
Load Balancing
Galera Replication
backups
www.codership.com
62
Backup by Disconnecting a Node
Load Balancing
backups
www.codership.com
63
Backup by SST
www.codership.com
64
Backup by SST API
SST request
Garbd
node1 node2 node3
wsrep_sst_donor=node3
wsrep_sst_method=backup
Galera Replication
www.codership.com
65
Backup by SST API
Donor launches
Load Balancing
wsrep_sst_backup
wsrep_sst_backup
node1 node2 node3
.
Galera Replication .
.
www.codership.com
66
Backup by SST API
wsrep_sst_backup
Load Balancing
prepares the backup
wsrep_sst_backup
node1 node2 node3
.
Galera Replication .
.GTID
backups
www.codership.com
67
Backup by SST API
Galera Replication
www.codership.com
68
Backup by xtrabackup
www.codership.com
69
Schema Upgrades
Schema Upgrades
www.codership.com
71
Total Order Isolation
www.codership.com
72
Total Order Isolation
www.codership.com
73
Total Order Isolation
www.codership.com
74
Total Order Isolation
www.codership.com
75
Total Order Isolation
www.codership.com
76
Rolling Schema Upgrade
www.codership.com
77
Rolling Schema Upgrade
www.codership.com
78
Rolling Schema Upgrade
www.codership.com
79
Rolling Schema Upgrade
ALTER...
ALTER processing
node3
node1 node2
Slave queue
www.codership.com
80
Rolling Schema Upgrade
Node re-syncs to
replication
node1 node2 node3
Slave queue
www.codership.com
81
Rolling Schema Upgrade
Slave queue
www.codership.com
82
Rolling Schema Upgrade
www.codership.com
83
wsrep_on=OFF
www.codership.com
84
Schema Upgrades
● Best practices:
➔ Plan your upgrades
➔ Try to be backwards compatible
➔ Rehearse your upgrades
➔ Find out DDL execution time
➔ Go for RSU if possible
●ALTER TABLE to create new autoinc
column will cause issues
● Every node has different autoinc increment
and offset settings
www.codership.com
85
Create autoinc Column
node1 node2
myTable myTable
Aaa Aaa
Bbb Bbb
Ccc Ccc
www.codership.com
86
Create autoinc Column
node1 node2
myTable myTable
Aaa 1 Aaa 2
Bbb 4 Bbb 5
Ccc 7 Ccc 8
www.codership.com
87
MySQL Replication Topologies
Galera as MySQL Slave
MySQL
MySQL Node 1
slave slave
a Node 3
Node 2
www.codership.com
89
Galera as MySQL Master
Same server_id in
all nodes
Node 1
Node 2 Node 3
master
MySQL replication
a MySQL
slave
www.codership.com
90
MySQL Replication Bottleneck
MySQL
master
MySQL
slave
www.codership.com
93
Migrating to Galera Clustering
MySQL
master
Galera
MySQL Node 1
slave
www.codership.com
94
Migrating to Galera Clustering
MySQL
master
Galera
MySQL Node 1
slave
www.codership.com
95
Migrating to Galera Clustering
MySQL
master
Galera
MySQL
Node 1
slave
a
Galera Galera
Node 2 Node 3
www.codership.com
96
Migrating to Galera Clustering
MySQL
master
Galera
MySQL
Node 1
slave
a
Galera Galera
Node 2 Node 3
www.codership.com
97
Migrating to Galera Clustering
Galera
Node 1
a
Galera Galera
Node 2 Node 3
www.codership.com
98
Detecting Slow Node
Detecting Slow Node
www.codership.com
101
Detecting Slow Node
www.codership.com
102
Parallel Replication
Parallel Replication
MySQL
Any number of slave applier
Slave thd Slave thd threads can be started
www.codership.com
104
Parallel Applying
www.codership.com
105
Cluster Notifications
Cluster Notifications
www.codership.com
107
MyISAM Replication
MyISAM Replication
● On experimental level
● MyISAM is phasing out not much demand to
complete
● Replicates SQL up-front, like TOI
● Use: wsrep_replicate_myisam=ON
● Should be used in master-slave model
● No checks for non-deterministic SQL
● Insert into t (r, time) values (rand(), now());
www.codership.com
109
Replicating over SSL/TLS
SSL / TLS
www.codership.com
111
SSL or VPN
www.codership.com
112
Using UDP Multicast
UDP Multicast
www.codership.com
114
Galera Project
Galera Project
● Galera Cluster for MySQL
● 5 years development
● based on MySQL server community edition
● Fully open source
● Active community
● ~3 releases per year
● Latest release 2.3
● Major release 3.0 in the works
● Galera Replication also used in:
● Percona XtraDB Cluster
● MariaDB Galera www.codership.com
Cluster 116
Codership
➢ Galera development
➢ Consulting and support services for Galera
➢ Technology and support partners:
➢ Percona ➢ SkySQL
➢ FromDual ➢ Monty Program
➢ Capside ➢ Severalnines
We are hiring!!!
R&D and Q/A positions open
www.codership.com
118
Questions?