18
MySQL 5.6 Replication for Architects Kristian Köhntopp

MySQL Replication Topologies and Architectures

Embed Size (px)

Citation preview

MySQL 5.6 Replication for ArchitectsKristian Köhntopp

Scale Out2

Slave Server

Master Server

Client

writes

reads(through LB)

Types of Slaves

• Standard R/O Slave.

• Slave for long running queries.

• Aggregation to secondary local schema.

• Slave for ad-hoc queries.

• Slave for fulltext searches.

• Local schema mods (Table Type, Indices).

3

Multi-Level Slaves4

Slave Server

Master Server

Slave Server

Local Master Server

Heathrow Amsterdam

Multi-Level Slaves

• Intermediate Slave requires

• log_slave_updates = 1

• Loop detection: All machines require

• server_id = n

• Since 5.5: Also a machine UUID defined.

• Each machine needs their own id.

5

Replication is not HA6

Slave Server

Master Server DesignatedBackup Master

binlog.000018Offset 743271

binlog.000012Offset 393273?

Replication is not HA

• Master and Backup Master have different binlog positions.

• The distance between them is not constant

• Log into Backup, enter command.

• MySQL 5.6 ff: Global Transaction ID.

• Galera!

7

Ring Structures8

Server #1

Server #3

Server #2

Ring Structures

• A slave can have only one master.

• A master can have many slaves.

• A ring is a valid replication structure.

• log_slave_updates, server_id critical.

9

Ring Structures

• Ring structures are fragile:

• Each ring member has its own binlog position.

• Server #2 fails, binlog position is lost.

• How do you recover?

• We try to avoid replication rings.

10

Ring Structures

• Inserts into rings are complicated

• Server #1: INSERT INTO t (id, data) VALUES (NULL, 10)

• Server #2: INSERT INTO t (id, data) VALUES (NULL, 20)

• Assigned auto_increment values?

11

Ring Structures

• Workaround:

• auto_increment_increment (aii) = n

• n is ring circumference

• auto_increment_offset (aio) = o

• o is server # in ring

• Server #1 assigns 0, 3, 6, Server #2 assigns 1, 4, 7

12

Ring Structures

• Gaps exist:

• Server #1 can be already at 300, while Server #2 is still at 7

• Solves insert problem, but not concurrent UPDATES

• Change record 7 on two servers concurrently → instant disaster

13

Ring Structures

• True multimaster solutions exist.

• All of them require 2PC or make assumptions.

• 2PC, 3PC, Paxos:

• Extremely sensitive to latency.

• That means: SLOW!

14

Ring Structures

• Note:

• A ring-with-2 is not a multimaster database.

15

Proper HA16

Slave Server

Master Server Backup Master

Disk Mirroror

Shared Disk

VirtualIP Number

Mobile between Hosts

Proper HA

• Master active, Backup passive

• Hard partition of capacity, no potential for overcommit.

• Master and Backup binary identical.

• binary log position interchangeable.

• Mobile Virtual IP Number

• On failure migrate VIP, restart service.

17

Proper HA

• Shared Disk Solutions:

• NetApp or other SAN.

• Disk Mirror Solutions:

• DRBD or other disk update shipping (ZFS).

• Mobile VIP:

• heartbeat, pacemaker, Veritas, etc.

18