understanding mysql group replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · mysql...

91

Upload: others

Post on 23-Aug-2020

34 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update
Page 2: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

Copyright © 2017, Oracle and/or its affiliates. All rights reserved.

Understanding MySQL Group Replication

Libing Song([email protected])Software EngineerMySQL Replication Team

Page 3: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Safe Harbor 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.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 3

Page 4: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Program Agenda

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

Page 5: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Background

Use cases

Deployment modes

Features

Performance

Architecture

Conclusion

Program Agenda

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

1

2

3

4

5

6

5

7

Page 6: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Background

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

1

Page 7: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Database Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

ServerB

ServerA

App

INSERT ...

INSERT ... INSERT ...

Replication“The process of generating and reproducing multiple copies of data at one or more sites.”,Database Systems: A Practical Approach to Design, Implementation, and Management, Thomas M. Connolly, Carolyn E. Begg, Third Edition, 2002.

7

Page 8: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Database Replication: Overview

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

INSERT ...Server

B

binary log

INSERT ...

relay log

INSERT ...Server

A

binary log

App

ReceiverMeta-data

Update

ApplierMeta-data

Update

INSERT ...

Comm. Framework

8

Page 9: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Coordination Between Servers

MySQL Database Replication: Some Notes

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

A B Since 3.23

A B

semi-synchronous (plugin)

A CB

group replication (plugin)

transactions

transactions

Since 5.5

Since 5.7.17

asynchronous (native)

transactions, membership, coordination

acks

And now in MySQL 8 as of 8.0.1

9

Page 10: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Group Replication

• What is MySQL Group Replication?“Single/Multi-primary update everywhere replication plugin for MySQL with built-in automatic distributed recovery, conflict detection and group membership.”

• What does the MySQL Group Replication plugin do for the user?– Removes the need for handling server fail-over.

– Provides fault tolerance.

– Enables update everywhere setups.

– Automates group reconfiguration (handling of crashes, failures, re-connects).

– Provides a highly available replicated database.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 10

Page 11: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Group Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

Replication Group

Clients

11

Page 12: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

GR 0.8.0 labs (beta)performance enhancementsreplication stream compressionSSL supportIP whitelistingread-only modeerror log enhancementssplit brain handling

The Road to Group Replication in MySQL 8 and InnoDB Clusters

MySQL 5.6.10

MySQL 5.7.9lifecycle interfacesP_S tables for GRServer side changes

GR 0.2.0 labsHello world!

GR 0.3.0 labssupport for corosync 2.x

GR 0.4.0 labsversion handling

GR 0.5.0 labsauto-inc fields handlingrecovery enhancements

GR 0.6.0 labsmulti-platform supportPaxos-based consensus

GR 0.7.0 labsbug fixes

GR 0.9.0 labs (RC)multi-threaded appliersupport

Single-primary mode

GR is GA inMySQL Server5.7.17

...

GR is released withMySQL 8.0.1 andInnoDB Cluster GA

12

Page 13: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Use cases

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

2

Page 14: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Use Cases

• Elastic Replication– Environments that require a very fluid replication infrastructure, where the number of

servers has to grow or shrink dynamically and with as little pain as possible.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

14

Page 15: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Use Cases

• Highly Available Shards– Sharding is a popular approach to achieve write scale-out. Users can use MySQL

Group Replication to implement highly available shards. Each shard can map into a Replication Group.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P P P P P P P P P P P

15

Group Replication Group Group Replication Group Group Replication Group

Page 16: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Use Cases

• Alternative to Master-Slave replication

• Single-primary mode provides further automation on such setups– Automatic PRIMARY/SECONDARY roles assignment

– Automatic new PRIMARY election on PRIMARY failures

– Automatic setup of read/write modes on PRIMARY and SECONDARIES

– Global consistent view of which server is the PRIMARY

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

S S S S P S

Primary

16

Page 17: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Single-primary

Deployment modes

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

3

3.1

Page 18: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Single-primary mode

• Configuration mode that makes a single member act as a writeable master (PRIMARY) and the rest of the members act as hot-standbys (SECONDARIES).– The group itself coordinates automatically to figure out which is the member that will

act as the PRIMARY, through a primary election mechanism.

• Single-primary mode is the default mode– Closer to classic asynchronous replication setups, simpler to reason about from the

beginning.

– Avoids some of the limitations of multi-primary mode by default.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 18

Page 19: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Single-primary mode

• Automatic primary promotion election.

• Secondaries are automatically set to read-only.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

S S S S P S

Primary

19

Page 20: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Single-primary mode

• Automatic primary election mechanism.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

S S S P S

Primary

20

Page 21: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Single-primary mode

• The current primary member UUID can be known by executing the following SQL statement.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

mysql> SELECT * FROM performance_schema.global_status WHEREVARIABLE_NAME='group_replication_primary_member';

VARIABLE_NAME VARIABLE_VALUEgroup_replication_primary_member dcd3b36b-79c5-11e6-97b8-00212844d44e

21

Page 22: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary

Single-primary

Deployment modes

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

3

3.1

3.2

Page 23: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary update everywhere!

• Configuration mode that makes all members writable– Enabled by setting option --group_replication_single_primary_mode to OFF

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 23

P P P P P

Page 24: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary update everywhere!

• Any two transactions on different servers can write to the same tuple.

• Conflicts will be detected and dealt with.– First committer wins rule.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1

24

Page 25: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary update everywhere!

• Any two transactions on different servers can write to the same tuple.

• Conflicts will be detected and dealt with.– First committer wins rule.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

UPDATE t1 SET a=4 WHERE a=2UPDATE t1 SET a=3 WHERE a=1 OKOK

25

Page 26: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary update everywhere!

• Any two transactions on different servers can write to the same tuple.

• Conflicts will be detected and dealt with.– First committer wins rule.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1

26

Page 27: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Multi-primary update everywhere!

• Any two transactions on different servers can write to the same tuple.

• Conflicts will be detected and dealt with.– First committer wins rule.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

UPDATE t1 SET a=2 WHERE a=1UPDATE t1 SET a=3 WHERE a=1 OK

27

Page 28: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

Page 29: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• Server that joins the group will automatically synchronize with the others.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P N

I want to play with you

29

Page 30: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• Server that joins the group will automatically synchronize with the others.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P N

ONLINERECOVERING

30

Page 31: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• Server that joins the group will automatically synchronize with the others.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P N

ONLINE

31

Page 32: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• If a server leaves the group, the others will automatically be informed.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P P

My machine needs maintenanceor a system crash happens

Each membership configurationis identified by a view_id

view_id: 6

32

Page 33: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• If a server leaves the group, the others will automatically be informed.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

33

Page 34: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Automatic distributed server recovery!

• Server that (re)joins the group will automatically synchronize with the others.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P P

RECOVERING -> ONLINE

view_id: 7

34

Page 35: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

Page 36: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Look & Feel!

• MySQL Plugin– Regular MySQL Plugin. Nothing new.

• MySQL InnoDB– Use InnoDB as normally you would. Nothing new.

– Transparent optimizations in InnoDB to better support Group Replication.

• MySQL Performance Schema–Monitor Group Replication using regular Performance Schema tables. Nothing new.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 36

Page 37: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL Look & Feel!

• Outcome– Group Replication is no alien component.

– Existing MySQL users feel right at home.

–New MySQL users only have to learn MySQL tech, nothing else.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 37

Page 38: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full GTID support

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

4.3

Page 39: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full GTID support!

• All group members share the same UUID, the group name.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

INSERT y;Will have GTID: group_name:2

INSERT x;Will have GTID: group_name:1

39

Page 40: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full GTID support!

• Users can specify the identifier for the transaction.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

INSERT y;Will have GTID: group_name:1

SET GTID_NEXT= “UUID:50”INSERT x;

40

Page 41: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full GTID support!

• You can even replicate from a outside server to a group, global identifiers will be preserved.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

Conflicts will be detected!

41

Page 42: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full GTID support!

• You can also replicate from a group to a outside server, global identifiers will be preserved.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

42

Page 43: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Auto-increment configuration/handling

Full GTID support

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

4.3

4.4

Page 44: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Auto-increment configuration/handling

• Group is configured to not generate the same auto-increment value on all members.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

INSERT y;y: 4

INSERT z;z: 11

INSERT x;x: 1

44

Page 45: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Auto-increment configuration/handling

• By default, the offset is provided by server_id and increment is 7.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

INSERT y;y: 4

INSERT z;z: 11

INSERT x;x: 1

server_id: 1server_id: 4

45

Page 46: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Auto-increment configuration/handling

• Users can change the increment size to their needs using GROUP_REPLICATION_AUTO_INCREMENT_INCREMENT option.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

INSERT y;y: 4

INSERT z;z: 11

INSERT x;x: 1

server_id: 1server_id: 4

46

Page 47: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Plugin version access control

Auto-increment configuration/handling

Full GTID support

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

4.3

4.4

4.5

Page 48: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Plugin Version Access Control

• When joining, versions are crucial when determining if a member is compatible with a group.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

5.7.13 5.7.13 5.7.14 5.7.15 5.7.12

Member with different patchversion is allowed to join

48

Page 49: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Plugin Version Access Control

• When joining, versions are crucial when determining if a member is compatible with a group.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

8.0.0 8.0.0 8.0.0 8.0.0 5.7.15

Member with lower major versionthan the major version inthe group is not allowed to join

49

Page 50: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Plugin Version Access Control

• When joining, versions are crucial when determining if a member is compatible with a group.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

5.7.14 5.7.14 5.7.15 5.7.15 8.0.0

Member with higher majorversion is allowed to join butis not allowed to do writes

50

Page 51: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Built-in communication engine

Plugin version access control

Auto-increment configuration/handling

Full GTID support

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

4.3

4.4

4.5

4.6

Page 52: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Built-in Communication Engine

• Feature rich new replication plugin based on proven distributed systems algorithms (Paxos).– Compression, multi-platform, dynamic membership, distributed agreement, quorum

based message passing, SSL, IP whitelisting.

• No third-party software required.

• No network multicast support required.–MySQL Group Replication can operate on cloud based installations where multicast is

unsupported.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 52

Page 53: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Read-only mode

Built-in communication engine

Plugin version access control

Auto-increment configuration/handling

Full GTID support

MySQL Look & Feel

Automatic distributed server recovery

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.1

4.2

4.3

4.4

4.5

4.6

4.7

Page 54: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Read-only mode

• When a member joins the group, during distributed recovery, read-only mode is automatically set.

• On the unlikely event of a member failure, read-only mode is set automatically to prevent inconsistency with the group and member state changes to ERROR.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

P P P P P

54

Page 55: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full stack secure connections

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.8

Page 56: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Full stack secure connections

• Group Replication supports secure connections along the complete stack:– Distributed recovery connections

– Connections between members

– Client connections

• IP Whitelisting– Restrict which hosts are allowed to connect to the group

– By default it is set to the value AUTOMATIC, which allows connections from private subnetworks active on the host

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 56

Page 57: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Parallel applier support

Full stack secure connections

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.8

4.9

Page 58: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Parallel applier support

• Reduces applier lag and improves replication performance considerably.

• The same configuration options as asynchronous replication.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

--slave_parallel_workers=NUMBER--slave_parallel_type=logical_clock--slave_preserve_commit_order=ON

58

Page 59: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Parallel applier support

• Write set Based Transaction Dependencies– Already used on Group Replication from the beginning

– Speedup distributed recovery time

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

master> SET @@GLOBAL.binlog_transaction_dependency_tracking=WRITESET;Query OK, 0 rows affected (0,00 sec)

master> SET @@GLOBAL.binlog_transaction_dependency_tracking=WRITESET_SESSION;Query OK, 0 rows affected (0,00 sec)

master> SET @@GLOBAL.binlog_transaction_dependency_tracking=COMMIT_ORDER; -- defaultQuery OK, 0 rows affected (0,00 sec

59

Page 60: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction SAVEPOINT support

Parallel applier support

Full stack secure connections

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.8

4.9

4.10

Page 61: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction SAVEPOINT support

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

mysql> BEGIN;Query OK, 0 rows affected (0,00 sec)

mysql> INSERT INTO t1 VALUES(1);Query OK, 1 row affected (0,00 sec)

mysql> SAVEPOINT S1;Query OK, 0 rows affected (0,00 sec)

mysql> INSERT INTO t1 VALUES(2);Query OK, 1 row affected (0,00 sec)

mysql> ROLLBACK TO S1;Query OK, 0 rows affected (0,00 sec)

mysql> COMMIT;Query OK, 0 rows affected (0,00 sec)

61

Page 62: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Requirements

Transaction SAVEPOINT support

Parallel applier support

Full stack secure connections

Features

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

4

4.8

4.9

4.10

4.11

Page 63: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Requirements (by design)

• Requires InnoDB storage engine

• Primary key is required on every table

• Requires global transaction identifiers turned on

• Requires binary log turned on

• Requires binary log row format

• Optimistic execution: transactions may abort on COMMIT due to conflicts with concurrent transactions on other members

• Up to 9 servers in the group

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

• Serializable (on multi-primary)

• Cascading Foreign Keys (on multi-primary)

• Binary log events checksum

Forbidden

• Concurrent DDL (on multi-primary)

• SELECT *** FOR UPDATE does not have group locking (on multi-primary)

Warnings

63

Page 64: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Performance

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

5

Page 65: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Performance

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

5000

10000

15000

20000

25000

30000

2 3 5 7 9

THR

OU

GH

PU

T (T

PS)

NUMBER OF SERVERS IN THE GROUP.

Group Replication Throughput(as perceived by the client application)

Single-master Sustained Single-master Peak Multi-master Sustained

Multi-master Peak Single-server (MySQL 5.7.14)

More on this subject on the series of replication performance blogs at: http://mysqlhighavailability.com/category/performance/

Servers9 Dual Xeon E5-2660-v3Enterprise SSD Storage10Gbps Ethernet Network

Client1 Dual Xeon E5-2699-v310Gbps Ethernet NetworkSysbench 0.5 RW workload

Peak Throughput (i.e., no flow control)The number of transactions that writers can propagate to the group (per second).

Sustained Throughput (i.e., flow control)The number of transactions that can be propagated to the group without increasing the replication lag on any member (per second).

65

Page 66: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Performance

• On a sustained throughput:–Multi-primary performance degrades gracefully while going from a group with 2

servers to a group with 9 servers.

– Single-primary performance degrades marginally when growing the group size.

• On a peak throughput:–Multi-primary exhibits 1.8X speedup when compared to the single server.• Read load is balanced across the servers in the group.

• Write load is lower since execution is balanced across the group, whereas in single-primary mode the primary becomes a bottleneck.

–With a single-primary there is no lag on the other members.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 66

Page 67: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

ArchitectureThe Theories of Group Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

6

6.1

Page 68: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

The Theories of Group Replication• State Machine Replication– All servers are initialized at same state.

– Same inputs in same order generate same output state.

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 68

DB-1

Client T1

Broadcaster

DB-3

ClientT3

DB-2

T1T3T2

Client

T2

Broadcaster

State Machine Replication Model

Page 69: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

The Theories of Group Replication• State Machine Replication– All servers are initialized at same state.

– Same inputs in same order generate same output state.

• Atomic Broadcast System–Messages are totally ordered

– All servers receive same messages in same order

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 69

DB-1

Client

T1

T1T3T2

AtomicBroadcaster

DB-3

Client

T3

T1T3T2

AtomicBroadcaster

DB-2

T1T3T2

Client

T2

AtomicBroadcaster

Distributed State Machine Replication Model

Page 70: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Group Replication Architecture

ArchitectureThe Theories of Group Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

6

6.1

6.2

Page 71: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Group Replication Architecture• Broadcast Binary Log Events– Row based data log

– Captures and broadcasts binary log events after transaction execution

• Certification(Conflict Detection)– Execution before atomic broadcasting causes

conflict

– All conflicting transactions are broadcasted

– But only the first broadcasted transaction can commit, others are rolled back

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 71

PaxosBroadcaster

PaxosBroadcaster

PaxosBroadcaster

Client

T1

DB-1

BinlogEvents

Client

T2

DB-2 Client

T3

DB-3

MySQL Group Replication Architecture

BinlogEvents

BinlogEvents

BinlogEvents

BinlogEvents

BinlogEvents

Page 72: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Group Replication Architecture• Binlog Event Applier– Injects binlog events into relay log

– Controls binlog event automatically

• Paxos Based Atomic Broadcaster– Concensus

– Require majority servers available

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 72

PaxosBroadcaster

PaxosBroadcaster

PaxosBroadcaster

Client

T1

DB-1

BinlogEvents

Client

T2

DB-2 Client

T3

DB-3

MySQL Group Replication Architecture

BinlogEvents

BinlogEvents

BinlogEvents

BinlogEvents

BinlogEvents

Page 73: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Group Replication Architecture

ArchitectureThe Theories of Group Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

6

6.1

6.2

Transaction Life Circle6.3

Page 74: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction Life Circle

• Local Transaction– Executed by the client

– T1 is local transaction on DB-1

• Remote Transaction– Replicated from other servers

– T2,T3 are remote transaction on DB-1

74Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

MySQL Group Replication Architecture

PaxosBroadcaster

PaxosBroadcaster

PaxosBroadcaster

Client

T1

DB-1

BinlogEvents

Client

T2

DB-2 Client

T3

DB-3

Page 75: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction Life Circle

• Local Transaction Succeeds

75Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

DB-2

COMMITPrepare

Certify

Binlog

CommitOK

T1

T1

Paxo

s DB-3

Succeeds

Page 76: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction Life Circle

• Local Transaction Fails

76Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

DB-2

COMMITPrepare

Certify

RollbackERROR

T1

T1

Paxo

s DB-3

Fails

Page 77: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction Life Circle

• Remote Transaction Succeeds

77Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

DB-2

COMMITPrepare

Certify

Binlog

CommitOK

T1

T1

Paxo

s

Certify

Apply

T1P

axos

Relay Log

SucceedsSucceeds

Page 78: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Transaction Life Circle

• Remote Transaction Fails

78Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

DB-2

COMMITPrepare

Certify

RollbackERROR

T1

T1

Paxo

s

CertifyT1P

axos

Fails

DropFails

Page 79: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Group Replication Architecture

ArchitectureThe Theories of Group Replication

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

6

6.1

6.2

Transaction Life Circle6.3

Certification(Conflict Detection)6.4

Page 80: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Primary Key Based Conflict Detection– Possible conflict if two transactions updated

same rows

–Never conflict if two transactions updated different rows

– Don’t support DDL yet

80Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

DB-2

DB-3DB-1

T1:UPDATE t1SET c1 = 2WHERE PK = 1

T2:UPDATE t1SET c1 = 3WHERE PK = 1

Page 81: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Snapshot Version– Snapshot version is the value of

gtid_executed variable before broadcasting the transaction

– Snapshot of certifying transaction must include the GTIDs of the certified transactions which updated the same rows

81Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

gtid_executed:group_name:1-100

gtid_executed:group_name:1-100

DB-2

DB-3DB-1

T1:UPDATE t1SET c1 = 2WHERE PK = 1

T2:UPDATE t1SET c1 = 3WHERE PK = 1

Page 82: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Conflict Detection Database– A list of certified transactions’ PK HASH and

GTID set pairs.

– Every member has one.

82Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

gtid_executed:group_name:1-100

gtid_executed:group_name:1-100

PK HASH GTID SET

db1.t1.pk=1 group_name:1-50

DB-2

DB-3DB-1

T1:UPDATE t1SET c1 = 2WHERE PK = 1

T2:UPDATE t1SET c1 = 3WHERE PK = 1

Page 83: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Conflict Detection– T2’s snapshot includes the GTID set in

conflict detection database, so certification succeeds.group_name:1-100 > group_name:1-50

83Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

T1: UPDATE t1 SET c1 = 2 WHERE PK = 1Snapshot: group_name:1-100

PK HASH GTID SET

db1.t1.pk = 1 group_name:1-50

Certify

T2: UPDATE t1 SET c1 = 2 WHERE PK = 1Snapshot: group_name:1-100

Succeeds

Page 84: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Conflict Detection– T2’s snapshot includes the GTID set in

conflict detection database, so certification succeeds.group_name:1-100 > group_name:1-50

• Update Detection Database– Fill GTID SET with T2’s snapshot and GTID

– Suppose T2’s GTID is group_name:101

84Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

T1: UPDATE t1 SET c1 = 2 WHERE PK = 1Snapshot: group_name:1-100

Certify

T2: UPDATE t1 SET c1 = 2 WHERE PK = 1Snapshot: group_name:1-100

PK HASH GTID SET

db1.t1.pk = 1 group_name:1-101

Succeeds

Page 85: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Certification

• Conflict Detection– T1’s snapshot do NOT include the GTID set

in conflict detection database, so certification fails.group_name:1-100 < group_name:1-101

85Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

PK HASH GTID SET

db1.t1.pk = 1 group_name:1-101

Certify

T1: UPDATE t1 SET c1 = 2 WHERE PK = 1Snapshot: group_name:1-100

Fails

Page 86: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Conclusion

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

7

Page 87: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Summary• Cloud Friendly

– Great technology for deployments where elasticity is a requirement, such as cloud based infrastructures.

• Integrated

–With server core through a well defined API.

– With GTIDs, row based replication, performance schema tables.

• Autonomic and Operations Friendly

– It is self-healing: no admin overhead for handling server fail-overs.

– Provides fault-tolerance, enables multi-primary update everywhere and a dependable MySQL service.

• Plugin GA version available with MySQL 5.7.17+, available on 8.0.1+

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 87

Page 88: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

MySQL InnoDB Cluster: The End Goal

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China

S1 S2 S3 S4 S…

M

M M

MySQL Connector

Application

MySQL Router

MySQL Connector

Application

MySQL Router

MySQL Shell

HA

Rep

licaS

et1

S1 S2 S3 S4 S…

M

M M

MySQL Connector

Application

MySQL Router

HA

Rep

licaS

et 2

Rep

licaS

et 3

MySQL Connector

Application

MySQL Router

S1 S2 S3 S4

M

M M

HA

88

Page 89: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

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

Where to go from here?

• Packages– http://www.mysql.com/downloads/

• Documentation– http://dev.mysql.com/doc/refman/5.7/en/group-replication.html

– http://dev.mysql.com/doc/refman/8.0/en/group-replication.html

• Blogs from the Engineers (news, technical information, and much more)– http://mysqlhighavailability.com

Thursday, 24th August 2017 Opensource Database Forum, Beijing, China 89

Page 90: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update
Page 91: Understanding MySQL Group Replicationbos.itdks.com/4660aa8b5c4b42e4b3d30fb9bd652a94.pdf · MySQL Group Replication •What is MySQL Group Replication? “Single/Multi-primary update

Thanks关注开源数据库论坛