Top Banner
Peter Zaitsev, CEO, Percona Moscow MySQL User Meetup Moscow,Russia MySQL Replication Options
72

MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

Oct 11, 2019

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 Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

Peter Zaitsev, CEO, Percona

Moscow MySQL User Meetup Moscow,Russia

MySQL Replication Options

Page 2: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com2

Few Words About Percona

Your Partner in MySQL and MongoDB Success

100% Open Source Software

“No Lock in Required” Solutions

and Services

We work with MySQL, MariaDB, MongoDB,

Amazon RDS and Aurora

2

Page 3: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com3

In This Presentation

Why Replication ?

How to think about Replication

Overview of what MySQL Has to Offer

Page 4: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com4

Replication

Having Multiple Copies of the data, updated with

changes

Page 5: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com5

Why Replication

Availability Scalability

Performance

Page 6: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com6

Availability

Service Stays up when component

fails

Page 7: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com7

Availability via Redundancy

Have more than one system

Works well for stateless systems

Is not enough for databases

Page 8: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com8

Availability via Replication

Redundant Computing Resource

Paired with Replicated Data

Page 9: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com9

Component Failure

Node Failures • Total Crash • Process Crash • Stall/Unresponsive • Consistency Issues

Network Failures • Single Port Failures • Partitions • Complicated Failures

Page 10: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com10

Scalability

Scales Reads

Does not Scale Writes very well

Data Distribution is needed for scaling writes

Page 11: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com11

Performance

Reduce response time by maintaining replica closer to

user

Page 12: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com12

Talking about

Full Database Replication • System of Record

Partial Database Replication Can be used as • Cache • Synchronization of Client Data

Page 13: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com13

Where Replication Happens

Storage Level

Database Level

Application Level

Page 14: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com14

Storage Level Replication

Replication RAID

Typically provides cold standby

Simple choice which works with many systems

Amazon Aurora – Smart Storage

Page 15: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com15

Database level

Most Flexible

Most Common

Hot/Warm Spare

Some can do Active-Active

Page 16: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com16

Application Level

Hard to get right

Rarely used, even more so used right

Partial Replication/Syncronization

Smart conflict resolution

Cross Vendor Redundancy

Page 17: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com17 www.percona.com

Replication Properties

Page 18: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com18

Number of Writable Nodes

Single Writer (Master)

Write Anywhere (Multi Master)

Page 19: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com19

Single Master

All writes go to the single node

One way replication stream

Simple

No Conflicts

Replication aware Application or Connector

Page 20: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com20

Multiple Active Masters

Can write to multiple masters

Replication is multi-directional

More Complicated

Possibility of Conflicts

Page 21: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com21

Sync or Async

Synchronous Replication

Asynchronous Replication

Page 22: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com22

Synchronous Replication

Data “Persisted” on Target Server

Guarantees No Data Loss if Source server fails

Conflicts can be easily prevented

Expensive

Page 23: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com23

What “Persisted” means ?

In Memory • Assumes power loss of both servers

does not happen

On Disk • Handles Total Loss of Master and

Power loss on the Slave

Page 24: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com24

Asynchronous Replication

Anything not Synchronous

Many different variants exist!

Page 25: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com25

Asynchronous Properties

Commit on Master • What happens with

Persistence ? • What happens with

Visibility ?

Page 26: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com26

Persistence

Uncommitted Data on Master

Committed Data on Master

Date in Slave’s memory

Data on Slave’s Disk (log)

Page 27: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com27

Visibility

Results be visible by concurrent sessions before acknowledgement • Phantom Reads

Results can’t be visible by concurrent sessions • No Phantom Reads

Page 28: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com28

Conflits

No Conflict Handling

Conflict Detection

Conflict Resolution

Conflict Prevention

Page 29: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com29

Acknowledgements

Applies both to Sync and Some Async

How many node have successfully replicated data ?

All ?

One ?

Majority ?

Page 30: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com30

Level of Control

Global Control vs Database Control

Control by Writer vs Reader

Page 31: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com31

Number of Replicas

On (2 nodes)

Two or more (3+ nodes)

Page 32: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com32

2 nodes

Basic Redundancy

Need Help with Failure detection and Split Brain

No Redundancy in case of node maintainance

Page 33: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com33

3+ Nodes

Much better Redundancy

Quorum based failure handling works out of the box

Can do node maintenance without redundancy loss

Page 34: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com34

Failure Detection and Promotion

Built-In

Handled by External Tools

Page 35: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com35

Replica Provisioning

Manual

Automatic

Page 36: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com36

Gotchas

Distributed systems are complicated. All products have their own gotchas.

Page 37: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com37 www.percona.com

MySQL Replication

Page 38: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com38

“Classic” MySQL Replication

Fully Asynchronous

No Failure Detection and Promotion

Manual Provisioning

Can run Multi-Master

No Conflict Handling

Page 39: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com39

Semi-Sync Replication 5.6

Wait for one of the slaves to ack update before response to client

Commits too soon on the Master

“Phantom Reads” / Possible loss of visible changes

Can switch to asynchronous mode

Page 40: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com40

Semi-Sync Replication 5.7

Commits on the Master only after slave acknowledges

Update invisible to other clients until slave acknowledges

Can be Configured to have MySQL 5.6 behavior

Page 41: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com41

Making MySQL Replication Better

MHA

MySQL Failover

PRM

Page 42: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com42 www.percona.com

Percona XtraDB Cluster and “Galera”

Page 43: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com43

Percona XtraDB ClusterVirtually Synchronous Replication

Well known Innodb Storage Engine

All Reads are Local

Parallel Replication

Write to any node behavior

Built in Node Provisioning and HA

Works great in the Cloud !

Page 44: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com44

PXC vs Galera

Galera • Is replication

technology/library • Compare to Linux

Kernel

Percona XtraDB Cluster • Percona Server • Enabling Enhancements • Galera Library • Provisioning Tools • HA and Load Balancing • Integrated together and

Tested • Compare to Linux

Distribution

Page 45: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com45

PXC Data Architecture

Page 46: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com46

Architecture Concepts

All Nodes Have Full copy of Data

Every Node is Equal

No Central Management

No SPOF

Page 47: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com47

Understanding Cluster

The cluster can be seen as a meeting !

Page 48: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com48

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

48

Page 49: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com49

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

49

Page 50: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com50

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

50

Page 51: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com51

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

51

Page 52: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com52

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

52

Page 53: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com53

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

53

Page 54: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com54

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

54

Page 55: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com55

PXC (Galera cluster) is a meeting 55

Page 56: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com56

PXC (Galera cluster) is a meeting

???

56

Page 57: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com57

4fd8824d-ad5b-11e2-0800-73d6929be5cf

New meeting !

57

Page 58: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com58

Cluster Reads

Reads are always Local

Stale Reads can be allowed or disallowed

Page 59: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com59

Cluster Writes

Write on one node or Write Anywhere

Certification Based Replication

Communication on Commit only

Asynchronous Application

Parallel Replication

Page 60: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com60

Transaction Commit Flow

Page 61: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com61

Loss of connectivity

Quorum 61

Network Problem

Does not accept Reads & Writes

Page 62: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com62

Automatic Node Provisioning

writes

writeswrites

new node joining

data is copied via SST or IST

62

Page 63: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com63

Automatic Node Provisioning

writes

writeswrites

new node joiningwhen ready

writes

63

Page 64: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com64

Dedicated shared HAProxy application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

HA PROXY

64

Page 65: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com65

HAProxy on application sideapplication server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

65

HA PROXY HA PROXY HA PROXY

Page 66: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com66

Scaling Writes ?

Shard over PXC Cluster rather than MySQL Replicas

Page 67: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com67

Thinks To Keep in MindUse Innodb storage engine

Primary Key on all tables

Avoid Large write transactions (changing many rows)

Plan Data size for SST time correctly

Hot Rows

Optimistic Locking

Page 68: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com68

MySQL Group Replication

Similar to Galera

Currently in Development

Better integrated with MySQL

No Automated provisioning (yet)

Page 69: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com69

MySQL Cluster

Mostly In Memory Storage

Synchronous Replication

Pessimistic Locking

Conflict Detection with Async Replication

Niche Use Only

Page 70: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com70

New Developments

MySQL Fabric

MySQL Router

MariaDB Max Scale

Page 71: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com71

Percona Live 2016 call for papers is Open

Call for Papers Open until November 29, 2015

MySQL, MongoDB, NoSQL, Data in The Cloud

Anything to make Data Happy!

http://bit.ly/PL16Call

71

Page 72: MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your Partner in MySQL and MongoDB Success 100% Open Source Software “No Lock in Required”

www.percona.com72 www.percona.com

Peter Zaitsev [email protected]

P.S We’re Hiring http://bit.ly/PerconaJobs

Thank You!