Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic...

90
Percona XtraDB Cluster Kenny Gryp @gryp 07 03 2017 1

Transcript of Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic...

Page 1: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Percona XtraDB Cluster

Kenny Gryp@gryp 07 03 2017 1

Page 2: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Agenda

• Default asynchronous MySQL replication• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read Scaling

• Limitations

2

Page 3: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Percona

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

• Our contributions to the MySQL community include:• Percona Server for MySQL, Percona XtraDB Cluster• Percona Server for MongoDB• Percona XtraBackup: online backup• Percona Toolkit• Percona Monitoring & Management…

3

Page 4: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Agenda

• Default asynchronous MySQL Replication

• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read Scaling

• Limitations

4

Page 5: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

MySQL Replication

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

5

Page 6: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Traditional Replication Approach

Server 1 Server 2replication stream

“master” “slave”

6

Page 7: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

MySQL Replication 7

1 2

3 4

5 6

• Common Topologies:• Master-Master (Only 1 active master)• 1 or more layers of replication

Page 8: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• Slaves can be used for reads:• asynchronous, stale data is the rule• data loss possible (*semi-sync)

MySQL Replication 8

1 2

3 4

5 6

Page 9: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• non-trivial:• external monitoring• scripts for failover• add node == restore backup• much better in

MySQL 5.6: GTIDs

MySQL Replication

1 2

3 4

5 6

9

Page 10: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Agenda

• Default asynchronous MySQL Replication• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read Scaling

• Limitations

10

Page 11: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

11Data Centric

DATA

Server 1 Server 2 Server 3 Server N ...

Page 12: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

12Percona XtraDB Cluster

Page 13: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

13Percona XtraDB Cluster

• All nodes have a full copy of the data• Every node is equal• No central management, no SPOF

Page 14: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

14Understanding Galera

38The cluster can be seen as a meeting !

Page 15: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

15

Page 16: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

16

Page 17: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

17

Page 18: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

18

Page 19: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

19

Page 20: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

20

Page 21: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

bfb912e5-f560-11e2-0800-1eefab05e57d

21

Page 22: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting 22

Page 23: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

???

23

Page 24: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

PXC (Galera cluster) is a meeting

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

New meeting !

24

Page 25: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

What is Percona XtraDB Cluster ?

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

scripts)• + Percona Changes to Galera

25

Page 26: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

26

• 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 organisations that demand excellent performance and reliability from their MySQL database server.

Percona Server

Page 27: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

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 multi-master, synchronous replication

• Other 'Similar' Implementations: • MariaDB Galera Cluster• Galera Cluster For MySQL

27

Page 28: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

What is Percona XtraDB Cluster ?

Fullcompatibility with existing

systems

28

Page 29: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

What is Percona XtraDB Cluster ?

Minimal effortsto migrate

29

Page 30: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

What is Percona XtraDB Cluster ?

Minimal effortsto return back

to MySQL

30

Page 31: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

31Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 32: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

32Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 33: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

33(Virtual) Synchronous Replication

• Writesets (transactions) are replicated to all available nodes on commit (and queued on each)

• Writesets are individually “certified” on every node, deterministically.Either it is committed on all nodes or no node at all (NO 2PC)

• Queued writesets are applied on those nodes independently and asynchronously

• Flow Control avoids too much ‘lag’

Page 34: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

34(Virtual) Synchronous Replication

Page 35: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

35(Virtual) Synchronous Replication

• Reads can read old data• Flow Control (by default 16 trx) avoids lag• wsrep_sync_wait=1 can be enabled to

ensure full synchronous reads• Latency: writes are fast, only at COMMIT,

communication with other nodes happen

Page 36: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

36Stale Reads

Page 37: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

37Latency

Page 38: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

38Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 39: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Multi-Master Replication

• You can write to any node in your cluster*• Writes are ordered inside the cluster

writes

writeswrites

39

Page 40: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

40Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 41: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Parallel Replication

• Standard MySQL

Application writes N threads Apply 1 thread

(MySQL 5.6:max 1 thread per schema, 5.7: Interval Based)

41

Page 42: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Parallel Replication

• PXC / Galera

Application writes N threads Apply M threads

(wsrep_slave_threads)

42

Page 43: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

43Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 44: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Quorum Based

• If a node does not see more than 50% of the total amount of nodes: reads/writes are not accepted.

• Split brain is prevented• This requires at least 3 nodes to be effective• a node can be an arbitrator (garbd), joining the

communication, but not having any MySQL running

• Can be disabled (but be warned!)

44

Page 45: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• Loss of connectivity

Quorum Based 45

Network Problem

Does not accept Reads & Writes

Page 46: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• 4 Nodes • 2 DC

Quorum Based 46

Page 47: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• Default quorum configuration:4 Nodes, 0 Nodes have quorum

Quorum Based 47

Network Problem

Page 48: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• With garbd Arbitrator:

Quorum Based Arbitrator 48

Network Problem

garbd(no data)

Page 49: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

49Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 50: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

50Certification

Page 51: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

51Optimistic Locking

• Communication to the other nodes of the cluster only happens during COMMIT, this affects locking behavior.

• Optimistic Locking is done:• InnoDB Locking happens local to the

node• During COMMIT/Certification, the other

nodes bring deadlocks

Page 52: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

52Optimistic Locking

• Some Characteristics:• also COMMIT and SELECT’s can fail on

deadlock• Might require application changes:

Not all applications handle this properly

Page 53: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

53Traditional InnoDB Locking

system 1Transaction 1

Transaction 2BEGIN

Transaction1

BEGINUPDATE t WHERE id=14

UPDATE t WHERE id=14...

COMMIT

Waits on COMMIT in trx 1

Page 54: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

54InnoDB Locking With PXC

system 1Transaction 1

Transaction 2BEGIN

Transaction1

BEGINUPDATE t WHERE id=14

UPDATE t WHERE id=14...

COMMITDML,COMMIT or SELECT

ERROR due row conflict

system 2

...

Page 55: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

55InnoDB Locking With PXC

system 1Transaction 1

Transaction 2BEGIN

Transaction1

BEGINUPDATE t WHERE id=14

UPDATE t WHERE id=14...

COMMITCOMMIT

ERROR due row conflict

system 2

...ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

Page 56: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

56Optimistic Locking

Page 57: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

57Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 58: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Automatic Node Provisioning

• When a node joins the cluster:• the data is automatically copied • when finished: the new node is automatically

ready and accepting connections• 2 different types of joining:

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

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

58

Page 59: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

StateTransfer Summary

Full dataSST

IncrementalIST

New node

Node longtime

disconnected

Nodedisconnected

short time

59

Page 60: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Snapshot State Transfer

mysqldump

Smalldatabases

rsync

Donordisconnectedfor copy time

Faster

XtraBackup

Donoravailable

Slower

60

Page 61: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Incremental State Transfer

Node wasin the cluster

Disconnectedfor maintenance

Nodecrashed

61

Page 62: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Automatic Node Provisioning

writes

writeswrites

new node joining

data is copied via SST or IST

62

Page 63: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Automatic Node Provisioning

writes

writeswrites

new node joiningwhen ready

writes

63

Page 64: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

64Features

• 'Synchronous' Replication• Multi Master• Parallel Applying• Quorum Based• Certification/Optimistic Locking• Automatic Node Provisioning• PXC Specific Features

Page 65: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

65PXC Specific Features

• PXC Strict mode• Extended PFS support• ProxySQL integration• SST/XtraBackup Changes• Bug-Fixes

Page 66: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

66PXC Strict Mode

Prevent experimental/unsupported features:• Only Allow InnoDB Operations• Prevent Changing binlog_format!=ROW• Require Primary Key on tables• Disable Unsupported Features:• GET_LOCK, LOCK TABLES, CTAS

• FLUSH TABLES <tables> WITH READ LOCK

• tx_isolation=SERIALIZABLE

Page 67: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

67PERFORMANCE_SCHEMA Support

• Improve troubleshooting/debugging using Performance Schema

• Threads• Files• Stages• Mutexes

• https://www.percona.com/live/plam16/sessions/exploring-percona-xtradb-cluster-using-performance-schema

• https://www.percona.com/doc/percona-xtradb-cluster/5.7/manual/performance_schema_instrumentation.html

Page 68: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

68ProxySQL

• Layer 7 MySQL Load Balancer• Open Source • R/W Splitting• Connection management• Transparent Reconnect• Query Caching (TTL)• 'Sharding' (User, Schema or Regex)

Page 69: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

69ProxySQL & PXC Integration

• PXC includes ProxySQL as load balancer:• proxysql-admin• ProxySQL schedulers:

• Health Checks• Reconfigures Nodes

• PXC Maintenance Mode• Tell Load Balancer to rebalance load

Page 70: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

ProxySQL

• Different possible setups:• be a dedicated layer• integrated at application layer• integrated at database layer

70

Page 71: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Dedicated shared ProxySQL application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

ProxySQL

71

Page 72: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Dedicated shared ProxySQL application server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

ProxySQL

72

Page 73: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

ProxySQL on application sideapplication server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

73

ProxySQL ProxySQL ProxySQL

Page 74: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

ProxySQL 'Endless' Possibilitiesapplication server 1 application server 2 application server 3

PXC node 1 PXC node 2 PXC node 3

74

ProxySQL ProxySQL ProxySQL

ProxySQL ProxySQL

Page 75: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

75Load Balancers Alternatives

• ProxySQL (L7)• HAProxy (L4)• ScaleArc (L7, $$)• MySQL Router (L7, quite new)• MaxScale (L7, $ BS-License)

Page 76: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Agenda

• Default asynchronous MySQL Replication• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read

Scaling• Limitations

76

Page 77: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

77Use Cases

• High Availability• WAN Replication• Read Scaling

Page 78: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

High Availability 78

• Each node is the same (no master-slave)• Consistency ensured, no data loss• Quorum avoids split-brain• Cluster issues are immediately handled on• no ‘failover’ necessary• no external scripts, no SPOF

Page 79: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

79WAN replication

MySQL

MySQL

MySQL

• No impact on reads• No impact within a trx• Communication only happens during

COMMIT (or if autocommit=1)• Use higher timeouts and

send windows

Page 80: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

• Beware of increased latency• Within EUROPE EC2

• COMMIT: 0.005100 sec• EUROPE <-> JAPAN EC2

• COMMIT: 0.275642 sec

80WAN replication - latency

MySQL

MySQL

MySQL

Page 81: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

81WAN replication with MySQL asynchronous replication

MySQL

MySQL

MySQL

• You can mix both types of replication• Good option on slow WAN link• Requires more nodes

MySQL

MySQL

MySQL

MySQL

MySQL MySQL

Page 82: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Cluster Segmentation - WAN 82

Page 83: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

83Read Scaling

• No Read/Write Splitting necessary in App.• Write to all nodes(*)

Page 84: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Example Architecture

Application Layer

ProxySQL

84

PXC

Page 85: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Agenda

• Default asynchronous MySQL Replication• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read Scaling

• Limitations

85

Page 86: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

86Limitations

• Supports only InnoDB tables• MyISAM support will most likely stay in

alpha.• The weakest node limits write

performance• All tables must have a Primary Key!

Page 87: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

87Limitations

• Large Transactions are not recommended if you write on all nodes simultaneously

• Long Running Transactions• If the workload has a hotspot then

(frequently writing to the same rows across multiple nodes)

• Solution: Write to only 1 node

Page 88: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

88Limitations

• By Default DDL is done in TOI• Blocks ALL writes during schema change• For certain operations:

wsrep_osu_method=RSU

• pt-online-schema-change

Page 89: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

Summary

• Default asynchronous MySQL Replication• Percona XtraDB Cluster:• Introduction / Features / Load Balancing

• Use Cases:• High Availability / WAN Replication / Read Scaling

• Limitations

89

Page 90: Percona XtraDB Cluster€¦ · WSREP and Galera • WSREP API is a project to develop generic replication plugin interface for databases (WriteSet Replication) • Galera is a wsrep

90Resources

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

• PXC articles on Percona Blog: https://www.percona.com/blog/category/percona-xtradb-cluster/

• Slideshare: https://www.slideshare.net/Grypyrg/pxc-introduction-34774802

Questions?Kenny Gryp - @gryp