MySQL InnoDB Cluster & Group Replication in a Nutshell: Hands-On Tutorial

Similar documents
MySQL Group Replication in a nutshell

MySQL InnoDB Cluster & Group Replication in a Nutshell: Hands-On Tutorial

Introduction to MySQL InnoDB Cluster

MySQL Group Replication in a nutshell

High Availability Using MySQL Group Replication

State of MySQL Group Replication

Everything You Need to Know About MySQL Group Replication

MySQL InnoDB Cluster. MySQL HA Made Easy! Miguel Araújo Senior Software Developer MySQL Middleware and Clients. FOSDEM 18 - February 04, 2018

MySQL Group Replication. Bogdan Kecman MySQL Principal Technical Engineer

MySQL Multi-Source Replication

MySQL Group Replication & MySQL InnoDB Cluster

MySQL Point-in-Time Recovery like a Rockstar

The Exciting MySQL 5.7 Replication Enhancements

MySQL High Availability

MySQL Replication, the Community Sceptic Roundup. Giuseppe Maxia Quality Assurance Architect at

MySQL HA Solutions Selecting the best approach to protect access to your data

The New Replication Features in MySQL 8. Luís Soares Principal Software Engineer, MySQL Replication Lead

MySQL Replication: What's New In MySQL 5.7 and MySQL 8. Luís Soares Software Development Director MySQL Replication

MySQL Replication: Latest Developments

replic8 The Eighth Generation of MySQL Replication Sven Sandberg MySQL Replication Core Team Lead

MySQL as a Document Store. Ted Wennmark

Operational DBA In a Nutshell - HandsOn Reference Guide

State of the Dolphin Developing new Apps in MySQL 8

Mix n Match Async and Group Replication for Advanced Replication Setups. Pedro Gomes Software Engineer

Consistent Reads Using ProxySQL and GTID. Santa Clara, California April 23th 25th, 2018

MySQL Replication : advanced features in all flavours. Giuseppe Maxia Quality Assurance Architect at

Migrating to XtraDB Cluster 2014 Edition

Kenny Gryp. Ramesh Sivaraman. MySQL Practice Manager. QA Engineer 2 / 60

MySQL High Availability

MySQL InnoDB Cluster. New Feature in MySQL >= Sergej Kurakin

What's new in MySQL 5.5 and 5.6 replication

Percona XtraDB Cluster

What s new in Percona Xtradb Cluster 5.6. Jay Janssen Lead Consultant February 5th, 2014

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

HA solution with PXC-5.7 with ProxySQL. Ramesh Sivaraman Krunal Bauskar

MySQL High Availability Solutions. Alex Poritskiy Percona

MySQL Replication. Rick Golba and Stephane Combaudon April 15, 2015

Backup and Recovery Strategy

MySQL GTID Implementation, Maintenance, and Best Practices. Brian Cain (Dropbox) Gillian Gunson (GitHub) Mark Filipi (SurveyMonkey)

Group Replication: A Journey to the Group Communication Core. Alfranio Correia Principal Software Engineer

Percona XtraDB Cluster ProxySQL. For your high availability and clustering needs

MySQL Replication Advanced Features In 20 minutes

Cluster Mysql8 InnoDB

MySQL High Availability. Michael Messina Senior Managing Consultant, Rolta-AdvizeX /

The Hazards of Multi-writing in a Dual-Master Setup

Aurora, RDS, or On-Prem, Which is right for you

Oracle Exam 1z0-883 MySQL 5.6 Database Administrator Version: 8.0 [ Total Questions: 100 ]

MySQL Replication Update

Building Highly Available and Scalable Real- Time Services with MySQL Cluster

MySQL 5.6 New Replication Features

MySQL Enterprise High Availability

MySQL High available by design

MySQL Architecture Design Patterns for Performance, Scalability, and Availability

Setting up Multi-Source Replication in MariaDB 10.0

Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

How Facebook Got Consistency with MySQL in the Cloud Sam Dunster

Percona XtraDB Cluster MySQL Scaling and High Availability with PXC 5.7 Tibor Korocz

Improvements in MySQL 5.5 and 5.6. Peter Zaitsev Percona Live NYC May 26,2011

Choosing a MySQL HA Solution Today. Choosing the best solution among a myriad of options

MySQL for Database Administrators Ed 3.1

CO MySQL for Database Administrators

MariaDB 10.3 vs MySQL 8.0. Tyler Duzan, Product Manager Percona

Percona XtraDB Cluster 5.7 Enhancements Performance, Security, and More

MySQL Document Store. How to replace a NoSQL database by MySQL without effort but with a lot of gains?

What s New in MySQL 5.7 Geir Høydalsvik, Sr. Director, MySQL Engineering. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Welcome to Virtual Developer Day MySQL!

High availability with MariaDB TX: The definitive guide

MySQL Replication Options. Peter Zaitsev, CEO, Percona Moscow MySQL User Meetup Moscow,Russia

Choosing a MySQL HA Solution Today

MySQL usage of web applications from 1 user to 100 million. Peter Boros RAMP conference 2013

InnoDB: Status, Architecture, and Latest Enhancements

EXPERIENCES USING GH-OST IN A MULTI-TIER TOPOLOGY

Migrating to Aurora MySQL and Monitoring with PMM. Percona Technical Webinars August 1, 2018

ProxySQL - GTID Consistent Reads. Adaptive query routing based on GTID tracking

Diagnosing Failures in MySQL Replication

2) One of the most common question clients asks is HOW the Replication works?

Highly Available Database Architectures in AWS. Santa Clara, California April 23th 25th, 2018 Mike Benshoof, Technical Account Manager, Percona

MySQL with Windows Server 2008 R2 Failover Clustering

Support for replication is built into MySQL. There are no special add-ins or applications to install.

ITS. MySQL for Database Administrators (40 Hours) (Exam code 1z0-883) (OCP My SQL DBA)

MySQL 5.6: Advantages in a Nutshell. Peter Zaitsev, CEO, Percona Percona Technical Webinars March 6, 2013

Reliable Crash Detection and Failover with Orchestrator

MySQL & NoSQL: The Best of Both Worlds

MySQL Database Administrator Training NIIT, Gurgaon India 31 August-10 September 2015

Which technology to choose in AWS?

MySQL As A Service. Operationalizing 19 Years of Infrastructure at GoDaddy

Modern Development With MySQL

G a l e r a C l u s t e r Schema Upgrades

MySQL 8.0: Atomic DDLs Implementation and Impact

MySQL Performance Tuning 101

Using the MySQL Document Store

Enterprise Open Source Databases

ProxySQL Tutorial. With a GPL license! High Performance & High Availability Proxy for MySQL. Santa Clara, California April 23th 25th, 2018

MySQL Cluster Web Scalability, % Availability. Andrew

Choosing a MySQL High Availability Solution. Marcos Albe, Percona Inc. Live Webinar June 2017

10. Replication. CSEP 545 Transaction Processing Philip A. Bernstein Sameh Elnikety. Copyright 2012 Philip A. Bernstein

3 / 120. MySQL 8.0. Frédéric Descamps - MySQL Community Manager - Oracle

1Z Oracle. MySQL 5 Database Administrator Certified Professional Part I

Understanding Percona XtraDB Cluster 5.7 Operation and Key Algorithms. Krunal Bauskar PXC Product Lead (Percona Inc.)

Setting Up Master-Master Replication With MySQL 5 On Debian Etch

Transcription:

1 / 284

2 / 284

3 / 284 MySQL InnoDB Cluster & Group Replication in a Nutshell: Hands-On Tutorial Percona Live 2017 - Santa Clara Frédéric Descamps - MySQL Community Manager - Oracle Kenny Gryp - MySQL Practice Manager - Percona

4 / 284 Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose 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 up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle s product remains at the sole discretion of Oracle.

5 / 284 Who are we?

6 / 284

7 / 284 Frédéric Descamps @lefred MySQL Evangelist Managing MySQL since 3.23 devops believer http://about.me/lefred

8 / 284 Kenny Gryp @gryp MySQL Practice Manager

9 / 284 Matt Lord @mattalord Senior MySQL Product Manager

10 / 284 get more at the conference MySQL Group Replication

11 / 284 Other sessions Everything You Need to Know About MySQL Group Replication Luìs Soares & Nuno Carvalho Thursday April 27th 1:50PM - 2:40PM - Ballroom F MySQL Group Replication, Percona XtraDB Cluster, Galera Cluster Ramesh Sivaraman & Kenny Gryp Thursday April 27th 3:00PM - 3:50PM - Ballroom E

12 / 284 Agenda Prepare your workstation

13 / 284 Agenda Prepare your workstation MySQL InnoDB Cluster & Group Replication concepts

14 / 284 Agenda Prepare your workstation MySQL InnoDB Cluster & Group Replication concepts Migration from Master-Slave to GR

15 / 284 Agenda Prepare your workstation MySQL InnoDB Cluster & Group Replication concepts Migration from Master-Slave to GR How to monitor?

16 / 284 Agenda Prepare your workstation MySQL InnoDB Cluster & Group Replication concepts Migration from Master-Slave to GR How to monitor? Application interaction

17 / 284 VirtualBox Setup your workstation

18 / 284 Setup your workstation Install VirtualBox 5 On the USB key, copy PL17_GR.ova on your laptop and doubleclick on it Ensure you have vboxnet2 network interface (VirtualBox Preferences -> Network -> Host-Only Networks -> +) Start all virtual machines (mysql1, mysql2, mysql3 & mysql4) Install putty if you are using Windows

19 / 284 Setup your workstation Install VirtualBox 5 On the USB key, copy PL17_GR.ova on your laptop and doubleclick on it Ensure you have vboxnet2 network interface (VirtualBox Preferences -> Network -> Host-Only Networks -> +) Start all virtual machines (mysql1, mysql2, mysql3 & mysql4) Install putty if you are using Windows Try to connect to all VM s from your terminal or putty (root password is X) : ssh -p 8821 root@127.0.0.1 to mysql1 ssh -p 8822 root@127.0.0.1 to mysql2 ssh -p 8823 root@127.0.0.1 to mysql3 ssh -p 8824 root@127.0.0.1 to mysql4

20 / 284 LAB1: Current situation

21 / 284 LAB1: Current situation launch run_app.sh on mysql1 into a screen session verify that mysql2 is a running slave

22 / 284 Summary +--------+----------+--------------+-----------------+ ROLE SSH PORT INTERNAL IP +--------+----------+--------------+-----------------+ mysql1 master 8821 192.168.56.11 mysql2 slave 8822 192.168.56.12 mysql3 n/a 8823 192.168.56.13 mysql4 n/a 8824 192.168.56.14 +--------+----------+--------------+-----------------+

23 / 284 Easy High Availability MySQL InnoDB Cluster

24 / 284 Ease-of-Use Built-inHA InnoDB cluster Out-of-BoxSolution EverythingIntegr ated ExtremeScale-Out HighP erformance

25 / 284 Our vision in 4 steps MySQLDocumentStore Relational &DocumentModels E1 E3 ReadScale-Out AsyncReplication +A utof ailover E2 MySQLHA Out-Of-BoxHA WriteScale-Out E4 Sharding

MySQLConnector MySQLConnector 26 / 284 Step 2 s Architecture Application Application MySQLRouter MySQLRouter Mp MySQLShell M InnoDB cluster M

MySQLConnector MySQLConnector 27 / 284 Step 3 s Architecture Application Application MySQLRouter MySQLRouter Mp MySQLShell M InnoDB cluster M S1 S2 S3 S4 S...

MySQLRouter MySQLRouter MySQLRouter MySQLRouter MySQLRouter 28 / 284 Step 4 s Architecture Application MySQLConnector Application MySQLConnector Application MySQLConnector Application MySQLConnector Application MySQLConnector Mp Mp Mp MySQLShell replicaset1 S1 M M InnoDB cluster S2 S3 S4 S... replicaset2 M M InnoDB cluster S1 S2 S3 S4 S... replicaset3 M M InnoDB cluster S1 S2 S3 S4 S...

29 / 284 the magic explained Group Replication Concept

30 / 284 Group Replication: heart of MySQL InnoDB Cluster

31 / 284 Group Replication: heart of MySQL InnoDB Cluster

32 / 284 MySQL Group Replication but what is it?!?

33 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL

34 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL GR is an implementation of Replicated Database State Machine theory

35 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL GR is an implementation of Replicated Database State Machine theory GR allows to write on all Group Members (cluster nodes) simultaneously while retaining consistency

36 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL GR is an implementation of Replicated Database State Machine theory GR allows to write on all Group Members (cluster nodes) simultaneously while retaining consistency GR implements conflict detection and resolution

37 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL GR is an implementation of Replicated Database State Machine theory GR allows to write on all Group Members (cluster nodes) simultaneously while retaining consistency GR implements conflict detection and resolution GR allows automatic distributed recovery

38 / 284 MySQL Group Replication but what is it?!? GR is a plugin for MySQL, made by MySQL and packaged with MySQL GR is an implementation of Replicated Database State Machine theory GR allows to write on all Group Members (cluster nodes) simultaneously while retaining consistency GR implements conflict detection and resolution GR allows automatic distributed recovery Supported on all MySQL platforms!! Linux, Windows, Solaris, OSX, FreeBSD

39 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol

40 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine

41 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine Paxos based protocol

42 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine Paxos based protocol its task: deliver messages across the distributed system:

43 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine Paxos based protocol its task: deliver messages across the distributed system: atomically

44 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine Paxos based protocol its task: deliver messages across the distributed system: atomically in Total Order

45 / 284 MySQL Group Communication System (GCS) MySQL Xcom protocol Replicated Database State Machine Paxos based protocol its task: deliver messages across the distributed system: atomically in Total Order MySQL Group Replication receives the Ordered 'tickets' from this GCS subsystem.

46 / 284 And for users?

47 / 284 And for users? not longer necessary to handle server fail-over manually or with a complicated script

48 / 284 And for users? not longer necessary to handle server fail-over manually or with a complicated script GR provides fault tolerance

49 / 284 And for users? not longer necessary to handle server fail-over manually or with a complicated script GR provides fault tolerance GR enables update-everywhere setups

50 / 284 And for users? not longer necessary to handle server fail-over manually or with a complicated script GR provides fault tolerance GR enables update-everywhere setups GR handles crashes, failures, re-connects automatically

51 / 284 And for users? not longer necessary to handle server fail-over manually or with a complicated script GR provides fault tolerance GR enables update-everywhere setups GR handles crashes, failures, re-connects automatically Allows an easy setup of a highly available MySQL service!

52 / 284 OK, but how does it work?

53 / 284 OK, but how does it work? it s just magic!

54 / 284 OK, but how does it work? it s just magic!... no, in fact the writeset delivery is synchronous and then certification and apply of the changes are local to each nodes and happen asynchronous.

55 / 284 OK, but how does it work? it s just magic!... no, in fact the writeset delivery is synchronous and then certification and apply of the changes are local to each nodes and happen asynchronous. not that easy to understand... right?

56 / 284 OK, but how does it work? it s just magic!... no, in fact the writeset delivery is synchronous and then certification and apply of the changes are local to each nodes and happen asynchronous. not that easy to understand... right? As a picture is worth a 1000 words, let s illustrate this...

57 / 284 MySQL Group Replication (autocommit)

58 / 284 MySQL Group Replication (autocommit)

59 / 284 MySQL Group Replication (autocommit)

60 / 284 MySQL Group Replication (autocommit)

61 / 284 MySQL Group Replication (autocommit)

62 / 284 MySQL Group Replication (autocommit)

63 / 284 MySQL Group Replication (autocommit)

64 / 284 MySQL Group Replication (autocommit)

65 / 284 MySQL Group Replication (autocommit)

66 / 284 MySQL Group Replication (autocommit)

67 / 284 MySQL Group Replication (autocommit)

68 / 284 MySQL Group Replication (autocommit)

69 / 284 MySQL Group Replication (full transaction)

70 / 284 MySQL Group Replication (full transaction)

71 / 284 MySQL Group Replication (full transaction)

72 / 284 MySQL Group Replication (full transaction)

73 / 284 MySQL Group Replication (full transaction)

74 / 284 MySQL Group Replication (full transaction)

75 / 284 MySQL Group Replication (full transaction)

76 / 284 MySQL Group Replication (full transaction)

77 / 284 MySQL Group Replication (full transaction)

78 / 284 Group Replication : Total Order Delivery - GTID

79 / 284 Group Replication : Total Order Delivery - GTID

80 / 284 Group Replication : Total Order Delivery - GTID

81 / 284 Group Replication : Total Order Delivery - GTID

82 / 284 Group Replication : Total Order Delivery - GTID

83 / 284 Group Replication : Total Order Delivery - GTID

84 / 284 Group Replication : Total Order Delivery - GTID

85 / 284 Group Replication : Total Order Delivery - GTID

86 / 284 Group Replication : Total Order Delivery - GTID

87 / 284 Group Replication : Total Order Delivery - GTID

88 / 284 Group Replication : Total Order Delivery - GTID

89 / 284 Group Replication : Total Order Delivery - GTID

90 / 284 Group Replication : Total Order Delivery - GTID

91 / 284 Group Replication : Total Order Delivery - GTID

92 / 284 Group Replication : Total Order Delivery - GTID

93 / 284 Group Replication : Total Order Delivery - GTID

94 / 284 Group Replication : Total Order Delivery - GTID

95 / 284 Group Replication : Total Order Delivery - GTID

96 / 284 Group Replication : Total Order Delivery - GTID

97 / 284 Group Replication: return commit Asynchronous Replication:

98 / 284 Group Replication: return from commit (2) Semi-Sync Replication:

99 / 284 Group Replication: return from commit (3) Group Replication:

100 / 284 Group Replication : Optimistic Locking Group Replication uses optimistic locking during a transaction, local (InnoDB) locking happens optimistically assumes there will be no conflicts across nodes (no communication between nodes necessary) cluster-wide conflict resolution happens only at COMMIT, during certification Let s first have a look at the traditional locking to compare.

101 / 284 Traditional locking

102 / 284 Traditional locking

103 / 284 Traditional locking

104 / 284 Traditional locking

105 / 284 Traditional locking

106 / 284 Traditional locking

107 / 284 Optimistic Locking

108 / 284 Optimistic Locking

109 / 284 Optimistic Locking

110 / 284 Optimistic Locking

111 / 284 Optimistic Locking

112 / 284 Optimistic Locking

113 / 284 Optimistic Locking The system returns error 149 as certification failed: ERROR 1180 (HY000): Got error 149 during COMMIT

114 / 284 Certification Certification is the process that only needs to answer the following unique question:

115 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied?

116 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions

117 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes

118 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation

119 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node

120 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node communication with other members is not needed for certification

121 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node communication with other members is not needed for certification pass: enter in the apply queue

122 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node communication with other members is not needed for certification pass: enter in the apply queue fail: drop the transaction

123 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node communication with other members is not needed for certification pass: enter in the apply queue fail: drop the transaction serialized by the total order in GCS/Xcom + GTID

124 / 284 Certification Certification is the process that only needs to answer the following unique question: can the write (transaction) be applied? based on unapplied earlier transactions such conflicts must come for other members/nodes certification is a deterministic operation certification individually happens on every member/node communication with other members is not needed for certification pass: enter in the apply queue fail: drop the transaction serialized by the total order in GCS/Xcom + GTID first committer wins rule

125 / 284 Drawbacks of optimistic locking having a first-committer-wins system means conflicts will more likely happen with:

126 / 284 Drawbacks of optimistic locking having a first-committer-wins system means conflicts will more likely happen with: large transactions

127 / 284 Drawbacks of optimistic locking having a first-committer-wins system means conflicts will more likely happen with: large transactions long running transactions

128 / 284 GTID GTIDs are the same as those used by asynchronous replication. mysql> SELECT * FROM performance_schema.replication_connection_status\g ************************** 1. row *************************** CHANNEL_NAME: group_replication_applier GROUP_NAME: afb80f36-2bff-11e6-84e0-0800277dd3bf SOURCE_UUID: afb80f36-2bff-11e6-84e0-0800277dd3bf THREAD_ID: NULL SERVICE_STATE: ON COUNT_RECEIVED_HEARTBEATS: 0 LAST_HEARTBEAT_TIMESTAMP: 0000-00-00 00:00:00 RECEIVED_TRANSACTION_SET: afb80f36-2bff-11e6-84e0-0800277dd3bf:1-57, f037578b-46b1-11e6-8005-08002774c31b:1-48937 LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00

129 / 284 GTID but transactions use the Group Name / UUID in the GTIDs mysql> show master status\g ************************** 1. row *************************** File: mysql4-bin.000001 Position: 1501 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: afb80f36-2bff-11e6-84e0-0800277dd3bf:1-57, f037578b-46b1-11e6-8005-08002774c31b:1-48937

130 / 284 Requirements exclusively works with InnoDB tables

131 / 284 Requirements exclusively works with InnoDB tables every table must have a PK defined

132 / 284 Requirements exclusively works with InnoDB tables every table must have a PK defined only IPV4 is supported

133 / 284 Requirements exclusively works with InnoDB tables every table must have a PK defined only IPV4 is supported a good network with low latency is important

134 / 284 Requirements exclusively works with InnoDB tables every table must have a PK defined only IPV4 is supported a good network with low latency is important maximum of 9 members per group

135 / 284 Requirements exclusively works with InnoDB tables every table must have a PK defined only IPV4 is supported a good network with low latency is important maximum of 9 members per group log-bin must be enabled and only binlog_format=row is supported

136 / 284 Requirements (2) enable GTIDs

137 / 284 Requirements (2) enable GTIDs replication meta-data must be stored in system tables --master-info-repository=table --relay-log-info-repository=table

138 / 284 Requirements (2) enable GTIDs replication meta-data must be stored in system tables --master-info-repository=table --relay-log-info-repository=table writesets extraction must be enabled --transaction-write-set-extraction=xxhash64

139 / 284 Requirements (2) enable GTIDs replication meta-data must be stored in system tables --master-info-repository=table --relay-log-info-repository=table writesets extraction must be enabled --transaction-write-set-extraction=xxhash64 log-slave-updates must also be enabled

140 / 284 Limitations binlog checksum is not supported --binlog-checksum=none

141 / 284 Limitations binlog checksum is not supported --binlog-checksum=none savepoints were not supported before 5.7.19 & 8.0.1

142 / 284 Limitations binlog checksum is not supported --binlog-checksum=none savepoints were not supported before 5.7.19 & 8.0.1 SERIALIZABLE is not supported as transaction isolation level

143 / 284 Limitations binlog checksum is not supported --binlog-checksum=none savepoints were not supported before 5.7.19 & 8.0.1 SERIALIZABLE is not supported as transaction isolation level http://lefred.be/content/mysql-group-replication-limitations-savepoints/ http://lefred.be/content/mysql-group-replication-and-table-design/

144 / 284 Is my workload ready for Group Replication? As the writesets (transactions) are replicated to all available nodes on commit, and as they are certified on every node, a very large writeset could increase the amount of certification errors.

145 / 284 Is my workload ready for Group Replication? As the writesets (transactions) are replicated to all available nodes on commit, and as they are certified on every node, a very large writeset could increase the amount of certification errors. Additionally, changing the same record on all the nodes (hotspot) concurrently will also cause problems.

146 / 284 Is my workload ready for Group Replication? As the writesets (transactions) are replicated to all available nodes on commit, and as they are certified on every node, a very large writeset could increase the amount of certification errors. Additionally, changing the same record on all the nodes (hotspot) concurrently will also cause problems. And finally, the certification uses the primary key of the tables, a table without PK is also a problem.

147 / 284 Is my workload ready for Group Replication? Therefore, when using Group Replication, we should pay attention to these points:

148 / 284 Is my workload ready for Group Replication? Therefore, when using Group Replication, we should pay attention to these points: PK is mandatory (and a good one is better)

149 / 284 Is my workload ready for Group Replication? Therefore, when using Group Replication, we should pay attention to these points: PK is mandatory (and a good one is better) avoid large transactions

150 / 284 Is my workload ready for Group Replication? Therefore, when using Group Replication, we should pay attention to these points: PK is mandatory (and a good one is better) avoid large transactions avoid hotspot

151 / 284 ready? Migration from Master-Slave to GR

152 / 284 The plan

153 / 284 The plan 1) We install and setup MySQL InnoDB Cluster on one of the new servers

154 / 284 The plan 2) We restore a backup 3) setup asynchronous replication on the new server.

155 / 284 The plan 4) We add a new instance to our group

156 / 284 The plan 5) We point the application to one of our new nodes. 6) We wait and check that asynchronous replication is caught up 7) we stop those asynchronous slaves

157 / 284 The plan 8) We attach the mysql2 slave to the group

158 / 284 The plan 9) Use MySQL Router for directing traffic

159 / 284 LAB2: Prepare mysql3 Asynchronous slave Latest MySQL 5.7 is already installed on mysql3. Let s take a backup on mysql1: [mysql1 ~]# xtrabackup --backup \ --target-dir=/tmp/backup \ --user=root \ --password=x --host=127.0.0.1 [mysql1 ~]# xtrabackup --prepare \ --target-dir=/tmp/backup

160 / 284 LAB2: Prepare mysql3 (2) Asynchronous slave Copy the backup from mysql1 to mysql3: [mysql1 ~]# scp -r /tmp/backup mysql3:/tmp And restore it: [mysql3 ~]# xtrabackup --copy-back --target-dir=/tmp/backup [mysql3 ~]# chown -R mysql. /var/lib/mysql

161 / 284 LAB3: mysql3 as asynchronous slave (2) Asynchronous slave Configure /etc/my.cnf with the minimal requirements: [mysqld]... server_id=3 enforce_gtid_consistency = on gtid_mode = on log_bin log_slave_updates

162 / 284 LAB2: Prepare mysql3 (3) Asynchronous slave Let s start MySQL on mysql3: [mysql3 ~]# systemctl start mysqld

163 / 284 LAB3: mysql3 as asynchronous slave (1) find the GTIDs purged change MASTER set the purged GTIDs start replication

164 / 284 LAB3: mysql3 as asynchronous slave (2) Find the latest purged GTIDs: [mysql3 ~]# cat /tmp/backup/xtrabackup_binlog_info mysql-bin.000002 167646328 b346474c-8601-11e6-9b39-08002718d305:1-771 Connect to mysql3 and setup replication: mysql> CHANGE MASTER TO MASTER_HOST="mysql1", MASTER_USER="repl_async", MASTER_PASSWORD='Xslave', MASTER_AUTO_POSITION=1; mysql> RESET MASTER; mysql> SET global gtid_purged="value FOUND PREVIOUSLY"; mysql> START SLAVE; Check that you receive the application s traffic

165 / 284 Administration made easy and more... MySQL-Shell

166 / 284 MySQL Shell The MySQL Shell is an interactive Javascript, Python, or SQL interface supporting development and administration for MySQL. MySQL Shell includes the AdminAPI--available in JavaScript and Python--which enables you to set up and manage InnoDB clusters. It provides a modern and fluent API which hides the complexity associated with configuring, provisioning, and managing an InnoDB cluster, without sacrificing power, flexibility, or security.

167 / 284 MySQL Shell (2) The MySQL Shell provides:

168 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations

169 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models

170 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting

171 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats

172 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats MySQL Standard and X Protocols

173 / 284 MySQL Shell (2) The MySQL Shell provides: Both Interactive and Batch operations Document and Relational Models CRUD Document and Relational APIs via scripting Traditional Table, JSON, Tab Separated output results formats MySQL Standard and X Protocols and more...

174 / 284 LAB4: MySQL InnoDB Cluster Create a single instance cluster Time to use the new MySQL Shell! [mysql3 ~]# mysqlsh Let s verify if our server is ready to become a member of a new cluster: mysql-js> dba.checkinstancecon guration('root@mysql3:3306')

175 / 284 LAB4: MySQL InnoDB Cluster Create a single instance cluster Time to use the new MySQL Shell! [mysql3 ~]# mysqlsh Let s verify if our server is ready to become a member of a new cluster: mysql-js> dba.checkinstancecon guration('root@mysql3:3306') Change the configuration! mysql-js> dba.con gurelocalinstance()

176 / 284 LAB4: MySQL InnoDB Cluster (2) Restart mysqld to use the new configuration: [mysql3 ~]# systemctl restart mysqld

177 / 284 LAB4: MySQL InnoDB Cluster (2) Restart mysqld to use the new configuration: [mysql3 ~]# systemctl restart mysqld Create a single instance cluster [mysql3 ~]# mysqlsh

178 / 284 LAB4: MySQL InnoDB Cluster (2) Restart mysqld to use the new configuration: [mysql3 ~]# systemctl restart mysqld Create a single instance cluster [mysql3 ~]# mysqlsh mysql-js> dba.checkinstancecon guration('root@mysql3:3306') mysql-js> \c root@mysql3:3306 mysql-js> cluster = dba.createcluster('perconalive')

179 / 284 LAB4: Cluster Status mysql-js> cluster.status() { "clustername": "perconalive", "defaultreplicaset": { "name": "default", "primary": "mysql3:3306", "status": "OK_NO_TOLERANCE", "statustext": "Cluster is NOT tolerant to any failures.", "topology": { "mysql3:3306": { "address": "mysql3:3306", "mode": "R/W", "readreplicas": {}, "role": "HA", "status": "ONLINE" } } } }

180 / 284 LAB5: add mysql4 to the cluster (1) Add mysql4 to the Group: restore the backup set the purged GTIDs use MySQL shell

181 / 284 LAB5: add mysql4 to the cluster (2) Copy the backup from mysql1 to mysql4: [mysql1 ~]# scp -r /tmp/backup mysql4:/tmp And restore it: [mysql4 ~]# xtrabackup --copy-back --target-dir=/tmp/backup [mysql4 ~]# chown -R mysql. /var/lib/mysql Start MySQL on mysql4: [mysql4 ~]# systemctl start mysqld

182 / 284 LAB5: MySQL shell to add an instance (3) [mysql4 ~]# mysqlsh Let s verify the config: mysql-js> dba.checkinstancecon guration('root@mysql4:3306')

183 / 284 LAB5: MySQL shell to add an instance (3) [mysql4 ~]# mysqlsh Let s verify the config: mysql-js> dba.checkinstancecon guration('root@mysql4:3306') And change the configuration: mysql-js> dba.con gurelocalinstance()

184 / 284 LAB5: MySQL shell to add an instance (3) [mysql4 ~]# mysqlsh Let s verify the config: mysql-js> dba.checkinstancecon guration('root@mysql4:3306') And change the configuration: mysql-js> dba.con gurelocalinstance() Restart the service to enable the changes: [mysql4 ~]# systemctl restart mysqld

185 / 284 LAB5: MySQL InnoDB Cluster (4) Group of 2 instances Find the latest purged GTIDs: [mysql4 ~]# cat /tmp/backup/xtrabackup_binlog_info mysql-bin.000002 167646328 b346474c-8601-11e6-9b39-08002718d305:1-77177 Connect to mysql4 and set GTID_PURGED [mysql4 ~]# mysqlsh mysql-js> \c root@mysql4:3306 mysql-js> \sql mysql-sql> RESET MASTER; mysql-sql> SET global gtid_purged="value FOUND PREVIOUSLY";

186 / 284 LAB5: MySQL InnoDB Cluster (5) mysql-sql> \js mysql-js> dba.checkinstancecon guration('root@mysql4:3306') mysql-js> \c root@mysql3:3306 mysql-js> cluster = dba.getcluster() mysql-js> cluster.checkinstancestate('root@mysql4:3306') mysql-js> cluster.addinstance("root@mysql4:3306") mysql-js> cluster.status()

187 / 284 Cluster Status mysql-js> cluster.status() { "clustername": "perconalive", "defaultreplicaset": { "name": "default", "primary": "mysql3:3306", "status": "OK_NO_TOLERANCE", "statustext": "Cluster is NOT tolerant to any failures.", "topology": { "mysql3:3306": { "address": "mysql3:3306", "mode": "R/W", "readreplicas": {}, "role": "HA", "status": "ONLINE" }, "mysql4:3306": { "address": "mysql4:3306", "mode": "R/O", "readreplicas": {}, "role": "HA", "status": "RECOVERING" } } }

188 / 284 Recovering progress On standard MySQL, monitor the group_replication_recovery channel to see the progress: mysql4> show slave status for channel 'group_replication_recovery'\g *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: mysql3 Master_User: mysql_innodb_cluster_rpl_user... Slave_IO_Running: Yes Slave_SQL_Running: Yes... Retrieved_Gtid_Set: 6e7d7848-860f-11e6-92e4-08002718d305:1-6, 7c1f0c2d-860d-11e6-9df7-08002718d305:1-15, b346474c-8601-11e6-9b39-08002718d305:1964-77177, e8c524df-860d-11e6-9df7-08002718d305:1-2 Executed_Gtid_Set: 7c1f0c2d-860d-11e6-9df7-08002718d305:1-7, b346474c-8601-11e6-9b39-08002718d305:1-45408, e8c524df-860d-11e6-9df7-08002718d305:1-2...

189 / 284 Migrate the application point the application to the cluster

190 / 284 LAB6: Migrate the application Now we need to point the application to mysql3, this is the only downtime!... [ 21257s] threads: 4, tps: 12.00, reads: 167.94, writes: 47.98, response time: 1 [ 21258s] threads: 4, tps: 6.00, reads: 83.96, writes: 23.99, response time: 1 [ 21259s] threads: 4, tps: 7.00, reads: 98.05, writes: 28.01, response time: 1 [ 31250s] threads: 4, tps: 8.00, reads: 111.95, writes: 31.99, response time: 3 [ 31251s] threads: 4, tps: 11.00, reads: 154.01, writes: 44.00, response time: 1 [ 31252s] threads: 4, tps: 11.00, reads: 153.94, writes: 43.98, response time: 1 [ 31253s] threads: 4, tps: 10.01, reads: 140.07, writes: 40.02, response time: 1 ^C [mysql1 ~]# run_app.sh mysql3

191 / 284 LAB6: Migrate the application Stop asynchronous replication on mysql2 and mysql3: mysql2> stop slave; mysql3> stop slave; Make sure gtid_executed range on mysql2 is lower or equal than on mysql3

192 / 284 LAB6: Migrate the application Stop asynchronous replication on mysql2 and mysql3: mysql2> stop slave; mysql3> stop slave; Make sure gtid_executed range on mysql2 is lower or equal than on mysql3 mysql[2-3]> show global variables like 'gtid_executed'\g mysql[2-3]> reset slave all;

193 / 284 Add a third instance previous slave (mysql2) can now be part of the cluster

194 / 284 LAB7: Add mysql2 to the group We first validate the instance using MySQL Shell and we configure it.

195 / 284 LAB7: Add mysql2 to the group We first validate the instance using MySQL Shell and we configure it. [mysql2 ~]# mysqlsh

196 / 284 LAB7: Add mysql2 to the group We first validate the instance using MySQL Shell and we configure it. [mysql2 ~]# mysqlsh mysql-js> dba.checkinstancecon guration('root@mysql2:3306') mysql-js> dba.con gurelocalinstance()

197 / 284 LAB7: Add mysql2 to the group We first validate the instance using MySQL Shell and we configure it. [mysql2 ~]# mysqlsh mysql-js> dba.checkinstancecon guration('root@mysql2:3306') mysql-js> dba.con gurelocalinstance() We also need to remove super_read_only from my.cnf to be able to use the shell to add the node to the cluster.

198 / 284 LAB7: Add mysql2 to the group We first validate the instance using MySQL Shell and we configure it. [mysql2 ~]# mysqlsh mysql-js> dba.checkinstancecon guration('root@mysql2:3306') mysql-js> dba.con gurelocalinstance() We also need to remove super_read_only from my.cnf to be able to use the shell to add the node to the cluster. [mysql2 ~]# systemctl restart mysqld

199 / 284 LAB7: Add mysql2 to the group (2) Back in MySQL shell we add the new instance: [mysql2 ~]# mysqlsh

200 / 284 LAB7: Add mysql2 to the group (2) Back in MySQL shell we add the new instance: [mysql2 ~]# mysqlsh mysql-js> dba.checkinstancecon guration('root@mysql2:3306') mysql-js> \c root@mysql3:3306 mysql-js> cluster = dba.getcluster() mysql-js> cluster.addinstance("root@mysql2:3306") mysql-js> cluster.status()

201 / 284 LAB7: Add mysql2 to the group (3) { "clustername": "perconalive", "defaultreplicaset": { "name": "default", "primary": "mysql3:3306", "status": "OK", "statustext": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": { "mysql2:3306": { "address": "mysql2:3306", "mode": "R/O", "readreplicas": {}, "role": "HA", "status": "ONLINE" }, "mysql3:3306": { "address": "mysql3:3306", "mode": "R/W", "readreplicas": {}, "role": "HA", "status": "ONLINE" }, "mysql4:3306": { "address": "mysql4:3306", "mode": "R/O", "readreplicas": {},

202 / 284 writing to a single server Single Primary Mode

203 / 284 Default = Single Primary Mode By default, MySQL InnoDB Cluster enables Single Primary Mode.

204 / 284 Default = Single Primary Mode By default, MySQL InnoDB Cluster enables Single Primary Mode. mysql> show global variables like 'group_replication_single_primary_mode'; +---------------------------------------+-------+ Variable_name Value +---------------------------------------+-------+ group_replication_single_primary_mode ON +---------------------------------------+-------+

205 / 284 Default = Single Primary Mode By default, MySQL InnoDB Cluster enables Single Primary Mode. mysql> show global variables like 'group_replication_single_primary_mode'; +---------------------------------------+-------+ Variable_name Value +---------------------------------------+-------+ group_replication_single_primary_mode ON +---------------------------------------+-------+ In Single Primary Mode, a single member acts as the writable master (PRIMARY) and the rest of the members act as hot-standbys (SECONDARY). The group itself coordinates and configures itself automatically to determine which member will act as the PRIMARY, through a leader election mechanism.

206 / 284 Who s the Primary Master? As the Primary Master is elected, all nodes part of the group knows which one was elected. This value is exposed in status variables:

207 / 284 Who s the Primary Master? As the Primary Master is elected, all nodes part of the group knows which one was elected. This value is exposed in status variables: mysql> show status like 'group_replication_primary_member'; +----------------------------------+--------------------------------------+ Variable_name Value +----------------------------------+--------------------------------------+ group_replication_primary_member 28a4e51f-860e-11e6-bdc4-08002718d305 +----------------------------------+--------------------------------------+

208 / 284 Who s the Primary Master? As the Primary Master is elected, all nodes part of the group knows which one was elected. This value is exposed in status variables: mysql> show status like 'group_replication_primary_member'; +----------------------------------+--------------------------------------+ Variable_name Value +----------------------------------+--------------------------------------+ group_replication_primary_member 28a4e51f-860e-11e6-bdc4-08002718d305 +----------------------------------+--------------------------------------+ mysql> select member_host as "primary master" from performance_schema.global_status join performance_schema.replication_group_members where variable_name = 'group_replication_primary_member' and member_id=variable_value; +---------------+ primary master +---------------+ mysql3 +---------------+

209 / 284 Create a Multi-Primary Cluster: It s also possible to create a Multi-Primary Cluster using the Shell:

210 / 284 Create a Multi-Primary Cluster: It s also possible to create a Multi-Primary Cluster using the Shell: mysql-js> cluster=dba.createcluster('perconalive',{multimaster: true})

211 / 284 Create a Multi-Primary Cluster: It s also possible to create a Multi-Primary Cluster using the Shell: mysql-js> cluster=dba.createcluster('perconalive',{multimaster: true}) A new InnoDB cluster will be created on instance 'root@mysql3:3306'. The MySQL InnoDB cluster is going to be setup in advanced Multi-Master Mode. Before continuing you have to con rm that you understand the requirements and limitations of Multi-Master Mode. Please read the manual before proceeding. I have read the MySQL InnoDB cluster manual and I understand the requirements and limitations of advanced Multi-Master Mode. Con rm [y N]:

212 / 284 Create a Multi-Primary Cluster: It s also possible to create a Multi-Primary Cluster using the Shell: mysql-js> cluster=dba.createcluster('perconalive',{multimaster: true}) A new InnoDB cluster will be created on instance 'root@mysql3:3306'. The MySQL InnoDB cluster is going to be setup in advanced Multi-Master Mode. Before continuing you have to con rm that you understand the requirements and limitations of Multi-Master Mode. Please read the manual before proceeding. I have read the MySQL InnoDB cluster manual and I understand the requirements and limitations of advanced Multi-Master Mode. Con rm [y N]: Or you can force it to avoid interaction (for automation) :

213 / 284 Create a Multi-Primary Cluster: It s also possible to create a Multi-Primary Cluster using the Shell: mysql-js> cluster=dba.createcluster('perconalive',{multimaster: true}) A new InnoDB cluster will be created on instance 'root@mysql3:3306'. The MySQL InnoDB cluster is going to be setup in advanced Multi-Master Mode. Before continuing you have to con rm that you understand the requirements and limitations of Multi-Master Mode. Please read the manual before proceeding. I have read the MySQL InnoDB cluster manual and I understand the requirements and limitations of advanced Multi-Master Mode. Con rm [y N]: Or you can force it to avoid interaction (for automation) : > cluster=dba.createcluster('perconalive',{multimaster: true, force: true})

214 / 284 get more info Monitoring

215 / 284 Performance Schema Group Replication uses Performance_Schema to expose status mysql3> SELECT * FROM performance_schema.replication_group_members\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 00db47c7-3e23-11e6-afd4-08002774c31b MEMBER_HOST: mysql3.localdomain MEMBER_PORT: 3306 MEMBER_STATE: ONLINE

216 / 284 Performance Schema Group Replication uses Performance_Schema to expose status mysql3> SELECT * FROM performance_schema.replication_group_members\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 00db47c7-3e23-11e6-afd4-08002774c31b MEMBER_HOST: mysql3.localdomain MEMBER_PORT: 3306 MEMBER_STATE: ONLINE mysql3> SELECT * FROM performance_schema.replication_connection_status\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier GROUP_NAME: afb80f36-2bff-11e6-84e0-0800277dd3bf SOURCE_UUID: afb80f36-2bff-11e6-84e0-0800277dd3bf THREAD_ID: NULL SERVICE_STATE: ON COUNT_RECEIVED_HEARTBEATS: 0 LAST_HEARTBEAT_TIMESTAMP: 0000-00-00 00:00:00 RECEIVED_TRANSACTION_SET: afb80f36-2bff-11e6-84e0-0800277dd3bf:1-2 LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00

217 / 284 Member State These are the different possible state for a node member: ONLINE OFFLINE RECOVERING ERROR: when a node is leaving but the plugin was not instructed to stop UNREACHABLE

218 / 284 Status information & metrics Members mysql> SELECT * FROM performance_schema.replication_group_members\g

219 / 284 Status information & metrics Members mysql> SELECT * FROM performance_schema.replication_group_members\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 00db47c7-3e23-11e6-afd4-08002774c31b MEMBER_HOST: mysql3.localdomain MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: e1544c9d-4451-11e6-9f5a-08002774c31b MEMBER_HOST: mysql4.localdomain.localdomain MEMBER_PORT: 3306 MEMBER_STATE: ONLINE

220 / 284 Status information & metrics Connections mysql> SELECT * FROM performance_schema.replication_connection_status\g

221 / 284 Status information & metrics Connections mysql> SELECT * FROM performance_schema.replication_connection_status\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier GROUP_NAME: afb80f36-2bff-11e6-84e0-0800277dd3bf SOURCE_UUID: afb80f36-2bff-11e6-84e0-0800277dd3bf THREAD_ID: NULL SERVICE_STATE: ON COUNT_RECEIVED_HEARTBEATS: 0 LAST_HEARTBEAT_TIMESTAMP: 0000-00-00 00:00:00 RECEIVED_TRANSACTION_SET: 5de4400b-3dd7-11e6-8a71-08002774c31b:1-814089, afb80f36-2bff-11e6-84e0-0800277dd3bf:1-2834 LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00 *************************** 2. row *************************** CHANNEL_NAME: group_replication_recovery GROUP_NAME: SOURCE_UUID: THREAD_ID: NULL SERVICE_STATE: OFF

222 / 284 Status information & metrics Local node status mysql> select * from performance_schema.replication_group_member_stats\g

223 / 284 Status information & metrics Local node status mysql> select * from performance_schema.replication_group_member_stats\g *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier VIEW_ID: 14679667214442885:4 MEMBER_ID: e1544c9d-4451-11e6-9f5a-08002774c31b COUNT_TRANSACTIONS_IN_QUEUE: 0 COUNT_TRANSACTIONS_CHECKED: 5961 COUNT_CONFLICTS_DETECTED: 0 COUNT_TRANSACTIONS_ROWS_VALIDATING: 0 TRANSACTIONS_COMMITTED_ALL_MEMBERS: 5de4400b-3dd7-11e6-8a71-08002774c31b:1-81408 afb80f36-2bff-11e6-84e0-0800277dd3bf:1-5718 LAST_CONFLICT_FREE_TRANSACTION: afb80f36-2bff-11e6-84e0-0800277dd3bf:5718

224 / 284 Performance_Schema You can find GR information in the following Performance_Schema tables: replication_applier_con guration replication_applier_status replication_applier_status_by_worker replication_connection_con guration replication_connection_status replication_group_member_stats replication_group_members

225 / 284 Status during recovery mysql> SHOW SLAVE STATUS FOR CHANNEL 'group_replication_recovery'\g

226 / 284 Status during recovery mysql> SHOW SLAVE STATUS FOR CHANNEL 'group_replication_recovery'\g *************************** 1. row *************************** Slave_IO_State: Master_Host: <NULL> Master_User: gr_repl Master_Port: 0... Relay_Log_File: mysql4-relay-bin-group_replication_recovery.00000... Slave_IO_Running: No Slave_SQL_Running: No... Executed_Gtid_Set: 5de4400b-3dd7-11e6-8a71-08002774c31b:1-814089, afb80f36-2bff-11e6-84e0-0800277dd3bf:1-5718... Channel_Name: group_replication_recovery

227 / 284 Sys Schema The easiest way to detect if a node is a member of the primary component (when there are partitioning of your nodes due to network issues for example) and therefore a valid candidate for routing queries to it, is to use the sys table. Additional information for sys can be downloaded at https://github.com/lefred/mysql_gr_routing_check/blob/master/addition_to_sys.sql On the primary node: [mysql? ~]# mysql < /tmp/addition_to_sys.sql

228 / 284 Sys Schema Is this node part of PRIMARY Partition: mysql3> SELECT sys.gr_member_in_primary_partition(); +------------------------------------+ sys.gr_node_in_primary_partition() +------------------------------------+ YES +------------------------------------+

229 / 284 Sys Schema Is this node part of PRIMARY Partition: mysql3> SELECT sys.gr_member_in_primary_partition(); +------------------------------------+ sys.gr_node_in_primary_partition() +------------------------------------+ YES +------------------------------------+ To use as healthcheck: mysql3> SELECT * FROM sys.gr_member_routing_candidate_status; +------------------+-----------+---------------------+----------------------+ viable_candidate read_only transactions_behind transactions_to_cert +------------------+-----------+---------------------+----------------------+ YES YES 0 0 +------------------+-----------+---------------------+----------------------+

230 / 284 LAB8: Sys Schema - Health Check On one of the non Primary nodes, run the following command: mysql-sql> ush tables with read lock;

231 / 284 LAB8: Sys Schema - Health Check On one of the non Primary nodes, run the following command: mysql-sql> ush tables with read lock; Now you can verify what the healthcheck exposes to you: mysql-sql> SELECT * FROM sys.gr_member_routing_candidate_status; +------------------+-----------+---------------------+----------------------+ viable_candidate read_only transactions_behind transactions_to_cert +------------------+-----------+---------------------+----------------------+ YES YES 950 0 +------------------+-----------+---------------------+----------------------+

232 / 284 LAB8: Sys Schema - Health Check On one of the non Primary nodes, run the following command: mysql-sql> ush tables with read lock; Now you can verify what the healthcheck exposes to you: mysql-sql> SELECT * FROM sys.gr_member_routing_candidate_status; +------------------+-----------+---------------------+----------------------+ viable_candidate read_only transactions_behind transactions_to_cert +------------------+-----------+---------------------+----------------------+ YES YES 950 0 +------------------+-----------+---------------------+----------------------+ mysql-sql> UNLOCK TABLES;

233 / 284 application interaction MySQL Router

234 / 284 MySQL Router MySQL Router is lightweight middleware that provides transparent routing between your application and backend MySQL Servers. It can be used for a wide variety of use cases, such as providing high availability and scalability by effectively routing database traffic to appropriate backend MySQL Servers.

235 / 284 MySQL Router MySQL Router is lightweight middleware that provides transparent routing between your application and backend MySQL Servers. It can be used for a wide variety of use cases, such as providing high availability and scalability by effectively routing database traffic to appropriate backend MySQL Servers. MySQL Router doesn t require any specific configuration. It configures itself automatically (bootstrap) using MySQL InnoDB Cluster s metadata.

236 / 284 LAB9: MySQL Router We will now use mysqlrouter between our application and the cluster.

237 / 284 LAB9: MySQL Router (2) Configure MySQL Router that will run on the app server (mysql1). We bootstrap it using the Primary-Master: [root@mysql1 ~]# mysqlrouter --bootstrap mysql3:3306 --user mysqlrouter Please enter MySQL password for root: WARNING: The MySQL server does not have SSL con gured and metadata used by the r Bootstrapping system MySQL Router instance... MySQL Router has now been con gured for the InnoDB cluster 'perconalive'. The following connection information can be used to connect to the cluster. Classic MySQL protocol connections to cluster 'perconalive': - Read/Write Connections: localhost:6446 - Read/Only Connections: localhost:6447 X protocol connections to cluster 'perconalive': - Read/Write Connections: localhost:64460 - Read/Only Connections: localhost:64470 [root@mysql1 ~]# chown -R mysqlrouter. /var/lib/mysqlrouter

238 / 284 LAB9: MySQL Router (3) Now let s modify the configuration file to listen on port 3306:

239 / 284 LAB9: MySQL Router (3) Now let s modify the configuration file to listen on port 3306: in /etc/mysqlrouter/mysqlrouter.conf: [routing:perconalive_default_rw] -bind_port=6446 +bind_port=3306

240 / 284 LAB9: MySQL Router (3) Now let s modify the configuration file to listen on port 3306: in /etc/mysqlrouter/mysqlrouter.conf: [routing:perconalive_default_rw] -bind_port=6446 +bind_port=3306 We can stop mysqld on mysql1 and start mysqlrouter into a screen session: [mysql1 ~]# systemctl stop mysqld [mysql1 ~]# systemctl start mysqlrouter

241 / 284 LAB9: MySQL Router (4) Before killing a member we will change systemd s default behavior that restarts mysqld immediately:

242 / 284 LAB9: MySQL Router (4) Before killing a member we will change systemd s default behavior that restarts mysqld immediately: in /usr/lib/systemd/system/mysqld.service add the following under [Service] RestartSec=30 [mysql3 ~]# systemctl daemon-reload

243 / 284 LAB9: MySQL Router (5) Now we can point the application to the router (back to mysql1): [mysql1 ~]# run_app.sh

244 / 284 LAB9: MySQL Router (5) Now we can point the application to the router (back to mysql1): [mysql1 ~]# run_app.sh Check app and kill mysqld on mysql3 (the Primary Master R/W node)! [mysql3 ~]# kill -9 $(pidof mysqld)

245 / 284 LAB9: MySQL Router (5) Now we can point the application to the router (back to mysql1): [mysql1 ~]# run_app.sh Check app and kill mysqld on mysql3 (the Primary Master R/W node)! [mysql3 ~]# kill -9 $(pidof mysqld) mysql2> select member_host as "primary" from performance_schema.global_status join performance_schema.replication_group_members where variable_name = 'group_replication_primary_member' and member_id=variable_value; +---------+ primary +---------+ mysql4 +---------+

246 / 284 ProxySQL / HA Proxy / F5 /... 3rd party router/proxy

247 / 284 3rd party router/proxy MySQL InnoDB Cluster can also work with third party router / proxy.

248 / 284 3rd party router/proxy MySQL InnoDB Cluster can also work with third party router / proxy. If you need some specific features that are not yet available in MySQL Router, like transparent R/W splitting, then you can use your software of choice.

249 / 284 3rd party router/proxy MySQL InnoDB Cluster can also work with third party router / proxy. If you need some specific features that are not yet available in MySQL Router, like transparent R/W splitting, then you can use your software of choice. The important part of such implementation is to use a good health check to verify if the MySQL server you plan to route the traffic is in a valid state.

250 / 284 3rd party router/proxy MySQL InnoDB Cluster can also work with third party router / proxy. If you need some specific features that are not yet available in MySQL Router, like transparent R/W splitting, then you can use your software of choice. The important part of such implementation is to use a good health check to verify if the MySQL server you plan to route the traffic is in a valid state. MySQL Router implements that natively, and it s very easy to deploy.

251 / 284 3rd party router/proxy MySQL InnoDB Cluster can also work with third party router / proxy. If you need some specific features that are not yet available in MySQL Router, like transparent R/W splitting, then you can use your software of choice. The important part of such implementation is to use a good health check to verify if the MySQL server you plan to route the traffic is in a valid state. MySQL Router implements that natively, and it s very easy to deploy. ProxySQL also has native support for Group Replication which makes it maybe the best choice for advanced users.