SlideShare a Scribd company logo
1
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
Replication Topology Changes for MySQL and MariaDB
September 29, 2015
Krzysztof Książek
Severalnines
krzysztof@severalnines.com
2
Copyright 2015 Severalnines AB
! We want to help all non-DBA people who look after
MySQL infrastructures
! Share tips and good practices
! Watch the replays of the previous webinars on our
Slideshare page
! http://www.slideshare.net/Severalnines/videos
3
“Become a MySQL DBA” series
Copyright 2015 Severalnines AB
! MySQL Replication topology changes
! using GTID
! using regular replication
! Failover process
! Using MaxScale for automatic re-routing of queries
! Other external tools useful when dealing with failover
4
Agenda
Copyright 2015 Severalnines AB
MySQL Replication topology changes
5
Copyright 2015 Severalnines AB
! Maintenances
! Adding an index on a large table
! Delete data and then rebuild a large table to reclaim
disk space
! Reslaving nodes for a planned failover
! Reslaving nodes after master crash
6
Why do we make changes in a replication chain?
Copyright 2015 Severalnines AB
! GTID allows for a flexible topology changes
! 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
7
Replication topology changes - GTID
Copyright 2015 Severalnines AB
! Far less flexible than GTID
! 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
8
Replication topology changes - no GTID
Copyright 2015 Severalnines AB
Replication topology changes - no GTID
9
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
10
Replication topology changes - no GTID
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
11
Replication topology changes - no GTID
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
troubles - investigate and
eliminate the culprit
12
Replication topology changes - no GTID
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
13
Replication topology changes - no GTID
Copyright 2015 Severalnines AB
Failover process
14
Copyright 2015 Severalnines AB
! Exact failover process may depend strongly on the
infrastructure that you use
! In short - it’s a process of moving writes from one
database node to another
! It may or may not be graceful, depending on your
application and tools that you use
15
Failover Process
Copyright 2015 Severalnines AB
! Requires downtime period
for a master switch
! Not ideal solution but
easiest to implement and it
will work with every
application that can be
stopped
! We are assuming the
topology we reached in our
previous slides, with failover
about to happen from DB1
to DB2
16
Offline failover
Copyright 2015 Severalnines AB
! As a first step, you need to stop all activity in your
application - you don’t want to have any writes hitting db
! You can monitor it using SHOW MASTER STATUS on the
master
! You can monitor binary logs to locate and identify writes
that hit the database
! Com_* counters can also be monitored
17
Offline failover
Copyright 2015 Severalnines AB
! Next step - you need to repoint your application to the
new master, DB2 in our example
! Depending on your setup you can:
! Change DNS entries
! Set read_only values accordingly on MySQL hosts
! Use your proxy’s settings to redirect connections from
one host to the other
18
Offline failover
Copyright 2015 Severalnines AB
! Once you pointed writes to a new master, you may want
to perform some tests before going back live
! All the time, ensure that any writes are happening only on
the correct host - new master, DB2 in our case
! Do not use any ‘hardcoded’ IP’s in your scripts - this may
become a serious problem when you will be performing a
failover
19
Offline failover
Copyright 2015 Severalnines AB
! Moving writes without downtime period - planned failover
! Stop the writes on the master, failover, move the writes to
the new master - sounds familiar?
! Main problem is - how to do it gracefuly?
! FTWRL + read_only = 1? May take too long
! read_only = 1? Will kill current connections
! Drop the user + wait few seconds + read_only = 1? Still not
ideal but may be acceptable
20
Online failover
Copyright 2015 Severalnines AB
! Proxies may help significantly in this regard - single point of
config change, immediate result
! Caching reads and writes can also be useful
! Application will have to be able to handle errors and
rollbacks as transition may but also may not be graceful
! Some of the tools can help you to make it graceful,
without application seeing any error at all
21
Online failover
Copyright 2015 Severalnines AB
Using MaxScale to reroute queries
22
Copyright 2015 Severalnines AB
! MaxScale can implement read-write split
! MaxScale can be used with MySQL replication backend
! It monitors health of the backend nodes
! It detects replication topology changes
! Makes easier to handle any changes like failover
23
Using MaxScale to reroute queries
Copyright 2015 Severalnines AB
! For reads, most of the failures are being handled
gracefully
! For writes, not yet - errors will be thrown and transactions
rolled back, application has to handle them
! But it should be handling them anyway, right?
! Experimental support for handling failovers (along with
reslaving) in the latest MaxScale
! No easy way of performing a planned failover, though
24
Using MaxScale to reroute queries
Confidential
Copyright 2015 Severalnines AB
External tools which help handling failover process
Copyright 2015 Severalnines AB
! Handles the failover process for you
! Both automatic failover and manual one
! Can be used as a standalone solution or a part of a set of
scripts or tools
! Integrates nicely with other tools in a manual failover
process
! Can work with GTID and regular replication
26
MHA
Copyright 2015 Severalnines AB
! Part of MySQL Utilities from Oracle
! Allows user to perform a manual failover
! Works only with GTID replication
! Checks for errant transactions
! Can be easily combined with other scripts through --exec-
before and --exec-after
27
mysqlrpladmin
Copyright 2015 Severalnines AB
! New addition to the ‘database-aware’ proxy family
! Works as a gateway for all connections to databases
! Performs read/write split based on user-defined set of rules
! Gives you ability to perform a sub second graceful
failover in case of a master-master replication.
! Works great with external scripts for handling topology
changes
28
ProxySQL
Copyright 2015 Severalnines AB
! Idea is simple - all queries go through proxy to backend nodes
! You can use failover script to switch a backend node into a
‘failover’ mode
! Proxy will not forward more connections to it, it will “buffer”
new connections
! Your failover script can wait till the current transactions finish or
timeout will be reached and transactions can be killed
! In a next step you can reconfigure the replication topology as
needed
29
ProxySQL
Copyright 2015 Severalnines AB
! Once there are no transactions running and new
topology has been set up, proxy can be reconfigured to
move writes to another backend
! Depends on how long are your transactions and how long
timeout is set, failover can take even a fraction of a
second
! Application will see temporary slowdown but should not
see any errors
! Additional scripting is required - ProxySQL doesn’t monitor
replication topology on it’s own
30
ProxySQL
Copyright 2015 Severalnines AB
! More blogs in “Become a MySQL DBA” series:
! http://www.severalnines.com/blog/become-mysql-
dba-blog-series-query-tuning-process
! http://www.severalnines.com/blog/become-mysql-
dba-blog-series-configuration-tuning-performance
! Contact: krzysztof@severalnines.com
31
Thank You!

More Related Content

What's hot (20)

PDF
The Complete MariaDB Server Tutorial - Percona Live 2015
Colin Charles
 
PDF
Pluk2011 deploy-mysql-like-a-devops-sysadmin
Frederic Descamps
 
PPTX
MySQL Multi Master Replication
Moshe Kaplan
 
PDF
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
Severalnines
 
PDF
Scaling LoL Chat to 70M Players
Michał Ptaszek
 
PDF
MySQL highav Availability
Baruch Osoveskiy
 
PPTX
Maria DB Galera Cluster for High Availability
OSSCube
 
PDF
Inspecting a multi everything linux system (plmce2k14)
Frederic Descamps
 
PPT
Rackspace Private Cloud presentation for ChefConf 2013
Joe Breu
 
PDF
Best practices for MySQL High Availability
Colin Charles
 
PPTX
Management and Automation of MongoDB Clusters - Slides
Severalnines
 
PPTX
How to Reduce Database Load with Sparse Branches
Perforce
 
PDF
MHA (MySQL High Availability): Getting started & moving past quirks
Colin Charles
 
PPTX
Warden @ Meet magento Romania 2021
alinalexandru
 
PDF
MySQL DevOps at Outbrain
Shlomi Noach
 
DOCX
Master master vs master-slave database
Wipro
 
PDF
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Severalnines
 
PPTX
Kafka at Peak Performance
Todd Palino
 
PDF
High Availability in GCE
Carmen Mason
 
PDF
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltStack
 
The Complete MariaDB Server Tutorial - Percona Live 2015
Colin Charles
 
Pluk2011 deploy-mysql-like-a-devops-sysadmin
Frederic Descamps
 
MySQL Multi Master Replication
Moshe Kaplan
 
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
Severalnines
 
Scaling LoL Chat to 70M Players
Michał Ptaszek
 
MySQL highav Availability
Baruch Osoveskiy
 
Maria DB Galera Cluster for High Availability
OSSCube
 
Inspecting a multi everything linux system (plmce2k14)
Frederic Descamps
 
Rackspace Private Cloud presentation for ChefConf 2013
Joe Breu
 
Best practices for MySQL High Availability
Colin Charles
 
Management and Automation of MongoDB Clusters - Slides
Severalnines
 
How to Reduce Database Load with Sparse Branches
Perforce
 
MHA (MySQL High Availability): Getting started & moving past quirks
Colin Charles
 
Warden @ Meet magento Romania 2021
alinalexandru
 
MySQL DevOps at Outbrain
Shlomi Noach
 
Master master vs master-slave database
Wipro
 
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Severalnines
 
Kafka at Peak Performance
Todd Palino
 
High Availability in GCE
Carmen Mason
 
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltStack
 

Viewers also liked (6)

PDF
Overview of Postgres 9.5
EDB
 
ODP
JSON By Example
Stefanie Janine Stölting
 
PDF
Performance improvements in PostgreSQL 9.5 and beyond
Tomas Vondra
 
PDF
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
PDF
Deep Dive Into How To Monitor MySQL or MariaDB Galera Cluster / Percona XtraD...
Severalnines
 
PPTX
What's new in MySQL Cluster 7.4 webinar charts
Andrew Morgan
 
Overview of Postgres 9.5
EDB
 
JSON By Example
Stefanie Janine Stölting
 
Performance improvements in PostgreSQL 9.5 and beyond
Tomas Vondra
 
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
Deep Dive Into How To Monitor MySQL or MariaDB Galera Cluster / Percona XtraD...
Severalnines
 
What's new in MySQL Cluster 7.4 webinar charts
Andrew Morgan
 
Ad

Similar to Webinar slides: Replication Topology Changes for MySQL and MariaDB (20)

PPT
MySQL HA Presentation
papablues
 
PDF
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
Severalnines
 
PDF
Reliable Data Replication by Cameron Morgan
ScyllaDB
 
PDF
EXPERIENCE WITH MYSQL HA SOLUTION AND GROUP REPLICATION
Mysql User Camp
 
PDF
Replication features, technologies and 3rd party Extinction
Ben Mildren
 
PDF
DATABASE AUTOMATION with Thousands of database, monitoring and backup
Saewoong Lee
 
PDF
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Severalnines
 
PPTX
Sql server 2019 New Features by Yevhen Nedaskivskyi
Alex Tumanoff
 
PDF
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
Dave Stokes
 
PPTX
Database CI/CD Pipeline
muhammadhashir57
 
PDF
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Severalnines
 
PDF
Cloud-Native Patterns and the Benefits of MySQL as a Platform Managed Service
VMware Tanzu
 
PDF
Micro services may not be the best idea
Samuel ROZE
 
PDF
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Continuent
 
PDF
Getting Modern With MySQL
All Things Open
 
PDF
Getting modern with my sql
Jakob Lorberblatt
 
PPT
Effective Usage of SQL Server 2005 Database Mirroring
webhostingguy
 
PPT
SQL Police
Marcus Davage
 
PDF
MySQL Replication
Mark Swarbrick
 
PPTX
Why does Microsoft care about NoSQL, SQL and Polyglot Persistence?
brianlangbecker
 
MySQL HA Presentation
papablues
 
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
Severalnines
 
Reliable Data Replication by Cameron Morgan
ScyllaDB
 
EXPERIENCE WITH MYSQL HA SOLUTION AND GROUP REPLICATION
Mysql User Camp
 
Replication features, technologies and 3rd party Extinction
Ben Mildren
 
DATABASE AUTOMATION with Thousands of database, monitoring and backup
Saewoong Lee
 
Webinar slides: The Holy Grail Webinar: Become a MySQL DBA - Database Perform...
Severalnines
 
Sql server 2019 New Features by Yevhen Nedaskivskyi
Alex Tumanoff
 
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
Dave Stokes
 
Database CI/CD Pipeline
muhammadhashir57
 
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Severalnines
 
Cloud-Native Patterns and the Benefits of MySQL as a Platform Managed Service
VMware Tanzu
 
Micro services may not be the best idea
Samuel ROZE
 
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Continuent
 
Getting Modern With MySQL
All Things Open
 
Getting modern with my sql
Jakob Lorberblatt
 
Effective Usage of SQL Server 2005 Database Mirroring
webhostingguy
 
SQL Police
Marcus Davage
 
MySQL Replication
Mark Swarbrick
 
Why does Microsoft care about NoSQL, SQL and Polyglot Persistence?
brianlangbecker
 
Ad

More from Severalnines (20)

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

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
July Patch Tuesday
Ivanti
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 

Webinar slides: Replication Topology Changes for MySQL and MariaDB

  • 1. 1 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: [email protected] during or after the webinar.
  • 2. Copyright 2015 Severalnines AB Replication Topology Changes for MySQL and MariaDB September 29, 2015 Krzysztof Książek Severalnines [email protected] 2
  • 3. Copyright 2015 Severalnines AB ! We want to help all non-DBA people who look after MySQL infrastructures ! Share tips and good practices ! Watch the replays of the previous webinars on our Slideshare page ! http://www.slideshare.net/Severalnines/videos 3 “Become a MySQL DBA” series
  • 4. Copyright 2015 Severalnines AB ! MySQL Replication topology changes ! using GTID ! using regular replication ! Failover process ! Using MaxScale for automatic re-routing of queries ! Other external tools useful when dealing with failover 4 Agenda
  • 5. Copyright 2015 Severalnines AB MySQL Replication topology changes 5
  • 6. Copyright 2015 Severalnines AB ! Maintenances ! Adding an index on a large table ! Delete data and then rebuild a large table to reclaim disk space ! Reslaving nodes for a planned failover ! Reslaving nodes after master crash 6 Why do we make changes in a replication chain?
  • 7. Copyright 2015 Severalnines AB ! GTID allows for a flexible topology changes ! 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 7 Replication topology changes - GTID
  • 8. Copyright 2015 Severalnines AB ! Far less flexible than GTID ! 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 8 Replication topology changes - no GTID
  • 9. Copyright 2015 Severalnines AB Replication topology changes - no GTID 9
  • 10. 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 10 Replication topology changes - no GTID
  • 11. 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 11 Replication topology changes - no GTID
  • 12. 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 troubles - investigate and eliminate the culprit 12 Replication topology changes - no GTID
  • 13. 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 13 Replication topology changes - no GTID
  • 14. Copyright 2015 Severalnines AB Failover process 14
  • 15. Copyright 2015 Severalnines AB ! Exact failover process may depend strongly on the infrastructure that you use ! In short - it’s a process of moving writes from one database node to another ! It may or may not be graceful, depending on your application and tools that you use 15 Failover Process
  • 16. Copyright 2015 Severalnines AB ! Requires downtime period for a master switch ! Not ideal solution but easiest to implement and it will work with every application that can be stopped ! We are assuming the topology we reached in our previous slides, with failover about to happen from DB1 to DB2 16 Offline failover
  • 17. Copyright 2015 Severalnines AB ! As a first step, you need to stop all activity in your application - you don’t want to have any writes hitting db ! You can monitor it using SHOW MASTER STATUS on the master ! You can monitor binary logs to locate and identify writes that hit the database ! Com_* counters can also be monitored 17 Offline failover
  • 18. Copyright 2015 Severalnines AB ! Next step - you need to repoint your application to the new master, DB2 in our example ! Depending on your setup you can: ! Change DNS entries ! Set read_only values accordingly on MySQL hosts ! Use your proxy’s settings to redirect connections from one host to the other 18 Offline failover
  • 19. Copyright 2015 Severalnines AB ! Once you pointed writes to a new master, you may want to perform some tests before going back live ! All the time, ensure that any writes are happening only on the correct host - new master, DB2 in our case ! Do not use any ‘hardcoded’ IP’s in your scripts - this may become a serious problem when you will be performing a failover 19 Offline failover
  • 20. Copyright 2015 Severalnines AB ! Moving writes without downtime period - planned failover ! Stop the writes on the master, failover, move the writes to the new master - sounds familiar? ! Main problem is - how to do it gracefuly? ! FTWRL + read_only = 1? May take too long ! read_only = 1? Will kill current connections ! Drop the user + wait few seconds + read_only = 1? Still not ideal but may be acceptable 20 Online failover
  • 21. Copyright 2015 Severalnines AB ! Proxies may help significantly in this regard - single point of config change, immediate result ! Caching reads and writes can also be useful ! Application will have to be able to handle errors and rollbacks as transition may but also may not be graceful ! Some of the tools can help you to make it graceful, without application seeing any error at all 21 Online failover
  • 22. Copyright 2015 Severalnines AB Using MaxScale to reroute queries 22
  • 23. Copyright 2015 Severalnines AB ! MaxScale can implement read-write split ! MaxScale can be used with MySQL replication backend ! It monitors health of the backend nodes ! It detects replication topology changes ! Makes easier to handle any changes like failover 23 Using MaxScale to reroute queries
  • 24. Copyright 2015 Severalnines AB ! For reads, most of the failures are being handled gracefully ! For writes, not yet - errors will be thrown and transactions rolled back, application has to handle them ! But it should be handling them anyway, right? ! Experimental support for handling failovers (along with reslaving) in the latest MaxScale ! No easy way of performing a planned failover, though 24 Using MaxScale to reroute queries
  • 25. Confidential Copyright 2015 Severalnines AB External tools which help handling failover process
  • 26. Copyright 2015 Severalnines AB ! Handles the failover process for you ! Both automatic failover and manual one ! Can be used as a standalone solution or a part of a set of scripts or tools ! Integrates nicely with other tools in a manual failover process ! Can work with GTID and regular replication 26 MHA
  • 27. Copyright 2015 Severalnines AB ! Part of MySQL Utilities from Oracle ! Allows user to perform a manual failover ! Works only with GTID replication ! Checks for errant transactions ! Can be easily combined with other scripts through --exec- before and --exec-after 27 mysqlrpladmin
  • 28. Copyright 2015 Severalnines AB ! New addition to the ‘database-aware’ proxy family ! Works as a gateway for all connections to databases ! Performs read/write split based on user-defined set of rules ! Gives you ability to perform a sub second graceful failover in case of a master-master replication. ! Works great with external scripts for handling topology changes 28 ProxySQL
  • 29. Copyright 2015 Severalnines AB ! Idea is simple - all queries go through proxy to backend nodes ! You can use failover script to switch a backend node into a ‘failover’ mode ! Proxy will not forward more connections to it, it will “buffer” new connections ! Your failover script can wait till the current transactions finish or timeout will be reached and transactions can be killed ! In a next step you can reconfigure the replication topology as needed 29 ProxySQL
  • 30. Copyright 2015 Severalnines AB ! Once there are no transactions running and new topology has been set up, proxy can be reconfigured to move writes to another backend ! Depends on how long are your transactions and how long timeout is set, failover can take even a fraction of a second ! Application will see temporary slowdown but should not see any errors ! Additional scripting is required - ProxySQL doesn’t monitor replication topology on it’s own 30 ProxySQL
  • 31. Copyright 2015 Severalnines AB ! More blogs in “Become a MySQL DBA” series: ! http://www.severalnines.com/blog/become-mysql- dba-blog-series-query-tuning-process ! http://www.severalnines.com/blog/become-mysql- dba-blog-series-configuration-tuning-performance ! Contact: [email protected] 31 Thank You!