N:1 Replication meets MHA

29
N:1 Replicatio n meets MHA 2014/07/11 MySQL Casual Talks vol6 do_aki

description

 

Transcript of N:1 Replication meets MHA

Page 1: N:1 Replication meets MHA

N:1 Replication meets

MHA2014/07/11 MySQL Casual Talks vol6

do_aki

Page 2: N:1 Replication meets MHA

@do_aki

@do_aki

http://do-aki.net/

Page 4: N:1 Replication meets MHA

MasterA

SlaveA+B

MasterB

N:1 Replication

Page 5: N:1 Replication meets MHA

MasterA

SlaveA+B

MasterB

CHANGE MATER TO ‘Master A’

repeat for ever per 2seconds

Page 6: N:1 Replication meets MHA

MasterA

SlaveA+B

MasterB

CHANGE MATER TO ‘Master B’

repeat for ever per 2seconds

Page 7: N:1 Replication meets MHA

MasterA

SlaveA1

SlaveA2

SlaveB1

MasterB

SlaveB2

SELEC

T SELEC

T

table

foobar…

table

hogepiyo…

Applicationbefore

(weak) relation

Page 8: N:1 Replication meets MHA

MasterA

SlaveA1

SlaveA2

SlaveB1

MasterB

SlaveB2

SELEC

T SELEC

T

table

foobar…

table

hogepiyo…

Applicationproblem

weak relatio

nImpossib

le

to use

“JOIN”

ex.

foo.id=h

oge.id

Page 9: N:1 Replication meets MHA

MasterA

SlaveA1

SlaveA2

SlaveB1

MasterB

SlaveB2

SlaveA+B

SELECTwith JOIN

Applicationobjective

Page 10: N:1 Replication meets MHA

Flowchart of N:1 Replicationwait for

Seconds_Behind_Master = 0

START SLAVE

STOP SLAVE IO_THREAD

MASTER_POS_WAIT(Master_Log_File,Read_Master_Log_Po

s)

Timeout?

START SLAVE IO_THREAD

STOP SLAVE

CHANGE MASTER TO ‘next master’

Yes

No

Page 11: N:1 Replication meets MHA

I talked about above at 3 years ago

Page 12: N:1 Replication meets MHA

Current N:1 Replication

• Work in my production for 3 years

• I almost never use time to maintenance

• can’t keep pace in some case– pt-online-schema-change– master server changed– need restart (relatively trouble)

Page 13: N:1 Replication meets MHA

Rewrit

e N:1

Replic

ation

progra

m

https://github.com/do-aki/n1repl

Page 14: N:1 Replication meets MHA

temporary rotation stop

• n1repl_command.pl stop– stop rotate replication connection– single replication is alive

• n1repl_command.pl start– start rotate replication connection

Page 15: N:1 Replication meets MHA

support changed master server

n1repl_command.pl switch \  --orig_master_host = masterA \  --orig_master_port = 3306 \  --orig_master_log_file = bin.00x\  --orig_master_log_pos = 893\  --new_master_host = masterB \  --new_master_pos = 3306 \  --new_master_log_file = bin.00x \  --new_master_log_pos = 1129\

Page 16: N:1 Replication meets MHA

A’

n1repl switch (before)

A

A+B

B

Page 17: N:1 Replication meets MHA

A’

n1repl swith (after)

A

A+B

B

Page 18: N:1 Replication meets MHA

support MHA for MySQL?

Page 19: N:1 Replication meets MHA

MHA for MySQL

• Master High Availability Manager and tools for MySQL(https://code.google.com/p/mysql-master-ha/)

• Automating master failover– slave promotes to master when master goes down

– include “Graceful master switch” function (masterha_master_switch --master_state=alive)

http://www.slideshare.net/matsunobu/automated-master-failover/44

Page 20: N:1 Replication meets MHA

MHA (master switch) 1

current master(orig_master)

other slaves

candidate of master

(new_master)

write

Page 21: N:1 Replication meets MHA

MHA (master switch) 2

writerecord binlog filename and position(orig_master_log_file, orig_master_log_pos)

Page 22: N:1 Replication meets MHA

MHA (master switch) 3

MASTER_POS_WAIT( orig_master_log_file, orig_master_log_pos)

record binlog(new_master_log_file, new_master_log_pos)

write

Page 23: N:1 Replication meets MHA

MHA (master switch) 4

other slaves:MASTER_POS_WAIT( orig_master_log_file, orig_master_log_pos)

CHANGE MASTER TO ‘new_master’(new_master_log_file, new_master_log_pos)

write

write

Page 24: N:1 Replication meets MHA

MHA (master switch) 5

write

complete!

Page 25: N:1 Replication meets MHA

similar mechanism

• wait replication delay is zero• change connection• specify same (orig->new) position

• it’s looked N:1 Replication code

Page 26: N:1 Replication meets MHA

support changed master server

n1repl_command.pl switch \  --orig_master_host = masterA \  --orig_master_port = 3306 \  --orig_master_log_file = bin.00x\  --orig_master_log_pos = 893\  --new_master_host = masterB \  --new_master_pos = 3306 \  --new_master_log_file = bin.00x \  --new_master_log_pos = 1129\

Page 27: N:1 Replication meets MHA

But but but...

• Don’t work when master is dead

• MHA has hook functions call specified script *without* binlog file and position!

Page 28: N:1 Replication meets MHA

Conclusion

• N:1 Replication not support MHA…

• please expect “JIKAISAKU”

Page 29: N:1 Replication meets MHA

Any question?