Top Banner
© 2017 Percona 1 Peter Zaitsev, CEO MySQL Replication – Advanced Features In 20 minutes FOSDEM, Brussels, Belgium February 2nd, 2019
36

MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

May 20, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona1

Peter Zaitsev, CEO

MySQL Replication – Advanced FeaturesIn 20 minutes

FOSDEM, Brussels, BelgiumFebruary 2nd, 2019

Page 2: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona2

Question #1

Who in this room is using some kind of MySQL

Replication ?

Page 3: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona3

Question #2

•Classical MySQL Replication

•MySQL Group Replication

•Galera Replication (including Percona XtraDB Cluster)

Which Type of MySQL

Replication do you use

Page 4: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona4

Replication in MySQLA brief Time Line

Page 5: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona5

MySQL Replication

MySQL 3.23

• Initial Statement Replication Implemented

MySQL 4.0

• Split IO Thread and SQL Thread

MySQL 5.1

• Row and Mixed replication modes supported

MySQL 5.6

• Per Database Parallel Replication

• GTID Support

MySQL 5.7

• General Parallel Replication

• Multi-Source Replication

• Group Replication / MySQL Innodb Cluster

Page 6: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona6

Galera Based Replication Technology

Similar to MySQL Group Replication but more mature

Available for MySQL, Percona, MariaDB

Alternative Track

Page 7: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona7

Replication in MariaDB

Is not 100% Same as in MySQL

Different GTID Implementation

Different parallel replication

Not instrumented in the same way

Number of features became available in MariaDB Earlier

Not covering MariaDB in this Presentation

Page 8: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona8

Advanced Replication

Page 9: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona9

Basic Replication Topology

Page 10: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona10

What is Basic Replication ?

Statement Replication

Replication of the Full

Database

Using Binary Log Position

Single TierTopology

Single Thread AsynchronousWrite to Single

Master

Keep Slave Meta-Data Data

in Files

Master-Slave-Replication

Manual Failover & Traffic

Management

Page 11: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona11

Statement vs Row Replication

•STATEMENT

•ROW

•MIXED

Configured on the Master as binlog_format

Page 12: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona12

How Rows are Logged ?

•Full

•Minimal

•Noblob

binlog_row_image

Page 13: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona13

Missing Seeing Queries ?

Also Log Query For informational Purposes

binlog_rows_query_log_events

Off by Default

Page 14: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona14

Replication of Full Database

Full Replication Most Simple for Troubleshooting and Recovery

Can replicate only portions of the database

Can add additional data to the slaves

Page 15: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona15

Replication Filering

• Binlog_do_db

• Binlog_ignore_db

On the Master (writing binary

log)

• Replicate_do_db

• Replicate_ignore_db

• Replicate_wild_do_table

• Replicate_wild_ignore_table

On the Slave

Page 16: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona16

Position Identification

By Binary Log Position

•File: mysql-bin.000003

•Position: 73

By GTID

•3E11FA47-71CA-11E1-9E33-C80AA9429562:23

Page 17: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona17

What is in GTID ?

GTID = source_id:transaction_id

Source_id is Server_uuid of Originating Server

Always Preserved on the Slaves

Track which transactions executed

mysql.gtid_executed table (5.7) + binlog

Page 18: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona18

GTID Benefits and Drawbacks

Automatic Position Discovery

Easy Slave Promotion

Discovery of Missed Transactions

Pain in the Ass with Manual Troubleshooting

Page 19: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona19

Replication Topologies

Single Tier Master-Slave

Bi-Directional

Tree

Ring

Directed Graph

Page 20: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona20

Options For Complicated Topologies

•Store copy of applied statements in local binlog

•Disabled by default until MySQL 8

Log_slave_updates

Page 21: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona21

Parallel Replication

Single Thread Replication is typical limiting factor

Parallel Replication for multiple Databases since 5.6

Parallel Replication for same table since 5.7

Page 22: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona22

Managing Parallel Replication

slave-parallel-workers

slave-parallel-type=DATABASE|LOGICAL_CLOCK

slave_preserve_commit_order

Page 23: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona23

Standard MySQL Replication - Asynchronous

Data Persisted on the Master

… Eventually Transferred to the Slave

After that Eventually Applied on the Slave

Replication Lag is Unbound

Data Loss can happen on Master Loss

Page 24: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona24

Semi-Synchronous Replication in MySQL

• Both on Master and SlavePlugin Required

• INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';Master

• INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';Slave

Page 25: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona25

Semi-Sync Replication Options

Master: rpl_semi_sync_master_enabled

Master: rpl_semi_sync_master_timeout

Master: rpl_semi_sync_master_wait_point=AFTER_SYNC|AFTER_COMMIT

Master: rpl_semi_sync_master_wait_for_slave_count

Slave: rpl_semi_sync_slave_enabled

Page 26: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona26

MySQL Replication Active Multi-Master

Recipe for problems with Async/SemiSync Replication

Design Application to Avoid Conflicts

MySQL Group Replication

PXC/Galera Based Solutions

Page 27: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona27

Multi-Master with MySQL Classic Replication

auto_increment_offset

auto_increment_increment

slave_exec_mode=idempotent

Page 28: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona28

Replication Position information

Master_info_repository=FILE|TABLE

Relay_log_info_repository=FILE|TABLE

Sync_master_info

Sync_relay_log_info

Relay_log_recovery

Less Problem with GTID Replication

Page 29: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona29

Master Slave Replication ?

Most Commonly Used Variant

MySQL Group Replication is other Option

Percona XtraDB Cluster/Galera - Community Alternative

Page 30: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona30

MySQL Group Replication Overview

Inspired by Galera Ideas (and Success)

Built on top of standard MySQL Replication

Available as Plugin for MySQL 5.7

Considered GA, Very Actively Developed

Page 31: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona31

Difference from MySQL Replication

No Master/Slave but Group Membership

Transactions are committed when they are certified by majority of nodes (Paxos)

Does not accept writes if there is no Quorum

Flow Control to prevent unlimited replication lag

Nodes encountering inconsistency leave the cluster

Conflict Detection and Resolution (or avoidance)

Simple FailOver

Page 32: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona32

MySQL Group Replication - Writes

By Default configures itself as Single Primary

Can configure to allow writes to any node

Page 33: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona33

MySQL Group Replication Limitations

No Automated node Provisioning

Manual Recovery of nodes with network failure

No way (yet) to ensure node does not read stale data

Page 34: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona34

MySQL Innodb Cluster

Page 35: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

© 2017 Percona35

Advanced Replication tools to Consider

•OrchestratorAutomating Failover

•ProxySQLRead Write Splitting and Traffic Management

•Vitess Sharding

Page 36: MySQL Replication Advanced Features - FOSDEM · MySQL Replication MySQL 3.23 •Initial Statement Replication Implemented MySQL 4.0 •Split IO Thread and SQL Thread MySQL 5.1 •Row

DATABASE PERFORMANCE

MATTERSDatabase Performance MattersDatabase Performance MattersDatabase Performance MattersDatabase Performance MattersDatabase Performance Matters