127
Skalbarhet och tillgänglighet med MySQL-replikering Sven Sandberg ([email protected]) Principal Software Engineer, MySQL Replication Core Team (För tillfället föräldraledig)

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

Embed Size (px)

DESCRIPTION

Skala dina applikationsdata och leverera service utan avbrott med hjälp av MySQL-replikering! I Drupal sparas vanligen all dynamisk data i en MySQL-databas. MySQL är världens mest populära open source-databas och den används i 9 av världens 10 mest använda webbsajter. Med replikering kan databasen dupliceras till flera servrar. Facebook, PayPal, Twitter, Wikipedia, YouTube och Zappos förlitar sig på MySQL-replikering för att hantera tiotals miljoner användare tillförlitligt och för att hantera sin exponentiella tillväxt genom att skala ut på standardhårdvara. Välkommen till detta föredrag för en praktisk demonstration av MySQL-replikering, där vi går igenom hur du: - konfigurerar och kalibrerar MySQL-replikering; - skalar dina tjänster med MySQL-replikering; - skapar självläkande kluster med MySQL-replikering.

Citation preview

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

Skalbarhet och tillgänglighet med MySQL-replikering

Sven Sandberg ([email protected])Principal Software Engineer, MySQL Replication Core Team(För tillfället föräldraledig)

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

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.

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `3

OverviewMySQL Replication Design

Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `4

OverviewMySQL Replication Design

Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `5

Industry Leaders Rely On MySQLReplication Design Setting Up

CloudOEM & ISVsWeb & Enterprise

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `7

Replication: Copy Changes Master → Slave

M M/S S

S

S

S

M

SM

M

Server can be master, slave or both

Master can have multiple slaves

Slave can only have one master

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `8

Replication: Copy Changes Master → Slave

M/S

SM

M

Circular replication is also possible

You can simulate multiplemasters by time-sharing

M/S

M/S

M/S

M/S

M/S

SM

MSwitch

every 5 sec

Replication Design Setting Up

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `10

Why Replication? – Performance

Read scale-out

M S

write clients read clients

Morereads?More

slaves!

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `11

Why Replication? – Performance

Read scale-out

M SS

S

S

M

write clients read clientsread clients

write clients

Morereads?More

slaves!

Replication Design Setting Up

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

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

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

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

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

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 thenew master

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `15

Why Replication? – Long-distance Data Distribution

CB

BAAC

Image fromwww.ginkgomaps.com

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `16

Replication Design Setting Up

Cool!So, give me a 7 minintro to replication.

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `17

OverviewMySQL Replication Design

Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `18

All Changes Written to Binary Log

binary log

Client

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `19

All Changes Written to Binary Log

binary log

Clientcreate table t (a int);

Replication Design Setting Up

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `22

All Changes Written to Binary Log

create...insert...

binary log

Client

Table t1

create table t (a int);insert into t values (1);

Replication Design Setting Up

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

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 sendsrequest to start replication

to master

2. Master sendsstream of replication data

to slave

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `24

create...

Binary Log Sent to Slave, Re-executedReplication Design Setting Up

B

binary log

A

binary log

Client

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

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

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `28

create...insert...

Binary Log Sent to Slave, Re-executed

Table t1

Table t

Replication Design Setting Up

create...

B

binary log

create...insert...A

binary log

Client

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `29

create...insert...

Binary Log Sent to Slave, Re-executed

Table t1

Table t1

Replication Design Setting Up

create...insert...B

binary log

create...insert...A

binary log

Client

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

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

ClientDumpthread

IOthread

SQLthread

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t1

Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t1

Table t

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t1

Table t1

Replication Design Setting Up

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t Table tAtomic → db and logconsistent after crashAtomic → db and logconsistent after crash

Asynchronous Asynchronous Asynchronous

(Atomictoo)

(Atomictoo)

Replication Design Setting Up

Network

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `40

Replication Design Setting Up

Replicationseems fantastic!

I want to try!

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `41

OverviewMySQL Replication Design

Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `42

Setting Up Replication

Master's my.cnf:

server­id=1log­bin=master­bin

Slave's my.cnf:

server­id=2log­bin=slave­binrelay­log=slave­relay­binlog­slave­updates

Replication Design Setting Up

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

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

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

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

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

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 logso far

Five events:One CREATE and

one INSERT

Replication Design Setting Up

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `46

Check Replication Status

On slave:

> SHOW SLAVE STATUS\G…

Slave_IO_Running Yes

Slave_SQL_Running Yes

Last_IO_Errno 0

Last_IO_Error

Last_SQL_Errno 0

Last_SQL_Error

Both slave threadsare running

If any thread stopswith an error,look for error

message here

Replication Design Setting Up

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

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&A3. Q&A

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

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

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

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

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

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

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

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!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `64

Fail-over

C

A

Make a shortcutin 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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `66

Fail-over

C

A

B

D

Takeout 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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `67

Fail-over

C

A

B

D

MaintainD offline,without

disruptingservice

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

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

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

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

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

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

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:numbera61678ba­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

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

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

fileheader

trans-action

trans-action

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `73

Fail-over: Design: Protocol

Example 1: tree

A

(crashed)(master)

Aid1,trx1,id2,trx2,id3,trx3

binlog

(slave)

Cid1,trx1

binlog(slave)

id1,trx1,id2,trx2 B

binlog

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `74

Fail-over: Design: Protocol

Example 1: tree

A

(crashed)(master)

Aid1,trx1,id2,trx2,id3,trx3

binlog

(slave)

Cid1,trx1

binlog(slave)

id1,trx1,id2,trx2 B

binlog

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Crash

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `75

Fail-over: Design: Protocol

Example 1: tree

(slave)

Cid1,trx1

binlog(slave)

id1,trx1,id2,trx2 B

binlog

A

(crashed)(crashed)

Aid1,trx1,id2,trx2,id3,trx3

binlog id1

id2, trx2,...

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `78

Fail-over: Design: Protocol

Example 1: tree Example 2: circle

id1,trx1,id2,trx2 B

binlog

id2,trx2

A

binlog

C

binlog

client clienttrx2 trx1

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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

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

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

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

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

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

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 forfail-over!

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

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

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

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=onenforce­gtid­consistency=onlog­binlog­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

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

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 onnew master

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `86

Fail-over: Perform

Perform fail-over

C

B

ACHANGE MASTER TOMASTER_HOST = 'B',MASTER_PORT = <B's port>,MASTER_USER = '<user name>'MASTER_PASSWORD = 'secret';

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `87

Fail-over: Perform

Perform fail-over

CHANGE MASTER TOMASTER_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

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

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?

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

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

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `92

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Now I cando fail-over!

But how do I avoidlosing data after

a crash?

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

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

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

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

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

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 allchanges from master”

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

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

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

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

ClientDumpthread

IOthread

SQLthread

Table t Table t

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Network

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

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

ClientDumpthread

IOthread

SQLthread

Table t Table tAtomic → db and logconsistent after crashAtomic → db and logconsistent after crash

Asynchronous Asynchronous Asynchronous

(Atomictoo)

(Atomictoo)

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Network

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

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

ClientDumpthread

IOthread

SQLthread

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `101

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

So semi-syncensures slave has all

changes before my appgets notified.

Anything else that helpsconsistency after

a crash?

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `102

Overview

Meta-datasafe on disk

MySQL Replication

Crash-Tolerance Failover

Reduce Risk for Data Loss

– Semi-sync– Transactional meta-data

Performance– Transactional meta-data– Multi-threaded slave

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

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

IOthread

SQLthread

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `104

Replication Metadata in Tables

File: updated aftertransaction commit

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Trans-action

Updateposition

Trans-action

Updateposition

Crashpossible

Table: updated atomically attransaction commit

Consistent after server crash

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

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=TABLEslave­info­repository=TABLEdefault­storage­engine=InnoDB

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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 improveslave performance?

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

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

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `109

Performance: Replication Metadata In TablesCrash-tolerance Fail-over Reduce Risk for Data Loss Performance

File: separate disk syncfor the file

Trans-action

Updateposition

Trans-action

Updateposition

Sync

Table: leverage sync from storage engine

(even better: group commit)

Again, use transactional engine

Sync Sync

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `110

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

Ahh, sotransactional meta-data

is double-good!How else can I improve

slave performance?

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

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

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

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 writerthreads on master

Writes are serializedin binary log

Single applieron slave →

Can becomebottleneck

Client

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `113

Performance: Parallel Slave Threads

B

binary logrelay log

A

binary log

Client

ClientClient

Coordinatorthread (reading)

Multiple workerthreads! (executing)

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `115

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

relay log

3 workerthreadsCoordinator

thread

w1w2w3

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `116

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB1w1w2w3

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `117

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB1

DB2

w1w2w3

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `118

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB1

DB2

w1w2w3

DB3

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `119

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB1

DB2

w1w2w3

DB3

Coordinator waits for w1 to finishbefore feeding DB1 update to w3

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `120

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB2

w1w2w3

DB3

Coordinator waits for w1 to finishbefore feeding DB1 update to w3

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `121

Performance: Parallel Slave Threads

Parallelize by schema (database)

B

Trx1: DB1Trx2: DB2

Trx3: DB3+DB1

3 workerthreadsCoordinator

thread

DB2

w1w2w3

DB3

Coordinator waits for w1 to finishbefore feeding DB1 update to w3

DB1

relay log

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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 CPUsand number of databases.

No exact formula –measure what's best for you!

Crash-tolerance Fail-over Reduce Risk for Data Loss Performance

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

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 yousummarize?

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `124

SummaryMySQL Replication

Crash-Tolerance Failover

Reduce Risk for Data Loss

– Semi-sync– Transactional meta-data

Performance– Transactional meta-data– Multi-threaded slave

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | `125

Semi-sync

GlobalTransactionIdentifiers

ReplicationBase

TransactionalMetadata

Parallel slave

My.cnf:server­id=<different number for each server>log­bin=<host>­binrelay­log=<host>­relay­binlog­slave­updatesmaster­info­repository=TABLEslave­info­repository=TABLEdefault­storage­engine=InnoDBgtid­mode=onenforce­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

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

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: [email protected] Blog: svenmysql.blogspot.co.uk

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

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. | 127