Elastic Scalability in MySQL Fabric using OpenStack Mats Kindahl Senior Principal Software Developer Narayanan Venkateswaran Principal Software Developer 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.
Session Outline 1 Elasticity in Computing 2 OpenStack 3 Introduction to MySQL Fabric 4 Elasticity in MySQL Fabric using OpenStack 5 Closing Remarks & Thoughts for the Future
Elasticity in Computing
What is Elasticity? [Elasticity] is defined as the degree to which a system is able to adapt to workload changes by provisioning and deprovisioning resources in an autonomic manner
Elasticity from our Perspective Managing server failures Managing read load Read load increases Problem: Read servers overloaded Solution: Add more read servers Managing shards A shard is hot or full Problem: slower queries Solution: Split the shard A server in a group fails Slave is promoted Problem: Availability is affected Solution: Add replacement node
OpenStack
What is OpenStack? OpenStack is a free and opensource software cloud computing software platform What is that?
Cloud Computing According to NIST Resouce pooling Resources are assigned and reassigned based on customer demand Broad network access Capabilities are accessed over the network through standard mechanisms Measured service On-demand self-service Customer can unilaterally provision computing capabilities Rapid elasticity Capabilities can be elastically provisioned and released
OpenStack Deployment Example Controller Controller Node Manages Identities Manages Images Manages Block Storage Compute Node (Virtual) machine host Contain hypervisor Spawn and destroy virtual machines Compute (VM Host)
Introduction to MySQL Fabric
What is MySQL Fabric? An extensible and easy-touse framework for managing a farm of MySQL servers supporting high-availability and sharding
What does all that mean? Management System Framework Manages a MySQL Farm Distributed Framework Procedure execution State store Transaction Routing Written in Python Latest Release 1.5.2 GA Open Source Extensible Extensions are first-class High-availability groups Semi-automatic sharding You can participate Suggest features Report bugs Contribute patches MySQL 5.6 is focus
MySQL Fabric: Goals & Features Decision logic in connector Connector API extensions Multi-table sharding Sharding functions Support transactions Support full SQL Load balancing Eliminates network hop Reduce network load Eliminate single point of failure Scale naturally: not a bottleneck Read-write split Weighted round-robin Shard operations Range (Consistent) hash Shard move Shard split Global updates Global tables Schema updates Cloud integration Support elasticity Servers on-demand
A Brief History of MySQL Fabric MySQL Fabric 1.4 First public release Sept 2013 MySQL Fabric 1.4.3 GA May 2014 High-availability groups Failure detection Load balancing Range and hash sharding Shard move and split Connector/J support Connector/PHP support Connector/Python support Doctrine Hibernate MySQL Fabric 1.5 MySQL Fabric 1.5.1 RC in Aug 2014 MySQL Fabric 1.5.2 GA in Sept 2014 Cloud Integration (WL#6432) MySQL-RPC support (WL#7600) Connector/NET support Labs: C API
Birds-eye View Operator Application Database Servers Connector XML-RPC MySQL-RPC Connector Connector SQL MySQL Fabric Node SQL High Availability Groups
High-Level Components Fabric-aware Connectors Python, PHP, Java,.NET, C Enhanced Connector API Connector MySQL Fabric Node Application Manage information about farm Provide status information Execute procedures MySQL Servers Connector MySQL Fabric Node Organized in high-availability groups Handling application data High Availability Group Connector
MySQL Fabric Node Architecture Protocols Connector Connector? AMQP MySQL-RPC XML-RPC Connector Sh MySQL Fabric Framework Executor HA State Store (Persister) Extensions? MySQL Backing Store
High-Availability Concepts Redundancy Monitoring Duplicate components Detecting failing components Monitor load Procedures Activate replacements Distribute load
MySQL Fabric and the Cloud Using OpenStack for Elasticity
Server Providers Server Creation Create new server instances Server Filling Fill instance with data Internal Memory Clone from an existing server Disk Size Restore a backup Number of CPUs Configured for the purpose GTID enabled Binary log enabled Correct engines enabled L Q S My Set up replication ic r b Fa Point secondary to primary Custom filling operation d u o l +C d e l d n a h ic y r d b a a e Alr SQL F y M in
Server Providers A server factory Abstract concept Extension interface added to MySQL Fabric Possible to support multiple providers OpenStack Nova (in MySQL Fabric 1.5) OpenStack Trove Amazon AWS Amazon RDS Custom hardware registry
MySQL Fabric and OpenStack MySQL Fabric Node Application High-Availability Groups / Shards OpenStack Instance
Adding a new provider to MySQL Fabric Register a provider with MySQL Fabric Provide API address and user credentials Provider type OPENSTACK spawns new virtual machines mysqlfabric provider register my_stack mats xyzzy http://example.net:5000/v2.0/ my_project --provider_type=openstack
Creating a new server from MySQL Fabric Create a new machine using the registered provider Provide an image to use for the machine You have to set up the image beforehand Provide a cloud-init script to set up MySQL server mysqlfabric machine create my_stack --image name= Oracle Linux 7 amd64 --flavor name=m1.small --userdata=mysql-oracle-linux-init
Creating a snapshot from MySQL Fabric Create a snapshot of an existing machine Return an provider-internal name of the snapshot Can be used to create your golden image mysqlfabric snapshot create my_stack 903476b7-db4d-4d63-84e6-f79c7d0cec31
Elasticity using providers Read load increases Server is lost Spawn new read servers High-availability is reduced Add them to the group Spawn new server Add it to the group Shard is overloaded Spawn new servers for a shard Create a new shard Split existing shard Can we automate this? Yes, we can!
Events MySQL Fabric executor Event driven Queue Events will trigger execution of procedures Procedures can trigger events themselves Each step of a procedure is called a job Backing Store Procedures Written in Python Interacts with servers Write state changes into backing store Lock manager for conflict resolution Conservative two-phase locking strategy Avoid deadlocks
Automatically adding a server to a group Register procedure for event @on_event decorator Accept event to register for Fetch the group the server belonged to Fetch a new server from the provider Add the server to the group @on_event(server_lost) def _add_server(group_id, server_uuid): group = Group.fetch(group_id) machines = PROVIDER.create_machines( parameters ) server = MySQLServer( server_uuid, address ) MySQLServer.add(server) group.add(server) _configure_as_slave(server)
Events MySQL Fabric procedure execution Before starting a job: Queue Aquire the necessary locks Checkpoint execution state in backing store Start a transaction on the backing store Backing Store When executing job: Make updates to backing store inside transaction Interact with servers After executing a job: Wh Mark job completed in internal log Commit transaction on backing store ut o b at a s? e h s cr a
Events MySQL Fabric executor recovery Two types of jobs: Queue Idempotent: Restart the job Not idempotent: Execute compensation Recovery procedure Start the executor Collect unfinished checkpoints Execute compensation activity for each job associated with the checkpoint Backing Store if there is one Re-schedule each job
Defining an compensation procedure Use the @undo decorator Compensating action Search for the machine by UUID Give it back to provider Compensating actions need to be idempotent @_add_server.undo def _undo_add_srv(group_id, server_uuid): meta_filters = { 'mysql fabric machine group uuid': server_uuid } machines = MANAGER.search_machines( {}, meta_filters ) for machine in machines: MANAGER.destroy_machine( machine.uuid )
Example using Rackspace Provider mysqlfabric provider register my_rackspace mats xyzzy https://lon.identity.api.rackspacecloud.com/v2.0/ tenant accountnumber extra auth_system=rackspace provider_type OPENSTACK mysqlfabric machine create my_rackspace image id=8c964b3f 8c15 4966 86ee 7a55824df564 ns i g u flavor name="512mb Standard Instance" l p n tio e a t c o i N nt e h t u a or f g) t n r i o om pp c u ( s e r i u Req
Experiments with Amazon AWS mysqlfabric provider register my_amazon AKIAIOSFODNN7EXAMPLE wjalrxutnfemi/k7mdeng/bpxrficyexamplekey eu west 1 provider_type=amazon mysqlfabric machine create my_amazon image image id=ami 892fe1fe flavor name=t2.micro Note! Not in MySQL Fabric 1.5 Will be on MySQL Labs
Experiments with OpenStack Trove mysqlfabric provider register my_trove mats xyzzy https://lon.identity.api.rackspacecloud.com/v2.0/ tenant 123456 extra service_type=rax:database provider_type=openstack.database mysqlfabric server create my_trove flavor name="512mb Instance" size 1 users mats:xyzzy databases employee datastore MySQL datastore_version 5.6 Note! Not in MySQL Fabric 1.5 Will be on MySQL Labs
Closing remarks
What do we have now? High-availability Range and hash sharding Shard move and shard split Transaction properties Virtual connections Cloud integration Server providers OpenStack Nova Connectors report failures Custom failure detectors Credentials Command-line XML-RPC MySQL-RPC Distributed failure detector Connector/Python Connector/PHP Connector/J Connector/NET Interfaces Connector APIs Enhanced connectors Group Concept Slave promotion Sharding RFC 2617 SSL support
Thoughts for the Future Connector multi-cast Improve extension support Improve procedures support Focus on ease-of-use Cloud support OpenStack Trove Amazon AWS Amazon RDS Django? More connectors? MySQL-RPC Protocol? Done! More frameworks? Command-line interface More protocols UNION of result sets More complex operations? Extension interfaces C/C++? In Labs! Fabric-unaware connectors? More HA group types DRBD MySQL Cluster Amazon RDS?
Thoughts for the Future Automatic sharding Single-query transactions? Speculative execution? Cross-shard queries? Efficient initial sharding Better use of resources Node failure stop execution Execution restart on recovery Replicated State Machine (RSM) Independent tables Multi-way shard split Highly-available executor Multiple shard mappings Paxos? Raft? Fail-over execution Session consistency We have a distributed database It should look like a single database Read monotonicity Write monotonicity
Reading for the Interested MySQL Forum: Fabric, Sharding, HA, Utilities http://forums.mysql.com/list.php?144 MySQL Fabric Documentation http://dev.mysql.com/doc/mysql-utilities/1.4/en/fabric.html Migrating From an Unsharded to a Sharded Setup http://vnwrites.blogspot.com/2013/09/mysqlfabric-sharding-migration.html Configuring and running MySQL Fabric http://alfranio-distributed.blogspot.com/2014/03/mysqlfabric-installation.html
Want to contribute? Check it Test it and send us use-case and feature suggestions and send comments to the forum Break it and send in bugs to http://bugs.mysql.com
Keeping in Touch Mats Kindahl Narayanan Venkateswaran Alfranio Correia Geert Vanderkelen Twitter: @mkindahl http://mysqlmusings.blogspot.com Twitter: @alfranio http://alfranio-distributed.blogspot.com Twitter: @vn_tweets http://vnwrites.blogspot.com Twitter: @geertjanvdk http://geert.vanderkelen.org
Safe Harbor Statement 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, and timing of any features or functionality described for Oracle s products remains at the sole discretion of Oracle.