N:1 Replication meets MHA
-
Upload
doaki -
Category
Technology
-
view
3.542 -
download
0
description
Transcript of N:1 Replication meets MHA
N:1 Replication meets
MHA2014/07/11 MySQL Casual Talks vol6
do_aki
@do_aki
@do_aki
http://do-aki.net/
About N:1 Replication
• Multi Master to Single Slave Replication
• a.k.a Multi-source Replication– MariaDB 10 (https
://mariadb.com/kb/en/mariadb/mariadb-documentation/replication-cluster-multi-master/replication/multi-source-replication/)
– MySQL 5.7 (labs)(http://www.mysqlperformanceblog.com/2013/10/02/mysql-5-7-multi-source-replication/)
• N:1 Replication work on MySQL5.0!
MasterA
SlaveA+B
MasterB
N:1 Replication
MasterA
SlaveA+B
MasterB
CHANGE MATER TO ‘Master A’
repeat for ever per 2seconds
MasterA
SlaveA+B
MasterB
CHANGE MATER TO ‘Master B’
repeat for ever per 2seconds
MasterA
SlaveA1
SlaveA2
SlaveB1
MasterB
SlaveB2
SELEC
T SELEC
T
table
foobar…
table
hogepiyo…
Applicationbefore
(weak) relation
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
MasterA
SlaveA1
SlaveA2
SlaveB1
MasterB
SlaveB2
SlaveA+B
SELECTwith JOIN
Applicationobjective
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
I talked about above at 3 years ago
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)
Rewrit
e N:1
Replic
ation
progra
m
https://github.com/do-aki/n1repl
temporary rotation stop
• n1repl_command.pl stop– stop rotate replication connection– single replication is alive
• n1repl_command.pl start– start rotate replication connection
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\
A’
n1repl switch (before)
A
A+B
B
A’
n1repl swith (after)
A
A+B
B
support MHA for MySQL?
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
MHA (master switch) 1
current master(orig_master)
other slaves
candidate of master
(new_master)
write
MHA (master switch) 2
writerecord binlog filename and position(orig_master_log_file, orig_master_log_pos)
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
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
MHA (master switch) 5
write
complete!
similar mechanism
• wait replication delay is zero• change connection• specify same (orig->new) position
• it’s looked N:1 Replication code
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\
But but but...
• Don’t work when master is dead
• MHA has hook functions call specified script *without* binlog file and position!
Conclusion
• N:1 Replication not support MHA…
• please expect “JIKAISAKU”
Any question?