mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 08:51:44 +00:00
Merge pt-osc-metadata-lock-bug-1113301.
This commit is contained in:
@@ -346,7 +346,7 @@ sub get_dbh {
|
||||
# Set character set and binmode on STDOUT.
|
||||
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
|
||||
$sql = qq{/*!40101 SET NAMES "$charset"*/};
|
||||
PTDEBUG && _d($dbh, ':', $sql);
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
eval { $dbh->do($sql) };
|
||||
if ( $EVAL_ERROR ) {
|
||||
die "Error setting NAMES to $charset: $EVAL_ERROR";
|
||||
@@ -361,13 +361,8 @@ sub get_dbh {
|
||||
}
|
||||
}
|
||||
|
||||
if ( my $var = $self->prop('set-vars') ) {
|
||||
$sql = "SET $var";
|
||||
PTDEBUG && _d($dbh, ':', $sql);
|
||||
eval { $dbh->do($sql) };
|
||||
if ( $EVAL_ERROR ) {
|
||||
die "Error setting $var: $EVAL_ERROR";
|
||||
}
|
||||
if ( my $vars = $self->prop('set-vars') ) {
|
||||
$self->set_vars($dbh, $vars);
|
||||
}
|
||||
|
||||
# Do this after set-vars so a user-set sql_mode doesn't clobber it; See
|
||||
@@ -450,6 +445,57 @@ sub copy {
|
||||
return \%new_dsn;
|
||||
}
|
||||
|
||||
sub set_vars {
|
||||
my ($self, $dbh, $vars) = @_;
|
||||
|
||||
return unless $vars;
|
||||
|
||||
foreach my $var ( sort keys %$vars ) {
|
||||
my $val = $vars->{$var}->{val};
|
||||
|
||||
(my $quoted_var = $var) =~ s/_/\\_/;
|
||||
my ($var_exists, $current_val);
|
||||
eval {
|
||||
($var_exists, $current_val) = $dbh->selectrow_array(
|
||||
"SHOW VARIABLES LIKE '$quoted_var'");
|
||||
};
|
||||
my $e = $EVAL_ERROR;
|
||||
if ( $e ) {
|
||||
PTDEBUG && _d($e);
|
||||
}
|
||||
|
||||
if ( $vars->{$var}->{default} && !$var_exists ) {
|
||||
PTDEBUG && _d('Not setting default var', $var,
|
||||
'because it does not exist');
|
||||
next;
|
||||
}
|
||||
|
||||
if ( $current_val && $current_val eq $val ) {
|
||||
PTDEBUG && _d('Not setting var', $var, 'because its value',
|
||||
'is already', $val);
|
||||
next;
|
||||
}
|
||||
|
||||
my $sql = "SET SESSION $var=$val";
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
eval { $dbh->do($sql) };
|
||||
if ( my $set_error = $EVAL_ERROR ) {
|
||||
chomp($set_error);
|
||||
$set_error =~ s/ at \S+ line \d+//;
|
||||
my $msg = "Error setting $var: $set_error";
|
||||
if ( $current_val ) {
|
||||
$msg .= " The current value for $var is $current_val. "
|
||||
. "If the variable is read only (not dynamic), specify "
|
||||
. "--set-vars $var=$current_val to avoid this warning, "
|
||||
. "else manually set the variable and restart MySQL.";
|
||||
}
|
||||
warn $msg . "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
@@ -405,9 +405,9 @@ sub one_nibble {
|
||||
return $self->{one_nibble};
|
||||
}
|
||||
|
||||
sub chunk_size {
|
||||
sub limit {
|
||||
my ($self) = @_;
|
||||
return $self->{limit} + 1;
|
||||
return $self->{limit};
|
||||
}
|
||||
|
||||
sub set_chunk_size {
|
||||
|
@@ -18,45 +18,6 @@
|
||||
# OptionParser package
|
||||
# ###########################################################################
|
||||
{
|
||||
# Package: OptionParser
|
||||
# OptionParser parses command line options from a tool's POD. By default
|
||||
# it parses a description and usage from the POD's SYNOPSIS section and
|
||||
# command line options from the OPTIONS section.
|
||||
#
|
||||
# The SYNOPSIS section should look like,
|
||||
# (start code)
|
||||
# =head1 SYNOPSIS
|
||||
#
|
||||
# Usage: mk-archiver [OPTION...] --source DSN --where WHERE
|
||||
#
|
||||
# mk-archiver nibbles records from a MySQL table. The --source and --dest
|
||||
# arguments use DSN syntax; if COPY is yes, --dest defaults to the key's value
|
||||
# from --source.
|
||||
#
|
||||
# Examples:
|
||||
# ...
|
||||
# (end code)
|
||||
# The key, required parts are the "Usage:" line and the following description
|
||||
# paragraph.
|
||||
#
|
||||
# The OPTIONS section shoud look like,
|
||||
# (start code)
|
||||
# =head1 OPTIONS
|
||||
#
|
||||
# Optional rules, one per line.
|
||||
#
|
||||
# =over
|
||||
#
|
||||
# =item --analyze
|
||||
#
|
||||
# type: string
|
||||
#
|
||||
# Run ANALYZE TABLE afterwards on L<"--source"> and/or L<"--dest">.
|
||||
# ect.
|
||||
# (end code)
|
||||
# The option's full name is given as the "=item". The next, optional para
|
||||
# is the option's attributes. And the next, required para is the option's
|
||||
# description (the first period-terminated sentence).
|
||||
package OptionParser;
|
||||
|
||||
use strict;
|
||||
@@ -66,6 +27,7 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use List::Util qw(max);
|
||||
use Getopt::Long;
|
||||
use Data::Dumper;
|
||||
|
||||
my $POD_link_re = '[LC]<"?([^">]+)"?>';
|
||||
|
||||
@@ -1318,6 +1280,45 @@ sub _parse_synopsis {
|
||||
);
|
||||
};
|
||||
|
||||
sub set_vars {
|
||||
my ($self, $file) = @_;
|
||||
$file ||= $self->{file} || __FILE__;
|
||||
|
||||
my %user_vars;
|
||||
my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
|
||||
if ( $user_vars ) {
|
||||
foreach my $var_val ( @$user_vars ) {
|
||||
my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
|
||||
die "Invalid --set-vars value: $var_val\n" unless $var && $val;
|
||||
$user_vars{$var} = {
|
||||
val => $val,
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
my %default_vars;
|
||||
my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
|
||||
if ( $default_vars ) {
|
||||
%default_vars = map {
|
||||
my $var_val = $_;
|
||||
my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
|
||||
die "Invalid --set-vars value: $var_val\n" unless $var && $val;
|
||||
$var => {
|
||||
val => $val,
|
||||
default => 1,
|
||||
};
|
||||
} split("\n", $default_vars);
|
||||
}
|
||||
|
||||
my %vars = (
|
||||
%default_vars, # first the tool's defaults
|
||||
%user_vars, # then the user's which overwrite the defaults
|
||||
);
|
||||
PTDEBUG && _d('--set-vars:', Dumper(\%vars));
|
||||
return \%vars;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
Reference in New Issue
Block a user