SlideShare a Scribd company logo
Ulf Wendel, Oracle


     MySQL 5.6
Global Transaction Ids
  Use case: Failover
   MySQL 5.6, PECL/mysqlnd_ms 1.3
The speaker says...
It is all about MySQL Replication. MySQL Replication is the
database scale-out solution of the LAMP stack. MySQL
Replication is using lazy primary copy (master/slave).
Built-in global transaction identifier of MySQL 5.6
make server failover semi-automatic.


PECL/mysqlnd_ms features connection failover since
1.0, comes with a client-side emulation of global
transaction identifier since 1.2, supports the use of
the MySQL 5.6 built-in global transaction identifier
since 1.3 (under development) but goes beyond the
failover aspect. In this slide set – use case #1 failover.
MySQL Replication
Primary copy (master/slave) for read-scale out
  Writes/updates: master
  Reads: slaves


                        MySQL Master

                  Log 7, Pos 34: UPDATE x=1
                  Log 7, Pos 35: UPDATE x=9


      MySQL Slave 1                      MySQL Slave 2

  Log 2, Pos 1: UPDATE x=1          Log 8, Pos 1: UPDATE x=1
  Log 2, Pos 2: UPDATE x=9
The speaker says...
Use case #1: Master failover.


In a MySQL Replication setup all writes/updates must be
executed at the master. PECL/mysqlnd_ms, a transparent
plugin for the PHP mysqlnd library, does the necessary R/W
split for you.


The master logs all updates. Slaves read the updates
and replay them. Slaves copy updates from the
primary, thus the name primary copy. The copy
process is asynchronous. Replicas may lag behind. There is
one master – it is a single point of failure.
Using GTIDs for master failover
Slave to master promotion after master outage
  Which slave is the most current?
  How to copy transactions from S1 to S2?


                        MySQL Master

                 Log 7, Pos 34: UPDATE x=1
                 Log 7, Pos 35: UPDATE x=9


      MySQL Slave 1                        MySQL Slave 2

 Log 2, Pos 1: UPDATE x=1              Log 8, Pos 1: UPDATE x=1
 Log 2, Pos 2: UPDATE x=9
The speaker says...
The master fails, it becomes unavailable alltogether. A slave
must be promoted to become the new master.


It is hard to tell which slave has the latest
transactions. Transactions are referenced by log file
offsets. The highest log position does not necessarily
the refer to the latest transaction.


Identification of transactions is hard. Log positions cannot
be compared among replicas because different log
file settings may result in different offsets. For
example, two replicas may use different setting for log
rotation.
Global transaction identifier
Combination of server id and sequence number
  Emulation: PECL/mysqlnd_ms 1.2, MySQL Proxy
  Built-in: MySQL 5.6


                       MySQL Master

            Log 7, Pos 34, GTID M:1: UPDATE x=1
            Log 7, Pos 35, GTID M:2: UPDATE x=9


         MySQL Slave 1                MySQL Slave 2

    … , GTID M:1: UPDATE x=1   … , GTID M:1: UPDATE x=1
    … , GTID M:2: UPDATE x=9
The speaker says...
A global transaction identifier is a cluster-wide
unique transaction identifier. MySQL 5.6 can generate it
automatically. MySQL Proxy and PECL/mysqlnd_ms 1.2
feature client-side emulations for use with any MySQL
version.


The sequence number makes it easy to identify the
latest transactions for a given master. This helps to
identify the most current slave. Because it is now easy
to uniquely identify a transaction it is clear Slave 1 should
be the new master. Slave 2 becomes a slave of Slave 1.
Slave 2 continues replication with transaction M:2.
Availability improved, solved?
Master failover improved!
  Scriptable, unattended failover possible
  No 3rd party solution required


MySQL Master (was: Slave 1)
      MySQL Master

 … , GTID M:1: UPDATE x=1
 … , GTID M:2: UPDATE x=9
 … , GTID S:1: UPDATE x=0
                                     MySQL Slave 2
 … , GTID S:2: UPDATE x=9
                                … , GTID M:1: UPDATE x=1
                                … , GTID M:2: UPDATE x=9
                                … , GTID S:1: UPDATE x=0
The speaker says...
The introduction of GTIDs is a milestone towards improving
the availability of a MySQL Replication cluster. The MySQL
5.6 Reference manual will give details, including some
limitations of GTIDs.


The client side has not been considered yet. How to
handle connection failures, how to handle permanent
server failures?
PECL/mysqlnd_ms failover
Slave connection failover is easy...
  Catch error, rerun statement, plugin picks next server
  Connection handle remains useable
  Automatic (no error) mode exists (not recommended)

                     PECL/mysqlnd_ms


                           Fail...     … over

   MySQL Master          MySQL Slave            MySQL Slave
The speaker says...
Failing over a read-only client connection to a slave
is easy. In case of an error PECL/mysqlnd_ms can either
silently failover to the next slave or master or, the plugin
returns an error. Automatic and silent failover is not
recommended as connection state is lost. Instead,
applications should catch the error, handle the failed
transaction and rerun their transaction. Upon execution of
the next statement, PECL/mysqlnd_ms fails over to another
server. The connection handle remains valid and useable.

Failover in a single master primary copy cluster is
impossible: where to sent the write?
PECL/mysqlnd_ms deployment
Cluster topology change requires deployment
  Client configuration lists servers and roles
  Slave to master promotion requires deployment
  Addition or removal of slave requires deployment

                    PECL/mysqlnd_ms


         Where to fail over?

    MySQL Master        MySQL Slave        MySQL Slave
The speaker says...
Load balancers, including those load balancers that are part
of the driver, must be reconfigured after cluster topology
has changed (membership, roles).


Deploy the PECL/mysqlnd_ms configuration as part
of your slave to master promotion! The load balancer
configuration update should be done after the cluster has
been reconfigured and the new master is in place.
In the next slide set...
GTID Use case #2: consistency
  Session consistency (read-your-writes)
  PECL/mysqlnd_ms 1.2 and above
THE END


Contact: ulf.wendel@oracle.com

More Related Content

ODP
Vote NO for MySQL
PDF
DIY: A distributed database cluster, or: MySQL Cluster
ODP
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
ODP
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
ODP
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
ODP
MySQL Group Replication
ODP
The mysqlnd replication and load balancing plugin
ODP
NoSQL in MySQL
Vote NO for MySQL
DIY: A distributed database cluster, or: MySQL Cluster
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL Group Replication
The mysqlnd replication and load balancing plugin
NoSQL in MySQL

What's hot (20)

ODP
PoC: Using a Group Communication System to improve MySQL Replication HA
ODP
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
KEY
Intro to PECL/mysqlnd_ms (4/7/2011)
ODP
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
ODP
MySQL 5.7 clustering: The developer perspective
ODP
Built-in query caching for all PHP MySQL extensions/APIs
ODP
PHP mysqlnd connection multiplexing plugin
ODP
Data massage: How databases have been scaled from one to one million nodes
PDF
HTTP Plugin for MySQL!
PDF
MySQL Group Replication
PDF
Highly Available MySQL/PHP Applications with mysqlnd
PPTX
MySQL Multi Master Replication
PDF
Introduction to Galera
PPT
Mysql high availability and scalability
ODP
Award-winning technology: Oxid loves the query cache
PDF
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
PDF
Using and Benchmarking Galera in different architectures (PLUK 2012)
PDF
Scaling with sync_replication using Galera and EC2
PDF
Introduction to Galera Cluster
PDF
Webinar slides: Introducing Galera 3.0 - Now supporting MySQL 5.6
PoC: Using a Group Communication System to improve MySQL Replication HA
MySQL native driver for PHP (mysqlnd) - Introduction and overview, Edition 2011
Intro to PECL/mysqlnd_ms (4/7/2011)
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
MySQL 5.7 clustering: The developer perspective
Built-in query caching for all PHP MySQL extensions/APIs
PHP mysqlnd connection multiplexing plugin
Data massage: How databases have been scaled from one to one million nodes
HTTP Plugin for MySQL!
MySQL Group Replication
Highly Available MySQL/PHP Applications with mysqlnd
MySQL Multi Master Replication
Introduction to Galera
Mysql high availability and scalability
Award-winning technology: Oxid loves the query cache
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Using and Benchmarking Galera in different architectures (PLUK 2012)
Scaling with sync_replication using Galera and EC2
Introduction to Galera Cluster
Webinar slides: Introducing Galera 3.0 - Now supporting MySQL 5.6
Ad

Similar to MySQL 5.6 Global Transaction Identifier - Use case: Failover (20)

ODP
MySQL 101 PHPTek 2017
PDF
Replication Tips & Trick for SMUG
PDF
MySQL User Camp: GTIDs
PDF
Replication skeptic
PDF
Replication Tips & Tricks
PPTX
Running gtid replication in production
PPTX
MySQL Replication Overview -- PHPTek 2016
PDF
FOSSASIA 2015: MySQL Group Replication
PDF
MySQL Replication Troubleshooting for Oracle DBAs
PDF
MySQL 5.6 Replication Webinar
PDF
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
ZIP
My sql replication advanced techniques presentation
PDF
MySQL Group Replication - HandsOn Tutorial
PDF
MySQL Replication
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
PDF
MySQL Replication Update -- Zendcon 2016
PDF
MySQL High Availability with Group Replication
PDF
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
PDF
MySQL Parallel Replication: inventory, use-case and limitations
PDF
Demystifying MySQL Replication Crash Safety
MySQL 101 PHPTek 2017
Replication Tips & Trick for SMUG
MySQL User Camp: GTIDs
Replication skeptic
Replication Tips & Tricks
Running gtid replication in production
MySQL Replication Overview -- PHPTek 2016
FOSSASIA 2015: MySQL Group Replication
MySQL Replication Troubleshooting for Oracle DBAs
MySQL 5.6 Replication Webinar
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
My sql replication advanced techniques presentation
MySQL Group Replication - HandsOn Tutorial
MySQL Replication
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Update -- Zendcon 2016
MySQL High Availability with Group Replication
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
MySQL Parallel Replication: inventory, use-case and limitations
Demystifying MySQL Replication Crash Safety
Ad

More from Ulf Wendel (7)

ODP
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
ODP
PHPopstar der PHP Unconference 2011
ODP
The power of mysqlnd plugins
ODP
Mysqlnd query cache plugin benchmark report
ODP
mysqlnd query cache plugin: user-defined storage handler
ODP
Mysqlnd query cache plugin statistics and tuning
ODP
Mysqlnd Async Ipc2008
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
PHPopstar der PHP Unconference 2011
The power of mysqlnd plugins
Mysqlnd query cache plugin benchmark report
mysqlnd query cache plugin: user-defined storage handler
Mysqlnd query cache plugin statistics and tuning
Mysqlnd Async Ipc2008

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Big Data Technologies - Introduction.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.

MySQL 5.6 Global Transaction Identifier - Use case: Failover

  • 1. Ulf Wendel, Oracle MySQL 5.6 Global Transaction Ids Use case: Failover MySQL 5.6, PECL/mysqlnd_ms 1.3
  • 2. The speaker says... It is all about MySQL Replication. MySQL Replication is the database scale-out solution of the LAMP stack. MySQL Replication is using lazy primary copy (master/slave). Built-in global transaction identifier of MySQL 5.6 make server failover semi-automatic. PECL/mysqlnd_ms features connection failover since 1.0, comes with a client-side emulation of global transaction identifier since 1.2, supports the use of the MySQL 5.6 built-in global transaction identifier since 1.3 (under development) but goes beyond the failover aspect. In this slide set – use case #1 failover.
  • 3. MySQL Replication Primary copy (master/slave) for read-scale out Writes/updates: master Reads: slaves MySQL Master Log 7, Pos 34: UPDATE x=1 Log 7, Pos 35: UPDATE x=9 MySQL Slave 1 MySQL Slave 2 Log 2, Pos 1: UPDATE x=1 Log 8, Pos 1: UPDATE x=1 Log 2, Pos 2: UPDATE x=9
  • 4. The speaker says... Use case #1: Master failover. In a MySQL Replication setup all writes/updates must be executed at the master. PECL/mysqlnd_ms, a transparent plugin for the PHP mysqlnd library, does the necessary R/W split for you. The master logs all updates. Slaves read the updates and replay them. Slaves copy updates from the primary, thus the name primary copy. The copy process is asynchronous. Replicas may lag behind. There is one master – it is a single point of failure.
  • 5. Using GTIDs for master failover Slave to master promotion after master outage Which slave is the most current? How to copy transactions from S1 to S2? MySQL Master Log 7, Pos 34: UPDATE x=1 Log 7, Pos 35: UPDATE x=9 MySQL Slave 1 MySQL Slave 2 Log 2, Pos 1: UPDATE x=1 Log 8, Pos 1: UPDATE x=1 Log 2, Pos 2: UPDATE x=9
  • 6. The speaker says... The master fails, it becomes unavailable alltogether. A slave must be promoted to become the new master. It is hard to tell which slave has the latest transactions. Transactions are referenced by log file offsets. The highest log position does not necessarily the refer to the latest transaction. Identification of transactions is hard. Log positions cannot be compared among replicas because different log file settings may result in different offsets. For example, two replicas may use different setting for log rotation.
  • 7. Global transaction identifier Combination of server id and sequence number Emulation: PECL/mysqlnd_ms 1.2, MySQL Proxy Built-in: MySQL 5.6 MySQL Master Log 7, Pos 34, GTID M:1: UPDATE x=1 Log 7, Pos 35, GTID M:2: UPDATE x=9 MySQL Slave 1 MySQL Slave 2 … , GTID M:1: UPDATE x=1 … , GTID M:1: UPDATE x=1 … , GTID M:2: UPDATE x=9
  • 8. The speaker says... A global transaction identifier is a cluster-wide unique transaction identifier. MySQL 5.6 can generate it automatically. MySQL Proxy and PECL/mysqlnd_ms 1.2 feature client-side emulations for use with any MySQL version. The sequence number makes it easy to identify the latest transactions for a given master. This helps to identify the most current slave. Because it is now easy to uniquely identify a transaction it is clear Slave 1 should be the new master. Slave 2 becomes a slave of Slave 1. Slave 2 continues replication with transaction M:2.
  • 9. Availability improved, solved? Master failover improved! Scriptable, unattended failover possible No 3rd party solution required MySQL Master (was: Slave 1) MySQL Master … , GTID M:1: UPDATE x=1 … , GTID M:2: UPDATE x=9 … , GTID S:1: UPDATE x=0 MySQL Slave 2 … , GTID S:2: UPDATE x=9 … , GTID M:1: UPDATE x=1 … , GTID M:2: UPDATE x=9 … , GTID S:1: UPDATE x=0
  • 10. The speaker says... The introduction of GTIDs is a milestone towards improving the availability of a MySQL Replication cluster. The MySQL 5.6 Reference manual will give details, including some limitations of GTIDs. The client side has not been considered yet. How to handle connection failures, how to handle permanent server failures?
  • 11. PECL/mysqlnd_ms failover Slave connection failover is easy... Catch error, rerun statement, plugin picks next server Connection handle remains useable Automatic (no error) mode exists (not recommended) PECL/mysqlnd_ms Fail... … over MySQL Master MySQL Slave MySQL Slave
  • 12. The speaker says... Failing over a read-only client connection to a slave is easy. In case of an error PECL/mysqlnd_ms can either silently failover to the next slave or master or, the plugin returns an error. Automatic and silent failover is not recommended as connection state is lost. Instead, applications should catch the error, handle the failed transaction and rerun their transaction. Upon execution of the next statement, PECL/mysqlnd_ms fails over to another server. The connection handle remains valid and useable. Failover in a single master primary copy cluster is impossible: where to sent the write?
  • 13. PECL/mysqlnd_ms deployment Cluster topology change requires deployment Client configuration lists servers and roles Slave to master promotion requires deployment Addition or removal of slave requires deployment PECL/mysqlnd_ms Where to fail over? MySQL Master MySQL Slave MySQL Slave
  • 14. The speaker says... Load balancers, including those load balancers that are part of the driver, must be reconfigured after cluster topology has changed (membership, roles). Deploy the PECL/mysqlnd_ms configuration as part of your slave to master promotion! The load balancer configuration update should be done after the cluster has been reconfigured and the new master is in place.
  • 15. In the next slide set... GTID Use case #2: consistency Session consistency (read-your-writes) PECL/mysqlnd_ms 1.2 and above