/usr/share/perl5/MHA/BinlogPosFindManager.pm is in mha4mysql-node 0.54-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | #!/usr/bin/env perl
# Copyright (C) 2011 DeNA Co.,Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
package MHA::BinlogPosFindManager;
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use MHA::BinlogManager;
use MHA::BinlogHeaderParser;
use MHA::BinlogPosFinder;
use MHA::BinlogPosFinderXid;
use MHA::BinlogPosFinderElp;
use MHA::NodeConst;
use MHA::NodeUtil;
sub new {
my $class = shift;
my $self = {
binlog_manager => undef,
server_id => undef,
target_mlf => undef,
target_rmlp => undef,
master_version => undef,
find_logname_only => undef,
finder => undef,
debug => undef,
@_,
};
return bless $self, $class;
}
sub create_finder_elp($) {
my $self = shift;
return new MHA::BinlogPosFinderElp(
name => "BinlogPosFinderElp",
master_version => $self->{master_version},
server_id => $self->{server_id},
relay_dir => $self->{binlog_manager}->{dir},
target_rmlp => $self->{target_rmlp},
end_log => $self->{binlog_manager}->{end_log},
handle_raw_binlog => $self->{binlog_manager}->{handle_raw_binlog},
debug => $self->{debug},
);
}
sub create_finder_xid($) {
my $self = shift;
return new MHA::BinlogPosFinderXid(
name => "BinlogPosFinderXid",
master_version => $self->{master_version},
server_id => $self->{server_id},
relay_dir => $self->{binlog_manager}->{dir},
target_rmlp => $self->{target_rmlp},
end_log => $self->{binlog_manager}->{end_log},
handle_raw_binlog => $self->{binlog_manager}->{handle_raw_binlog},
debug => $self->{debug},
);
}
# Recursively reading relay log files in descending order
sub find_target_relay_log($$$$) {
no warnings qw(recursion);
my $self = shift;
my $relay_file = shift;
my $master_file_on_upper_relay_log = shift;
my $post_relay_has_init_rotate_event = shift;
my $relay_dir = $self->{binlog_manager}->{dir};
my %status = ();
my $has_init_rotate_event = 0;
# master log file on this relay log
# master log pos at the starting of this relay log
my ( $current_mlf, $starting_mlp );
print "Reading $relay_file\n";
my $parser = new MHA::BinlogHeaderParser(
dir => $relay_dir,
file => $relay_file,
self_server_id => $self->{server_id},
master_version => $self->{master_version},
debug => $self->{debug},
);
$parser->open_binlog();
$parser->parse_init_headers();
if ( $parser->{has_real_rotate_event} ) {
$current_mlf = $parser->{current_mlf};
$has_init_rotate_event = 1 if ( $parser->{has_real_init_rotate_event} );
}
$self->{master_version} = $parser->{master_version}
unless ( $self->{master_version} );
if (
(
!$self->{finder}
|| ( $self->{finder} && $self->{finder}->{name} eq "BinlogPosFinderXid" )
)
&& $self->{master_version}
&& MHA::NodeUtil::mysql_version_ge( $self->{master_version}, "5.0.48" )
)
{
$self->{finder} = $self->create_finder_elp();
}
else {
$self->{finder} = $self->create_finder_xid() unless ( $self->{finder} );
}
# master's rotate event not found in this relay log
unless ($current_mlf) {
# i.e. If master's init rotate event "Rotate to mysqld-bin.000123 (pos 4)" is written in the relay log mysqld-relay-bin.000444 and if mysqld-relay-bin.000443 does not have master's rotate event, mysqld-relay-bin.000443 should have binlog events from mysqld-bin.000122 (mysqld-bin.000123 - 1). If mysqld-relay-bin.000442 does not have master's rotate event, mysqld-relay-bin.000443 should have binlog events from mysqld-bin.000122.
if ( $post_relay_has_init_rotate_event == 1 ) {
$current_mlf =
MHA::BinlogManager::get_prev_file($master_file_on_upper_relay_log);
}
else {
$current_mlf = $master_file_on_upper_relay_log;
}
}
$starting_mlp = $self->{finder}->get_starting_master_pos($parser);
$parser->close_binlog();
if ( $current_mlf && defined($starting_mlp) ) {
print
" $relay_file contains master $current_mlf from position $starting_mlp\n";
}
# Target position should be within this relay log
# Determining starting relay log position
# Starting relay log position equals to just after the end_log_pos that equals to $read_master_log_pos.
if ( $current_mlf
&& defined($starting_mlp)
&& $current_mlf eq $self->{target_mlf}
&& $starting_mlp <= $self->{target_rmlp} )
{
if ( $self->{find_logname_only} ) {
$status{status} = 0;
$status{start_rlf} = $relay_file;
return %status;
}
return $self->{finder}->find_starting_relay_pos($relay_file);
}
else {
$self->find_target_relay_log(
MHA::BinlogManager::get_prev_file($relay_file),
$current_mlf, $has_init_rotate_event );
}
}
1;
|