In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. MHA elects the array maintained by the main library
In the code that tells MHA to choose master, we must explain the context of the four arrays maintained.
(1) Alive_slaves array:
Server is not master, and the slave library is normal. If the server in the latest array has enough relay logs to recover the backward slave library (catching up with the master library), it will be put into the array of this Alive_slaves (this code is in the ServerManager.pm: init_servers function)
If ($server- > {dead}) {$self- > add_dead_server ($server);} elsif ($server- > {unmanaged}) {$self- > add_unmanaged_slave ($server) } # join the alive_server array if it is not dead or unmanaged. If the show slave status does not return 0E0, and the server is not the original main library, and the sql thread is correct and can be recovered with the relay log, join the alive_slave data, otherwise join the failed--slave array else {$self- > add_alive_server ($server) If ($server- > {not_slave} eq'0' & &! $server- > {orig_master}) {if (! $server- > is_sql_thread_error () & &! $server- > {lack_relay_log}) {$self- > add_alive_slave ($server);} else {$self- > add_failed_slave ($server);}} (2) Latest array
Select the latest server of relaylog in the alive_slaves array. If there is more than one server in this array, the Read_master_log_pos,master_log_file of server must be equal (this code is in the ServerManager.pm: identify_latest_slaves function)
My @ slaves = $self- > get_alive_slaves (); my @ latest = (); foreach (@ slaves) {my $a = $latest [0] {Master_Log_File}; my $b = $latest [0] {Read_Master_Log_Pos} If (# find_oldest=0, that is, the most full relaylog slave we have taken. As for why it is an array, it is because there is not only one with the latest relaylog, but there may be multiple ((that is, the slave in the array). )! $find_oldest & & (! $a & &! defined ($b)) | | ($_-> {Master_Log_File} gt $latest [0] {Master_Log_File}) | | ($_-> {Master_Log_File} ge $latest [0] {Master_Log_File})) & & $_-> {Read_Master_Log_Pos} > $latest [0] {Read_Master_Log_Pos}) {@ latest = () Push (@ latest, $_);} (3) Perf array
This does not need much explanation, that is, the value of candidate_master is configured in the MHA configuration file, which can be greater than 1.
(4) Bad array: (for code, see ServerManager.pm:get_bad_candidate_masters)
1) detect faulty server
2) the server of no_master is set in MHA configuration file
3) log_bin does not have an open server
4) incompatible versions of server (it's okay to copy from a higher version to a lower version, but if the lower version is selected as the main library, heh heh)
5) copy server that lags far behind
II. Election of the main library of MHA
(1) the switch of the main library is specified with the highest priority (usually this is a manual switch)
(2) if server is in the latest array and in the perf array, it will be returned first
(3) if server is in the alive_servers array and in the perf array, it will be returned first.
(4) if server is in lastest, return it first.
(5) if server is in alive_servers, return
(6) otherwise the election will be lost.
The priority here is 1-> 6, which is implemented in (ServerManager.pm: select_new_master)
Sub select_new_master {my $self = shift; my $prio_new_master_host = shift; my $prio_new_master_port = shift; my $check_replication_delay = shift; $check_replication_delay = 1 if (! defined ($check_replication_delay)); my $log = $self- > {logger}; my @ latest = $self- > get_latest_slaves (); my @ slaves = $self- > get_alive_slaves () My @ pref = $self- > get_candidate_masters (); my @ bad = $self- > get_bad_candidate_masters ($latest [0], $check_replication_delay); # switching specifies master, that is, if with the highest priority ($prio_new_master_host & & $prio_new_master_port) {my $new_master = $self- > get_alive_server_by_hostport ($prio_new_master_host, $prio_new_master_port) If ($new_master) {my $a = $self- > get_server_from_by_id (\ @ bad, $new_master- > {id}); unless ($a) {$log- > info ("$prio_new_master_host can be new master."); return $new_master;} else {$log- > error ("$prio_new_master_host is bad as a new master!"); return } else {$log- > error ("$prio_new_master_host is not alive!"); return;}} $log- > info ("Searching new master from slaves.."); $log- > info ("Candidate masters from the configuration file:"); $self- > print_servers (\ @ pref); $log- > info ("Non-candidate masters:"); $self- > print_servers (\ @ bad) # if perf (candidate_master is not set) and there is no slave that does not comply with (master-slave delay, version, etc.), and lastest [0] is set to a priority, return return $latest [0] if ($# pref)
< 0 && $#bad < 0 && $latest[0]->{latest_priority}) # if the priority is set, select canidate_master from the lastest array. If so, return (implied lastest [0] priority; if lastest [0] is also canidate_master, it must be returned first) # latest_priority defaults to 1 if ($latest [0]-> {latest_priority}) {$log- > info ("Searching from candidate_master slaves which have received the latest relay log events..") if ($# pref > = 0) Foreach my $h (@ latest) {foreach my $p (@ pref) {if ($h-> {id} eq $p-> {id}) {return $h if (! $self- > get_server_from_by_id (\ @ bad, $p-> {id}));}} $log- > info ("Not found.") If ($# pref > = 0);} # new master is not latest # candidate_master is selected here, not master $log- > info ("Searching from all candidate_master slaves..") in the latest array If ($# pref > = 0); foreach my $s (@ slaves) {foreach my $p (@ pref) {if ($s-> {id} eq $p-> {id}) {my $a = $self- > get_server_from_by_id (\ @ bad, $p-> {id}); return $s unless ($a);}} $log- > info ("Not found.") If ($# pref > = 0); # followed by if ($latest [0]-> {latest_priority}) ($latest [0]-> {latest_priority}) {$log- > info ("Searching from all slaves which have received the latest relay log events.."); foreach my $h (@ latest) {my $a = $self- > get_server_from_by_id (\ @ bad, $h-> {id}); return $h unless ($a) } $log- > info ("Not found.");} # none of latest servers can not be a master $log- > info ("Searching from all slaves.."); foreach my $s (@ slaves) {my $a = $self- > get_server_from_by_id (\ @ bad, $s-> {id}); return $s unless ($a);} $log- > info ("Not found."); return;}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.