advanced mysql replication architectures - luis soares

50
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Upload: mysql-brasil

Post on 09-May-2015

2.307 views

Category:

Technology


2 download

DESCRIPTION

Arquiteturas avançadas e usos curiosos do recurso nativo de replicação do MySQL. Também são detalhadas algumas novidades da versão 5.6 que elevam a Replicação MySQL a outro nível.

TRANSCRIPT

Page 1: Advanced MySQL Replication Architectures - Luis Soares

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

Insert Information Protection Policy Classification from Slide 8

Page 2: Advanced MySQL Replication Architectures - Luis Soares

2 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Insert Information Protection Policy Classification from Slide 8

ADVANCED MYSQL REPLICATION ARCHITECTURES

Luís Soares Lars Thalmann, Development Director, Sr. Software Developer Replication, Connectors and BackupMySQL Replication Team Lead Mats Kindahl, Lead Software Dev, Replication

Oracle Open World Latin America 2011

Page 3: Advanced MySQL Replication Architectures - Luis Soares

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

Page 4: Advanced MySQL Replication Architectures - Luis Soares

4 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

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.

Page 5: Advanced MySQL Replication Architectures - Luis Soares

5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Agenda

● MySQL Replication Basics

● Traditional Architectures

● Load Balancing

● Data Aggregation and Multi-source Replication

● Hierarchical Replication

● Data Integration

● Advanced Replication Architectures Enablers

Page 6: Advanced MySQL Replication Architectures - Luis Soares

6 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySQL Replication Basics

Page 7: Advanced MySQL Replication Architectures - Luis Soares

7 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Components

● Master

● Changes data

● Logs changes (events) into a file (the binary log)

● Slave

● Retrieves events from the master

● Replays the events on the slaves databases

● Binary Log

● Records every change on the master (in either format: row or statement)

● Split into transactional groups

Page 8: Advanced MySQL Replication Architectures - Luis Soares

8 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Big Picture

Session Dump

Binary log

I/O SQL

Relay log

SlaveMaster

SessionSession

Page 9: Advanced MySQL Replication Architectures - Luis Soares

9 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Propagation of Changes

● Asynchronous Replication

● Transactions committed immediately

● Events are propagated after the commit operation is acknowledged

● Faster but vulnerable to lost updates on server crashes and inconsistency

● Built into the server

● Semi-synchronous Replication

● Master commits transaction but waits for N slaves to acknowledge having received and stored the correspondent event before replying to the client

Page 10: Advanced MySQL Replication Architectures - Luis Soares

10 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Traditional Architectures

Page 11: Advanced MySQL Replication Architectures - Luis Soares

11 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Single Master, Single Slave

Master

Slave

● Backups

● Reports

● Disaster Recovery (geographically distant servers)

● Recovering from Human errors (Time-delayed replication)

● Add more slaves seamlessly

Page 12: Advanced MySQL Replication Architectures - Luis Soares

12 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Scaling-out read operations

Master

Slave

Client

SlaveSlave

Writes

Reads

● Off-loading the master

● Different type of queries routed to different servers

● Different hardware profiles for master and slaves

● SSD for enhancing master performance

● Large RAM / caches to enhance Slaves performance

● Load Balancing

● Query routing policies

Page 13: Advanced MySQL Replication Architectures - Luis Soares

13 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Relay Server

● Relay Slave.

● Blackhole storage engine.

● No data stored on the relay slave.

● Reduce load at the master.

● Improved master side filtering.

● Sensitive data can be kept only at one physical server.

● Relay has binary log active.S1S1

Master

Relay

Slave N

Page 14: Advanced MySQL Replication Architectures - Luis Soares

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

High Availability

Slave

MasterMaster

Master Master

Master Master

Virtula IP Manager

Shared/replicated disk

Master MasterMaster

Binlog Binlog

Active/PassiveShared disk

CircularReplication

Dual Masters

Page 15: Advanced MySQL Replication Architectures - Luis Soares

15 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

High Availability

● High Availability: fail over

● Servers can crash (hardware, software or even power failure).

● Services should not.

● Dual masters, circular replication (conflict free partition workload on each).

● Seamless fail-over of affected partitions

● Scaling out with slaves.

● Ready to step up and replace a failed master (on dual masters watch out whether the slave is already ahead of second master – slave promotion instead)

● Active / Passive – binlog is shared by the two master's, on fail-over binlog positions match

Page 16: Advanced MySQL Replication Architectures - Luis Soares

16 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Load Balancing

Page 17: Advanced MySQL Replication Architectures - Luis Soares

17 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Load Balancing

Client

Writes to a master.

Reads from a pool of slaves.

Which one?

Master

Slave Slave Slave

Page 18: Advanced MySQL Replication Architectures - Luis Soares

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

Load Balancing: Application Level

Client

Writes to a masterMaster

LBSlave Slave Slave

Which server shouldI use for this query?

Page 19: Advanced MySQL Replication Architectures - Luis Soares

19 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Load Balancing: Intermediate Proxy

Client

Writes to a master

Reads from a slave in a pool of slaves.

Master

LB

Slave Slave Slave

Read/Write Split

Page 20: Advanced MySQL Replication Architectures - Luis Soares

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

Load Balancing

● Requires monitoring tools (status and performance)

● Servers crash every now and then!

● Requires intelligent query routing (reads vs writes)

● Which queries go where?

● Session consistency is something to keep in mind!

● Enter MySQL Proxy, PHP mysqlnd, ...

● http://dev.mysql.com/doc/refman/5.5/en/mysql-proxy.html

● http://dev.mysql.com/downloads/connector/php-mysqlnd

● http://blog.ulf-wendel.de/?p=320

Page 21: Advanced MySQL Replication Architectures - Luis Soares

21 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Hierarchical Replication

Page 22: Advanced MySQL Replication Architectures - Luis Soares

22 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Hierarchical Replication

Client

Writes

Reads

Hundreds of slaves connected to the master.

Master

...Master becomes

overloaded!

Page 23: Advanced MySQL Replication Architectures - Luis Soares

23 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Hierarchical Replication

Client

Writes

Reads

Hundreds of slaves more down the hierarchy ...

Master

RelaySlave

RelaySlave

Leaf or Relay Servers

Page 24: Advanced MySQL Replication Architectures - Luis Soares

24 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Hierarchical Replication

● Scale-out hundreds of servers

● Blackhole storage engine on relays.

● Relay servers have binary logs ON, leaf slaves do not need it.

● Group data domains/partitions

● Sensitive information routed through parts of the hierarchy.

● Event filtering.

Page 25: Advanced MySQL Replication Architectures - Luis Soares

25 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Hierarchical Replication

● Hierarchy-wide consistency!

● Asynchronous propagation => writes take time to propagate from master to slaves: reads on a slave may show stale data.

● Event positions are filename and offset => different on every intermediate slave.

● Wait for data to propagate.

● global transaction identifiers.

● poll each relay server down the chain until data has propagated.

Page 26: Advanced MySQL Replication Architectures - Luis Soares

26 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Data Aggregation: Multi-source Replication

Page 27: Advanced MySQL Replication Architectures - Luis Soares

27 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multi-source Replication

● Why?

● Aggregate data from different masters, different data-centers, different clusters

● How?

● Time-share Replication

● Typically round-robin policy

● Aggregating data from clusters in different timezones

● Slave controlled by specific client

● You can do it all at SQL level

● Inter-cluster

● Requirements: Conflict free load

Page 28: Advanced MySQL Replication Architectures - Luis Soares

28 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multi-source Replication

Master 1 Master 3Master 2

Slave

Conflicts?ReplicationStream is

SingleThreaded

BinlogPosition

Bookkeeping

Page 29: Advanced MySQL Replication Architectures - Luis Soares

29 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multi-source Replication: Time share

Master 1 Master 3Master 2

SlaveControlClient

No conflict resolution, so let masters update different data

Page 30: Advanced MySQL Replication Architectures - Luis Soares

30 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multi-source Replication: Control Clientimport itertools

position = {}def round_robin_multi_master(slave, masters): current = masters[0] for master in itertools.cycle(masters): slave.sql("STOP SLAVE IO_THREAD"); mysqlrep.wait_for_empty_relay_log(slave) slave.sql("STOP SLAVE SQL_THREAD"); position[current.name] = mysqlrep.fetch_slave_position(slave) slave.change_master(position[current.name]) master.sql("START SLAVE") current = master sleep(60) # Sleep 1 minute

Page 31: Advanced MySQL Replication Architectures - Luis Soares

31 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Inter-cluster Multi-source Replication

MySQLCluster

MySQLCluster

MySQLCluster

Server Server

Server Server

Again, no conflict resolution, so let masters update different data

Page 32: Advanced MySQL Replication Architectures - Luis Soares

32 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Data Integration

Page 33: Advanced MySQL Replication Architectures - Luis Soares

33 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Integrate Data Into Other Systems

MySQLSlave

SOLR

Data MiningHBASE

Full Text Search

Client

Client

Client?

Binlog

DumpDump

Dump

Master

Page 34: Advanced MySQL Replication Architectures - Luis Soares

34 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Integrate Data Into Other Systemsvia mysql binary log API

Binlog

TransformerAPI

Dump Server

File

SOLR

Connects to and reads from the binlog source (either server or file)

Handles binlog events, translates them and pushes data to SOLR

Page 35: Advanced MySQL Replication Architectures - Luis Soares

35 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Event flow in the binary log API library when reading from a dump thread.

Integrate Data Into Other Systemsvia mysql binary log API

Page 36: Advanced MySQL Replication Architectures - Luis Soares

36 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Integrate Data Into Other Systems

● Library to process replication events

● API ready to use

● Simple, extensible, efficient

● Just hook a client thread in the wait_for_next_event handler

● It's out there:

● https://launchpad.net/mysql-replication-listener

● http://labs.mysql.com

Page 37: Advanced MySQL Replication Architectures - Luis Soares

37 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Advanced Replication Architectures Enablers

Page 38: Advanced MySQL Replication Architectures - Luis Soares

38 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Replication Metadata on System Tables 5.6DMR● Crash-safe (replication metadata stored in

transactional tables)

● Robust, highly available setups

● SQL interface to metadata

● Access data through regular user session

● Self-contained: time-shared multi-source easily implemented in SQL and in the server

● Make use of special features like MySQL events, stored procedures, triggers, etc...

VS

Page 39: Advanced MySQL Replication Architectures - Luis Soares

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

Global Transaction Identifiers

● Event positions in the binary log are a tuple: <filename, file offset>

● Not very intuitive in a large hierarchical topology

● Makes it hard to get most recent transaction - fail-over

● Global transaction identifiers: <server_id, tx_seqno>

● Makes hierarchical consistency checks and fail-over close to trivial

● Early feature preview available on MySQL labs:

● http://labs.mysql.com

Page 40: Advanced MySQL Replication Architectures - Luis Soares

40 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySQL Utilities: What is it?

● A collection of Python utilities for managing MySQL databases

● Part of MySQL Workbench 5.2.31

● Available under the GPLv2 license

● Written in Python

● Easily enhanced using a growing code library

● Python library to grow solutions for common administrative problems

Enterprise

Ready!

Page 41: Advanced MySQL Replication Architectures - Luis Soares

41 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySQL Utilities: What is it?

Scripts

CommandModule

CommonModule

MySQL Utilities Library

mysqlprocgrep

mysql.utilities.command mysql.utilities.common

Enterprise

Ready!

Page 42: Advanced MySQL Replication Architectures - Luis Soares

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

MySQL Utilities: What can I do with it?

● Easily administer MySQL servers from the command line

● mysqldbcompare – compare databases

● mysqldbcopy – copy databases between servers

● mysqlprocgrep – search process information

● mysqlrplshow – show a graph of your topology

● mysqlreplicate – setup replication

● mysqlrplcheck – check replication configuration

● ...

● Build your own tools on top of the core of the library, e.g., automate timeshare multi-source replication setup or failing-over to a slave

Enterprise

Ready!

Page 43: Advanced MySQL Replication Architectures - Luis Soares

43 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySQL Utilities: Where to go from here?

Download MySQL Workbench from:

http://www.mysql.com/downloads/workbench/

You can also download the latest development source code tree for the MySQL Workbench Utilities from:

http://launchpad/net/mysql-utilities

Enterprise

Ready!

Page 44: Advanced MySQL Replication Architectures - Luis Soares

44 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySQL Proxy

● Simple program in-between client and mysql server

● Monitor, analyze, transform, load balance

● Use cases and possibilities are enormous

● Available at:

● http://dev.mysql.com/doc/refman/5.5/en/mysql-proxy.html

Page 45: Advanced MySQL Replication Architectures - Luis Soares

45 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

The Binary Log API

● A C++ library used for connecting to a MySQL server and process the replication stream as a slave.

● Enables complex setups and data streaming to heterogeneous slaves.

● Available at:

● https://launchpad.net/mysql-replication-listener

● http://labs.mysql.com (binaries)

Page 46: Advanced MySQL Replication Architectures - Luis Soares

46 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Summary

Page 47: Advanced MySQL Replication Architectures - Luis Soares

47 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Summary

● MySQL replication concepts and components: replication is simple

● Popular MySQL replication use case scenarios: replication is flexible and versatile

● Scenarios that take MySQL replication to a whole new more advanced level:

● Load Balancing

● Hierarchical replication

● Data replication and aggregation

● Data integration

● MySQL features that are enablers for more advanced replication scenarios

Page 48: Advanced MySQL Replication Architectures - Luis Soares

48 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Q&A

Page 49: Advanced MySQL Replication Architectures - Luis Soares

49 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Page 50: Advanced MySQL Replication Architectures - Luis Soares

50 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Insert Information Protection Policy Classification from Slide 8