building simple and complex clusters with tungsten replicator

88
©Continuent 2012. Giuseppe Maxia QA Director Continuent, Inc @datacharmer This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. Building simple and complex replication clusters with Tungsten Replicator 1 1 Tuesday, February 7, 12

Upload: giuseppe-maxia

Post on 16-May-2015

1.730 views

Category:

Technology


2 download

DESCRIPTION

Creating simple and complex database replication cluster with Tungsten Replicator

TRANSCRIPT

Page 1: Building simple and complex clusters with tungsten replicator

©Continuent 2012.

Giuseppe MaxiaQA DirectorContinuent, Inc

@datacharmer

This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License.

Building simple and complex

replication clusters with Tungsten

Replicator

1

1Tuesday, February 7, 12

Page 2: Building simple and complex clusters with tungsten replicator

From the user'sstandpoint

2Tuesday, February 7, 12

Page 3: Building simple and complex clusters with tungsten replicator

BINARY LOG

REPLICATION

MySQLDBMS

trans

actio

n

trans

actio

n

trans

actio

n

trans

actio

n

trans

actio

ntra

nsac

tion

trans

actio

ntra

nsac

tion

trans

actio

ntra

nsac

tion

trans

actio

n

MySQLDBMS

transactiontransaction

transactiontransaction

transactiontransaction

transactiontransaction

transactiontransaction

transactiontransaction

MySQL replicationis single threaded

3Tuesday, February 7, 12

Page 4: Building simple and complex clusters with tungsten replicator

MySQLDBMS

MySQLDBMS

MySQLDBMS

MySQLDBMS

master

slave slaveslave

MySQLDBMS

MySQLDBMS

MySQLDBMS

MySQLDBMS

master master master

slave

single source multi source (fan-in)

multiple sources?4Tuesday, February 7, 12

Page 5: Building simple and complex clusters with tungsten replicator

MySQLDBMS

MySQLDBMS

MySQLDBMS

MySQLDBMS

mastermaster

master master

from this to this

multiple masters?

5Tuesday, February 7, 12

Page 6: Building simple and complex clusters with tungsten replicator

MySQLDBMS

MySQLDBMS

MySQLDBMS

MySQLDBMS

mastermaster

master master

Avoiding conflicts?

INSERT RECORD

A

INSERT RECORD

A

MODIFY RECORD

B

MODIFY RECORD

B

6Tuesday, February 7, 12

Page 7: Building simple and complex clusters with tungsten replicator

MySQLDBMS

MySQLDBMS

MySQLDBMS

master

slaveslave

MySQLDBMS

MySQLDBMS

MySQLDBMS

master

slaveslave

MySQLDBMS

MySQLDBMS

MySQLDBMS

master

slaveslave

Seamless failover?

7Tuesday, February 7, 12

Page 8: Building simple and complex clusters with tungsten replicator

MySQLDBMS

MySQLDBMS

mysql master

postgresqlmysql

Replicating to something else?

oracle mongodb

8Tuesday, February 7, 12

Page 9: Building simple and complex clusters with tungsten replicator

All these examples tell us:

Nice dream, but MySQL can’t do it

9Tuesday, February 7, 12

Page 10: Building simple and complex clusters with tungsten replicator

Enter Tungsten Replicator

10Tuesday, February 7, 12

Page 11: Building simple and complex clusters with tungsten replicator

http://code.google.com/p/tungsten-replicator

100% GPL v2Open Source

11Tuesday, February 7, 12

Page 12: Building simple and complex clusters with tungsten replicator

What can it do?

• Easy failover

• Multiple masters

• Multiple sources to a single slave

• Conflict prevention

• Parallel replication

• Replicate to Oracle and PostgreSQL database

12Tuesday, February 7, 12

Page 13: Building simple and complex clusters with tungsten replicator

©Continuent 2012.

star-schema

master-slave Heterogeneous Direct slave

fan-in slave all-masters

MySQL

Oracle

Oracle

MySQL

RegularMySQL Master

13Tuesday, February 7, 12

Page 14: Building simple and complex clusters with tungsten replicator

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

14Tuesday, February 7, 12

Page 15: Building simple and complex clusters with tungsten replicator

Parallel replication

15Tuesday, February 7, 12

Page 16: Building simple and complex clusters with tungsten replicator

Parallel replication facts

✓Sharded by database

✓Good choice for slave lag problems

❖Bad choice for single database projects

16Tuesday, February 7, 12

Page 17: Building simple and complex clusters with tungsten replicator

Parallel Replication test

binary logs

MySQL slave

Tungsten slave

OFFLINE

STOPPED

replicator alpha

direct: alpha(slave)

Concurrent sysbenchon 30 databasesrunning for 1 hour

TOTAL DATA: 130 GBRAM per server: 20GB

Slaves will have 1 hour lag17Tuesday, February 7, 12

Page 18: Building simple and complex clusters with tungsten replicator

measuring results

binary logs

MySQL slave

Tungsten slave

ONLINE

START

replicator alpha

direct: alpha(slave)

Recording catch-up time

18Tuesday, February 7, 12

Page 19: Building simple and complex clusters with tungsten replicator

MySQL native replication

slave catch up in 04:29:30

19Tuesday, February 7, 12

Page 20: Building simple and complex clusters with tungsten replicator

Tungsten parallel replication

slave catch up in 00:55:40

20Tuesday, February 7, 12

Page 21: Building simple and complex clusters with tungsten replicator

Parallel replication made simpler

FROM HERE ....21Tuesday, February 7, 12

Page 22: Building simple and complex clusters with tungsten replicator

Parallel replication made simpler

TO HERE22Tuesday, February 7, 12

Page 23: Building simple and complex clusters with tungsten replicator

Parallel replication made simpler

23Tuesday, February 7, 12

Page 24: Building simple and complex clusters with tungsten replicator

parallel replicationdirect slave facts

24Tuesday, February 7, 12

Page 25: Building simple and complex clusters with tungsten replicator

parallel replicationdirect slave facts

✓No need to install Tungsten on the master

24Tuesday, February 7, 12

Page 26: Building simple and complex clusters with tungsten replicator

parallel replicationdirect slave facts

✓No need to install Tungsten on the master

✓Tungsten runs only on the slave

24Tuesday, February 7, 12

Page 27: Building simple and complex clusters with tungsten replicator

parallel replicationdirect 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)

24Tuesday, February 7, 12

Page 28: Building simple and complex clusters with tungsten replicator

parallel replicationdirect 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

24Tuesday, February 7, 12

Page 29: Building simple and complex clusters with tungsten replicator

parallel replicationdirect 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

24Tuesday, February 7, 12

Page 30: Building simple and complex clusters with tungsten replicator

Multiple masters

25Tuesday, February 7, 12

Page 31: Building simple and complex clusters with tungsten replicator

multiple masters

• Tungsten Replicator recipe: use more services

26Tuesday, February 7, 12

Page 32: Building simple and complex clusters with tungsten replicator

Bi-directional replication

27Tuesday, February 7, 12

Page 33: Building simple and complex clusters with tungsten replicator

Bi-directional replication with slaves

28Tuesday, February 7, 12

Page 34: Building simple and complex clusters with tungsten replicator

Multiple sources

29Tuesday, February 7, 12

Page 35: Building simple and complex clusters with tungsten replicator

multiple sources

• Tungsten Replicator recipe is still valid: use more services

30Tuesday, February 7, 12

Page 36: Building simple and complex clusters with tungsten replicator

Multiple source replication

31Tuesday, February 7, 12

Page 37: Building simple and complex clusters with tungsten replicator

Multiple masters replication: 3 nodes

32Tuesday, February 7, 12

Page 38: Building simple and complex clusters with tungsten replicator

Multiple masters replication: 4 nodes

33Tuesday, February 7, 12

Page 39: Building simple and complex clusters with tungsten replicator

star topologies

34Tuesday, February 7, 12

Page 40: Building simple and complex clusters with tungsten replicator

Conflict prevention

35Tuesday, February 7, 12

Page 41: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

36Tuesday, February 7, 12

Page 42: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

36Tuesday, February 7, 12

Page 43: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

• Defined dynamically

36Tuesday, February 7, 12

Page 44: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

• Defined dynamically

• Applied either at the master or at the slave

36Tuesday, February 7, 12

Page 45: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

• Defined dynamically

• Applied either at the master or at the slave

• methods:

36Tuesday, February 7, 12

Page 46: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

• Defined dynamically

• Applied either at the master or at the slave

• methods:

• make replication fail

36Tuesday, February 7, 12

Page 47: Building simple and complex clusters with tungsten replicator

Conflict prevention facts

• Sharded by database

• Defined dynamically

• Applied either at the master or at the slave

• methods:

• make replication fail

• drop silently

36Tuesday, February 7, 12

Page 48: Building simple and complex clusters with tungsten replicator

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 warning36Tuesday, February 7, 12

Page 49: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Tungsten Conflict prevention points

37Tuesday, February 7, 12

Page 50: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Tungsten Conflict prevention points

37Tuesday, February 7, 12

Page 51: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Tungsten Conflict prevention points

37Tuesday, February 7, 12

Page 52: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on master

38Tuesday, February 7, 12

Page 53: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on masterINSERT A x,y

INSERT Ax,z

38Tuesday, February 7, 12

Page 54: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on masterINSERT A x,y

INSERT Ax,z

38Tuesday, February 7, 12

Page 55: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on slave

39Tuesday, February 7, 12

Page 56: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on slaveINSERT A x,y

INSERT Ax,z

39Tuesday, February 7, 12

Page 57: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: Fail on slaveINSERT A x,y

INSERT Ax,z

39Tuesday, February 7, 12

Page 58: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: Fail on slave(Multiple sources)

40Tuesday, February 7, 12

Page 59: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: Fail on slaveINSERT A x,y

INSERT Ax,z

(Multiple sources)

40Tuesday, February 7, 12

Page 60: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: Fail on slaveINSERT A x,y

INSERT Ax,z

(Multiple sources)

40Tuesday, February 7, 12

Page 61: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: DROP on master

41Tuesday, February 7, 12

Page 62: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: DROP on masterINSERT B x,y

41Tuesday, February 7, 12

Page 63: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: DROP on masterINSERT B x,y

INSERT Bx,z

41Tuesday, February 7, 12

Page 64: Building simple and complex clusters with tungsten replicator

host1host3

master

host2

M

MS

SS

host4

S

Prevention methods: DROP on master

INSERT Bx,z

41Tuesday, February 7, 12

Page 65: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: DROP on slave(Multiple sources)

42Tuesday, February 7, 12

Page 66: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: DROP on slaveINSERT A x,y

INSERT Ax,z

(Multiple sources)

42Tuesday, February 7, 12

Page 67: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: DROP on slave

INSERT Bx,z

(Multiple sources)

INSERT B x,y

43Tuesday, February 7, 12

Page 68: Building simple and complex clusters with tungsten replicator

host1

master

host2

M

M

host3

S

Prevention methods: DROP on slave

INSERT Bx,z

(Multiple sources)

43Tuesday, February 7, 12

Page 69: Building simple and complex clusters with tungsten replicator

Tungsten in practiceInstallation

44Tuesday, February 7, 12

Page 70: Building simple and complex clusters with tungsten replicator

Installation

• Check the requirements

• Get the binaries

• Expand the tarball

• Run ./tools/tungsten-installer

45Tuesday, February 7, 12

Page 71: Building simple and complex clusters with tungsten replicator

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

46Tuesday, February 7, 12

Page 72: Building simple and complex clusters with tungsten replicator

Installation types

• master / slave

• slave - direct

47Tuesday, February 7, 12

Page 73: Building simple and complex clusters with tungsten replicator

master/slave

binlog

THL

THL

slave

slave

master

host1host2

host3

THL

48Tuesday, February 7, 12

Page 74: Building simple and complex clusters with tungsten replicator

slave direct

binlogTHL

slavemaster

relay log

host1host2

host3

THL

slave

relay log

49Tuesday, February 7, 12

Page 75: Building simple and complex clusters with tungsten replicator

sample installation

• 4 servers

• qa.r1.continuent.com r1

• qa.r2.continuent.com r2

• qa.r3.continuent.com r3

• qa.r4.continuent.com r4

• MySQL 5.1

• tungsten-replicator-2.0.4

50Tuesday, February 7, 12

Page 76: Building simple and complex clusters with tungsten replicator

Installation (1)# starting at node 4, but any would do

for N in 1 2 3 4do ssh r$N mkdir tinstalldone

cd tinstalltar -xzf /path/to/tungsten-replicator-2.0.4.tar.gzcd tungsten-replicator-2.0.4

51Tuesday, February 7, 12

Page 77: Building simple and complex clusters with tungsten replicator

Installation (2)export TUNGSTEN_BASE=$HOME/tinstall

./tools/tungsten-installer \ --master-slave \ --master-host=r1 \ --datasource-user=tungsten \ --datasource-password=secret \ --service-name=dragon \ --home-directory=$TUNGSTEN_BASE \ --cluster-hosts=r1,r2,r3,r4 \ --start

1 2 3 4 5 6 7 8 9

52Tuesday, February 7, 12

Page 78: Building simple and complex clusters with tungsten replicator

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

53Tuesday, February 7, 12

Page 79: Building simple and complex clusters with tungsten replicator

What does the installation do

host4

1: Validate all servers

✔✗✔

host1

✔✗✔

host2

✔✗✔

host3

✔✗✔

Report all errors54Tuesday, February 7, 12

Page 80: Building simple and complex clusters with tungsten replicator

What does the installation do

host4

1 (again): Validate all servers

host1

host2

host3

✔✔ ✔ ✔

55Tuesday, February 7, 12

Page 81: Building simple and complex clusters with tungsten replicator

What does the installation do

2: install Tungsten in all servers

host3

$HOME/ tinstall/ config/ releases/ relay/ logs/ tungsten/

host4host1

host2

56Tuesday, February 7, 12

Page 82: Building simple and complex clusters with tungsten replicator

examplessh 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

57Tuesday, February 7, 12

Page 83: Building simple and complex clusters with tungsten replicator

examplessh 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

58Tuesday, February 7, 12

Page 84: Building simple and complex clusters with tungsten replicator

Installation - direct./tools/tungsten-installer \ --direct \ --master-host=r1 \ --slave-host=r4 \ --master-user=tungsten \ --slave-user=tungsten \ --master-password=secret \ --slave-password=secret \ --service-name=Castor \ --channels=1 \ --home-directory=$TUNGSTEN_BASE \ --start-and-report

59Tuesday, February 7, 12

Page 85: Building simple and complex clusters with tungsten replicator

http://bit.ly/tr20_cookbook

60Tuesday, February 7, 12

Page 86: Building simple and complex clusters with tungsten replicator

© Continuent 2011© Continuent 2011

Tungsten Replicator vs. Enterprise

Feature Replicator EnterpriseSimple admin with trepctl X XMySQL Row/Statement 5.0/5.1/5.5 X XMulti-master replication X XParallel apply (2.0) X XDistributed management with cctrl XAutomated failover and recovery XZero-downtime upgrade XSQL routing and load-balancing XFloating IP support X

61Tuesday, February 7, 12

Page 87: Building simple and complex clusters with tungsten replicator

Conclusion and Q&A

62Tuesday, February 7, 12

Page 88: Building simple and complex clusters with tungsten replicator

©Continuent 2012. 63

Continuent Web Site:http://www.continuent.com

Tungsten Replicator 2.0:http://code.google.com/p/tungsten-replicator

Check out our blogs!http://scale-out-blog.blogspot.comhttp://datacharmer.blogspot.comhttp://flyingclusters.blogspot.com

560 S. Winchester Blvd., Suite 500 San Jose, CA 95128 Tel (866) 998-3642 Fax (408) 668-1009e-mail: [email protected]

63Tuesday, February 7, 12