45
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | MySQL Fabric - High Availability & Automated Sharding for MySQL Ted Wennmark ([email protected]) Principal System Consultant MySQL EMEA

MySQL Fabric - High Availability & Automated Sharding for MySQL

Embed Size (px)

DESCRIPTION

Introduction to scaling MySQL.

Citation preview

Page 1: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric - High Availability & Automated Sharding for MySQL

Ted Wennmark ([email protected]) Principal System Consultant MySQL EMEA

Page 2: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Safe Harbor Statement

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

2

Page 3: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

3

Page 4: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

4

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

Page 5: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Business Priorities for IT Focus on driving the business rather than on infrastructure

Deliver new services

Real-Time Insight from

Data

Simplify Architecture

Fast Time to Market

5

Page 6: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Application Requirements

High Availability Scale Data & User Loads

OLTP & Analytics Elastic

Responsive & Agile

6

Page 7: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

An extensible and easy-to-use framework for managing a farm of MySQL server supporting high-availability and sharding

MySQL Fabric

7

Page 8: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric 1.5 High Availability + Sharding-Based Scale-out

• High Availability:

• Server monitoring with auto-promotion and transparent application failover

• Fabric-aware connectors rather than proxy: Python, Java, .NET & PHP

• Lower latency, bottleneck-free

• Optionally scale-out through sharding • Application provides shard key

• Range or Hash

• Tools for resharding

• Global updates & tables

MySQL Fabric

Connector

Application

Read-slaves

SQL

HA group

Read-slaves

HA Group

8

Page 9: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

9

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

Page 10: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Layers of High Availability

Redundant Access to Data

Data Redundancy

Redundant App Servers

Routing to the Data

10

Page 11: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

First Step To High Availability

MySQL Replication

M S

Replication

Page 12: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Replication Components

Insert...

Insert...

B

binary log

Insert...

relay log

Insert...

A

binary log

Client

Sender thread

Receiver thread

Applier Threads

Network

Master

info

Relay Log Info

Page 13: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Redundancy: If master crashes, promote slave to master

C

B

A

Replication: High Availability

C

B

A Crash

C

B

A

B is the new master

Uh Oh! Whew!

Page 14: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric Framework (HA)

All Data

Primary Secondary

Extra Read

Replicas

MySQL Fabric Controller

SQL Queries

State &

Routing Info

HA Group

Coordination

and Control

Page 15: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Replication & MySQL Fabric HA & how this effects failover

• MySQL Replication is the initial implementation used in HA Groups

• PRIMARY = Replication Master & receives all writes

• Failover

• MySQL Fabric detects failure of PRIMARY/Master

• Selects a SECONDARY/Slave and promotes it

• Updates State Store

• Pushes state change to Fabric-aware connectors

15

Page 16: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

High-Availability Group Concept

• Abstract Concept

• Set of servers

• Server attributes

• Connector Attributes

• Connection information

• Mode: read-only, read-write, ...

• Weight: distribute load

• Management Attributes • State: state/role of the server

State: Primary Mode: Read-Write Host: server-1.example.com

16

Page 17: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Create HA Groups and add Servers

• Define a group

mysqlfabric group create my_group

• Add servers to group

mysqlfabric group add my_group server1.example.com

mysqlfabric group add my_group server2.example.com

17

Page 18: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Create HA Groups and add Servers

• Promote one server to be primary

mysqlfabric group promote my_group

• Tell failure detector to monitor group

mysqlfabric group activate my_group

18

Page 19: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

19

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

Page 20: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Scaling MySQL

● Scale up / Vertical scaling

– Buy more or faster disk

– Buy more memory

– Buy more or faster CPU's

● Scale out / Horizontal scaling

– Shard by function

– Shard by columns

– Shard by rows

Page 21: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Scaling on dense, multi-core, multi-thread servers

• 10s - 100GBs RAM

• SSDs Scale across cores within a single instance

You can get a long way with MySQL 5.6!

Scale-Up with MySQL 5.6 Scaling-Up can take you a long way

Page 22: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Read scale-out

M S

S

S

S

M

write clients read clients read clients

write clients

More reads? More

slaves!

Replication To Scale Reads

Page 23: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

On-line Backup and Reporting

Offloading master of some duties

M

S

write clients

business intelligent client apps reporting client apps big queries client apps

Page 24: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

C B

B A A C

Image from www.ginkgomaps.com

Geographic Replication

Page 25: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

M M?

write clients write clients

More writes? More

Masters?

What about Write scale-out?

M?

M?

We will discuss sharding with MySQL Fabric later on...

Page 26: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

What is sharding?

• Divide your dataset into several pieces, think of horizontal partitioning where each partition resides on dedicated instance/HW.

• Statements are spread amongst all shards.

• Each shard will normally be located on dedicated server.

Page 27: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Benefits of Sharding

• Write scalability

• Can handle more writes

• Large data set

• Database too large

• Does not fit on single server

• Improved performance

• Smaller index size

• Smaller working set

• Improve performance

UID 10000-20000 UID 20001-40000

27

Page 28: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric Sharding Architecture

Shards

MySQL Fabric Node

Application

Global Group

Global Updates

Shard Updates

Replication

28

Page 29: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric Sharding Features

• Connector API Extensions

• Support Transactions

• Support full SQL

• Decision logic in connector • Reducing network load

• Shard Multiple Tables

• Using same key

• Global Updates

• Global tables

• Schema updates

• Sharding Functions

• Range

• (Consistent) Hash

• Shard Operations • Shard move

• Shard split

29

Page 30: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Routing Transactions

Shard #2

Shard #1

Shard #3

Executor

App Server Connector Cache

State Store

30

Page 31: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Routing Transactions

Shard #2

Shard #1

Shard #3

Executor

App Server Connector Cache

State Store

App Server Connector Cache

31

Page 32: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric (HA + Sharding)

Global Data

Primary Secondary

Shard 1

Primary Secondary

Shard 2

Primary Secondary

MySQL Fabric Controller

SQL Queries

Server/Shard State

& Mapping

Global Group HA Group

Coordination

and Control

HA Group

Extra Read

Replicas

Extra Read

Replicas

Page 33: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric: Sharding Setup

• Set up some groups • my_global – for global updates

• my_group.N – for the shards

• Add servers to the groups

• Create a shard mapping

• A “distributed database”

• Mapping keys to shards

• Give information on what tables are sharded

• Add shards

33

Page 34: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric: Moving and Splitting Shards

• Moving a shard (id=5) from existing group to another (my_group.8)

• mysqlfabric sharding move 5 my_group.8

• Splitting a shard (id=5) into two parts with new half stored in group my_group.6

• mysqlfabric sharding split 5 my_group.6

34

Page 35: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Connector API: Shard Specific Query

• Indicate tables to be used in query • Property: tables

• Fabric will compute map

conn.set_property(tables=["test.subscribers"], key=sub_no, \

mode=fabric.MODE_READWRITE)

cur = conn.cursor()

cur.execute(

"INSERT INTO subscribers VALUES (%s, %s, %s)",

(sub_no, first_name, last_name))

• Provide sharding key • Property: key

• Fabric will compute shard

35

Page 36: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Connector API: Shard Specific Query

• Provide tables in query – Property: tables

– Fabric will compute map

conn.set_property(tables=[“test.subscribers“,”test.titles”], key=sub_no, \

mode=fabric.MODE_READONLY)

cur = conn.cursor()

cur.execute(

"SELECT first_name, last_name FROM subscribers "

"WHERE sub_no = %s", (sub_no, )

)

for row in cur:

print row

Provide sharding key – Property: key

– Fabric will compute shard

Joins within the shard (or with global tables) supported

36

Page 37: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Connector API: Global Update • Provide tables in query

– Property: tables

– Fabric will compute map

– (Likely to not be needed)

conn.set_property(tables=[’test.subscribers'], scope='GLOBAL')

cur = conn.cursor()

cur.execute("ALTER TABLE test.subscirbers ADD nickname VARCHAR(64)")

• Set global scope – Property: scope

– Query goes to global group

37

Page 38: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric Node

MySQL

MySQL Fabric Framework

Executor State Store (Persister)

Sh

HA

MySQL AMQP XML-RPC

? ?

Protocols

Extensions

Backing Store

Extensible Architecture

38

Page 39: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric: Goals & Features • Connector API Extensions

• Support Transactions

• Support full SQL

• Fabric-Aware Connectors at GA:

• PHP + Doctrine, Python, Java + Hibernate

• Decision logic in connector

• Reducing network load

• Load Balancing

• Read-Write Split

• Distribute transactions

• Global Updates

• Global tables

• Schema updates

• Shard Multiple Tables

• Using same key

• Sharding Functions

• Range

• (Consistent) Hash

• Shard Operations

• Shard move

• Shard split

39

Page 40: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric – Current Limitations

• Routing is dependent on Fabric-aware connectors

• Currently Java (+ Hibernate), PHP (+ Doctrine) & Python

• MySQL Fabric node is a single (non-redundant process)

• HA Maintained as connectors continue to route using local caches

• Establishes asynchronous replication • Manual steps to switch to

semisynchronous

• Sharding not completely transparent to application (must provide shard key – column from application schema)

• No cross-shard joins or other queries

• Management is through CLI or XML/RPC API

• No GUI

40

Page 41: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

41

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

Page 42: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Oracle MySQL HA & Scaling Solutions

MySQL Replication

MySQL Fabric Oracle VM Template

Oracle Clusterware

Solaris Cluster

Windows Cluster

DRBD MySQL Cluster

App Auto-Failover ✖ ✔ ✔ ✔ ✔ ✔ ✔ ✔

Data Layer Auto-Failover ✖ ✔ ✔ ✔ ✔ ✔ ✔ ✔

Zero Data Loss MySQL 5.7 MySQL 5.7 ✔ ✔ ✔ ✔ ✔ ✔

Platform Support All All Linux Linux Solaris Windows Linux All

Clustering Mode Master +

Slaves Master +

Slaves Active/Passi

ve Active/Passive

Active/Passive

Active/Passive

Active/Passive

Multi-Master

Failover Time N/A Secs Secs + Secs + Secs + Secs + Secs + < 1 Sec

Scale-out Reads ✔ ✖ ✖ ✖ ✖ ✖ ✔

Cross-shard operations N/A ✖ N/A N/A N/A N/A N/A ✔

Transparent routing ✖ For HA ✔ ✔ ✔ ✔ ✔ ✔

Shared Nothing ✔ ✔ ✖ ✖ ✖ ✖ ✔ ✔

Storage Engine InnoDB+ InnoDB+ InnoDB+ InnoDB+ InnoDB+ InnoDB+ InnoDB+ NDB

Single Vendor Support ✔ ✔ ✔ ✔ ✔ ✖ ✔ ✔

42

Page 43: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Program Agenda

43

1

2

3

4

5

Requirements for Next Gen Services

Simple, transparent High Availability

Delivering SQL & ACID at scale

Where MySQL Fabric fits with Oracle’s other MySQL solutions

Getting started

Page 44: MySQL Fabric - High Availability & Automated Sharding for MySQL

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL Fabric Resources

• Download and try http://dev.mysql.com/downloads/fabric/

• Documentation http://dev.mysql.com/doc/mysql-utilities/1.4/en/fabric.html

• Forum (MySQL Fabric, Sharding, HA, Utilities) http://forums.mysql.com/list.php?144

• Tutorial: MySQL Fabric - adding High Availability and Scaling to MySQL http://www.clusterdb.com/mysql-fabric/mysql-fabric-adding-high-availability-and-scaling-to-mysql

• White Paper: MySQL Fabric - A Guide to Managing MySQL High Availability and Scaling Out http://www.mysql.com/why-mysql/white-papers/mysql-fabric-product-guide

44

Page 45: MySQL Fabric - High Availability & Automated Sharding for MySQL