Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL Fabric Tutorial, October 2014

3,048 views

Published on

Tutorial describing how to get started with MySQL Fabric

Published in: Software
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/hBEuO ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

MySQL Fabric Tutorial, October 2014

  1. 1. MySQL Fabric Tutorial Lars Thalmann, Development Director Narayanan Venkateswaran, Principal Software Engineer Mats Kindahl, Sr. Principal Software Engineer Copyright © 2014, Oracle and/or its affiliates. AAllll All rriigghhttss rights rreesseerrvveedd.. reserved. ||
  2. 2. 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. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 2014-10-02
  3. 3. Tutorial Outline 1 What is MySQL Fabric? 2 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | 3 4 5 Downloading and Installing High Availability Sharding Closing Remarks
  4. 4. What is MySQL Fabric? Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  5. 5. What is MySQL Fabric? An extensible and easy-to-use framework for managing a farm of MySQL servers supporting high-availability and sharding Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  6. 6. What does all that mean? ● Management System – Manages a MySQL Farm – Distributed Framework Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Framework – Procedure execution – State store – Transaction Routing ● Extensible – Extensions are first-class – High-availability groups – “Semi-automatic” sharding ● Written in Python ● Latest Release 1.5.2 GA ● Open Source – You can participate – Suggest features – Report bugs – Contribute patches ● MySQL 5.6 is focus
  7. 7. Birds-eye View Application SQL Connector Connector Connector High Availability Groups SQL Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Operator MySQL Fabric Node Database Servers
  8. 8. Downloading & Installing Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  9. 9. Download & Install ● Download MySQL Connector Python – http://dev.mysql.com/downloads/connector/python/ – This connector is needed for MySQL Fabric ● Download MySQL Utilities – http://dev.mysql.com/downloads/utilities/ – MySQL Fabric is part of the MySQL Utilities release ● Install MySQL Connector Python – For Ubuntu, simply click on the downloaded deb package ● Install MySQL Utilities – For Ubuntu, simply click on the downloaded deb package – Note that MySQL Connector Python must be installed before this step Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  10. 10. Download & Install ● Install MySQL Server 5.6 – For Ubuntu 14.04, just two commands: ● sudo apt-get install mysql-client-core-5.6 ● sudo apt-get install mysql-server-5.6 – MySQL 5.6 server is needed for the MySQL Fabric backing store – For the rest of the tutorial, we will assume that you have this server running Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  11. 11. Starting MySQL Fabric Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  12. 12. Starting Fabric $ mysqlfabric Usage: mysqlfabric [­­param, ­­config] <grp> <cmd> [arg, ...]. MySQL Fabric 1.5.2 ­MySQL server farm management framework Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Options: ­­version show program's version number and exit ­h, ­­help show this help message and exit ­­param= CONFIG_PARAMS Override a configuration parameter. ­­config= FILE Read configuration from FILE. Basic commands: help <grp> <cmd> Show help for command help commands List all commands help groups List all groups
  13. 13. Getting Help Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  14. 14. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Getting Help $ mysqlfabric help groups Available groups: statistics, group, dump, manage, server, role, user, threat, sharding, event $ mysqlfabric help group Commands available in group 'group' are: group activate group_id [­­synchronous] group description group_id [­­description= NONE] [­­synchronous] group deactivate group_id [­­synchronous] group create group_id [­­description= NONE] [­­synchronous] group remove group_id server_id [­­synchronous] group add group_id address [­­timeout= 5] [­­update_ only] [­­synchronous] group health group_id group lookup_servers group_id [­­server_ id=NONE] [­­status= NONE] [­­mode= NONE] group destroy group_id [­­force] [­­synchronous] group demote group_id [­­update_ only] [­­synchronous] group promote group_id [­­slave_ id=NONE] [­­update_ only] [­­synchronous] group lookup_groups [­­group_ id=NONE]
  15. 15. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Getting Help $ mysqlfabric help group demote group demote group_id [­­update_ only] [­­synchronous] Demote the current master if there is one. If users just want to update the state store and skip provisioning steps such as configuring replication, the update_only parameter must be set to true. Otherwise any write access to the master is blocked, slaves are synchronized with the master, stopped and their replication configuration reset. Note that no slave is promoted as master.
  16. 16. Configuring Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  17. 17. MySQL Fabric Users ● Backing Store User – The user identity that Fabric will use to modify the backing store – Can be configured in /etc/mysql/fabric.cfg [storage] Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Server User – The user identity used to connect to managed MySQL Servers – Can be configured in /etc/mysql/fabric.cfg [servers] ● Admin user – The user identity used to control MySQL Fabric – Can be configured in /etc/mysql/fabric.cfg [protocol.xmlrpc] ● Invoked client tools user – The user identity used to connect to managed MySQL Servers via Fabric-invoked command-line tools – Can be configured in /etc/mysql/fabric.cfg [protocol.xmlrpc]
  18. 18. Configuring the backing store ● On the MySQL Backing Store Server – Create a Backing Store user on the backing store MySQL Server – Grant access for the user to the “fabric” database lars@silver3:~$ mysql ­u root mysql> CREATE USER 'fabric'@'localhost' IDENTIFIED BY 'SECRET'; mysql> GRANT ALL ON fabric.* TO 'fabric'@'localhost'; Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  19. 19. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Original lars@silver3:~$ sudo emacs /etc/mysql/fabric.cfg [DEFAULT] prefix = sysconfdir = /etc logdir = /var/log [storage] address = localhost:3306 user = fabric password = database = fabric auth_plugin = mysql_native_password connection_timeout = 6 connection_attempts = 6 connection_delay = 1 [servers] user = fabric password = [protocol.xmlrpc] address = localhost:32274 threads = 5 user = admin password = disable_authentication = no realm = MySQL Fabric ssl_ca = ssl_cert = ssl_key = [executor] executors = 5 [logging] level = INFO url = file:///var/log/fabric.log [sharding] mysqldump_program = /usr/bin/mysqldump mysqlclient_program = /usr/bin/mysql [statistics] prune_time = 3600 [failure_tracking] notifications = 300 notification_clients = 50 notification_interval = 60 failover_interval = 0 detections = 3 detection_interval = 6 detection_timeout = 1 prune_time = 3600 [connector] ttl = 1 [client] password =
  20. 20. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Edited lars@silver3:~$ sudo emacs /etc/mysql/fabric.cfg [DEFAULT] prefix = sysconfdir = /etc logdir = /var/log [storage] address = localhost:3306 user = fabric password = SECRET database = fabric auth_plugin = mysql_native_password connection_timeout = 6 connection_attempts = 6 connection_delay = 1 [servers] user = fabric password = [protocol.xmlrpc] address = localhost:32274 threads = 5 user = admin password = disable_authentication = yes realm = MySQL Fabric ssl_ca = ssl_cert = ssl_key = [executor] executors = 5 [logging] level = INFO url = file:///var/log/fabric.log [sharding] mysqldump_program = /usr/bin/mysqldump mysqlclient_program = /usr/bin/mysql [statistics] prune_time = 3600 [failure_tracking] notifications = 300 notification_clients = 50 notification_interval = 60 failover_interval = 0 detections = 3 detection_interval = 6 detection_timeout = 1 prune_time = 3600 [connector] ttl = 1 [client] password =
  21. 21. Creating the backing store Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  22. 22. Creating the backing store ● Create the database storing info for MySQL Fabric – Since we have disabled authentication for this tutorial, admin/xmlrpc password will actually not be used for anything $ mysqlfabric manage setup [INFO] 1411584079.046989 ­MainThread ­Initializing persister: user (fabric), server (localhost:3306), database (fabric). Finishing initial setup ======================= Password for admin user is not yet set. Password for admin/xmlrpc: Repeat Password: Password set. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  23. 23. A deeper look into the architecture Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  24. 24. Birds-eye View Application SQL Connector Connector Connector High Availability Groups SQL Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Operator MySQL Fabric Node Database Servers
  25. 25. High-Level Components ● Fabric-aware Connectors – Python, PHP, Java, .NET, C – 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 Application Connector High Availability Group Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Connector Connector MySQL Fabric Node
  26. 26. MySQL Fabric Node Architecture Connector ? Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | MySQL MySQL Fabric Framework Executor State Store (Persister) Sh ? HA AMQP MySQL-RPC XML-RPC Connector Connector Protocols Extensions Backing Store
  27. 27. Starting the Fabric server ● MySQL Fabric will be run in the foreground – You can also run as deamon in the backgroud, using --deamonize $ mysqlfabric manage start [INFO] 1411822940.181810 ­MainThread ­Initializing persister: user (root), server (localhost:13000), database (fabric). [INFO] 1411822940.188654 ­MainThread ­Loading Services. [WARNING] 1411822940.198591 ­MainThread ­Authentication disabled [INFO] 1411822940.198668 ­MainThread ­MySQL­RPC protocol server started, listening on localhost:32275 [WARNING] 1411822940.198773 ­MainThread ­Authentication disabled [INFO] 1411822940.212181 ­MainThread ­Executor started. [INFO] 1411822940.215672 ­MainThread ­Starting failure detector. [INFO] 1411822940.216747 ­XML­RPC­Server ­XML­RPC protocol server ('127.0.0.1', 32274) started. [INFO] 1411822940.217083 ­XML­RPC­Server ­Setting 1 XML­RPC session(s). [INFO] 1411822940.217331 ­XML­RPC­Session­0 ­Started XML­RPC­Session. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  28. 28. High Availability Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  29. 29. High-Availability Concepts Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Redundancy – Duplicate components ● Monitoring – Detecting failing components – Monitor load ● Procedures – Activate replacements – Distribute load
  30. 30. Using the Fabric client ● Create a High Availability group – The Fabric client will connect to the Fabric server that is configured in the Fabric.cfg file $ mysqlfabric group create "group­1" Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­254f8b62­8ea9­4350­a46e­77fefafc0f41 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­3 2 1411822993.11 Triggered by <mysql.fabric.events.Event object at 0x7fbdef77aa50>. 4 2 1411822993.12 Executing action (_create_group). 5 2 1411822993.12 Executed action (_create_group).
  31. 31. Add a MySQL server to the group ● The MySQL server is now managed by MySQL Fabric $ mysqlfabric group add group­1 localhost:13001 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­bb73e411­0705­47dd­86f9­b99798c97c9c 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­3 2 1411823050.61 Triggered by <mysql.fabric.events.Event object at 0x7fbdef77ae10>. 4 2 1411823050.61 Executing action (_add_server). 5 2 1411823050.62 Executed action (_add_server).
  32. 32. Add a second MySQL server to the group ● The MySQL servers are now managed by MySQL Fabric $ mysqlfabric group add group­1 localhost:13002 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­feba445d­47bd­4681­a8b8­8ae88d1d12a3 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­3 2 1411823077.84 Triggered by <mysql.fabric.events.Event object at 0x7fbdef77ae10>. 4 2 1411823077.84 Executing action (_add_server). 5 2 1411823077.85 Executed action(_add_server).
  33. 33. Listing the MySQL servers of the group ● Two servers in the high availability group $ mysqlfabric group lookup_servers group­1 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 server_uuid address status mode weight Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­1906aa45­4646­11e4­926f­e82aea9348c9 localhost:13001 SECONDARY READ_ONLY 1.0 1937e215­4646­11e4­926f­e82aea9348c9 localhost:13002 SECONDARY READ_ONLY 1.0
  34. 34. Promote a server to master ● Will pick the “best” server of the group – Since the servers are empty, this will be a random choice $ mysqlfabric group promote group­1 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­4295faef­e6e1­4df1­9493­1b9b9cdc3a48 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­3 2 1411823267.15 Triggered by <mysql.fabric.events.Event object at 0x7fbdef4615d0>. 4 2 1411823267.15 Executing action (_define_ha_operation). 5 2 1411823267.16 Executed action (_define_ha_operation).
  35. 35. Promote a specific server to become the master ● The server specified with --slave-id will be the master $ mysqlfabric group promote group­1 ­­slave_ id=1906aa45­4646­11e4­926f­e82aea9348c9 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­4295faef­e6e1­4df1­9493­1b9b9cdc3a48 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­3 2 1411823267.15 Triggered by <mysql.fabric.events.Event object at 0x7fbdef4615d0>. 4 2 1411823267.15 Executing action (_define_ha_operation). 5 2 1411823267.16 Executed action (_define_ha_operation).
  36. 36. Using the High Availability Group of the farm Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  37. 37. Birds-eye View Application SQL Connector Connector Connector High Availability Groups XML-RPC MySQL-RPC SQL Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Operator MySQL Fabric Node Database Servers
  38. 38. MySQL Connector Python ● There is also Java, PHP, Connector/C (labs), .Net – And support for frameworks Doctrine, Hibernate import mysql.connector from mysql.connector import fabric Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  39. 39. Create a table in the group ● Connect to Fabric, not to MySQL servers directly conn = mysql.connector.connect( fabric={"host" : "localhost", "port" : 32274, "username": "admin", "password" : "", 'report_errors': True }, user="root", password="", autocommit=True) conn.set_property(group="group­1", mode=fabric.MODE_READWRITE) cur = conn.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS employees") cur.execute("USE employees") cur.execute("DROP TABLE IF EXISTS employees") cur.execute( "CREATE TABLE employees (" " emp_no INT, first_name CHAR(40), last_name CHAR(40)" ")") Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  40. 40. Insert data into the group ● Specifying it is for group-1, read-write transaction def add_employee(conn, emp_no, first_name, last_name): conn.set_property(group="group­1", mode=fabric.MODE_READWRITE) cur = conn.cursor() cur.execute("USE employees") cur.execute( "INSERT INTO employees VALUES (%s, %s, %s)", (emp_no, first_name, last_name) ) # We need to keep track of what we have executed in order to, # at least, read our own updates from a slave. cur.execute("SELECT @@global.gtid_executed") for row in cur: print "Transactions executed on the master", row[0] return row[0] Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  41. 41. Select data from the group ● Specifying that it is group-1, and that this is a read-only transaction def find_employee(conn, emp_no, gtid_executed): conn.set_property(group="group­1", mode=fabric.MODE_READONLY) cur = conn.cursor() # Guarantee that a slave has applied our own updates before # reading anything. cur.execute( "SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('%s', 0)" % (gtid_executed, )) for row in cur: print "Had to synchronize", row, "transactions." cur.execute("USE employees") cur.execute( "SELECT first_name, last_name FROM employees " "WHERE emp_no = %s", (emp_no, )) for row in cur: print "Retrieved", row Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  42. 42. Failure Detection Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  43. 43. ● Monitors servers within each group Application Connector Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Failure Detector Fabric Monitoring ● On master failure, – mark server as faulty, and – trigger fail-over ● On slave failure, – mark as faulty Jan 2010 High Availability Group Connector Connector MySQL Fabric Node
  44. 44. Failure Detector (fabric.cfg) Fabric Monitoring 2x Engineering Staf 3x QA Staf 2x Support Staf Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | [failure_tracking] detections = 3 detection_interval = 6 detection_timeout = 1 detections The number of times a server fails alive checks, before being marked as FAULTY. detection_interval Time between alive checks. detection_timeout The time after which a server alive ping timeouts.
  45. 45. Distributed Failure Reporting ● Connector reports error to Fabric ● Error used to update backing store Application Connector Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | ● Trigger fail-over – Error count reaches threshold High Availability Group Connector Connector MySQL Fabric Node
  46. 46. Distributed Failure Reporting (fabric.cfg) 2x Engineering Staf 3x QA Staf 2x Support Staf Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | [failure_tracking] notifications = 300 notification_clients = 50 notification_interval = 60 failover_interval = 0 prune_time = 3600 notifications The number of error notifications required to mark a server FAULTY. notification_clients The number of clients that need to report an error to mark a server FAULTY.
  47. 47. Distributed Failure Reporting (fabric.cfg) notification_interval The interval of interest in which we want to verify error notifications. failover_interval The interval at which we can safely do a failover in a group without causing system instability. prune_time Interval at which we need to prune the error logs. 2x Engineering Staf 3x QA Staf 2x Support Staf Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  48. 48. Distributed Failure Reporting (Connector) Enabling Error Reporting ● The option to report errors is part of the Fabric configuration 2x Engineering Staf 3x QA Staf 2x Support Staf ● “report_errors” can be turned on as follows ● Causes a connector-server connection error to be reported to Fabric Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | fabric_config = { 'host': .., 'report_errors': True, } cnx = mysql.connector.connect(fabric=fabric_config)
  49. 49. Distributed Failure Reporting (Connector) Error Reporting ● The following errors are reported by default REPORT_ERRORS = ( errorcode.CR_SERVER_LOST, errorcode.CR_SERVER_GONE_ERROR, errorcode.CR_CONN_HOST_ERROR, errorcode.CR_CONNECTION_ERROR, errorcode.CR_IPSOCK_ERROR, ) ● The above can be extended by setting extra_failure_report from mysql.connector.fabric import extra_failure_report extra_failure_report([error_code_0, error_code_1, ...]) Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  50. 50. Distributed Failure Reporting (Connectors) Cache Invalidation 2x Engineering Staf 3x QA Staf 2x Support Staf ● Define which errors cause invalidation of the connector cache ● The following errors cause a cache invalidation by default RESET_CACHE_ON_ERROR = ( errorcode.CR_SERVER_LOST, errorcode.ER_OPTION_PREVENTS_STATEMENT, ) Jan 2010 Sept 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | ● The above can be extended by from mysql.connector.fabric import RESET_CACHE_ON_ERROR RESET_CACHE_ON_ERROR.append(error_code_0)
  51. 51. Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Sharding
  52. 52. Birds-eye View Application SQL Connector Connector Connector High Availability Groups XML-RPC MySQL-RPC SQL Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Operator MySQL Fabric Node Database Servers
  53. 53. Creating a sharding definition ● In this example, we use Hash sharding – Fabric also supports Range sharding – This will define Group-1 as the “global group” of the shard definition – Group-1 is not a shard – All shard groups that are added, will be slave groups to the global group $ mysqlfabric sharding create_definition HASH group­1 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­90bbd7a7­8996­4a5a­a971­32d10e3591c4 1 1 1
  54. 54. List the sharding definitions ● The created sharding definition has identifier 1 $ mysqlfabric dump shard_maps Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 mapping_id type_name global_group_id ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­1 HASH group­1 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  55. 55. Register a table to the sharding definition ● Table “db1.t1” to be sharded according to definition “1” – The table will be created later – The column “emp_no” will be used as the sharding key $ mysqlfabric sharding add_table 1 db1.t1 emp_no Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­57aa21ef­1315­4da7­8295­aa2a0f4339e0 1 1 1
  56. 56. Add shards (groups) to the sharding definition ● Add two groups as shards – Global Group: group-1 – Shards: group-2 and group-3 – --state=ENABLED will start replication $ mysqlfabric sharding add_shard 1 group­2, group­3 ­­state= ENABLED Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­f1e2d884­1d67­4a3a­b5d2­5b29b2a6d451 1 1 1
  57. 57. What do we have now? Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● The groups – One global group – Two shards
  58. 58. Using the Global Group of the farm Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  59. 59. Create a table (on all shards) ● Use the global group (SCOPE_GLOBAL) – Afterwards set back to the default, i.e. SCOPE_LOCAL – The properties are for the connection, not only for a single transaction conn.set_property(tables=["db1.t1"], scope=fabric.SCOPE_GLOBAL, mode=fabric.MODE_READWRITE) cur = conn.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS db1") cur.execute("USE db1") cur.execute("DROP TABLE IF EXISTS t1") cur.execute( "CREATE TABLE t1 (" " emp_no INT, " " first_name CHAR(40), " " last_name CHAR(40)" ")") conn.set_property(scope=fabric.SCOPE_LOCAL) Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  60. 60. Table propagated to all groups Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● The table – First created on the global group – Then replicated to the two shards
  61. 61. Using the Sharding Groups of the farm Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  62. 62. Inserting into the shards ● Using the table name and the sharding key def add_employee(conn, emp_no, first_name, last_name, gtid_executed): conn.set_property(tables=["db1.t1"], key=emp_no, mode=fabric.MODE_READWRITE, scope=fabric.SCOPE_LOCAL) cur = conn.cursor() synchronize(cur, gtid_executed) cur.execute("USE db1") cur.execute( "INSERT INTO t1 VALUES (%s, %s, %s)", (emp_no, first_name, last_name) ) conn.commit() Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  63. 63. Select data from the shards ● Using the table name and the sharding key – Will only execute this on the correct shard def find_employee(conn, emp_no, gtid_executed): conn.set_property(tables=["db1.t1"], key=emp_no, mode=fabric.MODE_READONLY) cur = conn.cursor() synchronize(cur, gtid_executed) cur.execute("USE db1") for row in cur: print "Had to synchronize", row, "transactions." cur.execute( "SELECT first_name, last_name FROM t1 " "WHERE empno = %s", (emp_no, ) ) for row in cur: print row Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  64. 64. Shard split Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  65. 65. Create a new group with MySQL servers ● Creating the 4th group ● Adding two servers ● Promote one of them to master $ mysqlfabric group create "group­4" $ mysqlfabric group add group­4 localhost:13007 $ mysqlfabric group add group­4 localhost:13008 $ mysqlfabric group promote group­4 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  66. 66. Sharding information ● Two shards 1, 2 ● Hosted on two groups “group-2” and “group-3” $ mysqlfabric dump sharding_information Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 schema_name table_name column_name lower_bound shard_id type_name group_id global_group ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­db1 t1 empno E6416... 1 HASH group­2 group­1 db1 t1 empno DC3AD... 2 HASH group­3 group­1 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  67. 67. Check how much data we have ● Checking on a MySQL server (shard 1 on “group-2”) directly mysql> use db1; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with ­A Database changed mysql> select count(empno) from t1; +­­­­­­­­­­­­­­+ | count(empno) | +­­­­­­­­­­­­­­+ | 1009 | +­­­­­­­­­­­­­­+ 1 row in set (0.00 sec) Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  68. 68. Split the shard into two shards ● Part of shard 1 (“group-2”) moved to “group-4” $ mysqlfabric sharding split_shard 1 group­4 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 uuid finished success result Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­80788beb­be2f­4b26­84f5­20bb2964ff70 1 1 1 state success when description ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­4 2 1411863534.16 Executing action (_check_shard_information). 4 2 1411863534.17 Executing action (_backup_source_shard). 4 2 1411863534.25 Executing action (_restore_shard_backup). 4 2 1411863534.37 Executing action (_setup_replication). 4 2 1411863534.39 Executing action (_setup_sync). 4 2 1411863534.4 Executing action (_setup_resharding_switch). 4 2 1411863535.45 Executing action (_prune_shard_tables_after_split).
  69. 69. How much data after the split? ● Checking on a MySQL server (shard 1 on “group-2”) directly mysql> use db1; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with ­A Database changed mysql> select count(empno) from t1; +­­­­­­­­­­­­­­+ | count(empno) | +­­­­­­­­­­­­­­+ | 532 | +­­­­­­­­­­­­­­+ 1 row in set (0.00 sec) Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  70. 70. Looking up servers responsible for sharding key ● For any sharding key, you can check which servers are responsible $ mysqlfabric sharding lookup_servers db1.t1 42000 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 server_uuid address status mode weight Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­83f2dd4f­46a1­11e4­94c4­e82aea9348c9 localhost:13007 SECONDARY READ_ONLY 1.0 8426dd92­46a1­11e4­94c4­e82aea9348c9 localhost:13008 PRIMARY READ_WRITE 1.0
  71. 71. Shard move Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  72. 72. Create a new group with MySQL servers ● Creating the 5th group ● Adding two servers ● Promote one of them to master $ mysqlfabric group create "group­5" $ mysqlfabric group add group­5 localhost:13009 $ mysqlfabric group add group­5 localhost:13010 $ mysqlfabric group promote group­5 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  73. 73. Looking up servers for a sharding key ● For any sharding key, you can check which servers are responsible (Ports 13007, 13008 = “group-4”) $ mysqlfabric sharding lookup_servers db1.t1 42000 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 server_uuid address status mode weight Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­83f2dd4f­46a1­11e4­94c4­e82aea9348c9 localhost:13007 SECONDARY READ_ONLY 1.0 8426dd92­46a1­11e4­94c4­e82aea9348c9 localhost:13008 PRIMARY READ_WRITE 1.0
  74. 74. Perform the shard move ● Move shard “4” to “group-5” $ mysqlfabric sharding move_shard 4 group­5 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 … Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  75. 75. Verify the move ● Afterwards, check which servers are responsible (Ports 13009, 13010 = “group-5”) $ mysqlfabric sharding lookup_servers db1.t1 42000 Fabric UUID: 5ca1ab1e­a007­feed­f00d­cab3fe13249e Time­To­Live: 1 server_uuid address status mode weight Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­8489b2ff­46a1­11e4­94c4­e82aea9348c9 localhost:13009 SECONDARY READ_ONLY 1.0 84bc4d59­46a1­11e4­94c4­e82aea9348c9 localhost:13010 PRIMARY READ_WRITE 1.0
  76. 76. Fabric Executor Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  77. 77. MySQL Fabric executor Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Event driven – Events will trigger execution of procedures – Procedures can trigger events themselves – Each step of a procedure is called a job ● 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 Queue Backing Store Events
  78. 78. 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) Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  79. 79. MySQL Fabric procedure execution ● Before starting a job: – Acquire the necessary locks – Checkpoint execution state in backing store – Start a transaction on the backing store ● When executing job: – Make updates to backing store inside transaction – Interact with servers ● After executing a job: – Mark job completed in internal log – Commit transaction on backing store Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Queue Backing Store Events What about crashes?
  80. 80. MySQL Fabric executor recovery ● Two types of jobs: – 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 … if there is one – Re-schedule each job Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | Queue Backing Store Events
  81. 81. Defining an compensation procedure ● Use the @undo decorator ● Compensating action – Search for the machine by UUID – Give it back to provider ● Compensating actions shall succeed @_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 ) Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  82. 82. Going Forward Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  83. 83. What do we have now? ● High-availability – Group Concept – Slave promotion Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Sharding – Range and hash sharding – Shard move and shard split ● Connector APIs – Transaction properties – “Virtual” connections ● Cloud integration – “Server providers” – OpenStack Nova ● Enhanced connectors – Connector/Python – Connector/PHP – Connector/J – Connector/NET ● Interfaces – Command-line – XML-RPC – MySQL-RPC ● Distributed failure detector – Connectors report failures – Custom failure detectors ● Credentials – RFC 2617 – SSL support
  84. 84. 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 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  85. 85. Want to contribute? Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. | ● Check it – … and send us use-case and feature suggestions ● Test it – … and send comments to the forum ● Break it – … and send in bugs to http://bugs.mysql.com
  86. 86. Keeping in Touch Lars Thalmann Twitter: @larsthalmann http://larsthalmann.blogspot.com Mats Kindahl Twitter: @mkindahl http://mysqlmusings.blogspot.com Alfranio Correia Twitter: @alfranio http://alfranio-distributed.blogspot.com Narayanan Venkateswaran Twitter: @vn_tweets http://vnwrites.blogspot.com Geert Vanderkelen Twitter: @geertjanvdk http://geert.vanderkelen.org Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  87. 87. MySQL Central Sessions ● Elastic Scalability in MySQL Fabric with OpenStack Thursday, Oct 2, 1:15 PM-2:00 PM Moscone South, 252 ● MySQL Fabric: High Availability at Different Levels Wednesday, Oct 1, 2:00 PM-2:45 PM Moscone South, 250 Copyright © 2014, Oracle and/or its affiliates. 2014-10-02 All rights reserved. |
  88. 88. 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. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 2014-10-02

×