MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

40
MySQL InnoDB Cluster Olivier Dasini MySQL Principal Soluons Architect EMEA [email protected] @freshdaz hp://dasini.net/blog/ Copyright 2017, Oracle and/or its affiliates. All rights reserved A complete High Availability soluon for MySQL Meetup AFUP Paris / Oracle MySQL – 2 mai 2017

Transcript of MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Page 1: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

MySQL InnoDB Cluster

Olivier Dasini

MySQL Principal Solutions Architect [email protected]@freshdazhttp://dasini.net/blog/

Copyright 2017, Oracle and/or its affiliates. All rights reserved

A complete High Availability solution for MySQL

Meetup AFUP Paris / Oracle MySQL – 2 mai 2017

Page 2: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2015, 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 InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Me, Myself & I

➢ MySQL Geek✔ Addicted to MySQL for 15+ years!

✔ Playing with databases for 20+ years

➢ MySQL Writer, Blogger and Speaker

➢ MySQL Principal Solutions Architect EMEA at Oracle

➢ Stay tuned :✔ @freshdaz

✔ http://dasini.net/blog

3

Page 4: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Program Agenda

1

2

3

High Availability

MySQL InnoDB Cluster

Lab : Deploying MySQL InnoDB Cluster

4

Page 5: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Page 6: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

High Availability: The Causes of Downtime

6

40.00%

40.00%

20.00%

Software/Application Human Error Hardware

* Source: Gartner Group 1998 survey

A study by the Gartner Group projected that through 2015, 80% of downtime will be due to people and process issues

Page 7: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

High Availability: The Business Cost of Downtime

• Calculate a cost per minute of downtime

– Average revenue generated per-minute over a year

– Cost of not meeting any customer SLAs

– Factor in costs that are harder to quantify

1. Revenue

2. Reputation

3. Customer sentiment

4. Stock price

5. Service’s success

6. Company’s very existence

7

THIS is why HA matters!

Page 8: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright 2017, Oracle and/or its affiliates. All rights reserved

HA solutions with MySQL : Replication modes

• Asynchronous => MySQL Replication

— MySQL Default; In parallel: Master acks to app and sends transaction to slave

— Fast; Risk of lost changes if master dies

• Semi-Synchronous => MySQL Replication w/ semisynchronous plugin

— MySQL 5.5+ Enhanced in MySQL 5.7; Serially: Master waits for change to be received by slave then In parallel ack to app and apply changes on slave

— Intermediate latency; Lossless (MySQL 5.7)

• Virtual-Synchronous => MySQL InnoDB Cluster w/ MySQL Group Replication

— MySQL Group Replication; Multi-masters updates on nodes applied in parallel

— MySQL Plugin delivered by MySQL for MySQL :)

— Intermediate latency; Best suited to small transactions; Lossless

• Synchronous => MySQL NDB Cluster

— Only available with MySQL Cluster; Serially: Master waits for change to be applied on all slaves before ack to app

— Higher latency; If Active/Active, best suited to small transactions; Lossless

Page 9: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Replication

9

Page 10: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright 2017, Oracle and/or its affiliates. All rights reserved

Use MySQL Replication For HA

12

Redundancy: If master crashes, promote slave to master

B

C

CrashCrash

B is thenew master

Ouch!!! Whew!

https://dev.mysql.com/downloads/utilities/

B

C

A

C

B

Slave promotion managed by mysqlrpladmin or mysqlfailover

Page 11: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

NDB Cluster

13

Page 12: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 14

MySQL NDB Cluster Data Nodes

Clients

Application Layer

Data LayerManagement

MySQL NDB Cluster Architecture

Page 13: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

•MySQL NDB Cluster– In memory distributed database

–NDB storage engine

–Automatic sharding

–Native access via several API

–Read/write consistency

–Read/write scalability

–Management via MCM/mgm-tool

MySQL NDB Cluster

Rock Solid Availability

In-MemoryReal-Time

Performance

ExtremeRead & Write

Scalability

Elasticity

Page 14: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Program Agenda

1

2

3

High Availability

MySQL InnoDB Cluster

Demo : Deploying MySQL InnoDB Cluster

17

Page 15: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 18

MySQL InnoDB ClusterCollection of products that work together to provide a complete High Availability solution for MySQL

Page 16: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

InnoDB Cluster

19

App Servers withMySQL Router

MySQL Group Replication

“High Availability becomes a core first class feature of MySQL!”

MySQL ShellSetup, Manage,

Orchestrate

Page 17: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 20

MySQL InnoDB Cluster: The Big Picture

M

App

M M

MySQL Shell and Orchestration Tooling

App

Simple Mapping, State and Extra Metadata

Control, Coordinate,Provision

Monitoring (MEM)

MySQL Router

MySQL Group Replication

MySQL Router

Page 18: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

MySQL Group ReplicationNative, built-in High Availability for your MySQL databases

21

Page 19: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Group Replication

22

App Servers withMySQL Router

MySQL Group Replication

MySQL ShellSetup, Manage,

Orchestrate

Page 20: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

MySQL Group Replication: What Is It?

• Group Replication library

– Implementation of Replicated Database State Machine theory• MySQL GCS is based on Paxos (variant of Mencius)

– Provides virtually synchronous replication for MySQL 5.7+

– Supported on all MySQL platforms• Linux, Windows, Solaris, OSX, FreeBSD

“Multi-master update anywhere replication plugin for MySQL with built-in conflict detection and resolution, automatic distributed recovery, and group membership.”

24

http://dasini.net/blog/2016/11/08/deployer-un-cluster-mysql-group-replication/

Page 21: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

• A Highly Available distributed MySQL database service

– Clustering eliminates single points of failure (No SPOF)• Allows for online maintenance

– Removes the need for manually handling server fail-over

– Provides distributed fault tolerance and self-healing

– Enables Active/Active update anywhere setups

– Automates reconfiguration (adding/removing nodes, crashes, failures)

–Makes it easy to scale up/down based on demand

– Automatically ensures data consistency ie no data loss• Detects and handles conflicts

• Prevents data loss

• Prevents data corruption

25

MySQL Group Replication: What Does It Provide?

Page 22: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

MySQL Group Replication: Performance Comparison

29

Page 23: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Storage Engine InnoDB

Distributed Architecture Shared nothing

Network failure protection Quorum

NoSQL APIs MySQL Document Store / InnoDB Memcached

Replication Virtually Synchronous

Database Failover Automatic

OS Supported Linux, Windows, Solaris, OSX, FreeBSD

Operational Complexity Medium

Administration Standard (MySQL)

MySQL Group Replication overview

Page 24: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

MySQL Group Replication wrap-up• Cloud Friendly

– Great technology for deployments where elasticity is a requirement, such as cloud based infrastructures.

• Integrated

– With server core through a well defined API.

– With GTIDs, row based replication, performance schema tables.

• Autonomic and Operations Friendly

– It is self-healing: no admin overhead for handling server fail-overs.

– Provides fault-tolerance, enables multi-master update everywhere and a dependable MySQL service.

38

Page 25: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 39

App Servers withMySQL Router

MySQL Group Replication

MySQL ShellSetup, Manage,

Orchestrate

Router 2.1

Page 26: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

MySQL Router 2.1

• MySQL Router is lightweight middleware that provides transparent routing between your application and back-end MySQL Servers.

• MySQL Router also provides High Availability and Scalability by effectively routing database traffic to appropriate back-end MySQL Servers.

• The pluggable architecture also enables developers to extend MySQL Router for custom use cases.

40

Page 27: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 42

Shell

App Servers withMySQL Router

MySQL Group Replication

MySQL ShellSetup, Manage,

Orchestrate

Page 28: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

MySQL Shell

43

A single unified client for all administrative and operations tasks

• Advanced command-line client and code editor for the MySQL Server

• Multi-Language: JavaScript, Python, and SQL– Naturally scriptable

• Supports both Document and Relational models

• Exposes full Development and Admin API

”MySQL Shell provides the developer and DBA with a single intuitive, flexible, and powerful interface for all MySQL related tasks!”

Page 29: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

MySQL InnoDB Cluster: Architecture

Page 30: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Program Agenda

1

2

3

High Availability

MySQL InnoDB Cluster

Demo : Deploying MySQL InnoDB Cluster

46

Page 31: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

Deploying MySQL InnoDB Cluster in Single-Primary Mode

Page 32: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 1/6

http://dasini.net/blog/2017/03/13/tester-mysql-innodb-cluster/

1/ Connect to MySQL Shell

$ mysqlsh

2/ Deploy 3 local MySQL instances on ports : 3310 - 3320 - 3330

mysql-js> dba.deploySandboxInstance(3310)

mysql-js> dba.deploySandboxInstance(3320)

mysql-js> dba.deploySandboxInstance(3330)

• Deploying local sandbox MySQL Instances

Now we have 3 MySQL server instances running on ports 3310, 3320 and 3330.

Page 33: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 2/6

Stopmysql-js> dba.stopSandboxInstance(3310);

Startmysql-js> dba.startSandboxInstance(3320);

Kill : simulate an unexpected halt while testing failovermysql-js> dba.killSandboxInstance(3330);

Delete : Completely removes the sandbox instance from your file systemmysql-js> dba.deleteSandboxInstance(3330);

• Managing local sandbox MySQL Instances

Once a sandbox instance is running, it is possible to change its status at any time :

Page 34: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 3/6

Check instance configuration before the deployment

mysql-js> dba.checkInstanceConfiguration('root@localhost:3310')

mysql-js> dba.checkInstanceConfiguration('root@localhost:3320')

mysql-js> dba.checkInstanceConfiguration('root@localhost:3330')

• Checking the configuration

Configuration issues could be fixed manually or with configureLocalInstance

e.g.

mysql-js> dba.configureLocalInstance('root@localhost:3310')

Page 35: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 4/6

1/ Connect to instance 3310mysql-js> \c root@localhost:3310

2/ Create the clustermysql-js> var cluster=dba.createCluster('demoCluster');

3/ Check the transaction set and add node 3320 to the clustermysql-js> cluster.checkInstanceState('root@localhost:3320')mysql-js> cluster.addInstance('root@localhost:3320')

4/ Check the transaction set and add node 3330 to the clustermysql-js> cluster.checkInstanceState('root@localhost:3330')mysql-js> cluster.addInstance('root@localhost:3330')

5/ Check cluster statusmysql-js> cluster.status()

• Deploying the InnoDB Cluster

Page 36: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Page 37: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 5/6

# Bootstrap MySQL Router $ mysqlrouter --bootstrap root@localhost:3310 --directory ~/demoSandbox

# Start MySQL router $ ~/demoSandbox/start.sh

• Deploying the Router

The following connection information can be used to connect to the cluster.

Classic MySQL protocol connections to cluster 'demoCluster':- Read/Write Connections: localhost : 6446- Read/Only Connections: localhost : 6447

X protocol connections to cluster 'demoCluster':- Read/Write Connections: localhost : 64460- Read/Only Connections: localhost : 64470

Page 38: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Testing MySQL InnoDB Cluster in a sandbox – Demo 6/6

1/ Connect to MySQL Router (default port = 6446)$ mysqlsh --uri=root@localhost:64466446

2/ Select primary node’s portmysql-js> \sql

mysql-sql>

SELECT @@port; -- display 3310

3/ Primary node crash!mysql-sql> \js

mysql-js>

dba.killSandboxInstance(3310)

• Failover

4/ Select primary node’s portmysql-js> \c root@localhost:6446

mysql-sql>

SELECT @@port; -- display 3320

5/ Member is back to the groupmysql-sql> \js

mysql-js> dba.startSandboxInstance(3310)

var cluster = dba.getCluster('demoCluster')

mysql-js> cluster.rejoinInstance('root@localhost:3310')

mysql-js> cluster.status()

Page 39: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris

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

Thank you!

Page 40: MySQL InnoDB Cluster - Meetup Oracle MySQL / AFUP Paris