Top Banner
MySQL 5.6 Replication: Self-Healing Clusters with GTIDs
49

Mysql Pn Replication Gtid Failover

Dec 25, 2015

Download

Documents

DumilKumar

Mysql Pn Replication Gtid Failover
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mysql Pn Replication Gtid Failover

MySQL 5.6 Replication: Self-Healing Clusters with GTIDs

Page 2: Mysql Pn Replication Gtid Failover

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: Mysql Pn Replication Gtid Failover

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

Overview

PART 1

  Fail-over Base –  Global Transaction Identifiers –  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

Page 4: Mysql Pn Replication Gtid Failover

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

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

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

Page 5: Mysql Pn Replication Gtid Failover

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

Fail-over  Handle server crash with minimal disruption

 Example 1: tree

C

B

A

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

Page 6: Mysql Pn Replication Gtid Failover

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

Fail-over  Handle server crash with minimal disruption

 Example 1: tree

C

B

A Crash

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

Page 7: Mysql Pn Replication Gtid Failover

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

Fail-over

C

B

A

 Handle server crash with minimal disruption

 Example 1: tree

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

Page 8: Mysql Pn Replication Gtid Failover

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

Fail-over

C

B

A

Make B the new master

 Handle server crash with minimal disruption

 Example 1: tree

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

Page 9: Mysql Pn Replication Gtid Failover

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

Fail-over

C A B

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

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

Page 10: Mysql Pn Replication Gtid Failover

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

Fail-over

C A B Crash

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

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

Page 11: Mysql Pn Replication Gtid Failover

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

Fail-over

C A B

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

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

Page 12: Mysql Pn Replication Gtid Failover

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

Fail-over

C A B

Make A direct master of C

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

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

Page 13: Mysql Pn Replication Gtid Failover

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

Fail-over

C

A

B

D

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

 Example 3: circle

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

Page 14: Mysql Pn Replication Gtid Failover

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

Fail-over

C

A

B

D Crash

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

 Example 3: circle

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

Page 15: Mysql Pn Replication Gtid Failover

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

Fail-over

C

A

B

D

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

 Example 3: circle

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

Page 16: Mysql Pn Replication Gtid Failover

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

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

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

Page 17: Mysql Pn Replication Gtid Failover

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

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

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

Page 18: Mysql Pn Replication Gtid Failover

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

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

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

Page 19: Mysql Pn Replication Gtid Failover

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

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

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

Page 20: Mysql Pn Replication Gtid Failover

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

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

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

Page 21: Mysql Pn Replication Gtid Failover

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

 Handle server crash with minimal disruption

 Example 1: tree

 Example 2: line

 Example 3: circle

 Example 4: scheduled maintenance

 Example 5: arbitrary topology

Fail-over

A

B C

D

E

F

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

Page 22: Mysql Pn Replication Gtid Failover

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

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!

Page 23: Mysql Pn Replication Gtid Failover

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

Overview

  Introduction to MySQL Replication   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

Page 24: Mysql Pn Replication Gtid Failover

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

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

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

Page 25: Mysql Pn Replication Gtid Failover

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

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

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

Page 26: Mysql Pn Replication Gtid Failover

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

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

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

Page 27: Mysql Pn Replication Gtid Failover

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

Global Transaction Identifiers master> CREATE TABLE t1 (a INT); master> SELECT @@global.gtid_executed; a61678ba-4889-4279-9e58-45ba840af334:1 master> INSERT INTO t1 VALUES (1); master> INSERT INTO t1 VALUES (2); master> SELECT @@global.gtid_executed; a61678ba-4889-4279-9e58-45ba840af334:1-3

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

Note: interval

New variable: gtid_executed

Page 28: Mysql Pn Replication Gtid Failover

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

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

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

Page 29: Mysql Pn Replication Gtid Failover

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

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

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

Slave is missing one transaction Slave is missing one transaction

Page 30: Mysql Pn Replication Gtid Failover

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

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?

Page 31: Mysql Pn Replication Gtid Failover

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

Overview

  Introduction to MySQL Replication   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

Page 32: Mysql Pn Replication Gtid Failover

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

Page 33: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree

A

(crashed) (master)

A id1,trx1, id2,trx2, id3,trx3

(slave)

C id1,trx1 (slave)

id1,trx1, id2,trx2 B

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

Page 34: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree

A

(crashed) (master)

A id1,trx1, id2,trx2, id3,trx3

(slave)

C id1,trx1 Crash! (slave)

id1,trx1, id2,trx2 B

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

Page 35: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree

(slave)

C id1,trx1 (slave)

id1,trx1, id2,trx2 B

A

(crashed) (crashed)

A id1,trx1, id2,trx2, id3,trx3

id1

id2, trx2,...

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

What the slave has

What the slave does not have

Page 36: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

B A C

client client

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

Page 37: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

id1,trx1 B A C

client client trx1

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

Page 38: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

id1,trx1, id2,trx2 B

id2,trx2 A C

client client trx2 trx1

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

Page 39: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

id1,trx1, id2,trx2, id3,trx3

B id2,trx2

A C

client client trx2 trx1, trx3

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

Page 40: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

id1,trx1, id2,trx2, id3,trx3

B id2,trx2

A C

client client trx2 trx1, trx3

Crash!

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

Page 41: Mysql Pn Replication Gtid Failover

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

Automatic Positioning  Example 1: tree  Example 2: circle

id1,trx1, id2,trx2, id3,trx3

B id2,trx2

A C

client client trx2 trx1, trx3

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

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

What the slave has

What the slave does not have

Page 42: Mysql Pn Replication Gtid Failover

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

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?

Page 43: Mysql Pn Replication Gtid Failover

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

Overview

  Introduction to MySQL Replication   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

Page 44: Mysql Pn Replication Gtid Failover

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

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

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

Page 45: Mysql Pn Replication Gtid Failover

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

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

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

Page 46: Mysql Pn Replication Gtid Failover

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

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!

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

Page 47: Mysql Pn Replication Gtid Failover

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

Hands-On  Perform fail-over

C

B

A 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

Page 48: Mysql Pn Replication Gtid Failover

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

Hands-On  Perform fail-over

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

A

B

D

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

Page 49: Mysql Pn Replication Gtid Failover

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

Next Steps

  More on GTIDs –  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/