Top Banner
OSS4B: Percona XtraDB Cluster Introduction to parallel synchronous replication Frédéric Descamps 19 Sep 2013
67

Oss4b - pxc introduction

May 17, 2015

Download

Technology

Introduction to Percona XtraDB Cluster (Galera)
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: Oss4b   - pxc introduction

OSS4B: Percona XtraDB ClusterIntroduction to parallel synchronous

replication

Frédéric Descamps19 Sep 2013

Page 2: Oss4b   - pxc introduction

OSS4B: Percona XtraDB ClusterIntroduction to parallel synchronous

replication

Frédéric Descamps19 Sep 2013

Page 3: Oss4b   - pxc introduction

Who am I ?

• Frédéric Descamps “lefred”• @lefred• http://about.me/lefred• Percona Consultant since 2011• Managing MySQL since 3.23 (as far as

I remember)• devops believer

3

Page 4: Oss4b   - pxc introduction

Agenda

• Percona• MySQL Replication• Galera & PXC

4

Page 5: Oss4b   - pxc introduction

Percona

• We are the oldest and largest independent MySQL Support, Consulting, Remote DBA, Training, and Software Development company with a global, 24x7 staff of nearly 100 serving more than 2,000 customers in 50+ countries since 2006 !

• Our contributions to the MySQL community include open source server and tools software, books, and original research published on the MySQL Performance Blog.

5

Page 6: Oss4b   - pxc introduction

MySQL Replication6

If your HA is based on MySQL Replication -You may play a dangerous game !

Page 7: Oss4b   - pxc introduction

Traditional Replication Approach

Server-centric : “one server streams data to another”

7

Server 1 Server 2

replication stream

“master” “slave”

Page 8: Oss4b   - pxc introduction

This can lead to cool topologies !8

1

2

3

4

5

6

7 8 910

1213

14

15

16 17

18

19

11

Page 9: Oss4b   - pxc introduction

This can lead to cool topologies !9

1

2

3

4

5

6

7 8 910

1213

14

15

16 17

18

19

11

If node 4 crashes do we still have a cluster ?

Page 10: Oss4b   - pxc introduction

This can lead to cool topologies !10

1

2

3

4

5

6

7 8 910

1213

14

15

16 17

18

19

11If node 3 crashes and clients

failover to 2, how 3 joins back ?

Page 11: Oss4b   - pxc introduction

This can lead to cool topologies !11

1

2

3

4

5

6

7 8 910

1213

14

15

16 17

18

19

11

How do we backupthe cluster ?

Page 12: Oss4b   - pxc introduction

Galera (wsrep) Approach12

DATA

Server 1 Server 2 Server 3 Server N...

The dataset is synchronized between one or more servers: data-centric

Page 13: Oss4b   - pxc introduction

Data-centric

• Data does not belong to a node• Node belongs to data !

13

Page 14: Oss4b   - pxc introduction

What is Percona XtraDB Cluster ?

• Percona Server• + WSREP patches• + Galera library• + utilities (init, SST and cluster check

scripts)

14

Page 15: Oss4b   - pxc introduction

Percona Server

• This is a free open source solution, Percona Server is a MySQL alternative which offers breakthrough performance, scalability, features, and instrumentation. Self-tuning algorithms and support for extremely high-performance hardware make it the clear choice for organizations that demand excellent performance and reliability from their MySQL database server.

15

Page 16: Oss4b   - pxc introduction

WSREP and Galera

• WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication)

• Galera is a wsrep provider that implements true multi-master vritually synchronous replication

16

Page 17: Oss4b   - pxc introduction

What is Percona XtraDB Cluster ?17

Fullcompatibility with existing

systems

Page 18: Oss4b   - pxc introduction

What is Percona XtraDB Cluster ?18

Minimal effortsto migrate

Page 19: Oss4b   - pxc introduction

What is Percona XtraDB Cluster ?19

Minimal effortsto return back

to MySQL

Page 20: Oss4b   - pxc introduction

Features20

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 21: Oss4b   - pxc introduction

Features21

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 22: Oss4b   - pxc introduction

(Virtual) Synchronous Replication

• Different from asynchronous MySQL replication:

– Writesets (tx) are replicated to all available nodes on commit (and en-queued on each)

– Writesets are “certified” on every node– En-queued writesets are applied on

those nodes independently and asynchronously

22

Page 23: Oss4b   - pxc introduction

(Virtual) Synchronous Replication23

Page 24: Oss4b   - pxc introduction

Features24

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 25: Oss4b   - pxc introduction

Multi-Master Replication

• You can write to any node in your cluster• Don't worry about eventual out-of-sync

25

writes

writeswrites

Page 26: Oss4b   - pxc introduction

Features26

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 27: Oss4b   - pxc introduction

Parallel Replication

• Standard MySQL

27

Writes N threads

Apply 1 thread

Page 28: Oss4b   - pxc introduction

Parallel Replication

• PXC / Galera

28

Writes N threads

Apply M threads

Page 29: Oss4b   - pxc introduction

Features29

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 30: Oss4b   - pxc introduction

Data Consistency

• Writesets (transactions) are either applied on every node or not at all !

• Watch out split brain situation (minimum is 3 nodes)

30

Page 31: Oss4b   - pxc introduction

Features31

synchronousreplication

multi-masterreplication

parallelapplying on

slaves

dataconsistency

automaticnode

provisioning

Page 32: Oss4b   - pxc introduction

Automatic Node Provisioning

• When a node joins the cluster, the data is automatically copied and when finished the new node is automatically ready and accepting connections

• The node provisioning can be divided in 2 different approaches:

– SST (state snapshot transfer): full copy of the data

– IST (incremental state transfer): send only the missing writesets (if available)

32

Page 33: Oss4b   - pxc introduction

StateTransfer Summary33

Full dataSST

IncrementalIST

New node

Node longtime

disconnected

Nodedisconnected

short time

Page 34: Oss4b   - pxc introduction

Snapshot State Transfer34

mysqldump

Smalldatabases

rsync

Donordisconnectedfor copy time

Faster

XtraBackup

Donoravailable

Slower

Page 35: Oss4b   - pxc introduction

Incremental State Transfer35

Node wasin the cluster

Disconnectedfor maintenance

Nodecrashed

Page 36: Oss4b   - pxc introduction

Automatic Node Provisioning36

writes

writeswrites

new node joining

data is copied via SST or IST

Page 37: Oss4b   - pxc introduction

Automatic Node Provisioning37

writes

writeswrites

new node joiningwhen ready

writes

Page 38: Oss4b   - pxc introduction

Understanding Galera

38The cluster can be seen as a meeting !

Page 39: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting39

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 40: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting40

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 41: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting41

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 42: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting42

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 43: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting43

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 44: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting44

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 45: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting45

bfb912e5-f560-11e2-0800-1eefab05e57d

Page 46: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting46

Page 47: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting47

???

Page 48: Oss4b   - pxc introduction

PXC (Galera cluster) is a meeting48

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

New meeting !

Page 49: Oss4b   - pxc introduction

Why using a PXC ?

• High Availability !• Works perfect with a load balancer

(like Ha proxy)• WAN replication is also possible but

adds some delay to commit latency (100-300ms)

49

Page 50: Oss4b   - pxc introduction

PXC with a Load balancer

• PXC can be integrate with a load balancer and service can be checked using clustercheck or pyclustercheck

• The load balancer can be a dedicated one

• or integrated on each application servers

50

Page 51: Oss4b   - pxc introduction

Dedicated shared HAProxy

application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

HA PROXY

Page 52: Oss4b   - pxc introduction

Dedicated shared HAProxy

application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

HA PROXY

Page 53: Oss4b   - pxc introduction

Dedicated shared HAProxy

application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

HA PROXY

SST

available_when_donor=0

Page 54: Oss4b   - pxc introduction

HAProxy on application side

Page 55: Oss4b   - pxc introduction

HA Proxy frontend55

Page 56: Oss4b   - pxc introduction

WAN replication

MySQL

MySQL

MySQL

Works fine

Use higher timeouts and send windows

No impact on reads

No impact within a transaction

Increase commit latency

Page 57: Oss4b   - pxc introduction

WAN replication - latencies

MySQL

MySQL

MySQL

Beware of latencies

Within EUROPE EC2– INSERT INTO table: 0.005100 sec

EUROPE <-> JAPAN EC2– INSERT INTO table: 0.275642 sec

Page 58: Oss4b   - pxc introduction

WAN replication with MySQL asynchronous replication

MySQL

MySQL

MySQL

You can mix both replications

Good option on slow WAN link

Requires more nodes

If binlog position is lost, full cluster must be reprovisioned

MySQL

MySQL

MySQL

MySQL

MySQL MySQL

Page 59: Oss4b   - pxc introduction

So, is Percona XtraDB Cluster a perfect solution ?

59Limitations

Page 60: Oss4b   - pxc introduction

Limitations

Supports only InnoDB tables– MyISAM support is very basic and will stay in alpha.

Different locking: optimistic locking

The weakest node limits the write performance

For write intensive applications there could be datasize limit per node

All tables must have a Primary Key !

Page 61: Oss4b   - pxc introduction

Limitations (2)

Large transactions are not recommended if you write on all nodes simultaneously

If your application has a data hotspot then PXC may not be right for you.

Page 62: Oss4b   - pxc introduction

OPTIMISTIC locking for transactions on different servers

Traditional locking

system 1Transaction 1 Transaction 2

BEGIN

Transaction1

BEGIN

UPDATE t WHERE id=14 UPDATE t WHERE id=14

...

COMMITWaits on COMMIT in trx 1

Page 63: Oss4b   - pxc introduction

OPTIMISTIC locking for transactions on different servers

Optimistic locking

system 1Transaction 1 Transaction 2

BEGIN

Transaction1

BEGIN

UPDATE t WHERE id=14 UPDATE t WHERE id=14

...

COMMIT

system 2

...

COMMIT

ERROR due row conflict

Page 64: Oss4b   - pxc introduction

Credits

WSREP patches and Galera library is developed by Codership Oy

Percona & Codership will present on Percona Live UK 2013, Nov 11-12 http://www.percona.com/live/london-2013/

Page 65: Oss4b   - pxc introduction

Resources

Percona XtraDB Cluster website: http://www.percona.com/software/percona-xtradb-cluster/

Codership website: http://www.codership.com/wiki/doku.php

PXC articles on mysqlperformanceblog: http://www.mysqlperformanceblog.com/category/percona-xtradb-cluster/

Page 66: Oss4b   - pxc introduction

Percona provides

24 x 7 Support Services Quick and Easy Access to Consultants Same Day Emergency Data Recovery Remote DBA Services QUOTE OSS4B for Special Consulting Offer – Free Mini Health Audit with Gold Support and Free Performance Audit with Platinum Support Valid September-October 2013

[email protected] or 00442081330309

Page 67: Oss4b   - pxc introduction

Thank you !

Test it now using Vagrant !

Questions?