This document discusses MySQL replication limitations and how the open source Tungsten Replicator can address them. Tungsten Replicator allows for features beyond MySQL's native replication such as multi-master replication, conflict prevention, parallel replication to improve performance, and replicating to non-MySQL databases. It provides high availability by enabling seamless failover between masters and supports various replication topologies not possible with MySQL alone.
1. MySQL replication outside the box
Giuseppe Maxia
QA Director
Continuent, Inc
@datacharmer
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License.
Tuesday, October 25, 11 1
2. about me -Giuseppe Maxia
§ a.k.a. The Data Charmer
§ QA Director, Continuent, Inc
§ Long time hacking with database features
§ Formerly, database consultant, designer, coder.
§ A passion for QA
§ An even greater passion for open source
§ ... and community
§ Passionate blogger
§ http://datacharmer.blogspot.com
Tuesday, October 25, 11 2
4. transaction
transaction
MySQL transaction
transaction
transaction
DBMS transaction
transaction
transaction
transaction
transaction
transaction
transaction
BINARY LOG
ns act act tio n
tra ansio ns sac ntio
ac ion ion n
ac
nr tr tra aniton
tsa a n csio
nts ct n
rn a o
taa scti
r
trnsa
n
n
MySQL replication
tio
ct
tra
tra
REPLICATION
transaction
transaction
is single threaded
MySQL
DBMS
Tuesday, October 25, 11 4
5. master master master master
MySQL MySQL MySQL MySQL
DBMS DBMS DBMS DBMS
MySQL MySQL MySQL MySQL
DBMS DBMS DBMS DBMS
slave slave slave slave
single source multi source (fan-in)
multiple sources?
Tuesday, October 25, 11 5
6. from this to this
MySQL MySQL
DBMS DBMS
master master
MySQL MySQL
DBMS DBMS
master master
multiple masters?
Tuesday, October 25, 11 6
7. INSERT INSERT
RECORD RECORD
A A
MySQL MySQL
DBMS DBMS
master master
MySQL MySQL
DBMS DBMS
MODIFY master master MODIFY
RECORD RECORD
B B
Avoiding conflicts?
Tuesday, October 25, 11 7
8. master
Seamless failover?
MySQL
DBMS
master
MySQL
DBMS
master
MySQL
DBMS
MySQL MySQL
DBMS DBMS
slave slave MySQL
DBMS
MySQL
DBMS
slave slave
MySQL MySQL
DBMS DBMS
slave slave
Tuesday, October 25, 11 8
9. Replicating to something else?
mysql master
MySQL
DBMS
MySQL
DBMS
mysql postgresql oracle mongodb
Tuesday, October 25, 11 9
10. All these examples tell
us:
Nice dream, but
MySQL can’t do it
Tuesday, October 25, 11 10
15. What can it do?
• Easy failover
• Multiple masters
• Multiple sources to a single slave
• Conflict prevention
• Parallel replication
• Replicate to Oracle and PostgreSQL database
Tuesday, October 25, 11 13
17. Tungsten Replicator in
a nutshell
host1
host2
master
slave
binlog THL
global
transaction ID THL
trep_commit_seqno
origin seqno eventid
trep_commit_seqno
origin seqno eventid
Tuesday, October 25, 11 15
18. Main components
• Transaction History Logs (THL)
• roughly corresponding to MySQL relay logs
• have a lot of metadata
• Service database
• contains metadata for latest transactions
• Metadata is committed together with data
• Makes slaves crash proof
Tuesday, October 25, 11 16
35. Parallel replication facts
✓Sharded by database
✓Good choice for slave lag problems
❖Bad choice for single database projects
Tuesday, October 25, 11 33
38. before the test (2)
STOPPED
binary logs
MySQL slave
OFFLINE
Tungsten slave direct:
alpha
(slave)
replicator alpha
Tuesday, October 25, 11 36
39. starting the test
STOPPED
binary logs
MySQL slave Concurrent sysbench
on 30 databases
running for 1 hour
OFFLINE
TOTAL DATA: 130 GB
Tungsten slave direct:
alpha
RAM per server: 20GB
(slave)
replicator alpha
Slaves will have 1 hour lag
Tuesday, October 25, 11 37
40. measuring results
START
binary logs
MySQL slave
ONLINE Recording
catch-up time
Tungsten slave direct:
alpha
(slave)
replicator alpha
Tuesday, October 25, 11 38
41. MySQL native
replication
slave catch up in 04:29:30
Tuesday, October 25, 11 39
42. Tungsten parallel
replication
slave catch up in 00:55:40
Tuesday, October 25, 11 40
47. parallel replication
direct slave facts
✓No need to install Tungsten on the master
Tuesday, October 25, 11 44
48. parallel replication
direct slave facts
✓No need to install Tungsten on the master
✓Tungsten runs only on the slave
Tuesday, October 25, 11 44
49. parallel replication
direct slave facts
✓No need to install Tungsten on the master
✓Tungsten runs only on the slave
✓Replication can revert to native slave with two
commands (trepctl offline; start
slave)
Tuesday, October 25, 11 44
50. parallel replication
direct slave facts
✓No need to install Tungsten on the master
✓Tungsten runs only on the slave
✓Replication can revert to native slave with two
commands (trepctl offline; start
slave)
✓Native replication can continue on other slaves
Tuesday, October 25, 11 44
51. parallel replication
direct slave facts
✓No need to install Tungsten on the master
✓Tungsten runs only on the slave
✓Replication can revert to native slave with two
commands (trepctl offline; start
slave)
✓Native replication can continue on other slaves
❖Failover (either native or Tungsten) becomes a
manual task
Tuesday, October 25, 11 44
63. Conflict prevention
facts
• Sharded by database
Tuesday, October 25, 11 55
64. Conflict prevention
facts
• Sharded by database
• Defined dynamically
Tuesday, October 25, 11 55
65. Conflict prevention
facts
• Sharded by database
• Defined dynamically
• Applied either at the master or at the
slave
Tuesday, October 25, 11 55
66. Conflict prevention
facts
• Sharded by database
• Defined dynamically
• Applied either at the master or at the
slave
• methods:
Tuesday, October 25, 11 55
67. Conflict prevention
facts
• Sharded by database
• Defined dynamically
• Applied either at the master or at the
slave
• methods:
• make replication fail
Tuesday, October 25, 11 55
68. Conflict prevention
facts
• Sharded by database
• Defined dynamically
• Applied either at the master or at the
slave
• methods:
• make replication fail
• drop silently
Tuesday, October 25, 11 55
69. Conflict prevention
facts
• Sharded by database
• Defined dynamically
• Applied either at the master or at the
slave
• methods:
• make replication fail
• drop silently
• drop with warning
Tuesday, October 25, 11 55
91. Installation
• Check the requirements
• Get the binaries
• Expand the tarball
• Run ./tools/tungsten-installer
Tuesday, October 25, 11 64
92. REQUIREMENTS
• Java JRE or JDK (Sun/Oracle or Open-jdk)
• Ruby 1.8 (only during installation)
• ssh access to the same user in all nodes
• MySQL user with all privileges
Tuesday, October 25, 11 65
93. Installation types
• master / slave
• slave - direct
Tuesday, October 25, 11 66
97. Installation (1)
# starting at node 4, but any would do
for N in 1 2 3 4
do
ssh r$N mkdir tinstall
done
cd tinstall
tar -xzf /path/to/tungsten-replicator-2.0.4.tar.gz
cd tungsten-replicator-2.0.4
Tuesday, October 25, 11 70
99. Installation (2)
export TUNGSTEN_BASE=$HOME/tinstall
./tools/tungsten-installer
--master-slave # installation mode
--master-host=r1 # who’s the master
--datasource-user=tungsten # mysql username
--datasource-password=secret # mysql password
--service-name=dragon # name of the service
--home-directory=$TUNGSTEN_BASE # where we install
--cluster-hosts=r1,r2,r3,r4 # hosts in cluster
--start # start replicator after installing
Tuesday, October 25, 11 72
100. What does the
installation do
1: Validate all servers
host4 host1 host2 host3
✔ ✔ ✔ ✔
✗ ✗ ✗ ✗
✔ ✔ ✔ ✔
✔ ✔ ✔ ✔
Report all errors
Tuesday, October 25, 11 73
101. What does the
installation do
1 (again): Validate all servers
host4 host1 host2 host3
✔ ✔ ✔ ✔
✔ ✔ ✔ ✔
✔ ✔ ✔ ✔
✔ ✔ ✔ ✔
Tuesday, October 25, 11 74
102. What does the
installation do
2: install Tungsten in all servers
host4
$HOME/ host1
tinstall/ host2
config/ host3
releases/
relay/
logs/
tungsten/
Tuesday, October 25, 11 75
103. example
ssh r2 chmod 444 $HOME/tinstall
./tools/tungsten-installer
--master-slave --master-host=r1
--datasource-user=tungsten
--datasource-password=secret
--service-name=dragon
--home-directory=$HOME/tinstall
--thl-directory=$HOME/tinstall/logs
--relay-directory=$HOME/tinstall/relay
--cluster-hosts=r1,r2,r3,r4 --start
ERROR >> qa.r2.continuent.com >> /home/tungsten/
tinstall is not writeable
Tuesday, October 25, 11 76
104. example
ssh r2 chmod 755 $HOME/tinstall
./tools/tungsten-installer
--master-slave --master-host=r1
--datasource-user=tungsten
--datasource-password=secret
--service-name=dragon
--home-directory=$HOME/tinstall
--thl-directory=$HOME/tinstall/logs
--relay-directory=$HOME/tinstall/relay
--cluster-hosts=r1,r2,r3,r4 --start
# no errors
Tuesday, October 25, 11 77
109. replicator
• It’s the service provider
• You launch it once when you start
• You may restart it when you change
config
Tuesday, October 25, 11 82
110. trepctl
• Tungsten Replicator ConTroLler
• It’s the driving seat for your replication
• You can start, update, and stop services
• You can get specific info
Tuesday, October 25, 11 83
111. thl
• Transaction History List
• Gives you access to the Tungsten relay
logs
Tuesday, October 25, 11 84