Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

MySQL 5.

6 Replication:
Self-Healing Clusters with GTIDs

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 Oracles
products remains at the sole discretion of Oracle.

`2

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

PART 1
Fail-over Base
Global Transaction Identifiers

Overview

Automatic Positioning
Hands-On

PART 2
Under the Hood Become a GTID Expert
How Slave Preserves GTIDs
GTIDs Must Be Unique

Integration With Other Features


Seeking & Skipping: Empty Transactions
Purging Binary Logs
Provisioning a Slave From a Backup
`3

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Crash can happen to anyone:


Hardware failure
Human mistake
Bug
Natural disaster

Automatic fail-over with Global Transaction Identifiers:


Reduces admin overhead
Prevents planned downtime
Prevents unplanned downtime

`4

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree

B
A
C

`5

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree

B
A
Crash
C

`6

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree

B
A
C

`7

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree

Make B the new master

A
C

`8

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

`9

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

`10

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

B
Crash

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

`11

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree

Make A direct master of C

Example 2: line

`12

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Example 3: circle

`13

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

D
Crash

Example 3: circle

`14

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Example 3: circle

`15

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Example 3: circle

Make a shortcut
in the circle

`16

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Example 3: circle
Example 4: scheduled maintenance

`17

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption

Take
out D!

Example 1: tree
Example 2: line

Example 3: circle
Example 4: scheduled maintenance

`18

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Maintain
D offline,
without
disrupting
service

Example 3: circle
Example 4: scheduled maintenance

`19

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Fail-over

Handle server crash with minimal disruption


Example 1: tree
Example 2: line

Example 3: circle
Example 4: scheduled maintenance

`20

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

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

`21

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

D
C

E
F

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Wow!
I really want to get started
with fail-over. Tell me more!
`22

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

Introduction to MySQL Replication

Overview

Fail-over Base
Global Transaction Identifiers
Automatic Positioning
Hands-On

Under the Hood Become a GTID Expert


How Slave Preserves GTIDs
GTIDs Must Be Unique

Integration With Other Features


Seeking & Skipping: Empty Transactions
Purging Binary Logs
Provisioning a Slave From a Backup
`23

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers

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

`24

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers

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

`25

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers

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 ensures transaction gets the same GTID when re-executed

`26

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers


master> CREATE TABLE t1 (a INT);
master> SELECT @@global.gtid_executed;
a61678ba-4889-4279-9e58-45ba840af334:1

New variable:
gtid_executed

master> INSERT INTO t1 VALUES (1);


master> INSERT INTO t1 VALUES (2);
master> SELECT @@global.gtid_executed;
a61678ba-4889-4279-9e58-45ba840af334:1-3

`27

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

Note: interval

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers

master> SELECT @@global.gtid_executed;


a61678ba-4889-4279-9e58-45ba840af334:1-10000
slave> SELECT @@global.gtid_executed;
a61678ba-4889-4279-9e58-45ba840af334:1-9999

`28

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Global Transaction Identifiers

master> SELECT @@global.gtid_executed;


a61678ba-4889-4279-9e58-45ba840af334:1-10000
slave> SELECT @@global.gtid_executed;
a61678ba-4889-4279-9e58-45ba840af334:1-9999

Slave is missing
one transaction

`29

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

OK, I get it.


So we have GTIDs.
How are they used in fail-over?

`30

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

Introduction to MySQL Replication

Overview

Fail-over Base
Global Transaction Identifiers
Automatic Positioning
Hands-On

Under the Hood Become a GTID Expert


How Slave Preserves GTIDs
GTIDs Must Be Unique

Integration With Other Features


Seeking & Skipping: Empty Transactions
Purging Binary Logs
Provisioning a Slave From a Backup
`31

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

`32

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree

B
A

id1,trx1,
id2,trx2,
id3,trx3

(crashed)
(master)

id1,trx1,
id2,trx2

(slave)

id1,trx1

C
(slave)

`33

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree

B
id1,trx1,
id2,trx2,
ACrash!
id3,trx3
(crashed)
(master)

id1,trx1,
id2,trx2

(slave)

id1,trx1

C
(slave)

`34

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree

What the
slave has

B
A

id1,trx1,
id2,trx2,
id3,trx3

(crashed)
(crashed)

`35

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

id1,trx1,
id2,trx2

id1

(slave)
id2, trx2,...
What the
slave does
not have

id1,trx1

C
(slave)

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

`36

client

client

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

client

client trx1
id1,trx1

`37

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

client trx2

client trx1

id2,trx2

`38

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

id1,trx1,
id2,trx2

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

client trx2

client trx1, trx3

id2,trx2

`39

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

id1,trx1,
id2,trx2,
id3,trx3

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

client trx2

client trx1, trx3

id2,trx2

`40

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

id1,trx1,
id2,trx2,
id3,trx3

C Crash!

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Automatic Positioning
Example 1: tree
Example 2: circle

client trx2

client trx1, trx3

id2,trx2

What the
slave has
`41

B
id2
id1,trx1,id3,trx3,...

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

id1,trx1,
id2,trx2,
id3,trx3
What the
slave does
not have

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Awesome!
I'm really eager to get started.
How do I set it up?
`42

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

Introduction to MySQL Replication

Overview

Fail-over Base
Global Transaction Identifiers
Automatic Positioning
Hands-On

Under the Hood Become a GTID Expert


How Slave Preserves GTIDs
GTIDs Must Be Unique

Integration With Other Features


Seeking & Skipping: Empty Transactions
Purging Binary Logs
Provisioning a Slave From a Backup
`43

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Hands-On

Prerequisites:
Use transactional storage engine for all tables (InnoDB)
Don't use CREATE TABLE SELECT
Don't execute CREATE TEMPORARY TABLE or

DROP TEMPORARY TABLE inside a transaction

`44

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Hands-On

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.Execute:
> CHANGE MASTER TO MASTER_AUTO_POSITION = 1

`45

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Hands-On

Perform fail-over

On the slave, simply point to the new master:


> CHANGE MASTER TO MASTER_HOST = '<host>',
MASTER_PORT = <port number>,
MASTER_USER = '<user name>'
MASTER_PASSWORD = 'secret';
No positions needed!

`46

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

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Hands-On

Perform fail-over

B
A
C

`47

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

CHANGE MASTER TO
MASTER_HOST = 'B',
MASTER_PORT = <B's port>,
MASTER_USER = '<user name>'
MASTER_PASSWORD = 'secret';

Introduction to MySQL Replication ! Fail-over Base ! Under the Hood ! Integration With Other Features

Hands-On

Perform fail-over

`48

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

CHANGE MASTER TO
MASTER_HOST = 'A',
MASTER_PORT = <A's port>,
MASTER_USER = '<user name>'
MASTER_PASSWORD = 'secret';

More on GTIDs

Next
Steps

svenmysql.blogspot.co.uk

More on MySQL 5.6 Replication


http://dev.mysql.com/tech-resources/articles/

mysql-5.6-replication.html

Try Out MySQL 5.6RC


http://dev.mysql.com/downloads/mysql/

`49

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

You might also like