1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

Try to dynamically change option, restart if it fails

This commit is contained in:
msvensson@pilot.mysql.com
2008-01-07 19:44:48 +01:00
parent 8ba9c0afa7
commit 9087ee9170
6 changed files with 403 additions and 124 deletions

View File

@@ -0,0 +1,191 @@
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# 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; version 2 of the License.
#
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Options;
#
# Utility functions to work with list of options
#
use strict;
sub same($$) {
my $l1= shift;
my $l2= shift;
return compare($l1,$l2) == 0;
}
sub compare ($$) {
my $l1= shift;
my $l2= shift;
my @l1= @$l1;
my @l2= @$l2;
return -1 if @l1 < @l2;
return 1 if @l1 > @l2;
while ( @l1 ) # Same length
{
my $e1= shift @l1;
my $e2= shift @l2;
my $cmp= ($e1 cmp $e2);
return $cmp if $cmp != 0;
}
return 0; # They are the same
}
sub _split_option {
my ($option)= @_;
if ($option=~ /^--(.*)=(.*)$/){
return ($1, $2);
}
elsif ($option=~ /^--(.*)$/){
return ($1, undef)
}
elsif ($option=~ /^(.*)=(.*)$/){
return ($1, $2)
}
elsif ($option=~ /^-O$/){
return (undef, undef);
}
die "Unknown option format '$option'";
}
sub _build_option {
my ($name, $value)= @_;
if ($name =~ /^O, /){
return "-".$name."=".$value;
}
elsif ($value){
return "--".$name."=".$value;
}
return "--".$name;
}
#
# Compare two list of options and return what would need
# to be done to get the server running with the new settings
#
sub diff {
my ($from_opts, $to_opts)= @_;
my %from;
foreach my $from (@$from_opts)
{
my ($opt, $value)= _split_option($from);
next unless defined($opt);
$from{$opt}= $value;
}
#print "from: ", %from, "\n";
my %to;
foreach my $to (@$to_opts)
{
my ($opt, $value)= _split_option($to);
next unless defined($opt);
$to{$opt}= $value;
}
#print "to: ", %to, "\n";
# Remove the ones that are in both lists
foreach my $name (keys %from){
if (exists $to{$name} and $to{$name} eq $from{$name}){
#print "removing '$name' from both lists\n";
delete $to{$name};
delete $from{$name};
}
}
#print "from: ", %from, "\n";
#print "to: ", %to, "\n";
# Add all keys in "to" to result
my @result;
foreach my $name (keys %to){
push(@result, _build_option($name, $to{$name}));
}
# Add all keys in "from" that are not in "to"
# to result as "set to default"
foreach my $name (keys %from){
if (not exists $to{$name}) {
push(@result, _build_option($name, "default"));
}
}
return @result;
}
sub is_set {
my ($opts, $set_opts)= @_;
foreach my $opt (@$opts){
my ($opt_name1, $value1)= _split_option($opt);
foreach my $set_opt (@$set_opts){
my ($opt_name2, $value2)= _split_option($set_opt);
if ($opt_name1 eq $opt_name2){
# Option already set
return 1;
}
}
}
return 0;
}
sub toSQL {
my (@options)= @_;
my @sql;
foreach my $option (@options) {
my ($name, $value)= _split_option($option);
#print "name: $name\n";
if ($name =~ /^O, (.*)/){
push(@sql, "SET GLOBAL $1=$value");
} else {
my $sql_name= $name;
$sql_name=~ s/-/_/g;
push(@sql, "SET GLOBAL $sql_name=$value");
}
}
return join("; ", @sql);
}
sub toStr {
my $name= shift;
return "$name: ",
"['", join("', '", @_), "']\n";
}
1;

View File

@@ -31,7 +31,7 @@ our $skip_rpl;
our $do_test;
our $skip_test;
our $opt_skip_combination;
our $binlog_format;;
our $binlog_format;
our $enable_disabled;
our $default_storage_engine;
our $opt_with_ndbcluster_only;
@@ -83,8 +83,9 @@ sub init_pattern {
#
##############################################################################
sub collect_test_cases ($) {
sub collect_test_cases ($$) {
my $suites= shift; # Semicolon separated list of test suites
my $opt_cases= shift;
my $cases= []; # Array of hash(one hash for each testcase)
$do_test_reg= init_pattern($do_test, "--do-test");
@@ -92,15 +93,15 @@ sub collect_test_cases ($) {
foreach my $suite (split(",", $suites))
{
push(@$cases, collect_one_suite($suite));
push(@$cases, collect_one_suite($suite, $opt_cases));
}
if ( @::opt_cases )
if ( @$opt_cases )
{
# A list of tests was specified on the command line
# Check that the tests specified was found
# in at least one suite
foreach my $test_name_spec ( @::opt_cases )
foreach my $test_name_spec ( @$opt_cases )
{
my $found= 0;
my ($sname, $tname, $extension)= split_testname($test_name_spec);
@@ -236,6 +237,7 @@ sub split_testname {
sub collect_one_suite($)
{
my $suite= shift; # Test suite name
my $opt_cases= shift;
my @cases; # Array of hash
mtr_verbose("Collecting: $suite");
@@ -304,10 +306,10 @@ sub collect_one_suite($)
$suite_opts= opts_from_file($suite_opt_file);
}
if ( @::opt_cases )
if ( @$opt_cases )
{
# Collect in specified order
foreach my $test_name_spec ( @::opt_cases )
foreach my $test_name_spec ( @$opt_cases )
{
my ($sname, $tname, $extension)= split_testname($test_name_spec);
@@ -428,9 +430,15 @@ sub collect_one_suite($)
{
foreach my $test (@cases)
{
#print $test->{name}, " ", $comb, "\n";
my $new_test= {};
# Skip this combination if the values it provides
# already are set in master_opt or slave_opt
if (My::Options::is_set($test->{master_opt}, $comb->{comb_opt}) &&
My::Options::is_set($test->{slave_opt}, $comb->{comb_opt}) ){
next;
}
# Copy test options
my $new_test= {};
while (my ($key, $value) = each(%$test)) {
if (ref $value eq "ARRAY") {
push(@{$new_test->{$key}}, @$value);
@@ -450,6 +458,18 @@ sub collect_one_suite($)
push(@new_cases, $new_test);
}
}
# Add the plain test if it was not already added
# as part of a combination
my %added;
foreach my $new_test (@new_cases){
$added{$new_test->{name}}= 1;
}
foreach my $test (@cases){
push(@new_cases, $test) unless $added{$test->{name}};
}
#print_testcases(@new_cases);
@cases= @new_cases;
#print_testcases(@cases);
@@ -481,6 +501,7 @@ sub optimize_cases {
# --mysqld=--binlog-format=x, skip all test that does not
# support it
# =======================================================
#print "binlog_format: $binlog_format\n";
if (defined $binlog_format )
{
# =======================================================
@@ -488,6 +509,8 @@ sub optimize_cases {
# =======================================================
if ( defined $tinfo->{'binlog_formats'} )
{
#print "binlog_formats: ". join(", ", @{$tinfo->{binlog_formats}})."\n";
# The test supports different binlog formats
# check if the selected one is ok
my $supported=
@@ -513,23 +536,18 @@ sub optimize_cases {
mtr_match_prefix($opt, "--binlog-format=") || $test_binlog_format;
}
if (defined $test_binlog_format)
if (defined $test_binlog_format and
defined $tinfo->{binlog_formats} )
{
if ( defined $tinfo->{binlog_formats} )
my $supported=
grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
if ( !$supported )
{
my $supported=
grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
if ( !$supported )
{
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}=
"Doesn't support --binlog-format='$test_binlog_format'";
next;
}
$tinfo->{'skip'}= 1;
$tinfo->{'comment'}=
"Doesn't support --binlog-format='$test_binlog_format'";
next;
}
# Save binlog format for dynamic switching
$tinfo->{binlog_format_switch}= $test_binlog_format;
}
}
}
@@ -882,6 +900,12 @@ sub collect_one_test_case {
$tinfo->{extra_template_path}= $defaults_extra_file;
}
# ----------------------------------------------------------------------
# Append mysqld extra options to both master and slave
# ----------------------------------------------------------------------
push(@{$tinfo->{'master_opt'}}, @::opt_extra_mysqld_opt);
push(@{$tinfo->{'slave_opt'}}, @::opt_extra_mysqld_opt);
return $tinfo;
}

View File

@@ -29,8 +29,6 @@ sub mtr_script_exists(@);
sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@);
sub mtr_same_opts($$);
sub mtr_cmp_opts($$);
##############################################################################
#
@@ -189,35 +187,6 @@ sub mtr_exe_exists (@) {
}
sub mtr_same_opts ($$) {
my $l1= shift;
my $l2= shift;
return mtr_cmp_opts($l1,$l2) == 0;
}
sub mtr_cmp_opts ($$) {
my $l1= shift;
my $l2= shift;
my @l1= @$l1;
my @l2= @$l2;
return -1 if @l1 < @l2;
return 1 if @l1 > @l2;
while ( @l1 ) # Same length
{
my $e1= shift @l1;
my $e2= shift @l2;
my $cmp= ($e1 cmp $e2);
return $cmp if $cmp != 0;
}
return 0; # They are the same
}
sub mtr_milli_sleep {
die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1;
my ($millis)= @_;
@@ -225,33 +194,4 @@ sub mtr_milli_sleep {
select(undef, undef, undef, ($millis/1000));
}
#
# Compare two arrays and put all unequal elements into a new one
#
sub mtr_diff_opts ($$) {
my $l1= shift;
my $l2= shift;
my $found;
my @result;
foreach my $e1 (@$l1)
{
$found= undef;
foreach my $e2 (@$l2)
{
$found= 1 unless ($e1 ne $e2);
}
push(@result, $e1) unless (defined $found);
}
foreach my $e2 (@$l2)
{
$found= undef;
foreach my $e1 (@$l1)
{
$found= 1 unless ($e1 ne $e2);
}
push(@result, $e2) unless (defined $found);
}
return @result;
}
1;

View File

@@ -68,7 +68,9 @@ sub mtr_report_test_skipped ($) {
if ( $tinfo->{skip_detected_by_test} )
{
mtr_report("[ skip.] $tinfo->{'comment'}");
} else {
}
else
{
mtr_report("[ skip ] $tinfo->{'comment'}");
}
}

120
mysql-test/lib/t/Options.t Normal file
View File

@@ -0,0 +1,120 @@
# -*- cperl -*-
use Test::More qw(no_plan);
use strict;
use_ok("My::Options");
my @tests=
(
[
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=ms'],
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=statement'],
['--binlog-format=statement']
],
[
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=statement'],
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=mixed'],
['--binlog-format=mixed']
],
[
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=mixed'],
['--binlog-format=row', '--loose-skip-innodb', '--binlog-format=statement'],
['--binlog-format=statement']
],
[
['--binlog-format=mixed', '--loose-skip-innodb', '--binlog-format=row'],
['--binlog-format=statement', '--loose-skip-innodb', '--binlog-format=row'],
[ ]
],
[
['--binlog-format=row'],
[ ],
['--binlog-format=default']
],
[
[ ],
['--binlog-format=row'],
['--binlog-format=row']
],
[
[ ],
['-O', 'max_binlog_size=1' ],
['--max_binlog_size=1' ]
],
[
['-O', 'max_binlog_size=1' ],
['-O', 'max_binlog_size=1' ],
[ ],
],
[
['-O', 'max_binlog_size=1' ],
[ ],
['--max_binlog_size=default' ]
],
[
[ ],
['-O', 'max_binlog_size=1', '--binlog-format=row' ],
['--max_binlog_size=1', '--binlog-format=row' ]
],
[
['--binlog-format=statement' ],
['-O', 'max_binlog_size=1', '--binlog-format=row' ],
['--max_binlog_size=1', '--binlog-format=row']
],
[
[ '--binlog-format=statement' ],
['-O', 'max_binlog_size=1', '--binlog-format=statement' ],
['--max_binlog_size=1' ]
],
[
[ '--binlog-format=statement' ],
['-O', 'max_binlog_size=1', '--binlog-format=statement' ],
['--max_binlog_size=1' ]
],
[
[ '--binlog-format=statement' ],
['--relay-log=/path/to/a/relay-log', '--binlog-format=row'],
['--relay-log=/path/to/a/relay-log', '--binlog-format=row' ]
],
[
[ '--binlog-format=statement' ],
['--relay-log=/path/to/a/relay-log', '-O', 'max_binlog_size=1'],
['--max_binlog_size=1', '--relay-log=/path/to/a/relay-log', '--binlog-format=default' ]
],
);
my $test_no= 0;
foreach my $test (@tests){
print "test", $test_no++, "\n";
foreach my $opts (@$test){
print My::Options::toStr("", @$opts);
}
my $from= $test->[0];
my $to= $test->[1];
my @result= My::Options::diff($from, $to);
ok(My::Options::same(\@result, $test->[2]));
if (!My::Options::same(\@result, $test->[2])){
print "failed\n";
print My::Options::toStr("result", @result);
print My::Options::toStr("expect", @{$test->[2]});
}
print My::Options::toSQL(@result), "\n";
print "\n";
}