SlideShare a Scribd company logo
Copyright 2015 Severalnines AB
Managing MySQL Replication for High Availability
February 2, 2016
Krzysztof Książek
Severalnines
krzysztof@severalnines.com
1
2
Your host & some logistics
I'm Jean-Jérôme from the Severalnines Team
and I'm your host for today's webinar!
Feel free to ask any questions in the
Questions section of this application or via
the Chat box.
You can also contact me directly via the chat
box or via email: jj@severalnines.com
during or after the webinar.
Copyright 2015 Severalnines AB
! MySQL replication and ClusterControl (Demo)
! Deployment
! Topology changes
! Important metrics
! How to deal with
! Schema changes
! Topology changes
! Potential issues in MySQL replication

3
Agenda
Copyright 2015 Severalnines AB
! Available since 3.23
! Proven, robust, based on binary logs
! GTID introduced in MySQL 5.6
! Multi-threaded replication introduced in 5.6, vastly
improved in 5.7
! Asynchronous or semisynchronous
! Backbone of majority of large MySQL deployments
4
MySQL Replication
Copyright 2015 Severalnines AB
MySQL replication and ClusterControl
5
Copyright 2015 Severalnines AB
! Deployment process
! Add slave
! Promote slave
! Recover slave
! Monitoring of the replication environment
6
MySQL replication and ClusterControl
Copyright 2015 Severalnines AB
MySQL replication and ClusterControl
7
DEMO
Copyright 2015 Severalnines AB
Deployment scenarios for replication
8
Copyright 2015 Severalnines AB
! Single DC
! Master - slave
! Intermediate master
! Master - master
! Multi-DC
! Master - slave, over WAN
! Active - passive
! WAN replication with Galera or MySQL Cluster

9
Deployment scenarios for replication
Copyright 2015 Severalnines AB
Deployment scenarios for replication
10
Master - slave
Intermediate master
Copyright 2015 Severalnines AB
Deployment scenarios for replication
11
Master - master, active - standby
Two synchronous clusters

connected over WAN
Copyright 2015 Severalnines AB
How to deal with schema changes?
12
Copyright 2015 Severalnines AB
! Schema changes in MySQL
! Online DDL’s
! not-so-online DDL’s
! Rolling schema upgrades
! external tools like pt-online-schema-change
13
How to deal with schema changes?
Copyright 2015 Severalnines AB
! With MySQL replication lag is a serious limiting factor in
DDL’s
! Online DDL will be online only on the master
! Replication will be locked for the duration of the DDL
! Even when you use Multi-Threaded Slave
! Direct alters are suitable only for small tables
! unless you can accept replication lag, of course
14
How to deal with schema changes?
Copyright 2015 Severalnines AB
! Rolling Schema upgrades - run DDL from the bottom to the top
of replication chain
! SET SESSION sql_log_bin=0 to avoid errant transactions
! Once you reach the master, failover and then alter the old
master
! Schema changes have to be compatible, you’ll be running
DML’s on a mix of altered and not altered tables
! Schema changes have to be compatible, you’ll be reading
from a mix of altered and not altered tables

15
How to deal with schema changes?
Copyright 2015 Severalnines AB
! pt-online-schema-change - part of the Percona Toolkit
! Create a new table with desired schema
! Setup triggers to copy data from old to the new table
! Copy the data from old to new table in batches
! Rename table once the data has been copied
16
How to deal with schema changes?
Copyright 2015 Severalnines AB
How to deal with schema changes?
17
Copyright 2015 Severalnines AB
! Point-in-time change, you can use for any DDL
! Replication-aware, it can monitor lag and throttle itself
! Introduces additional load, slow down your system
! It has issues with foreign keys
! Can’t work with tables which have triggers
! Won’t work with tables without PK and unique key
18
How to deal with schema changes?
Copyright 2015 Severalnines AB
! Otherwise pt-online-schema-change is a very reliable tool
! Schema change may take a long time but it’s throttling
itself and can be paused at any time
! One of the most important tools in the DBA arsenal
! Sometimes it’s the only way to run a schema change
without downtime
19
How to deal with schema changes?
Copyright 2015 Severalnines AB
How to deal with topology changes?
20
Copyright 2015 Severalnines AB
! If you use GTID - it’s easy
! GTID allows for a flexible topology change
! CHANGE MASTER TO … MASTER_AUTO_POSITION=1;
! You can slave off every node in the replication chain
! Be aware of errant transactions, though
! http://www.severalnines.com/blog/mysql-replication-and-
gtid-based-failover-deep-dive-errant-transactions
21
How to deal with topology changes?
Copyright 2015 Severalnines AB
! If you do not use GITD, things are more complex
! Slave knows only a binlog position of itself and it’s master
! You can use binary and relay logs to identify position of a
given transaction in the replication chain but it’s a
complex and error prone process
! To avoid it, you have to stop writes on a involved subset of
hosts
22
How to deal with topology changes?
Copyright 2015 Severalnines AB
How to deal with topology changes?
23
Copyright 2015 Severalnines AB
! First step requires to slave
DB3 and DB4 off DB2
! You need to enable log-
slave-updates on DB2
! Stop DB2, DB3 and DB4 at
the same position using
START SLAVE UNTIL …
! Start it until a beginning of
binary log two files later
24
How to deal with topology changes?
Copyright 2015 Severalnines AB
! Locate your first position in binlog using mysqlbinlog tool
! START SLAVE UNTIL master_log_file='mysql-bin.000121',
master_log_pos=4;
! Run FLUSH LOGS on the master two times to rotate logs -
slaves should end up stopped at the same position
! Check the position on DB2 (SHOW MASTER STATUS)
! Use it to slave DB3 and DB4 off DB2
25
How to deal with topology changes?
Copyright 2015 Severalnines AB
! We should finally reach the
desired topology
! Next step - setup master -
master replication between
DB1 and DB2
! Confirm that DB2 is not taking
writes other than the replication
! Use server_id in binary logs for
that - you should see only DB1
! If it does writes, you’re in
trouble - investigate and
eliminate the culprit
26
How to deal with topology changes?
Copyright 2015 Severalnines AB
! Once confirmed writes are
not hitting DB2, execute
CHANGE MASTER TO … on
DB1 pointing it to the DB2 and
using any recent coordinates
! Monitor Exec_Master_Log_Pos
in the SHOW SLAVE STATUS on
DB1, it should be stable. If it
does increase, something is
still writing to DB2.
! Once all is set up, you are
ready for a failover
27
How to deal with topology changes?
Copyright 2015 Severalnines AB
Potential issues in MySQL replication
28
Copyright 2015 Severalnines AB
! Lag is inevitable part of MySQL replication, async or
semisync, it doesn’t matter
! Lag can be caused by large number of writes and DDL’s
! Multi-threaded slave + GTID is a good choice to minimize
lag caused by writes (for DDL’s - use pt-online-schema-
change)
! Hardware has to follow too, especially I/O subsystem
29
Potential issues in MySQL replication
Copyright 2015 Severalnines AB
! Data drift may happen even if you take all necessary
precautions
! Use ROW binary log format for the best data consistency
! Use read_only and super_read_only on slaves to minimize
possibilities of errant writes
! Use pt-table-checksum and pt-table-sync to keep an eye on
the data consistency
! When in doubt, rebuild a slave from the source of truth (master)

30
Potential issues in MySQL replication
Copyright 2015 Severalnines AB
! Errant transactions can ruin your day
! Those are transactions executed on a slave but not on a
master
! read_only and super_read_only can help to avoid them
! GTID_SUBSET(), GTID_SUBTRACT() will help you to detect them
! We’ve covered the topic here:

http://www.severalnines.com/blog/mysql-replication-and-
gtid-based-failover-deep-dive-errant-transactions

31
Potential issues in MySQL replication
Copyright 2015 Severalnines AB
! More blogs featuring MySQL replication:
! http://severalnines.com/blog/become-mysql-dba-blog-series-
common-operations-schema-changes
! http://severalnines.com/blog/become-mysql-dba-blog-series-
common-operations-replication-topology-changes
! http://severalnines.com/blog/become-mysql-dba-blog-series-live-
migration-using-mysql-replication
! http://severalnines.com/tutorials/mysql-replication-high-availability-
tutorial
! Contact: krzysztof@severalnines.com

32
Thank You!

More Related Content

PDF
Become a MySQL DBA: performing live database upgrades - webinar slides
PDF
Become a MySQL DBA - webinar series - slides: Which High Availability solution?
PDF
Become a MySQL DBA - slides: Deciding on a relevant backup solution
PDF
Become a MySQL DBA - Webinars - Schema Changes for MySQL Replication & Galera...
PDF
Webinar slides: Replication Topology Changes for MySQL and MariaDB
PPTX
Webinar slides - ClusterControl 1.2.11: with support for MariaDB’s MaxScale a...
PDF
Deep Dive Into How To Monitor MySQL or MariaDB Galera Cluster / Percona XtraD...
PPTX
Tips to drive maria db cluster performance for nextcloud
Become a MySQL DBA: performing live database upgrades - webinar slides
Become a MySQL DBA - webinar series - slides: Which High Availability solution?
Become a MySQL DBA - slides: Deciding on a relevant backup solution
Become a MySQL DBA - Webinars - Schema Changes for MySQL Replication & Galera...
Webinar slides: Replication Topology Changes for MySQL and MariaDB
Webinar slides - ClusterControl 1.2.11: with support for MariaDB’s MaxScale a...
Deep Dive Into How To Monitor MySQL or MariaDB Galera Cluster / Percona XtraD...
Tips to drive maria db cluster performance for nextcloud

What's hot (20)

PPTX
MySQL Multi Master Replication
PDF
Webinar slides: ClusterControl 1.4: The MySQL Replication & MongoDB Edition -...
PDF
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
PPTX
High Availability with MariaDB Enterprise
PDF
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
PDF
Geographically Distributed Multi-Master MySQL Clusters
PDF
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
PPTX
Management and Automation of MongoDB Clusters - Slides
PPTX
Maria DB Galera Cluster for High Availability
KEY
Drupal In The Cloud
PDF
Galera 3.0 Webinar Slides: Galera Monitoring & Management
PDF
MySQL highav Availability
DOCX
Master master vs master-slave database
PPTX
Javaeeconf 2016 how to cook apache kafka with camel and spring boot
PPTX
Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...
PDF
Methods of Sharding MySQL
PDF
Camel Kafka Connectors: Tune Kafka to “Speak” with (Almost) Everything (Andre...
PDF
The Complete MariaDB Server Tutorial - Percona Live 2015
PDF
MariaDB on Docker
PPTX
Running MariaDB in multiple data centers
MySQL Multi Master Replication
Webinar slides: ClusterControl 1.4: The MySQL Replication & MongoDB Edition -...
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
High Availability with MariaDB Enterprise
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Geographically Distributed Multi-Master MySQL Clusters
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
Management and Automation of MongoDB Clusters - Slides
Maria DB Galera Cluster for High Availability
Drupal In The Cloud
Galera 3.0 Webinar Slides: Galera Monitoring & Management
MySQL highav Availability
Master master vs master-slave database
Javaeeconf 2016 how to cook apache kafka with camel and spring boot
Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...
Methods of Sharding MySQL
Camel Kafka Connectors: Tune Kafka to “Speak” with (Almost) Everything (Andre...
The Complete MariaDB Server Tutorial - Percona Live 2015
MariaDB on Docker
Running MariaDB in multiple data centers
Ad

Similar to Webinar slides: Managing MySQL Replication for High Availability (20)

PDF
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
PDF
Introducing the Severalnines MySQL© Replication Blueprint
PDF
MySQL Replication Troubleshooting for Oracle DBAs
PPTX
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
PDF
MySQL High Availability Solutions
PDF
Mysqlhacodebits20091203 1260184765-phpapp02
PDF
MySQL High Availability Solutions
PDF
High Availability with MySQL
PDF
Buytaert kris my_sql-pacemaker
PDF
MySQL for Large Scale Social Games
PDF
MySQL Parallel Replication: inventory, use-case and limitations
PDF
Drupal Con My Sql Ha 2008 08 29
PDF
MySQL Replication Update -- Zendcon 2016
PDF
MySQL Scalability and Reliability for Replicated Environment
PPTX
MySQL High Availability Solutions - Feb 2015 webinar
ODP
MySQL HA with PaceMaker
PDF
My S Q L Replication Getting The Most From Slaves
PPTX
MySQL Replication Overview -- PHPTek 2016
PDF
Best practices for MySQL High Availability
PDF
MySQL Parallel Replication by Booking.com
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
Introducing the Severalnines MySQL© Replication Blueprint
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
MySQL High Availability Solutions
Mysqlhacodebits20091203 1260184765-phpapp02
MySQL High Availability Solutions
High Availability with MySQL
Buytaert kris my_sql-pacemaker
MySQL for Large Scale Social Games
MySQL Parallel Replication: inventory, use-case and limitations
Drupal Con My Sql Ha 2008 08 29
MySQL Replication Update -- Zendcon 2016
MySQL Scalability and Reliability for Replicated Environment
MySQL High Availability Solutions - Feb 2015 webinar
MySQL HA with PaceMaker
My S Q L Replication Getting The Most From Slaves
MySQL Replication Overview -- PHPTek 2016
Best practices for MySQL High Availability
MySQL Parallel Replication by Booking.com
Ad

More from Severalnines (20)

PDF
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
PPTX
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
PDF
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
PDF
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
PDF
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
PDF
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
PDF
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
PDF
WEBINAR SLIDES: CCX for Cloud Service Providers
PPTX
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
PDF
Kubernetes at Scale: Going Multi-Cluster with Istio
PDF
DIY DBaaS: A guide to building your own full-featured DBaaS
PDF
Cloud's future runs through Sovereign DBaaS
PPTX
Working with the Moodle Database: The Basics
PPTX
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
PDF
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
PDF
Webinar slides: How to Migrate from Oracle DB to MariaDB
PDF
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
PDF
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
PDF
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
PPTX
Disaster Recovery Planning for MySQL & MariaDB
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
WEBINAR SLIDES: CCX for Cloud Service Providers
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
Kubernetes at Scale: Going Multi-Cluster with Istio
DIY DBaaS: A guide to building your own full-featured DBaaS
Cloud's future runs through Sovereign DBaaS
Working with the Moodle Database: The Basics
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
Webinar slides: How to Migrate from Oracle DB to MariaDB
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Disaster Recovery Planning for MySQL & MariaDB

Recently uploaded (20)

PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
DOCX
Unit-3 cyber security network security of internet system
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Sims 4 Historia para lo sims 4 para jugar
PPT
tcp ip networks nd ip layering assotred slides
PPTX
Introduction to Information and Communication Technology
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
Digital Literacy And Online Safety on internet
Unit-1 introduction to cyber security discuss about how to secure a system
Introuction about WHO-FIC in ICD-10.pptx
international classification of diseases ICD-10 review PPT.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Module 1 - Cyber Law and Ethics 101.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
QR Codes Qr codecodecodecodecocodedecodecode
An introduction to the IFRS (ISSB) Stndards.pdf
Unit-3 cyber security network security of internet system
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
SASE Traffic Flow - ZTNA Connector-1.pdf
Sims 4 Historia para lo sims 4 para jugar
tcp ip networks nd ip layering assotred slides
Introduction to Information and Communication Technology
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Cloud-Scale Log Monitoring _ Datadog.pdf
Tenda Login Guide: Access Your Router in 5 Easy Steps
introduction about ICD -10 & ICD-11 ppt.pptx
Digital Literacy And Online Safety on internet

Webinar slides: Managing MySQL Replication for High Availability

  • 1. Copyright 2015 Severalnines AB Managing MySQL Replication for High Availability February 2, 2016 Krzysztof Książek Severalnines krzysztof@severalnines.com 1
  • 2. 2 Your host & some logistics I'm Jean-Jérôme from the Severalnines Team and I'm your host for today's webinar! Feel free to ask any questions in the Questions section of this application or via the Chat box. You can also contact me directly via the chat box or via email: jj@severalnines.com during or after the webinar.
  • 3. Copyright 2015 Severalnines AB ! MySQL replication and ClusterControl (Demo) ! Deployment ! Topology changes ! Important metrics ! How to deal with ! Schema changes ! Topology changes ! Potential issues in MySQL replication
 3 Agenda
  • 4. Copyright 2015 Severalnines AB ! Available since 3.23 ! Proven, robust, based on binary logs ! GTID introduced in MySQL 5.6 ! Multi-threaded replication introduced in 5.6, vastly improved in 5.7 ! Asynchronous or semisynchronous ! Backbone of majority of large MySQL deployments 4 MySQL Replication
  • 5. Copyright 2015 Severalnines AB MySQL replication and ClusterControl 5
  • 6. Copyright 2015 Severalnines AB ! Deployment process ! Add slave ! Promote slave ! Recover slave ! Monitoring of the replication environment 6 MySQL replication and ClusterControl
  • 7. Copyright 2015 Severalnines AB MySQL replication and ClusterControl 7 DEMO
  • 8. Copyright 2015 Severalnines AB Deployment scenarios for replication 8
  • 9. Copyright 2015 Severalnines AB ! Single DC ! Master - slave ! Intermediate master ! Master - master ! Multi-DC ! Master - slave, over WAN ! Active - passive ! WAN replication with Galera or MySQL Cluster
 9 Deployment scenarios for replication
  • 10. Copyright 2015 Severalnines AB Deployment scenarios for replication 10 Master - slave Intermediate master
  • 11. Copyright 2015 Severalnines AB Deployment scenarios for replication 11 Master - master, active - standby Two synchronous clusters
 connected over WAN
  • 12. Copyright 2015 Severalnines AB How to deal with schema changes? 12
  • 13. Copyright 2015 Severalnines AB ! Schema changes in MySQL ! Online DDL’s ! not-so-online DDL’s ! Rolling schema upgrades ! external tools like pt-online-schema-change 13 How to deal with schema changes?
  • 14. Copyright 2015 Severalnines AB ! With MySQL replication lag is a serious limiting factor in DDL’s ! Online DDL will be online only on the master ! Replication will be locked for the duration of the DDL ! Even when you use Multi-Threaded Slave ! Direct alters are suitable only for small tables ! unless you can accept replication lag, of course 14 How to deal with schema changes?
  • 15. Copyright 2015 Severalnines AB ! Rolling Schema upgrades - run DDL from the bottom to the top of replication chain ! SET SESSION sql_log_bin=0 to avoid errant transactions ! Once you reach the master, failover and then alter the old master ! Schema changes have to be compatible, you’ll be running DML’s on a mix of altered and not altered tables ! Schema changes have to be compatible, you’ll be reading from a mix of altered and not altered tables
 15 How to deal with schema changes?
  • 16. Copyright 2015 Severalnines AB ! pt-online-schema-change - part of the Percona Toolkit ! Create a new table with desired schema ! Setup triggers to copy data from old to the new table ! Copy the data from old to new table in batches ! Rename table once the data has been copied 16 How to deal with schema changes?
  • 17. Copyright 2015 Severalnines AB How to deal with schema changes? 17
  • 18. Copyright 2015 Severalnines AB ! Point-in-time change, you can use for any DDL ! Replication-aware, it can monitor lag and throttle itself ! Introduces additional load, slow down your system ! It has issues with foreign keys ! Can’t work with tables which have triggers ! Won’t work with tables without PK and unique key 18 How to deal with schema changes?
  • 19. Copyright 2015 Severalnines AB ! Otherwise pt-online-schema-change is a very reliable tool ! Schema change may take a long time but it’s throttling itself and can be paused at any time ! One of the most important tools in the DBA arsenal ! Sometimes it’s the only way to run a schema change without downtime 19 How to deal with schema changes?
  • 20. Copyright 2015 Severalnines AB How to deal with topology changes? 20
  • 21. Copyright 2015 Severalnines AB ! If you use GTID - it’s easy ! GTID allows for a flexible topology change ! CHANGE MASTER TO … MASTER_AUTO_POSITION=1; ! You can slave off every node in the replication chain ! Be aware of errant transactions, though ! http://www.severalnines.com/blog/mysql-replication-and- gtid-based-failover-deep-dive-errant-transactions 21 How to deal with topology changes?
  • 22. Copyright 2015 Severalnines AB ! If you do not use GITD, things are more complex ! Slave knows only a binlog position of itself and it’s master ! You can use binary and relay logs to identify position of a given transaction in the replication chain but it’s a complex and error prone process ! To avoid it, you have to stop writes on a involved subset of hosts 22 How to deal with topology changes?
  • 23. Copyright 2015 Severalnines AB How to deal with topology changes? 23
  • 24. Copyright 2015 Severalnines AB ! First step requires to slave DB3 and DB4 off DB2 ! You need to enable log- slave-updates on DB2 ! Stop DB2, DB3 and DB4 at the same position using START SLAVE UNTIL … ! Start it until a beginning of binary log two files later 24 How to deal with topology changes?
  • 25. Copyright 2015 Severalnines AB ! Locate your first position in binlog using mysqlbinlog tool ! START SLAVE UNTIL master_log_file='mysql-bin.000121', master_log_pos=4; ! Run FLUSH LOGS on the master two times to rotate logs - slaves should end up stopped at the same position ! Check the position on DB2 (SHOW MASTER STATUS) ! Use it to slave DB3 and DB4 off DB2 25 How to deal with topology changes?
  • 26. Copyright 2015 Severalnines AB ! We should finally reach the desired topology ! Next step - setup master - master replication between DB1 and DB2 ! Confirm that DB2 is not taking writes other than the replication ! Use server_id in binary logs for that - you should see only DB1 ! If it does writes, you’re in trouble - investigate and eliminate the culprit 26 How to deal with topology changes?
  • 27. Copyright 2015 Severalnines AB ! Once confirmed writes are not hitting DB2, execute CHANGE MASTER TO … on DB1 pointing it to the DB2 and using any recent coordinates ! Monitor Exec_Master_Log_Pos in the SHOW SLAVE STATUS on DB1, it should be stable. If it does increase, something is still writing to DB2. ! Once all is set up, you are ready for a failover 27 How to deal with topology changes?
  • 28. Copyright 2015 Severalnines AB Potential issues in MySQL replication 28
  • 29. Copyright 2015 Severalnines AB ! Lag is inevitable part of MySQL replication, async or semisync, it doesn’t matter ! Lag can be caused by large number of writes and DDL’s ! Multi-threaded slave + GTID is a good choice to minimize lag caused by writes (for DDL’s - use pt-online-schema- change) ! Hardware has to follow too, especially I/O subsystem 29 Potential issues in MySQL replication
  • 30. Copyright 2015 Severalnines AB ! Data drift may happen even if you take all necessary precautions ! Use ROW binary log format for the best data consistency ! Use read_only and super_read_only on slaves to minimize possibilities of errant writes ! Use pt-table-checksum and pt-table-sync to keep an eye on the data consistency ! When in doubt, rebuild a slave from the source of truth (master)
 30 Potential issues in MySQL replication
  • 31. Copyright 2015 Severalnines AB ! Errant transactions can ruin your day ! Those are transactions executed on a slave but not on a master ! read_only and super_read_only can help to avoid them ! GTID_SUBSET(), GTID_SUBTRACT() will help you to detect them ! We’ve covered the topic here:
 http://www.severalnines.com/blog/mysql-replication-and- gtid-based-failover-deep-dive-errant-transactions
 31 Potential issues in MySQL replication
  • 32. Copyright 2015 Severalnines AB ! More blogs featuring MySQL replication: ! http://severalnines.com/blog/become-mysql-dba-blog-series- common-operations-schema-changes ! http://severalnines.com/blog/become-mysql-dba-blog-series- common-operations-replication-topology-changes ! http://severalnines.com/blog/become-mysql-dba-blog-series-live- migration-using-mysql-replication ! http://severalnines.com/tutorials/mysql-replication-high-availability- tutorial ! Contact: krzysztof@severalnines.com
 32 Thank You!