MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your...

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

Transcript of MySQL Replication Options - Percona · MySQL Replication Options. 2 Few Words About Percona Your...

Peter Zaitsev, CEO, Percona

Moscow MySQL User Meetup Moscow,Russia

MySQL Replication Options

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

www.percona.com3

In This Presentation

Why Replication ?

How to think about Replication

Overview of what MySQL Has to Offer

www.percona.com4

Replication

Having Multiple Copies of the data, updated with

changes

www.percona.com5

Why Replication

Availability Scalability

Performance

www.percona.com6

Availability

Service Stays up when component

fails

www.percona.com7

Availability via Redundancy

Have more than one system

Works well for stateless systems

Is not enough for databases

www.percona.com8

Availability via Replication

Redundant Computing Resource

Paired with Replicated Data

www.percona.com9

Component Failure

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

Network Failures • Single Port Failures • Partitions • Complicated Failures

www.percona.com10

Scalability

Scales Reads

Does not Scale Writes very well

Data Distribution is needed for scaling writes

www.percona.com11

Performance

Reduce response time by maintaining replica closer to

user

www.percona.com12

Talking about

Full Database Replication • System of Record

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

www.percona.com13

Where Replication Happens

Storage Level

Database Level

Application Level

www.percona.com14

Storage Level Replication

Replication RAID

Typically provides cold standby

Simple choice which works with many systems

Amazon Aurora – Smart Storage

www.percona.com15

Database level

Most Flexible

Most Common

Hot/Warm Spare

Some can do Active-Active

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

www.percona.com17 www.percona.com

Replication Properties

www.percona.com18

Number of Writable Nodes

Single Writer (Master)

Write Anywhere (Multi Master)

www.percona.com19

Single Master

All writes go to the single node

One way replication stream

Simple

No Conflicts

Replication aware Application or Connector

www.percona.com20

Multiple Active Masters

Can write to multiple masters

Replication is multi-directional

More Complicated

Possibility of Conflicts

www.percona.com21

Sync or Async

Synchronous Replication

Asynchronous Replication

www.percona.com22

Synchronous Replication

Data “Persisted” on Target Server

Guarantees No Data Loss if Source server fails

Conflicts can be easily prevented

Expensive

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

www.percona.com24

Asynchronous Replication

Anything not Synchronous

Many different variants exist!

www.percona.com25

Asynchronous Properties

Commit on Master • What happens with

Persistence ? • What happens with

Visibility ?

www.percona.com26

Persistence

Uncommitted Data on Master

Committed Data on Master

Date in Slave’s memory

Data on Slave’s Disk (log)

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

www.percona.com28

Conflits

No Conflict Handling

Conflict Detection

Conflict Resolution

Conflict Prevention

www.percona.com29

Acknowledgements

Applies both to Sync and Some Async

How many node have successfully replicated data ?

All ?

One ?

Majority ?

www.percona.com30

Level of Control

Global Control vs Database Control

Control by Writer vs Reader

www.percona.com31

Number of Replicas

On (2 nodes)

Two or more (3+ nodes)

www.percona.com32

2 nodes

Basic Redundancy

Need Help with Failure detection and Split Brain

No Redundancy in case of node maintainance

www.percona.com33

3+ Nodes

Much better Redundancy

Quorum based failure handling works out of the box

Can do node maintenance without redundancy loss

www.percona.com34

Failure Detection and Promotion

Built-In

Handled by External Tools

www.percona.com35

Replica Provisioning

Manual

Automatic

www.percona.com36

Gotchas

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

www.percona.com37 www.percona.com

MySQL Replication

www.percona.com38

“Classic” MySQL Replication

Fully Asynchronous

No Failure Detection and Promotion

Manual Provisioning

Can run Multi-Master

No Conflict Handling

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

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

www.percona.com41

Making MySQL Replication Better

MHA

MySQL Failover

PRM

www.percona.com42 www.percona.com

Percona XtraDB Cluster and “Galera”

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 !

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

www.percona.com45

PXC Data Architecture

www.percona.com46

Architecture Concepts

All Nodes Have Full copy of Data

Every Node is Equal

No Central Management

No SPOF

www.percona.com47

Understanding Cluster

The cluster can be seen as a meeting !

www.percona.com48

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

48

www.percona.com49

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

49

www.percona.com50

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

50

www.percona.com51

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

51

www.percona.com52

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

52

www.percona.com53

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

53

www.percona.com54

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

54

www.percona.com55

PXC (Galera cluster) is a meeting 55

www.percona.com56

PXC (Galera cluster) is a meeting

???

56

www.percona.com57

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

New meeting !

57

www.percona.com58

Cluster Reads

Reads are always Local

Stale Reads can be allowed or disallowed

www.percona.com59

Cluster Writes

Write on one node or Write Anywhere

Certification Based Replication

Communication on Commit only

Asynchronous Application

Parallel Replication

www.percona.com60

Transaction Commit Flow

www.percona.com61

Loss of connectivity

Quorum 61

Network Problem

Does not accept Reads & Writes

www.percona.com62

Automatic Node Provisioning

writes

writeswrites

new node joining

data is copied via SST or IST

62

www.percona.com63

Automatic Node Provisioning

writes

writeswrites

new node joiningwhen ready

writes

63

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

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

www.percona.com66

Scaling Writes ?

Shard over PXC Cluster rather than MySQL Replicas

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

www.percona.com68

MySQL Group Replication

Similar to Galera

Currently in Development

Better integrated with MySQL

No Automated provisioning (yet)

www.percona.com69

MySQL Cluster

Mostly In Memory Storage

Synchronous Replication

Pessimistic Locking

Conflict Detection with Async Replication

Niche Use Only

www.percona.com70

New Developments

MySQL Fabric

MySQL Router

MariaDB Max Scale

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

www.percona.com72 www.percona.com

Peter Zaitsev [email protected]

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

Thank You!