Galera Schema
Galera Schema
Galera Schema
with Galera
February 2, 2020
Sveta Smirnova
Sveta Smirnova
•TOI
•RSU
•pt-online-schema-change (pt-osc)
3
Introduction
4
Introduction
4
How Galera works
5
How Galera works
5
Data Updates
6
Challenges of DDL
7
Challenges of DDL
•
Adding/removal of UNIQUE keys
•
Adding/removal columns
• Changing column definition
7
Challenges of DDL
7
TOI
Total Order Isolation (TOI)
9
TOI: Illustration
• 3-nodes cluster
•
Node A
• Node B
• Node C
10
TOI: Illustration
• Initial state
Node A Node B Node C
INSERT(103) UPDATE(101) SELECT(100)
UPDATE(104) INSERT(102) INSERT(112)
ALTER(105) DELETE(108) SELECT(113)
UPDATE(109) UPDATE(114)
10
TOI: Illustration
• Queries status
Node A Node B Node C
INSERT(103) UPDATE(101) SELECT(100)
UPDATE(104) INSERT(102) INSERT(112)
ALTER(105) DELETE(108) ! SELECT(113)
UPDATE(109) UPDATE(114)
10
TOI: Illustration
• ALTER in progress
Node A Node B Node C
ALTER(105) DELETE(108) INSERT(112)
UPDATE(109) ! SELECT(113)
UPDATE(114)
10
TOI: Illustration
• ALTER finished
Node A Node B Node C
DELETE(108) INSERT(112)
UPDATE(109) SELECT(113)
UPDATE(114)
10
PROCESSLIST: DML before ALTER
DML node> select DB, COMMAND, TIME, STATE, INFO from information_schema.processlist WHERE DB=’sbtest’;
+--------+---------+------+---------------------------------------------------+-----------------------+
| DB | COMMAND | TIME | STATE | INFO |
+--------+---------+------+---------------------------------------------------+-----------------------+
| sbtest | Query | 1 | wsrep: initiating pre-commit for write set (2886) | COMMIT |
| sbtest | Query | 1 | wsrep: initiating pre-commit for write set (2888) | COMMIT |
| sbtest | Query | 1 | wsrep: initiating pre-commit for write set (2884) | COMMIT |
| sbtest | Query | 1 | updating | DELETE FROM sbtest1.. |
| sbtest | Query | 1 | wsrep: initiating pre-commit for write set (2887) | COMMIT |
| sbtest | Query | 0 | wsrep: initiating pre-commit for write set (2889) | COMMIT |
| sbtest | Query | 1 | wsrep: initiating pre-commit for write set (2885) | COMMIT |
| sbtest | Query | 1 | wsrep: pre-commit/certification passed (2883) | COMMIT |
+--------+---------+------+---------------------------------------------------+-----------------------+
8 rows in set (0.00 sec)
11
PROCESSLIST: SELECT before ALTER
SELECT node> select DB, COMMAND, TIME, STATE, INFO from information_schema.processlist
-> WHERE DB=’sbtest’;
+--------+---------+------+-------------------+---------------------------------------+
| DB | COMMAND | TIME | STATE | INFO |
+--------+---------+------+-------------------+---------------------------------------+
| sbtest | Query | 0 | statistics | SELECT pad FROM sbtest2 WHERE id=5009 |
| sbtest | Query | 0 | starting | SELECT pad FROM sbtest3 WHERE id=4951 |
| sbtest | Query | 0 | statistics | SELECT pad FROM sbtest4 WHERE id=4954 |
| sbtest | Query | 0 | System lock | SELECT pad FROM sbtest2 WHERE id=5351 |
| sbtest | Query | 0 | cleaning up | SELECT pad FROM sbtest2 WHERE id=4954 |
| sbtest | Sleep | 0 | | NULL |
| sbtest | Query | 0 | Sending to client | SELECT pad FROM sbtest1 WHERE id=4272 |
| sbtest | Query | 0 | closing tables | SELECT pad FROM sbtest4 WHERE id=4722 |
+--------+---------+------+-------------------+---------------------------------------+
8 rows in set (0.00 sec)
12
ALTER
13
PROCESSLIST: DML during ALTER
DML node> select DB, COMMAND, TIME, STATE, INFO from information_schema.processlist
-> WHERE DB in (’sbtest’,’ddltest’);
+---------+---------+------+---------------------------------------------------+----------------------+
| DB | COMMAND | TIME | STATE | |
+---------+---------+------+---------------------------------------------------+----------------------+
| sbtest | Query | 36 | wsrep: initiating pre-commit for write set (7886) | COMMIT |
| sbtest | Query | 37 | wsrep: initiating pre-commit for write set (7882) | COMMIT |
| sbtest | Query | 27 | wsrep: initiating pre-commit for write set (7887) | COMMIT |
| sbtest | Query | 27 | wsrep: initiating pre-commit for write set (7888) | COMMIT |
| sbtest | Query | 36 | wsrep: initiating pre-commit for write set (7885) | COMMIT |
| sbtest | Query | 37 | wsrep: initiating pre-commit for write set (7883) | COMMIT |
| sbtest | Query | 37 | wsrep: initiating pre-commit for write set (7884) | COMMIT |
| sbtest | Query | 10 | wsrep: initiating pre-commit for write set (7889) | COMMIT |
| ddltest | Sleep | 38 | altering table | alter table sbtest1. |
+---------+---------+------+---------------------------------------------------+----------------------+
9 rows in set (0.00 sec)
14
PROCESSLIST: SELECT during ALTER
SELECT node> select DB, COMMAND, TIME, STATE, INFO from information_schema.processlist
-> WHERE DB in (’sbtest’,’ddltest’);
+---------+---------+------+-------------------+-------------------------------------------+
| DB | COMMAND | TIME | STATE | |
+---------+---------+------+-------------------+-------------------------------------------+
| sbtest | Sleep | 0 | | NULL |
| sbtest | Sleep | 0 | | NULL |
| sbtest | Query | 0 | Sending to client | SELECT pad FROM sbtest4 WHERE id=4989 |
| sbtest | Sleep | 0 | | NULL |
| sbtest | Query | 0 | query end | SELECT pad FROM sbtest2 WHERE id=4961 |
| sbtest | Sleep | 0 | | NULL |
| sbtest | Sleep | 0 | | NULL |
| sbtest | Sleep | 0 | | NULL |
| ddltest | Sleep | 39 | altering table | alter table sbtest1 add key k1(c, k, pad) |
+---------+---------+------+-------------------+-------------------------------------------+
9 rows in set (0.14 sec)
15
TOI Advantages
16
TOI Disadvantages
17
How to Perform Upgrade with TOI
18
When to Use TOI
19
When to Use TOI
• CREATE DATABASE
•
CREATE TABLE
19
When to Use TOI
21
User Responsibility
22
RSU Workflow
23
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
How Node Internally Executes DDL in RSU Mode?
24
RSU: Locking
• Not avoidable
• Updates to all objects on the node in RSU
25
RSU Advantages
26
RSU Disadvantages
27
RSU Disadvantages
•
Otherwise DDL fails with an error
27
RSU Disadvantages
27
RSU Disadvantages
27
RSU Disadvantages
•
Affected table must be offline
• Until the schema upgrade is done on all nodes
•
Unless this is schema-compatible change
27
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
28
How to Use RSU
30
pt-online-schema-change (pt-osc)
30
pt-online-schema-change (pt-osc)
30
pt-online-schema-change (pt-osc)
30
pt-online-schema-change (pt-osc)
30
pt-online-schema-change (pt-osc)
30
pt-online-schema-change (pt-osc)
•
Renames the copy into the original table name
30
pt-osc Advantages
31
pt-osc Disadvantages
32
How to Use pt-osc
• Run pt-osc
33
Which Method to Use?
34
Which Method to Use?
34
Which Method to Use?
34
Which Method to Use?
34
Which Method to Use?
35
More information
Galera Cluster
MariaDB Galera Cluster
pt-online-schema-change
36
Thank you!
www.slideshare.net/SvetaSmirnova
twitter.com/svetsmirnova
github.com/svetasmirnova
37
DATABASE PERFORMANCE
MATTERS