mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 05:00:45 +00:00
pt-archiver multple slave lag and OptionParser repeatable option
This commit is contained in:
@@ -784,6 +784,7 @@ sub new {
|
||||
'default' => 1,
|
||||
'cumulative' => 1,
|
||||
'negatable' => 1,
|
||||
'repeatable' => 1, # means it can be specified more than once
|
||||
);
|
||||
|
||||
my $self = {
|
||||
@@ -974,6 +975,7 @@ sub _pod_to_specs {
|
||||
desc => $para
|
||||
. (defined $attribs{default} ? " (default $attribs{default})" : ''),
|
||||
group => ($attribs{'group'} ? $attribs{'group'} : 'default'),
|
||||
attributes => \%attribs
|
||||
};
|
||||
}
|
||||
while ( $para = <$fh> ) {
|
||||
@@ -1027,6 +1029,7 @@ sub _parse_specs {
|
||||
|
||||
$opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
|
||||
$opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
|
||||
$opt->{is_repeatable} = $opt->{attributes}->{repeatable} ? 1 : 0;
|
||||
$opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
|
||||
|
||||
$opt->{group} ||= 'default';
|
||||
@@ -1170,12 +1173,22 @@ sub _set_option {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
if ($opt->{is_repeatable}) {
|
||||
push @{$opt->{value}} , $val;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($opt->{is_repeatable}) {
|
||||
push @{$opt->{value}} , $val;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
}
|
||||
$opt->{got} = 1;
|
||||
PTDEBUG && _d('Got option', $long, '=', $val);
|
||||
}
|
||||
@@ -1628,6 +1641,14 @@ sub _read_config_file {
|
||||
$parse = 0;
|
||||
next LINE;
|
||||
}
|
||||
|
||||
if ( $parse
|
||||
&& !$self->has('version-check')
|
||||
&& $line =~ /version-check/
|
||||
) {
|
||||
next LINE;
|
||||
}
|
||||
|
||||
if ( $parse
|
||||
&& (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
|
||||
) {
|
||||
@@ -5713,17 +5734,23 @@ sub main {
|
||||
# ########################################################################
|
||||
# Get lag dbh.
|
||||
# ########################################################################
|
||||
my $lag_dbh;
|
||||
my @lag_dbh;
|
||||
my $ms;
|
||||
if ( $o->get('check-slave-lag') ) {
|
||||
my $dsn_defaults = $dp->parse_options($o);
|
||||
my $dsn = $dp->parse($o->get('check-slave-lag'), $dsn_defaults);
|
||||
$lag_dbh = $dp->get_dbh($dp->get_cxn_params($dsn), { AutoCommit => 1 });
|
||||
my $lag_slaves_dsn = $o->get('check-slave-lag');
|
||||
$ms = new MasterSlave(
|
||||
OptionParser => $o,
|
||||
DSNParser => $dp,
|
||||
Quoter => $q,
|
||||
);
|
||||
# we get each slave's connection handler (and its id, for debug and reporting)
|
||||
for my $slave (@$lag_slaves_dsn) {
|
||||
my $dsn = $dp->parse($slave, $dsn_defaults);
|
||||
my $lag_dbh = $dp->get_dbh($dp->get_cxn_params($dsn), { AutoCommit => 1 });
|
||||
my $lag_id = $ms->short_host($dsn);
|
||||
push @lag_dbh , {'dbh' => $lag_dbh, 'id' => $lag_id}
|
||||
}
|
||||
}
|
||||
|
||||
# ########################################################################
|
||||
@@ -6305,14 +6332,21 @@ sub main {
|
||||
}
|
||||
|
||||
# Check slave lag and wait if slave is too far behind.
|
||||
foreach my $lag_server (@lag_dbh) {
|
||||
my $lag_dbh = $lag_server->{'dbh'};
|
||||
my $id = $lag_server->{'id'};
|
||||
if ( $lag_dbh ) {
|
||||
my $lag = $ms->get_slave_lag($lag_dbh);
|
||||
while ( !defined $lag || $lag > $o->get('max-lag') ) {
|
||||
PTDEBUG && _d('Sleeping: slave lag is', $lag);
|
||||
PTDEBUG && _d("Sleeping: slave lag for server '$id' is", $lag);
|
||||
if ($o->got('progress')) {
|
||||
_d("Sleeping: slave lag for server '$id' is", $lag);
|
||||
}
|
||||
sleep($o->get('check-interval'));
|
||||
$lag = $ms->get_slave_lag($lag_dbh);
|
||||
}
|
||||
}
|
||||
}
|
||||
} # ROW
|
||||
PTDEBUG && _d('Done fetching rows');
|
||||
|
||||
@@ -6883,9 +6917,10 @@ How often to check for slave lag if L<"--check-slave-lag"> is given.
|
||||
|
||||
=item --check-slave-lag
|
||||
|
||||
type: string
|
||||
type: string; repeatable: yes
|
||||
|
||||
Pause archiving until the specified DSN's slave lag is less than L<"--max-lag">.
|
||||
This option can be specified multiple times for checking more than one slave.
|
||||
|
||||
=item --columns
|
||||
|
||||
|
@@ -69,6 +69,7 @@ sub new {
|
||||
'default' => 1,
|
||||
'cumulative' => 1,
|
||||
'negatable' => 1,
|
||||
'repeatable' => 1, # means it can be specified more than once
|
||||
);
|
||||
|
||||
my $self = {
|
||||
@@ -308,6 +309,7 @@ sub _pod_to_specs {
|
||||
desc => $para
|
||||
. (defined $attribs{default} ? " (default $attribs{default})" : ''),
|
||||
group => ($attribs{'group'} ? $attribs{'group'} : 'default'),
|
||||
attributes => \%attribs
|
||||
};
|
||||
}
|
||||
while ( $para = <$fh> ) {
|
||||
@@ -377,6 +379,7 @@ sub _parse_specs {
|
||||
|
||||
$opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
|
||||
$opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
|
||||
$opt->{is_repeatable} = $opt->{attributes}->{repeatable} ? 1 : 0;
|
||||
$opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
|
||||
|
||||
$opt->{group} ||= 'default';
|
||||
@@ -568,12 +571,24 @@ sub _set_option {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
# have to make value an array if it is 'repeatable'
|
||||
if ($opt->{is_repeatable}) {
|
||||
push @{$opt->{value}} , $val;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
# have to make value an array if it is 'repeatable'
|
||||
if ($opt->{is_repeatable}) {
|
||||
push @{$opt->{value}} , $val;
|
||||
}
|
||||
else {
|
||||
$opt->{value} = $val;
|
||||
}
|
||||
}
|
||||
$opt->{got} = 1;
|
||||
PTDEBUG && _d('Got option', $long, '=', $val);
|
||||
}
|
||||
|
Reference in New Issue
Block a user