mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 17:04:00 +00:00
First working enhanced --set-vars in pt-osc: no "default: ...", instead default values are under MAGIC_set_vars, picked up by OptionParser and passed to DSNParser. Also increaes --retries from 3 to 10. TODO: more testing.
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,55 @@ sub copy {
|
||||
return \%new_dsn;
|
||||
}
|
||||
|
||||
sub set_vars {
|
||||
my ($self, $dbh, $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; }
|
||||
|
Reference in New Issue
Block a user