MySQL InnoDB Cluster Management and troubleshooting using MySQL Shell

Miguel Araújo Senior Developer MySQL Middleware and Clients September 18, 2019

Copyright © 2019 Oracle and/or its affiliates. Safe Harbor

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, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of .

Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events.

Copyright © 2019 Oracle and/or its affiliates. $ whoami

Copyright © 2019 Oracle and/or its affiliates. Miguel Araújo

• MySQL Developer since 2011 • AdminAPI Tech Lead @ MySQL Shell team • MySQL InnoDB Cluster evangelist • Living in Portugal • http://about.me/miguel-araujo • @M1guelAraujo

Copyright © 2019 Oracle and/or its affiliates. What’s Ahead

1. Introduction to InnoDB cluster 2. Node Provisioning 3. Monitoring 4. Maintenance and Troubleshooting 5. Final thoughts and resources

Copyright © 2019 Oracle and/or its affiliates. Introduction to InnoDB Cluster

Copyright © 2019 Oracle and/or its affiliates. InnoDB cluster

“A single product – MySQL – with high availability and scaling features baked in; providing an integrated end-to-end solution that is easy to use.”

• MySQL Group Replication

• MySQL Shell

• MySQL Router

Copyright © 2019 Oracle and/or its affiliates. MySQL InnoDB Cluster Goals

1 One Product: MySQL

• All components developed and integrated together

• Full stack testing

Copyright © 2019 Oracle and/or its affiliates. MySQL InnoDB Cluster Goals

1 One Product: 2 Easy to use! MySQL

• All components • One client: MySQL Shell developed and integrated together • Easy packaging

• Full stack testing • Integrated Orchestration

• Homogeneous servers

Copyright © 2019 Oracle and/or its affiliates. MySQL InnoDB Cluster Goals

1 One Product: 2 Easy to use! 3 Flexible and MySQL Modern

• All components • One client: MySQL Shell • SQL and noSQL together: developed and integrated X Protocol together • Easy packaging • Protocol Buffers • Full stack testing • Integrated Orchestration • Asynchronous API • Homogeneous servers • Developer friendly

Copyright © 2019 Oracle and/or its affiliates. MySQL InnoDB Cluster Goals

! Completely Open Source --- GPL No license required to have High Availability!

Copyright © 2019 Oracle and/or its affiliates. MySQL Shell

• Interactive multi-language console interface that supports development and administration for the MySQL Server:

• Supports JavaScript, Python and SQL

• Interactive and batch operations (scripting)

• Supports Document and Relational models (X and MySQL protocols)

Copyright © 2019 Oracle and/or its affiliates. MySQL Shell

• Exposes full Development and Administration :

• Scriptable “DevOps” APIS

• Unified interface for developers and DBAs

Copyright © 2019 Oracle and/or its affiliates. MySQL AdminAPI

• Creation and Management of InnoDB clusters

• Available in both JavaScript and Python; and command-line

• Simple and straight-forward

• Flexible, powerful and secure!

Copyright © 2019 Oracle and/or its affiliates. Creating a Cluster

// Configure servers for MySQL InnoDB cluster usage mysqlsh-js> dba.configureInstance(“clusteradmin@mysql1:3306”)

Copyright © 2019 Oracle and/or its affiliates. Creating a Cluster

// Configure servers for MySQL InnoDB cluster usage mysqlsh-js> dba.configureInstance(“clusteradmin@mysql1:3306”)

// Connect to target instance mysqlsh-js> \c clusteradmin@mysql1:3306

Copyright © 2019 Oracle and/or its affiliates. Creating a Cluster

// Configure servers for MySQL InnoDB cluster usage mysqlsh-js> dba.configureInstance(“clusteradmin@mysql1:3306”)

// Connect to target instance mysqlsh-js> \c clusteradmin@mysql1:3306

// Create the cluster mysqlsh-js> var cluster = dba.createCluster(“CodeOne19”)

Copyright © 2019 Oracle and/or its affiliates. Creating a Cluster

// Configure servers for MySQL InnoDB cluster usage mysqlsh-js> dba.configureInstance(“clusteradmin@mysql1:3306”)

// Connect to target instance mysqlsh-js> \c clusteradmin@mysql1:3306

// Create the cluster mysqlsh-js> var cluster = dba.createCluster(“CodeOne19”)

// Add instances to the cluster mysqlsh-js> cluster.addInstance(“clusteradmin@mysql2:3306”)

Copyright © 2019 Oracle and/or its affiliates. MySQL Router

• Transparent client routing between the application and the backend servers:

ü Application connection failover

• Native support for InnoDB clusters

• Stateless

Copyright © 2019 Oracle and/or its affiliates. Node Provisioning

Copyright © 2019 Oracle and/or its affiliates. Provisioning

• Provisioning a server is the process of configuring and getting it ready to be used in an InnoDB cluster.

• The server needs to have all clusters’ data to be able to join it

• That’s typically done by:

1. Performing a backup of one of the cluster members 2. Restoring the image in the new member that wants to join

Copyright © 2019 Oracle and/or its affiliates. Distributed Recovery

• Distributed recovery is a process that runs when a new member is added to the group and has missing transactions

• A donor that can provide the missing data is automatically selected

• The catch-up happens transparently and the server is synchronized with the rest of the cluster

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

• Incremental recovery fetches only the missing data based on the GTIDs into

- The cluster must be able to provide all the missing data

• Relies on the classic Asynchronous Replication

• Also provides group transactional information

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

Some data is inserted in the DB

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

The data modifications are stored in the binlog.

And the transactions are delivered to every cluster member

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

Group Replication is eventually synchronous.

Guarantees that transactions are delivered to all members in the same order.

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

The binlogs keep track of all data modifications.

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

A new member wants to join the cluster

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

A new member wants to join the cluster

The missing data is fetched and the server synchronizes with the rest of the cluster

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

A donor is automatically selected to fetch the missing data from, using plain Asynchronous Replication

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

A donor is automatically selected to fetch the missing data from, using plain Asynchronous Replication

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

A donor is automatically selected to fetch the missing data from, using plain Asynchronous Replication

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

The instance successfully joins the cluster!

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

May take a considerable amount of time !

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

• But what if the cluster members lost all binary logs?

• Or even... Just some data is missing that is not available on any binary log ?

• What about space constraints?

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

Some binary logs were purged. And the instance has no data yet.

Copyright © 2019 Oracle and/or its affiliates. Incremental Recovery to Provision

Some binary logs were purged. And the instance has no data yet.

Failed attempt to join the cluster !

Copyright © 2019 Oracle and/or its affiliates. MySQL Clone Plugin Available since 8.0.17 !

• Performs physical snapshots of

ü Really fast!

• Transfers the snapshots over the network to provision servers

ü Can be used remotely!

• Replaces all the server data

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

Distributed recovery = initial provisioning + online catch-up

• Seamless and automated solution for provisioning

• No external tools or scripting required

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

Common issues easily solved with clone:

• Very large datasets

• Incomplete binary log history

• Re-provision diverged instances

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

Some binary logs were purged. And the instance has no data yet.

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

Some binary logs were purged. And the instance has no data yet.

Clone required !

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

A donor is automatically selected. And a full snapshot of its data is performed.

Copyright © 2019 Oracle and/or its affiliates. Clone to Provision

The instance successfully joins the cluster!

Copyright © 2019 Oracle and/or its affiliates. Clone-based Recovery Demo

Copyright © 2019 Oracle and/or its affiliates. Copyright © 2019 Oracle and/or its affiliates. Which recovery shall be used?

• Incremental recovery is possible if:

• At least 1 member can provide the joiner with the same set of transactions it has processed. • The joiner does not have errants transactions

• Incremental recovery appropriate if:

• No purged transactions • Joiner does not have an empty GTID set • GTID support and binary logs were always enabled

Copyright © 2019 Oracle and/or its affiliates. AdminAPI Guidance

Incremental recovery safe and appropriate:

Copyright © 2019 Oracle and/or its affiliates. AdminAPI Guidance

Clone-based recovery required:

Copyright © 2019 Oracle and/or its affiliates. InnoDB cluster 8.0.17+

• Built-in support for full instance provisioning!

• AdminAPI transparently:

ü Setups the cluster to be ready for clone usage (plugin setup, user grants, etc.)

ü Detects every possible scenario and guides the user accordingly to the best provisioning method

ü Still allowing manual intervention to choose the provisioning method

Copyright © 2019 Oracle and/or its affiliates. Just a tip!

• Binlogs can now be purged frequently! ! • But (at least) one cluster member should keep them for 2 days (minimum) for recovery.

Copyright © 2019 Oracle and/or its affiliates. Monitoring

Copyright © 2019 Oracle and/or its affiliates. Node Provisioning Monitoring

The AdminAPI was extended to provide monitoring features:

• For any type of recovery method: clone or incremental

• Real-time progress information

• Detailed stage status

• Asynchronous progress information from cluster.status()

Copyright © 2019 Oracle and/or its affiliates. Node Provisioning Monitoring

ü Clone-based recovery real-time progress info

Copyright © 2019 Oracle and/or its affiliates. Node Provisioning Monitoring

ü Clone-based recovery progress from cluster.status()

Copyright © 2019 Oracle and/or its affiliates. Cluster Status mysqlsh-js> cluster.status()

Provides general information about the cluster and each member status

Copyright © 2019 Oracle and/or its affiliates. Extended Status mysqlsh-js> cluster.status({extended: 1})

Provides information of:

• GR Group name

• Group protocol version

• Cluster members UUIDs

• Cluster members roles and states

• Read-only settings

Copyright © 2019 Oracle and/or its affiliates. Extended Status mysqlsh-js> cluster.status({extended: 2})

Provides information of:

• Transactions processed by connection and applier

Copyright © 2019 Oracle and/or its affiliates. Extended Status mysqlsh-js> cluster.status({extended: 3})

Provides information of:

• Detailed stats about the replication machinery of each cluster member

Copyright © 2019 Oracle and/or its affiliates. Reporting Framework

• Built-in reports // displays the result one time mysqlsh-js> \show query

• User-defined reports // executes repeatedly with screen refresh mysqlsh-js> \watch query

// registers a user-defined-report mysqlsh-js> shell.registerReport()

Copyright © 2019 Oracle and/or its affiliates. Reporting Framework

• Built-in reports // displays the result one time mysqlsh-js> \show query

• User-defined reports // executes repeatedly with screen refresh mysqlsh-js> \watch query

! // registers a user-defined-report Monitor P_S to check which mysqlsh-js> shell.registerReport() secondary instance is slower

Copyright © 2019 Oracle and/or its affiliates. Maintenance and Troubleshooting

Copyright © 2019 Oracle and/or its affiliates. Maintenance

Monitoring a cluster can provide info/hints about:

• Faulty networks

• High latencies

• Server failures

• ...

Copyright © 2019 Oracle and/or its affiliates. Cluster Options mysqlsh-js> cluster.options()

Provides information of:

• The cluster global configuration options

• Each cluster member settings

Copyright © 2019 Oracle and/or its affiliates. Cluster options

expelTimeout memberWeight Avoid frequent member expels Next primary in line when a due to faulty network failover happens

exitStateAction autoRejoinTries Action when a server is expelled Rejoin attempts after an eviction from the cluster: abort, read-only, offline-mode

Copyright © 2019 Oracle and/or its affiliates. Changing Cluster Options

// Change the member-weight value of a member mysqlsh-js> cluster.setInstanceOption(“mysql2:3307”, “memberWeight”, 75)

Copyright © 2019 Oracle and/or its affiliates. Changing Cluster Options

// Change the member-weight value of a member mysqlsh-js> cluster.setInstanceOption(“mysql2:3307”, “memberWeight”, 75)

// Change the exit-state-action of a member mysqlsh-js> cluster.setInstanceOption(“mysql3”, “exitStateAction”, “ABORT_SERVER”)

Copyright © 2019 Oracle and/or its affiliates. Changing Cluster Options

// Change the member-weight value of a member mysqlsh-js> cluster.setInstanceOption(“mysql2:3307”, “memberWeight”, 75)

// Change the exit-state-action of a member mysqlsh-js> cluster.setInstanceOption(“mysql3”, “exitStateAction”, “ABORT_SERVER”)

// Change the expel-timeout of the cluster mysqlsh-js> cluster.setOption(“expelTimeout”, 60)

Copyright © 2019 Oracle and/or its affiliates. Consistency Levels

• InnoDB cluster operates, by default, in single-primary mode:

• Apps and users write to the primary instance

• What guarantees do we have that: • We always read the most up-to-date data? ? • We do not read stale data of an evicted server?

• Dirty reads do not happen?

Copyright © 2019 Oracle and/or its affiliates. Consistency Levels

// Create a cluster with “BEFORE” consistency level // Ensures that reads always read the most up-to-data data mysqlsh-js> cluster = dba.createCluster(“CodeOne19”, {consistency: “BEFORE”})

Copyright © 2019 Oracle and/or its affiliates. Consistency Levels

// Create a cluster with “BEFORE” consistency level // Ensures that reads always read the most up-to-data data mysqlsh-js> cluster = dba.createCluster(“CodeOne19”, {consistency: “BEFORE”})

// Change the consistency level at any time // AFTER ensures that there are no dirty reads mysqlsh-js> cluster.setOption(“consistency”, “AFTER”)

Copyright © 2019 Oracle and/or its affiliates. Topology Modes

• The cluster’s primary instance can be changed, immediately:

Copyright © 2019 Oracle and/or its affiliates. Topology Modes

• The topology-mode can be changed live:

// Change the topology-mode to multi-primary mysqlsh-js> cluster.switchToMultiPrimaryMode()

// Change back to single-primary-mode mysqlsh-js> cluster.switchToSinglePrimaryMode()

Copyright © 2019 Oracle and/or its affiliates. Security

• Internal recovery accounts have randomly secure generated passwords

• But security policies may enforce passwords lifetime

ü Support to reset a cluster’s recovery accounts credentials added

// Reset the recovery accounts credentials mysqlsh-js> cluster.resetRecoveryAccountsPassword()

Available in 8.0.18

Copyright © 2019 Oracle and/or its affiliates. Troubleshooting

Anything“ that can go wrong will go wrong.”

Copyright © 2019 Oracle and/or its affiliates. Troubleshooting

Anything“ that can go wrong will go wrong.”

• Shell’s interactive behavior provides the users with valuable information, by default.

• But sometimes more information is needed for troubleshooting...

Copyright © 2019 Oracle and/or its affiliates. Logging

$ mysqlsh –-log-level=8

Logging levels:

• 1: none

• 2: internal

• 3: error

• 4: warning

• 5: info

• 6, 7, 8: debug

Copyright © 2019 Oracle and/or its affiliates. Logging

$ mysqlsh –-verbose=4

Verbose output level:

• [1, 4]

• Enables diagnostic messages output

Copyright © 2019 Oracle and/or its affiliates. Logging

$ mysqlsh –-dba-log-=2

Log AdminAPI SQL:

• 0: no logging

• 1: log all queries except SELECT and SHOW

• 2: log all queries

Available in 8.0.18

Copyright © 2019 Oracle and/or its affiliates. Final Thoughts

• InnoDB cluster is THE built-in HA solution for MySQL • MySQL Clone Plugin pushed InnoDB cluster to a whole new level of usability! • InnoDB Cluster features built-in support for full instance provisioning

• MySQL Shell is the unified interface for developers and DBAs and the frontend manager for InnoDB cluster

Copyright © 2019 Oracle and/or its affiliates. Resources

• https://dev.mysql.com/doc/refman/8.0/en/mysql-innodb- cluster-userguide.html (InnoDB cluster userguide) https://dev.mysql.com/doc/dev/mysqlsh-api-javascript/8.0/ (Shell APIs JS Ref manual) https://dev.mysql.com/doc/dev/mysqlsh-api-python/8.0/ (Shell APIs Python Ref manual)

• https://mysqlhighavailability.com (Blogging) • http://mysqlserverteam.com/ (Blogging) • https://mysqlcommunity.slack.com (Community Slack)

Copyright © 2019 Oracle and/or its affiliates. Thank you!

Copyright © 2019 Oracle and/or its affiliates. MOAR MySQL

• MySQL Shell: The Best DBA Tool? How to Use MySQL Shell as a Framework for DBAs [DEV2056] • What’s New in MySQL Optimizer and Executor? [DEV2077] • MySQL Connector/J 8.0 Feature Review and How to Upgrade from Connector/J 5.1 [DEV6221] • MySQL 8.0 Enterprise Backup [DEV4110] • Group Replication: How I Stopped Worrying About Consistency and Focused on Building Apps [DEV3016]

Copyright © 2019 Oracle and/or its affiliates. Session Survey

Help us make the content even better. Please complete the session survey in the Mobile App.

Copyright © 2019 Oracle and/or its affiliates. Safe Harbor

The preceding 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, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation.

Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events.

Copyright © 2019 Oracle and/or its affiliates.