MariaDB Galera Cluster
MariaDB Galera Cluster
Seppo Jaakola
Codership
➢ Seppo Jaakola
➢ One of the Founders of Codership
Galera Cluster
➢ Galera releases since 2009
www.galeracluster.com
2
Galera Project
MySQL R&D
MariaDB
Community edition
www.galeracluster.com
3
MariaDB Galera Cluster R&D
www.galeracluster.com
4
Agenda
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Relay
www.galeracluster.com log
7
Master-Slave Async Replication
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Relay
www.galeracluster.com log
8
Master-Slave Async Replication
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Master node is trusted data
Source
And is used for recovery Relay
www.galeracluster.com log
9
Master-Slave Async Replication
If slave nodes are
not used for reading,
No immediate inconsistency
issues
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Relay
www.galeracluster.com log
10
Master-Slave Async Replication
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Relay
www.galeracluster.com log
11
Master-Slave Async Replication
read only
write
MariaDB
Slave
MariaDB
Relay
Master log
Bin
log
MariaDB
Slave
Relay
www.galeracluster.com log
12
Inconsistency for Master-Slave
read & write read & write read & write Read & write access to any node
Client can connect to any node
Replication is synchronous
Galera Replication
www.galeracluster.com
14
Multi-Master Replication
a MariaDB
www.galeracluster.com
15
Multi-Master Replication
a MariaDB
www.galeracluster.com
16
Inconsistency for Multi-Master
www.galeracluster.com
18
Inconsistency for Multi-Master
Galera Replication
www.galeracluster.com
19
Inconsistency for Multi-Master
Galera Replication
www.galeracluster.com
20
Reasons for Inconsistency
Reasons for Inconsistency
● Bad SST
● Full cluster Snapshot State Transfer is external operation
(to cluster), which happens through SST API
● Cluster picks a donor node to help the joining node to get
same state as active cluster
● 3 main variants: mysqldump, rsync and xtrabackup based
versions, (and more to come, MariaBackup)
● Improper SST leaves joining node with inconsistent
database
● Cluster misuse
● wsrep_on session and global variable, requires SUPER
privileges, tells if wsrep replication plugin should replicate
the transaction or not
● sql_log_bin session variable, skips binlogging for the
session in master node. With no binlog events, Galera has
www.galeracluster.com
23
nothing to replicate
Reasons for Inconsistency
● Replication filtering
● binlog_do* No binlogging in master node
● replicate_do* slave node does not apply incoming events
● Slave lag
● Not real inconsistency, but replication may be slow
● if reads happen from too old version of data, the
consequence for application is same as having inconsistent
database
● Bug
www.galeracluster.com
24
Consistent Reads from a Cluster
www.galeracluster.com
25
Consistent Reads from a Cluster
MariaDB MariaDB
38 39 40 41 42 43 44 45 46 47 48 49
www.galeracluster.com
26
Consistent Reads from a Cluster
www.galeracluster.com
27
Read Causality
MariaDB MariaDB
www.galeracluster.com
28
Read Causality
MariaDB MariaDB
www.galeracluster.com
29
Read Causality
MariaDB MariaDB
www.galeracluster.com
30
Read Causality
MariaDB MariaDB
www.galeracluster.com
31
Read Causality
www.galeracluster.com
32
Triggers, Stored Procedures, Events
www.galeracluster.com
33
Foreign Key Constraint
www.galeracluster.com
34
Async Replication
www.galeracluster.com
35
The Effect of Inconsistency
The Harm Done
replication
● e.g. with: --slave-skip-errors
● Note that, if replication errors are not dealt with, slaves
may become inconsistent and the inconsistency just gets
worse by the time
● Galera is very strict about inconsistency:
● Errors in DDL are neglected
● Any error in regular DML transaction replication will
cause emergency abort for the node
● Errors also in foreign key constraint validation, will cause
emergency abort www.galeracluster.com
37
Inconsistency for Multi-Master
www.galeracluster.com
38
Inconsistency for Multi-Master
Galera Replication
www.galeracluster.com
39
Inconsistency for Multi-Master
MariaDB
GRA_x_y.dat
Binlog
events
WS
Galera Replication
www.galeracluster.com
40
Could Some Errors Be Neglected?
www.galeracluster.com
41
Could Some Errors Be Neglected?
Begin
Select…
Select… reads
Select… Business logic
Update…
writes
Update…
Commit
www.galeracluster.com
42
Could Some Errors Be Neglected?
www.galeracluster.com
43
Could Some Errors Be Neglected?
www.galeracluster.com
44
About Foreign Key Constraint
www.galeracluster.com
45
Recovering from Inconsistency
How to Recover from Inconsistency
www.galeracluster.com
48
Detecting Inconsistencies
Detecting Inconsistencies up-front
www.galeracluster.com
50
Galera Consistency Checking
WS WS WS WS WS WS WS WS WS
945 946 947 948 949 950 951 952 953
Galera Replication
www.galeracluster.com
52
Galera Consistency Checking
INSERT...SELECT… /* !99997 */
WS WS WS WS WS WS WS WS WS
948 949 950 951 952 953 954 955 956
Galera Replication
www.galeracluster.com
53
Galera Consistency Checking
INSERT...SELECT… /* 99997 */
WS WS WS WS WS WS WS WS WS WS WS WS
954 955 956 957 958 959 960 961 962 963 964 965
Galera Replication
www.galeracluster.com
54
Galera Consistency Checking
WS WS WS WS WS WS WS WS WS WS WS
955 956 957 958 959 960 961 962 963 964 965
Galera Replication
www.galeracluster.com
55
Galera Consistency Checking
www.galeracluster.com
56
Optimizing Inconsistency Shutdown
Optimizing Inconsistency Shutdown
www.galeracluster.com
58
Inconsistency Shutdown
Galera Replication
www.galeracluster.com
59
Inconsistency Shutdown
t1 t1 t1
Galera Replication
www.galeracluster.com
60
Inconsistency Shutdown
Set wsrep_on=OFF
Insert into t values (8)
t1 t1 t1
Galera Replication
www.galeracluster.com
61
Inconsistency Shutdown
Set wsrep_on=ON
Delete from t;
t1 t1 t1
Del Del
8 8
www.galeracluster.com
62
Inconsistency Shutdown
Set wsrep_on=ON
Delete from t;
t1 t1 t1
Del Del
8 8
www.galeracluster.com
63
Inconsistency Shutdown
Node A, remains in
minority and changes to
Non-Primary
t1 t1 t1
www.galeracluster.com
64
Optimizing Consistency Shutdown
www.galeracluster.com
65
Inconsistency Shutdown
t1 t1 t1
8
Del Del
8 8
www.galeracluster.com
66
Consistency Voting
Node A Success
www.galeracluster.com
67
Inconsistency Shutdown
Consistency Voting
t1 t1 t1
www.galeracluster.com
68
Galera Consistency Voting Protocol
www.galeracluster.com
69
Summary
www.galeracluster.com
70
4