SlideShare una empresa de Scribd logo
1 de 127
Descargar para leer sin conexión
Skalbarhet och
tillgänglighet med
MySQL-replikering
Sven Sandberg (sven.sandberg@oracle.com)
Principal Software Engineer, MySQL Replication Core Team
(För tillfället föräldraledig)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`2
Safe Harbour Statement
The following is intended to outline our general product direction. It is
intended for information purposes only, and may not be incorporated into any
contract.
It is not a commitment to deliver any material, code, or functionality, and
should not be relied upon in making purchasing decisions. The development,
release, and timing of any features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`3
Overview
MySQL Replication
 Design
 Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`4
Overview
MySQL Replication
 Design
 Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`5
Industry Leaders Rely On MySQL
Replication  Design  Setting Up
Cloud
OEM & ISVsWeb & Enterprise
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`6
Replication: Copy Changes Master → Slave
 MySQL Master Server
– Changes data
– Sends changes to slave
 MySQL Slave Server
– Receives changes from master
– Applies received changes to database
M S
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`7
Replication: Copy Changes Master → Slave
M M/S S
S
S
S
M
S
M
M
Server can be master, slave or both
Master can have multiple slaves
Slave can only have one master
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`8
Replication: Copy Changes Master → Slave
M/S
S
M
M
Circular replication is also possible
You can simulate multiple
masters by time-sharing
M/S
M/S
M/S
M/S
M/S
S
M
M
Switch
every 5 sec
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`9
Why Replication? – Performance
 Read scale-out
M S
write clients read clients
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`10
Why Replication? – Performance
 Read scale-out
M S
write clients read clients
More
reads?
More
slaves!
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`11
Why Replication? – Performance
 Read scale-out
M S
S
S
S
M
write clients read clients
read clients
write clients
More
reads?
More
slaves!
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`12
Why Replication? – Redundancy
 If master crashes, promote slave to master
C
B
A
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`13
Why Replication? – Redundancy
 If master crashes, promote slave to master
C
B
A
Replication  Design  Setting Up
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`14
Why Replication? – Redundancy
 If master crashes, promote slave to master
C
B
A
B is the
new master
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`15
Why Replication? – Long-distance Data
Distribution
CB
BAAC
Image from
www.ginkgomaps.com
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`16
Replication  Design  Setting Up
Cool!
So, give me a 7 min
intro to replication.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`17
Overview
MySQL Replication
 Design
 Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`18
All Changes Written to Binary Log
binary log
Client
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`19
All Changes Written to Binary Log
binary log
Client
create table t (a int);
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`20
All Changes Written to Binary Log
create...
binary log
Client
Table t
create table t (a int);
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`21
All Changes Written to Binary Log
create...
binary log
Client
Table t
create table t (a int);
insert into t values (1);
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`22
All Changes Written to Binary Log
create...
insert...
binary log
Client
Table t
1
create table t (a int);
insert into t values (1);
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`23
Slave Initiates Replication
B
binary log
A
binary log
Client
Replication  Design  Setting Up
1. Slave sends
request to start replication
to master
2. Master sends
stream of replication data
to slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`24
create...
Binary Log Sent to Slave, Re-executed
Replication  Design  Setting Up
B
binary log
A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`25
create...
Binary Log Sent to Slave, Re-executed
Table t
Replication  Design  Setting Up
B
binary log
create...
A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`26
create...
Binary Log Sent to Slave, Re-executed
Table t Table t
Replication  Design  Setting Up
create...
B
binary log
create...
A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`27
create...
insert...
Binary Log Sent to Slave, Re-executed
Table t Table t
Replication  Design  Setting Up
create...
B
binary log
create...
A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`28
create...
insert...
Binary Log Sent to Slave, Re-executed
Table t
1
Table t
Replication  Design  Setting Up
create...
B
binary log
create...
insert...A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`29
create...
insert...
Binary Log Sent to Slave, Re-executed
Table t
1
Table t
1
Replication  Design  Setting Up
create...
insert...B
binary log
create...
insert...A
binary log
Client
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`30
Actually, Changes Land in Slave's Relay Log
B
binary logrelay log
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`31
create...
Actually, Changes Land in Slave's Relay Log
B
binary logrelay log
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`32
create...
Actually, Changes Land in Slave's Relay Log
B
binary logrelay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`33
create...
Actually, Changes Land in Slave's Relay Log
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`34
create...
Actually, Changes Land in Slave's Relay Log
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`35
create...
insert...
Actually, Changes Land in Slave's Relay Log
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`36
create...
insert...
Actually, Changes Land in Slave's Relay Log
create...
B
binary log
create...
relay log
create...
insert...A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t
1
Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`37
create...
insert...
Actually, Changes Land in Slave's Relay Log
create...
B
binary log
create...
insert...
relay log
create...
insert...A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t
1
Table t
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`38
create...
insert...
Actually, Changes Land in Slave's Relay Log
create...
insert...B
binary log
create...
insert...
relay log
create...
insert...A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t
1
Table t
1
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`39
create...
Replication is Asynchronous
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Atomic → db and log
consistent after crash
Atomic → db and log
consistent after crash
Asynchronous Asynchronous Asynchronous
(Atomic
too)
(Atomic
too)
Replication  Design  Setting Up
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`40
Replication  Design  Setting Up
Replication
seems fantastic!
I want to try!
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`41
Overview
MySQL Replication
 Design
 Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`42
Setting Up Replication
 Master's my.cnf:
server­id=1
log­bin=master­bin
 Slave's my.cnf:
server­id=2
log­bin=slave­bin
relay­log=slave­relay­bin
log­slave­updates
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`43
Setting Up Replication
 On master: create replication user
> CREATE USER `rpl_user`@`slave_host`;
> GRANT REPLICATION SLAVE ON *.* 
    TO `rpl_user`@`slave_host` IDENTIFIED BY 'secret';
> FLUSH PRIVILEGES;
 On slave: initiate replication
> CHANGE MASTER TO
  MASTER_HOST = 'master_host', MASTER_PORT = <port>,
  MASTER_USER = 'rpl_user', MASTER_PASSWORD = 'secret';
> START SLAVE;
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`44
Replicate!
 On master: execute some SQL
> USE test_db;
> CREATE TABLE t1 (a INT);
> INSERT INTO t1 VALUES (1);
 On slave: check that it replicated:
> SELECT * FROM test_db.t1;
a
1
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`45
Check Replication Status
 On master:
> SHOW BINARY LOGS;
> SHOW BINLOG EVENTS;
Log_name File_size
master-bin.000001 426
Log_name Pos Event_type sid end_pos Info
master-bin.000001 4 Format_desc 1 120 Server ver: 5.6.6-m9-log, Binlog ver: 4
master-bin.000001 120 Query 1 217 use `test`; CREATE TABLE t1 (a INT)
master-bin.000001 217 Query 1 296 BEGIN
master-bin.000001 296 Query 1 395 use `test`; INSERT INTO t1 VALUES (1)
master-bin.000001 395 Xid 1 426 COMMIT /* xid=21 */
One binary log
so far
Five events:
One CREATE and
one INSERT
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`46
Check Replication Status
 On slave:
> SHOW SLAVE STATUSG
…
Slave_IO_Running Yes
Slave_SQL_Running Yes
…
Last_IO_Errno 0
Last_IO_Error
Last_SQL_Errno 0
Last_SQL_Error
…
Both slave threads
are running
If any thread stops
with an error,
look for error
message here
Replication  Design  Setting Up
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`47
Replication  Design  Setting Up
Next? Vote!
1. Fail-over + Crash tolerance
2. Fail-over + Q&A
3. Q&A
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`48
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`49
Crash-Tolerance
 Can happen to anyone:
– Hardware failure
– Human mistake
– Bug
– Natural disaster
 Features in MySQL 5.6:
– Reduce admin overhead
– Prevent unplanned downtime
– Prevent planned downtime
Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`50
Crash-Tolerance
 Fail-over: “back on track” faster & more automatically
– Global Transaction Identifiers
 Reduce risk for data loss: less administration → less downtime
– Semi-synchronous replication → slave has all changes from master
– Update replication metadata transactionally → safe on disk
 Performance: help slave keep up with master
– Replication metadata in table – leverage disk sync from storage engine
– Multi-threaded slave
5.5
5.6
Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`51
Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance
OK.
Tell me about
fail-over!
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`52
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`53
Fail-over
 Handle server crash with minimal disruption
 Example 1: tree
C
B
A
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`54
Fail-over
 Handle server crash with minimal disruption
 Example 1: tree
C
B
A
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`55
Fail-over
C
B
A
 Handle server crash with minimal disruption
 Example 1: tree
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`56
Fail-over
C
B
A
Make B the new master
 Handle server crash with minimal disruption
 Example 1: tree
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`57
Fail-over
CA B
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`58
Fail-over
CA B
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`59
Fail-over
CA B
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`60
Fail-over
CA B
Make A direct master of C
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`61
Fail-over
C
A
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`62
Fail-over
C
A
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`63
Fail-over
C
A
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`64
Fail-over
C
A
Make a shortcut
in the circle
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`65
Fail-over
C
A
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
 Example 4: scheduled maintenance
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`66
Fail-over
C
A
B
D
Take
out D!
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
 Example 4: scheduled maintenance
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`67
Fail-over
C
A
B
D
Maintain
D offline,
without
disrupting
service
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
 Example 4: scheduled maintenance
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`68
Fail-over
C
A
B
D
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
 Example 4: scheduled maintenance
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`69
Fail-over
 Handle server crash with minimal disruption
 Example 1: tree
 Example 2: line
 Example 3: circle
 Example 4: scheduled maintenance
 Example 5: arbitrary topology
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
A
B
C
D
E
F
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`70
Fail-over: Design
 Server assigns Global Transaction Identifier (GTID) to every
transaction:
– server_uuid:number
a61678ba­4889­4279­9e58­45ba840af334:1
– server_uuid identifies the server; globally unique
– number is incremented by 1 for each transaction on this server
 Writes GTID to binary log
 Slave preserves GTID when re-executing transaction
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`71
Fail-over: Design: New Events In Binary Log
> SHOW BINLOG EVENTS;
Log_name Pos Event_type sid end_pos Info
master-bin.000001 4 Format_desc 1 120 Server ver: 5.6.12-m9-log, Binlog ver: 4
master-bin.000001 120 Prev_gtids 1 151
master-bin.000001 151 Gtid 1 199 SET @@GTID_NEXT= '<uuid>:1'
master-bin.000001 199 Query 1 296 use `test`; CREATE TABLE t1 (a INT)
master-bin.000001 296 Gtid 1 344 SET @@GTID_NEXT= '<uuid>:2'
master-bin.000001 344 Query 1 423 BEGIN
master-bin.000001 423 Query 1 522 use `test`; INSERT INTO t1 VALUES (1)
master-bin.000001 522 Xid 1 602 COMMIT /* xid=21 */
3 new events:
1 Previous_gtids +
2 Gtid
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
file
header
trans-
action
trans-
action
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`72
Fail-over: Design: Protocol
 Master-slave protocol:
– Slave sends to master:
range of identifiers of executed transactions to master
– Master sends all other transactions to slave
(slave)
id1,trx1,
id2,trx2
(master)
id1,trx1,
id2,trx2,
id3,trx3
binlog
A 2. id3, trx3, …
1. id1…id2
binlog
B
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`73
Fail-over: Design: Protocol
 Example 1: tree
A
(crashed)(master)
A
id1,trx1,
id2,trx2,
id3,trx3
binlog
(slave)
C
id1,trx1
binlog
(slave)
id1,trx1,
id2,trx2B
binlog
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`74
Fail-over: Design: Protocol
 Example 1: tree
A
(crashed)(master)
A
id1,trx1,
id2,trx2,
id3,trx3
binlog
(slave)
C
id1,trx1
binlog
(slave)
id1,trx1,
id2,trx2B
binlog
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`75
Fail-over: Design: Protocol
 Example 1: tree
(slave)
C
id1,trx1
binlog
(slave)
id1,trx1,
id2,trx2B
binlog
A
(crashed)(crashed)
A
id1,trx1,
id2,trx2,
id3,trx3
binlog id1
id2, trx2,...
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`76
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
B
binlog
A
binlog
C
binlog
client client
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`77
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
id1,trx1
B
binlog
A
binlog
C
binlog
client client trx1
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`78
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
id1,trx1,
id2,trx2B
binlog
id2,trx2
A
binlog
C
binlog
client clienttrx2 trx1
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`79
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
id1,trx1,
id2,trx2,
id3,trx3
B
binlog
id2,trx2
A
binlog
C
binlog
client clienttrx2 trx1, trx3
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`80
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
id1,trx1,
id2,trx2,
id3,trx3
B
binlog
id2,trx2
A
binlog
C
binlog
client clienttrx2 trx1, trx3
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`81
Fail-over: Design: Protocol
 Example 1: tree
 Example 2: circle
id1,trx1,
id2,trx2,
id3,trx3
B
binlog
id2,trx2
A
binlog
C
binlog
client clienttrx2 trx1, trx3
id2
id1,trx1,id3,trx3,...
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`82
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Wow!
Show me how to
configure for
fail-over!
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`83
Fail-over: Set Up
 Prerequisites:
– Configure replication as usual
– Use transactional storage engine for all tables (InnoDB)
– Don't use CREATE TABLE … SELECT
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`84
Fail-over: Set Up
 Prepare the server for fail-over
1. Sync and stop all servers
2. Add to every my.cnf:
gtid­mode=on
enforce­gtid­consistency=on
log­bin
log­slave­updates
3. Start all servers
4. Create replication user on every server that may become master
5. Execute:
> CHANGE MASTER TO MASTER_AUTO_POSITION = 1
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`85
Fail-over: Perform
 Perform fail-over
On each slave:
> CHANGE MASTER TO MASTER_HOST = '<host>',
                   MASTER_PORT = <port number>,
                   MASTER_USER = '<user name>'
                   MASTER_PASSWORD = 'secret';
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Credentials on
new master
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`86
Fail-over: Perform
 Perform fail-over
C
B
A
CHANGE MASTER TO
MASTER_HOST = 'B',
MASTER_PORT = <B's port>,
MASTER_USER = '<user name>'
MASTER_PASSWORD = 'secret';
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`87
Fail-over: Perform
 Perform fail-over
CHANGE MASTER TO
MASTER_HOST = 'C',
MASTER_PORT = <C's port>,
MASTER_USER = '<user name>'
MASTER_PASSWORD = 'secret';
C
A
B
D
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`88
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
I love GTIDs!
Can fail-over be
automated?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`89
Fail-over: Utilities
 Mysqlrpladmin
– Promote one slave to master
– mysqlrpladmin switchover
  ­­master='user[:pass]@host[:port][:sock]'
  ­­discover­slaves­login='user[:pass]'
  ­­new­master='user[:pass]@host[:port][:sock]'
– Many other admin tasks
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`90
Fail-over: Utilities
 Mysqlfailover
– Monitor master
– If master goes away, do automatic fail-over
– mysqlfailover
  ­­master='user[:password]@host[:port[:socket]]'
  ­­discover­slaves­login='user:password'
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`91
Fail-over: Utilities
 Video tutorial
– dev.mysql.com/tech­resources/articles/mysql­
replication­utilities.html 
 Blog
– drcharlesbell.blogspot.co.uk/2012/04/mysql­
utilities­and­global­transaction.html 
 Doc
– dev.mysql.com/doc/workbench/en/mysqlfailover.html
– dev.mysql.com/doc/workbench/en/mysqlrpladmin.htm 
 Download
– www.mysql.com/downloads/workbench/
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`92
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Now I can
do fail-over!
But how do I avoid
losing data after
a crash?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`93
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`94
Overview - less manual work
- reduce downtime
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`95
Overview - less manual work
- reduce downtime
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
a.k.a. “slave has all
changes from master”
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`96
Asynchronous vs Semi-sync Replication
 By default, replication is asynchronous
– Master does not wait for slave
– Fast
– ACK to app before slave receives change → changes lost if master dies
 New in MySQL 5.5: semi-synchronous replication plugin
– Master acks to app
only after changes are in slave's relay log
– Master has to wait
– Less risk for lost updates
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`97
create...
Replication is Asynchronous
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`98
create...
Replication is Asynchronous
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Atomic → db and log
consistent after crash
Atomic → db and log
consistent after crash
Asynchronous Asynchronous Asynchronous
(Atomic
too)
(Atomic
too)
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Network
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`99
create...
Semi-synchronous Replication
create...
B
binary log
create...
relay log
create...
A
binary log
Client
Dump
thread
IO
thread
SQL
thread
Table t Table t
Asynchronous
Network
Semi-synchronous replication:
statement is in slave's relay log
before client ack
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`100
Semi-synchronous Replication: Set Up
 Consists of two plugins: master plugin, slave plugin
 Installation: read the manual :-)
– http://dev.mysql.com/doc/refman/5.6/en/
replication­semisync­installation.html
 After installation:
– On master:
SET GLOBAL rpl_semi_sync_master_enabled = {0|1};
– On slave:
SET GLOBAL rpl_semi_sync_slave_enabled = {0|1};
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`101
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
So semi-sync
ensures slave has all
changes before my app
gets notified.
Anything else that helps
consistency after
a crash?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`102
Overview
Meta-data
safe on disk
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`103
Replication Metadata in Tables
 Slave threads maintain their current positions
– IO thread: where to read from master
– SQL thread: where to read from relay log
 Positions stored on disk
– Before: in file
– 5.6: in table
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
insert...
B
binary log
insert...
relay log
IO
thread
SQL
thread
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`104
Replication Metadata in Tables
 File: updated after
transaction commit
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Trans-
action
Update
position
Trans-
action
Update
position
Crash
possible
 Table: updated atomically at
transaction commit
 Consistent after server crash
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`105
Replication Metadata in Tables: Set Up
 Only meaningful if using transactional storage engine
 Add to slave's my.cnf:
master­info­repository=TABLE
slave­info­repository=TABLE
default­storage­engine=InnoDB
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`106
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Nice!
Also, won't slave be more
in sync if we improve
slave performance?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`107
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Slave less behind
→ less lost updates,
short fail-over time
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`108
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Slave less behind
→ less lost updates,
short fail-over time
Fewer disk syncs
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`109
Performance: Replication Metadata In Tables
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
 File: separate disk sync
for the file
Trans-
action
Update
position
Trans-
action
Update
position
Sync
 Table: leverage sync from
storage engine
 (even better: group commit)
 Again, use transactional engine
Sync Sync
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`110
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Ahh, so
transactional meta-data
is double-good!
How else can I improve
slave performance?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`111
Overview
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`112
Performance: Parallel Slave Threads
B
binary logrelay log
A
binary log
Client
Client
Parallel writer
threads on master
Writes are serialized
in binary log
Single applier
on slave →
Can become
bottleneck
Client
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`113
Performance: Parallel Slave Threads
B
binary logrelay log
A
binary log
Client
ClientClient
Coordinator
thread (reading)
Multiple worker
threads! (executing)
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`114
Performance: Parallel Slave Threads
 Parallelize by schema (database)
– Different worker threads never update same schema
– Effective if you partition data by schema
 Consistency
– Consistent within schema
– Eventually consistent between schemas
– Commit order may differ between master and slave, among slaves
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`115
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
relay log
3 worker
threads
Coordinator
thread
w1
w2
w3
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`116
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB1
w1
w2
w3
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`117
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB1
DB2
w1
w2
w3
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`118
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB1
DB2
w1
w2
w3
DB3
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`119
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB1
DB2
w1
w2
w3
DB3
Coordinator waits for w1 to finish
before feeding DB1 update to w3
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`120
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB2
w1
w2
w3
DB3
Coordinator waits for w1 to finish
before feeding DB1 update to w3
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`121
Performance: Parallel Slave Threads
 Parallelize by schema (database)
B
Trx1: DB1
Trx2: DB2
Trx3: DB3+DB1
3 worker
threads
Coordinator
thread
DB2
w1
w2
w3
DB3
Coordinator waits for w1 to finish
before feeding DB1 update to w3
DB1
relay log
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`122
Performance: Parallel Slave Threads: Set Up
 On slave:
> STOP SLAVE;
> SET SLAVE_PARALLEL_WORKERS = 4;
> START SLAVE;
Depends on number of CPUs
and number of databases.
No exact formula –
measure what's best for you!
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`123
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Thank you,
that's a lot of info!
Can you
summarize?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`124
Summary
MySQL Replication
Crash-Tolerance
 Failover
 Reduce Risk for Data Loss
– Semi-sync
– Transactional meta-data
 Performance
– Transactional meta-data
– Multi-threaded slave
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`125
Semi-sync
Global
Transaction
Identifiers
Replication
Base
Transactional
Metadata
Parallel slave
 My.cnf:
server­id=<different number for each server>
log­bin=<host>­bin
relay­log=<host>­relay­bin
log­slave­updates
master­info­repository=TABLE
slave­info­repository=TABLE
default­storage­engine=InnoDB
gtid­mode=on
enforce­gtid­consistency=on
 Client commands:
> CHANGE MASTER TO MASTER_AUTO_POSITION = 1;
> SET SLAVE_PARALLEL_WORKERS = 4;
> SET GLOBAL rpl_semi_sync_master_enabled = {0|1};
> SET GLOBAL rpl_semi_sync_slave_enabled = {0|1};
Summary
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`126
Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
Thank you!
Questions?Email: sven.sandberg@oracle.com
Blog: svenmysql.blogspot.co.uk
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |127

Más contenido relacionado

Similar a Drupal Camp Göteborg 2013: Skalbarhet och tillgänglighet med MySQL-replikering

MySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and ScalabilityMySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and ScalabilityShivji Kumar Jha
 
Using The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamLuís Soares
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document StoreTed Wennmark
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Geir Høydalsvik
 
Docker Compose Setup for MySQL InnoDB Cluster
Docker Compose Setup for MySQL InnoDB ClusterDocker Compose Setup for MySQL InnoDB Cluster
Docker Compose Setup for MySQL InnoDB ClusterBalasubramanian Kandasamy
 
How Oracle Single/Multitenant will change a DBA's life
How Oracle Single/Multitenant will change a DBA's lifeHow Oracle Single/Multitenant will change a DBA's life
How Oracle Single/Multitenant will change a DBA's lifeGuatemala User Group
 
Replication Whats New in Mysql 8
Replication Whats New in Mysql 8Replication Whats New in Mysql 8
Replication Whats New in Mysql 8Luís Soares
 
2 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v12 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v1Ivan Tu
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8Frederic Descamps
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...GeneXus
 
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!Frederic Descamps
 
MySQL 5.7 Replication News
MySQL 5.7 Replication News MySQL 5.7 Replication News
MySQL 5.7 Replication News Ted Wennmark
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012sqlhjalp
 
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Bram Adams
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Similar a Drupal Camp Göteborg 2013: Skalbarhet och tillgänglighet med MySQL-replikering (20)

MySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and ScalabilityMySQL Developer Day conference: MySQL Replication and Scalability
MySQL Developer Day conference: MySQL Replication and Scalability
 
Using The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change Stream
 
MySQL User Camp: GTIDs
MySQL User Camp: GTIDsMySQL User Camp: GTIDs
MySQL User Camp: GTIDs
 
MySQL Replication
MySQL ReplicationMySQL Replication
MySQL Replication
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
 
Docker Compose Setup for MySQL InnoDB Cluster
Docker Compose Setup for MySQL InnoDB ClusterDocker Compose Setup for MySQL InnoDB Cluster
Docker Compose Setup for MySQL InnoDB Cluster
 
Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
 
How Oracle Single/Multitenant will change a DBA's life
How Oracle Single/Multitenant will change a DBA's lifeHow Oracle Single/Multitenant will change a DBA's life
How Oracle Single/Multitenant will change a DBA's life
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
 
Replication Whats New in Mysql 8
Replication Whats New in Mysql 8Replication Whats New in Mysql 8
Replication Whats New in Mysql 8
 
2 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v12 ivan ma-mysql複製的演進和應用-twn- v1
2 ivan ma-mysql複製的演進和應用-twn- v1
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
 
Oracle 12 Upgrade
Oracle 12 UpgradeOracle 12 Upgrade
Oracle 12 Upgrade
 
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
 
MySQL 5.7 Replication News
MySQL 5.7 Replication News MySQL 5.7 Replication News
MySQL 5.7 Replication News
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012
 
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Drupal Camp Göteborg 2013: Skalbarhet och tillgänglighet med MySQL-replikering

  • 1. Skalbarhet och tillgänglighet med MySQL-replikering Sven Sandberg (sven.sandberg@oracle.com) Principal Software Engineer, MySQL Replication Core Team (För tillfället föräldraledig)
  • 2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`2 Safe Harbour Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`3 Overview MySQL Replication  Design  Setting Up
  • 4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`4 Overview MySQL Replication  Design  Setting Up
  • 5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`5 Industry Leaders Rely On MySQL Replication  Design  Setting Up Cloud OEM & ISVsWeb & Enterprise
  • 6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`6 Replication: Copy Changes Master → Slave  MySQL Master Server – Changes data – Sends changes to slave  MySQL Slave Server – Receives changes from master – Applies received changes to database M S Replication  Design  Setting Up
  • 7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`7 Replication: Copy Changes Master → Slave M M/S S S S S M S M M Server can be master, slave or both Master can have multiple slaves Slave can only have one master Replication  Design  Setting Up
  • 8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`8 Replication: Copy Changes Master → Slave M/S S M M Circular replication is also possible You can simulate multiple masters by time-sharing M/S M/S M/S M/S M/S S M M Switch every 5 sec Replication  Design  Setting Up
  • 9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`9 Why Replication? – Performance  Read scale-out M S write clients read clients Replication  Design  Setting Up
  • 10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`10 Why Replication? – Performance  Read scale-out M S write clients read clients More reads? More slaves! Replication  Design  Setting Up
  • 11. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`11 Why Replication? – Performance  Read scale-out M S S S S M write clients read clients read clients write clients More reads? More slaves! Replication  Design  Setting Up
  • 12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`12 Why Replication? – Redundancy  If master crashes, promote slave to master C B A Replication  Design  Setting Up
  • 13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`13 Why Replication? – Redundancy  If master crashes, promote slave to master C B A Replication  Design  Setting Up Crash
  • 14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`14 Why Replication? – Redundancy  If master crashes, promote slave to master C B A B is the new master Replication  Design  Setting Up
  • 15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`15 Why Replication? – Long-distance Data Distribution CB BAAC Image from www.ginkgomaps.com Replication  Design  Setting Up
  • 16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`16 Replication  Design  Setting Up Cool! So, give me a 7 min intro to replication.
  • 17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`17 Overview MySQL Replication  Design  Setting Up
  • 18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`18 All Changes Written to Binary Log binary log Client Replication  Design  Setting Up
  • 19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`19 All Changes Written to Binary Log binary log Client create table t (a int); Replication  Design  Setting Up
  • 20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`20 All Changes Written to Binary Log create... binary log Client Table t create table t (a int); Replication  Design  Setting Up
  • 21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`21 All Changes Written to Binary Log create... binary log Client Table t create table t (a int); insert into t values (1); Replication  Design  Setting Up
  • 22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`22 All Changes Written to Binary Log create... insert... binary log Client Table t 1 create table t (a int); insert into t values (1); Replication  Design  Setting Up
  • 23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`23 Slave Initiates Replication B binary log A binary log Client Replication  Design  Setting Up 1. Slave sends request to start replication to master 2. Master sends stream of replication data to slave
  • 24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`24 create... Binary Log Sent to Slave, Re-executed Replication  Design  Setting Up B binary log A binary log Client
  • 25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`25 create... Binary Log Sent to Slave, Re-executed Table t Replication  Design  Setting Up B binary log create... A binary log Client
  • 26. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`26 create... Binary Log Sent to Slave, Re-executed Table t Table t Replication  Design  Setting Up create... B binary log create... A binary log Client
  • 27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`27 create... insert... Binary Log Sent to Slave, Re-executed Table t Table t Replication  Design  Setting Up create... B binary log create... A binary log Client
  • 28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`28 create... insert... Binary Log Sent to Slave, Re-executed Table t 1 Table t Replication  Design  Setting Up create... B binary log create... insert...A binary log Client
  • 29. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`29 create... insert... Binary Log Sent to Slave, Re-executed Table t 1 Table t 1 Replication  Design  Setting Up create... insert...B binary log create... insert...A binary log Client
  • 30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`30 Actually, Changes Land in Slave's Relay Log B binary logrelay log A binary log Client Dump thread IO thread SQL thread Replication  Design  Setting Up Network
  • 31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`31 create... Actually, Changes Land in Slave's Relay Log B binary logrelay log A binary log Client Dump thread IO thread SQL thread Replication  Design  Setting Up Network
  • 32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`32 create... Actually, Changes Land in Slave's Relay Log B binary logrelay log create... A binary log Client Dump thread IO thread SQL thread Table t Replication  Design  Setting Up Network
  • 33. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`33 create... Actually, Changes Land in Slave's Relay Log B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Replication  Design  Setting Up Network
  • 34. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`34 create... Actually, Changes Land in Slave's Relay Log create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Replication  Design  Setting Up Network
  • 35. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`35 create... insert... Actually, Changes Land in Slave's Relay Log create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Replication  Design  Setting Up Network
  • 36. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`36 create... insert... Actually, Changes Land in Slave's Relay Log create... B binary log create... relay log create... insert...A binary log Client Dump thread IO thread SQL thread Table t 1 Table t Replication  Design  Setting Up Network
  • 37. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`37 create... insert... Actually, Changes Land in Slave's Relay Log create... B binary log create... insert... relay log create... insert...A binary log Client Dump thread IO thread SQL thread Table t 1 Table t Replication  Design  Setting Up Network
  • 38. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`38 create... insert... Actually, Changes Land in Slave's Relay Log create... insert...B binary log create... insert... relay log create... insert...A binary log Client Dump thread IO thread SQL thread Table t 1 Table t 1 Replication  Design  Setting Up Network
  • 39. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`39 create... Replication is Asynchronous create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Atomic → db and log consistent after crash Atomic → db and log consistent after crash Asynchronous Asynchronous Asynchronous (Atomic too) (Atomic too) Replication  Design  Setting Up Network
  • 40. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`40 Replication  Design  Setting Up Replication seems fantastic! I want to try!
  • 41. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`41 Overview MySQL Replication  Design  Setting Up
  • 42. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`42 Setting Up Replication  Master's my.cnf: server­id=1 log­bin=master­bin  Slave's my.cnf: server­id=2 log­bin=slave­bin relay­log=slave­relay­bin log­slave­updates Replication  Design  Setting Up
  • 43. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`43 Setting Up Replication  On master: create replication user > CREATE USER `rpl_user`@`slave_host`; > GRANT REPLICATION SLAVE ON *.*      TO `rpl_user`@`slave_host` IDENTIFIED BY 'secret'; > FLUSH PRIVILEGES;  On slave: initiate replication > CHANGE MASTER TO   MASTER_HOST = 'master_host', MASTER_PORT = <port>,   MASTER_USER = 'rpl_user', MASTER_PASSWORD = 'secret'; > START SLAVE; Replication  Design  Setting Up
  • 44. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`44 Replicate!  On master: execute some SQL > USE test_db; > CREATE TABLE t1 (a INT); > INSERT INTO t1 VALUES (1);  On slave: check that it replicated: > SELECT * FROM test_db.t1; a 1 Replication  Design  Setting Up
  • 45. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`45 Check Replication Status  On master: > SHOW BINARY LOGS; > SHOW BINLOG EVENTS; Log_name File_size master-bin.000001 426 Log_name Pos Event_type sid end_pos Info master-bin.000001 4 Format_desc 1 120 Server ver: 5.6.6-m9-log, Binlog ver: 4 master-bin.000001 120 Query 1 217 use `test`; CREATE TABLE t1 (a INT) master-bin.000001 217 Query 1 296 BEGIN master-bin.000001 296 Query 1 395 use `test`; INSERT INTO t1 VALUES (1) master-bin.000001 395 Xid 1 426 COMMIT /* xid=21 */ One binary log so far Five events: One CREATE and one INSERT Replication  Design  Setting Up
  • 46. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`46 Check Replication Status  On slave: > SHOW SLAVE STATUSG … Slave_IO_Running Yes Slave_SQL_Running Yes … Last_IO_Errno 0 Last_IO_Error Last_SQL_Errno 0 Last_SQL_Error … Both slave threads are running If any thread stops with an error, look for error message here Replication  Design  Setting Up
  • 47. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`47 Replication  Design  Setting Up Next? Vote! 1. Fail-over + Crash tolerance 2. Fail-over + Q&A 3. Q&A
  • 48. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`48 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 49. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`49 Crash-Tolerance  Can happen to anyone: – Hardware failure – Human mistake – Bug – Natural disaster  Features in MySQL 5.6: – Reduce admin overhead – Prevent unplanned downtime – Prevent planned downtime Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 50. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`50 Crash-Tolerance  Fail-over: “back on track” faster & more automatically – Global Transaction Identifiers  Reduce risk for data loss: less administration → less downtime – Semi-synchronous replication → slave has all changes from master – Update replication metadata transactionally → safe on disk  Performance: help slave keep up with master – Replication metadata in table – leverage disk sync from storage engine – Multi-threaded slave 5.5 5.6 Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 51. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`51 Crash-Tolerance  Fail-over  Reduce Risk for Data Loss  Performance OK. Tell me about fail-over!
  • 52. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`52 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 53. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`53 Fail-over  Handle server crash with minimal disruption  Example 1: tree C B A Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 54. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`54 Fail-over  Handle server crash with minimal disruption  Example 1: tree C B A Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Crash
  • 55. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`55 Fail-over C B A  Handle server crash with minimal disruption  Example 1: tree Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 56. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`56 Fail-over C B A Make B the new master  Handle server crash with minimal disruption  Example 1: tree Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 57. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`57 Fail-over CA B  Handle server crash with minimal disruption  Example 1: tree  Example 2: line Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 58. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`58 Fail-over CA B  Handle server crash with minimal disruption  Example 1: tree  Example 2: line Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Crash
  • 59. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`59 Fail-over CA B  Handle server crash with minimal disruption  Example 1: tree  Example 2: line Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 60. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`60 Fail-over CA B Make A direct master of C  Handle server crash with minimal disruption  Example 1: tree  Example 2: line Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 61. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`61 Fail-over C A B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 62. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`62 Fail-over C A B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Crash
  • 63. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`63 Fail-over C A B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 64. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`64 Fail-over C A Make a shortcut in the circle B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 65. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`65 Fail-over C A B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle  Example 4: scheduled maintenance Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 66. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`66 Fail-over C A B D Take out D!  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle  Example 4: scheduled maintenance Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 67. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`67 Fail-over C A B D Maintain D offline, without disrupting service  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle  Example 4: scheduled maintenance Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 68. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`68 Fail-over C A B D  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle  Example 4: scheduled maintenance Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 69. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`69 Fail-over  Handle server crash with minimal disruption  Example 1: tree  Example 2: line  Example 3: circle  Example 4: scheduled maintenance  Example 5: arbitrary topology Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance A B C D E F
  • 70. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`70 Fail-over: Design  Server assigns Global Transaction Identifier (GTID) to every transaction: – server_uuid:number a61678ba­4889­4279­9e58­45ba840af334:1 – server_uuid identifies the server; globally unique – number is incremented by 1 for each transaction on this server  Writes GTID to binary log  Slave preserves GTID when re-executing transaction Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 71. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`71 Fail-over: Design: New Events In Binary Log > SHOW BINLOG EVENTS; Log_name Pos Event_type sid end_pos Info master-bin.000001 4 Format_desc 1 120 Server ver: 5.6.12-m9-log, Binlog ver: 4 master-bin.000001 120 Prev_gtids 1 151 master-bin.000001 151 Gtid 1 199 SET @@GTID_NEXT= '<uuid>:1' master-bin.000001 199 Query 1 296 use `test`; CREATE TABLE t1 (a INT) master-bin.000001 296 Gtid 1 344 SET @@GTID_NEXT= '<uuid>:2' master-bin.000001 344 Query 1 423 BEGIN master-bin.000001 423 Query 1 522 use `test`; INSERT INTO t1 VALUES (1) master-bin.000001 522 Xid 1 602 COMMIT /* xid=21 */ 3 new events: 1 Previous_gtids + 2 Gtid Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance file header trans- action trans- action
  • 72. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`72 Fail-over: Design: Protocol  Master-slave protocol: – Slave sends to master: range of identifiers of executed transactions to master – Master sends all other transactions to slave (slave) id1,trx1, id2,trx2 (master) id1,trx1, id2,trx2, id3,trx3 binlog A 2. id3, trx3, … 1. id1…id2 binlog B Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 73. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`73 Fail-over: Design: Protocol  Example 1: tree A (crashed)(master) A id1,trx1, id2,trx2, id3,trx3 binlog (slave) C id1,trx1 binlog (slave) id1,trx1, id2,trx2B binlog Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 74. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`74 Fail-over: Design: Protocol  Example 1: tree A (crashed)(master) A id1,trx1, id2,trx2, id3,trx3 binlog (slave) C id1,trx1 binlog (slave) id1,trx1, id2,trx2B binlog Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Crash
  • 75. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`75 Fail-over: Design: Protocol  Example 1: tree (slave) C id1,trx1 binlog (slave) id1,trx1, id2,trx2B binlog A (crashed)(crashed) A id1,trx1, id2,trx2, id3,trx3 binlog id1 id2, trx2,... Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 76. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`76 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle B binlog A binlog C binlog client client Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 77. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`77 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle id1,trx1 B binlog A binlog C binlog client client trx1 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 78. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`78 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle id1,trx1, id2,trx2B binlog id2,trx2 A binlog C binlog client clienttrx2 trx1 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 79. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`79 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle id1,trx1, id2,trx2, id3,trx3 B binlog id2,trx2 A binlog C binlog client clienttrx2 trx1, trx3 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 80. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`80 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle id1,trx1, id2,trx2, id3,trx3 B binlog id2,trx2 A binlog C binlog client clienttrx2 trx1, trx3 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Crash
  • 81. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`81 Fail-over: Design: Protocol  Example 1: tree  Example 2: circle id1,trx1, id2,trx2, id3,trx3 B binlog id2,trx2 A binlog C binlog client clienttrx2 trx1, trx3 id2 id1,trx1,id3,trx3,... Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 82. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`82 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Wow! Show me how to configure for fail-over!
  • 83. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`83 Fail-over: Set Up  Prerequisites: – Configure replication as usual – Use transactional storage engine for all tables (InnoDB) – Don't use CREATE TABLE … SELECT Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 84. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`84 Fail-over: Set Up  Prepare the server for fail-over 1. Sync and stop all servers 2. Add to every my.cnf: gtid­mode=on enforce­gtid­consistency=on log­bin log­slave­updates 3. Start all servers 4. Create replication user on every server that may become master 5. Execute: > CHANGE MASTER TO MASTER_AUTO_POSITION = 1 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 85. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`85 Fail-over: Perform  Perform fail-over On each slave: > CHANGE MASTER TO MASTER_HOST = '<host>',                    MASTER_PORT = <port number>,                    MASTER_USER = '<user name>'                    MASTER_PASSWORD = 'secret'; Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Credentials on new master
  • 86. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`86 Fail-over: Perform  Perform fail-over C B A CHANGE MASTER TO MASTER_HOST = 'B', MASTER_PORT = <B's port>, MASTER_USER = '<user name>' MASTER_PASSWORD = 'secret'; Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 87. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`87 Fail-over: Perform  Perform fail-over CHANGE MASTER TO MASTER_HOST = 'C', MASTER_PORT = <C's port>, MASTER_USER = '<user name>' MASTER_PASSWORD = 'secret'; C A B D Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 88. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`88 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance I love GTIDs! Can fail-over be automated?
  • 89. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`89 Fail-over: Utilities  Mysqlrpladmin – Promote one slave to master – mysqlrpladmin switchover   ­­master='user[:pass]@host[:port][:sock]'   ­­discover­slaves­login='user[:pass]'   ­­new­master='user[:pass]@host[:port][:sock]' – Many other admin tasks Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 90. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`90 Fail-over: Utilities  Mysqlfailover – Monitor master – If master goes away, do automatic fail-over – mysqlfailover   ­­master='user[:password]@host[:port[:socket]]'   ­­discover­slaves­login='user:password' Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 91. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`91 Fail-over: Utilities  Video tutorial – dev.mysql.com/tech­resources/articles/mysql­ replication­utilities.html   Blog – drcharlesbell.blogspot.co.uk/2012/04/mysql­ utilities­and­global­transaction.html   Doc – dev.mysql.com/doc/workbench/en/mysqlfailover.html – dev.mysql.com/doc/workbench/en/mysqlrpladmin.htm   Download – www.mysql.com/downloads/workbench/ Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 92. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`92 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Now I can do fail-over! But how do I avoid losing data after a crash?
  • 93. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`93 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 94. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`94 Overview - less manual work - reduce downtime MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 95. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`95 Overview - less manual work - reduce downtime MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave a.k.a. “slave has all changes from master”
  • 96. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`96 Asynchronous vs Semi-sync Replication  By default, replication is asynchronous – Master does not wait for slave – Fast – ACK to app before slave receives change → changes lost if master dies  New in MySQL 5.5: semi-synchronous replication plugin – Master acks to app only after changes are in slave's relay log – Master has to wait – Less risk for lost updates Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 97. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`97 create... Replication is Asynchronous create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Network
  • 98. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`98 create... Replication is Asynchronous create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Atomic → db and log consistent after crash Atomic → db and log consistent after crash Asynchronous Asynchronous Asynchronous (Atomic too) (Atomic too) Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Network
  • 99. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`99 create... Semi-synchronous Replication create... B binary log create... relay log create... A binary log Client Dump thread IO thread SQL thread Table t Table t Asynchronous Network Semi-synchronous replication: statement is in slave's relay log before client ack Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 100. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`100 Semi-synchronous Replication: Set Up  Consists of two plugins: master plugin, slave plugin  Installation: read the manual :-) – http://dev.mysql.com/doc/refman/5.6/en/ replication­semisync­installation.html  After installation: – On master: SET GLOBAL rpl_semi_sync_master_enabled = {0|1}; – On slave: SET GLOBAL rpl_semi_sync_slave_enabled = {0|1}; Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 101. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`101 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance So semi-sync ensures slave has all changes before my app gets notified. Anything else that helps consistency after a crash?
  • 102. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`102 Overview Meta-data safe on disk MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 103. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`103 Replication Metadata in Tables  Slave threads maintain their current positions – IO thread: where to read from master – SQL thread: where to read from relay log  Positions stored on disk – Before: in file – 5.6: in table Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance insert... B binary log insert... relay log IO thread SQL thread
  • 104. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`104 Replication Metadata in Tables  File: updated after transaction commit Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Trans- action Update position Trans- action Update position Crash possible  Table: updated atomically at transaction commit  Consistent after server crash
  • 105. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`105 Replication Metadata in Tables: Set Up  Only meaningful if using transactional storage engine  Add to slave's my.cnf: master­info­repository=TABLE slave­info­repository=TABLE default­storage­engine=InnoDB Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 106. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`106 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Nice! Also, won't slave be more in sync if we improve slave performance?
  • 107. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`107 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave Slave less behind → less lost updates, short fail-over time
  • 108. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`108 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave Slave less behind → less lost updates, short fail-over time Fewer disk syncs
  • 109. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`109 Performance: Replication Metadata In Tables Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance  File: separate disk sync for the file Trans- action Update position Trans- action Update position Sync  Table: leverage sync from storage engine  (even better: group commit)  Again, use transactional engine Sync Sync
  • 110. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`110 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Ahh, so transactional meta-data is double-good! How else can I improve slave performance?
  • 111. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`111 Overview MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 112. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`112 Performance: Parallel Slave Threads B binary logrelay log A binary log Client Client Parallel writer threads on master Writes are serialized in binary log Single applier on slave → Can become bottleneck Client Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 113. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`113 Performance: Parallel Slave Threads B binary logrelay log A binary log Client ClientClient Coordinator thread (reading) Multiple worker threads! (executing) Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 114. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`114 Performance: Parallel Slave Threads  Parallelize by schema (database) – Different worker threads never update same schema – Effective if you partition data by schema  Consistency – Consistent within schema – Eventually consistent between schemas – Commit order may differ between master and slave, among slaves Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 115. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`115 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 relay log 3 worker threads Coordinator thread w1 w2 w3 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 116. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`116 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB1 w1 w2 w3 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 117. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`117 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB1 DB2 w1 w2 w3 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 118. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`118 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB1 DB2 w1 w2 w3 DB3 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 119. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`119 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB1 DB2 w1 w2 w3 DB3 Coordinator waits for w1 to finish before feeding DB1 update to w3 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 120. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`120 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB2 w1 w2 w3 DB3 Coordinator waits for w1 to finish before feeding DB1 update to w3 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 121. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`121 Performance: Parallel Slave Threads  Parallelize by schema (database) B Trx1: DB1 Trx2: DB2 Trx3: DB3+DB1 3 worker threads Coordinator thread DB2 w1 w2 w3 DB3 Coordinator waits for w1 to finish before feeding DB1 update to w3 DB1 relay log Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 122. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`122 Performance: Parallel Slave Threads: Set Up  On slave: > STOP SLAVE; > SET SLAVE_PARALLEL_WORKERS = 4; > START SLAVE; Depends on number of CPUs and number of databases. No exact formula – measure what's best for you! Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance
  • 123. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`123 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Thank you, that's a lot of info! Can you summarize?
  • 124. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`124 Summary MySQL Replication Crash-Tolerance  Failover  Reduce Risk for Data Loss – Semi-sync – Transactional meta-data  Performance – Transactional meta-data – Multi-threaded slave
  • 125. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`125 Semi-sync Global Transaction Identifiers Replication Base Transactional Metadata Parallel slave  My.cnf: server­id=<different number for each server> log­bin=<host>­bin relay­log=<host>­relay­bin log­slave­updates master­info­repository=TABLE slave­info­repository=TABLE default­storage­engine=InnoDB gtid­mode=on enforce­gtid­consistency=on  Client commands: > CHANGE MASTER TO MASTER_AUTO_POSITION = 1; > SET SLAVE_PARALLEL_WORKERS = 4; > SET GLOBAL rpl_semi_sync_master_enabled = {0|1}; > SET GLOBAL rpl_semi_sync_slave_enabled = {0|1}; Summary
  • 126. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |`126 Crash-tolerance  Fail-over  Reduce Risk for Data Loss  Performance Thank you! Questions?Email: sven.sandberg@oracle.com Blog: svenmysql.blogspot.co.uk
  • 127. Copyright © 2012, Oracle and/or its affiliates. All rights reserved. |127