mysql user camp : 20-june-14 : mysql fabric

36
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. MySQL Fabric

Upload: mysql-user-camp

Post on 27-Jan-2015

114 views

Category:

Software


1 download

DESCRIPTION

This pres

TRANSCRIPT

Page 1: Mysql User Camp : 20-June-14 : Mysql Fabric

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

MySQL Fabric

Page 2: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |2

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 decision. The development, release, and timing of any

features or functionality described for Oracle’s products remains at the sole discretion

of Oracle.

Safe Harbor Statement

Page 3: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3

Program Agenda

Handling Scaling What is sharding? Managing a Sharded Database Working with a Sharded Database

Page 4: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |4

What is this

sharding?

What are the

benefits of

sharding?

How do I shard my database

?

Page 5: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |5

It's all about scaling...

● Start with a single server

The Growing Enterprise

Page 6: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |6

It's all about scaling...

● Start with a single server● More and more page requests

● ...more and more reads

● What to do?● Scale out!

The Growing Enterprise

Page 7: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |7

It's all about scaling...

● Start with a single server● More and more page requests

● ...more and more reads

● What to do?● Scale out!

● Replicate to read servers

The Growing Enterprise

Page 8: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |8

It's all about scaling...

● Start with a single server● More and more page requests

● ...more and more reads

● What to do?● Scale out!

● Replicate to read servers

● Perform a read-write split● Writes go to master● Reads go to read servers

The Growing Enterprise

Page 9: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |9

It's all about scaling...

● More and more updates● Write load increases

● What now?

The Growing Enterprise

Page 10: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |10

It's all about scaling...

● More and more updates● Write load increases

● What now?● Add another master?

The Growing Enterprise

Page 11: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |11

It's all about scaling...

● More and more updates● Write load increases

● What now?● Add another master?

● Doesn't work...● Write load is replicated

The Growing Enterprise

Page 12: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |12

It's all about scaling...

● More and more updates● Write load increases

● What now?● Add another master?

● Doesn't work...● Write load is replicated

● Partition database● Distribute writes● Called sharding

The Growing Enterprise

UID 10000-20000 UID 20001-40000

Page 13: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |13

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

Page 14: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |14

High-level Architecture

● What components do we need?

● How are they deployed?

Page 15: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |15

Components for a Sharding Solution

Shard #2

Shard #1

Shard #3

Switch

StateStore Executor

QUERY

KEY

KEY

QUERY

Contain decision logicfor distributing queries

Contain informationabout location of shards

SHARD#

Page 16: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |16

Transaction and Shard Key Handling

● How are the transactions handled?

● How do get the shard key for a transaction?

● How to compute shard from key?

Page 17: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |17

BEGINSELECT salary INTO @s FROM salaries WHERE emp_no = 20101;SET @s = 1.1 * @s;INSERT INTO salaries VALUES (20101, @s);COMMITBEGININSERT INTO ... COMMIT

Sharding key? Ah, there it is!

Session state?

Hmm... looks likea read transaction

Oops.. it was awrite transaction!

Transaction done!Clear session state?

New transaction! Different shard?What about the session state?

Transaction Handling

Page 18: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |18

Transaction Handling

● Detecting transaction boundaries

● Managing session state

● Move session state between servers

– Easy to use

– Expensive and error prone

● Reset state after each transaction

– Transactions start with default session state

What aboutcrashes?

Where do I storethe session state?

Page 19: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |19

Mapping the Sharding Key

● What is a sharding key?● Single column● Multi column

– Same table?– Different tables?

● How is the key transformed?● Hash● Range● User-defined

ComputeShard#

Key

Shard#

(X)(X,Y,...)

RANGEHASHSomething else

Page 20: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |20

Granularity of Sharding

● Can multiple tables be sharded with the same key?

● Can we shard different tables different ways?

● Do we allow global tables?

● Do we allow cross-database queries?

Page 21: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |21

Sharded Tables

Table Rows

salaries 284 404 700

titles 44 330 800

employees 30 002 400

dept_emp 33 160 300

dept_manager 2 400

departments 900

In desperate needof sharding!

Foreign keys

Page 22: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |22

Multi-table Query with Sharded Tables

SELECT first_name, last_name, salaryFROM salaries JOIN employees USING (emp_no)WHERE emp_no = 21012 AND CURRENT_DATE BETWEEN from_date AND to_date;

● Referential Integrity Constraint● Example query joining salaries and employees● Same key, same shard: co-locate rows for same user

● JOIN normally based on equality● Using non-equality defeats purpose of foreign key

Page 23: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |23

Global Tables

Table Rows

salaries 284 404 700

titles 44 330 800

employees 30 002 400

dept_emp 33 160 300

dept_manager 2 400

departments 900

Do not really need to be sharded

Page 24: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |24

Multi-table Query with Global Tables

SELECT first_name, last_name, GROUP_CONCAT(dept_name) FROM employees JOIN dept_emp USING (emp_no) JOIN departments USING (dept_no)WHERE emp_no = 21012 GROUP BY emp_no;

● JOIN with departments table● Has no employee number, hence no sharding key● Table need to be present on all shards

● How do we update global tables?

Page 25: Mysql User Camp : 20-June-14 : Mysql Fabric

25

Insert Picture Here

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |

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

MySQL Fabric

Page 26: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |26

MySQL Fabric Architecture

High Availability Groups

Application

XML-RPC

SQL

SQL

Connector

Connector

Connector

Operator

MySQLFabricNode

ApplicationServers

Page 27: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |27

High-Level Components

● Fabric-aware Connectors● Python, PHP, and Java● Enhanced Connector API

● MySQL Fabric Node● Manage information about farm● Provide status information● Execute procedures

● MySQL Servers● Organized in High-Availability

Groups● Handling application data

High AvailabilityGroup

ApplicationConnector

Connector

Connector

MySQLFabricNode

Page 28: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |28

MySQL Fabric Node Architecture

MySQL

MySQL FabricFramework

ExecutorState Store(Persister)

Sh

HA

MySQLAMQP XML-RPC

??Connector

Connector

Connector

Protocols

Extensions

BackingStore

Page 29: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |29

MySQL Fabric: Prerequisites

● MySQL Servers (version 5.6.10 or later)● Backing store database server● Application datatabase servers

● Python 2.6 or 2.7● No support for 3.x yet

● MySQL Utilities 1.4● Available at

https://dev.mysql.com/downloads/tools/utilities● “Development release” tab

Page 30: Mysql User Camp : 20-June-14 : Mysql Fabric

30

Insert Picture Here

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |

Architecture forHigh-Availability

Page 31: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |31

High-Availability Group Concept

● Group of servers● Hardware redundancy● Data redundancy

● Generic Concept● Implementation-independent● Self-managed or externally

managed

● Different Types● Primary-Backup (Master-Slave)● Shared or Replicated Storage● MySQL Cluster

Done!

Examples Only

Not Yet Implemented

Page 32: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |32

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● Status: state/role of the

server

Status: PrimaryMode: Read-WriteHost: server-1.example.com

Page 33: Mysql User Camp : 20-June-14 : Mysql Fabric

33

Insert Picture Here

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |

Architecture forSharding

Page 34: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |34

Sharding Architecture

Shards

MySQL Fabric Node

Application

Connector

Connector

Connector

GlobalGroup

Global Updates

ShardUpdates

Replication

Support global updatefor off-line shards

Page 35: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |35

MySQL Fabric: Sharding Goals & 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● Using built-in executor● Shard move● Shard split

Page 36: Mysql User Camp : 20-June-14 : Mysql Fabric

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.| Percona Live | April 3, 2014 |36

Thank you!