Skip to content

Commit 9087ee9

Browse files
author
msvensson@pilot.mysql.com
committed
Try to dynamically change option, restart if it fails
1 parent 8ba9c0a commit 9087ee9

File tree

6 files changed

+403
-124
lines changed

6 files changed

+403
-124
lines changed

mysql-test/lib/My/Options.pm

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# -*- cperl -*-
2+
# Copyright (C) 2004-2006 MySQL AB
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; version 2 of the License.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
18+
package My::Options;
19+
20+
#
21+
# Utility functions to work with list of options
22+
#
23+
24+
use strict;
25+
26+
27+
sub same($$) {
28+
my $l1= shift;
29+
my $l2= shift;
30+
return compare($l1,$l2) == 0;
31+
}
32+
33+
34+
sub compare ($$) {
35+
my $l1= shift;
36+
my $l2= shift;
37+
38+
my @l1= @$l1;
39+
my @l2= @$l2;
40+
41+
return -1 if @l1 < @l2;
42+
return 1 if @l1 > @l2;
43+
44+
while ( @l1 ) # Same length
45+
{
46+
my $e1= shift @l1;
47+
my $e2= shift @l2;
48+
my $cmp= ($e1 cmp $e2);
49+
return $cmp if $cmp != 0;
50+
}
51+
52+
return 0; # They are the same
53+
}
54+
55+
56+
sub _split_option {
57+
my ($option)= @_;
58+
if ($option=~ /^--(.*)=(.*)$/){
59+
return ($1, $2);
60+
}
61+
elsif ($option=~ /^--(.*)$/){
62+
return ($1, undef)
63+
}
64+
elsif ($option=~ /^(.*)=(.*)$/){
65+
return ($1, $2)
66+
}
67+
elsif ($option=~ /^-O$/){
68+
return (undef, undef);
69+
}
70+
die "Unknown option format '$option'";
71+
}
72+
73+
74+
sub _build_option {
75+
my ($name, $value)= @_;
76+
if ($name =~ /^O, /){
77+
return "-".$name."=".$value;
78+
}
79+
elsif ($value){
80+
return "--".$name."=".$value;
81+
}
82+
return "--".$name;
83+
}
84+
85+
86+
#
87+
# Compare two list of options and return what would need
88+
# to be done to get the server running with the new settings
89+
#
90+
sub diff {
91+
my ($from_opts, $to_opts)= @_;
92+
93+
my %from;
94+
foreach my $from (@$from_opts)
95+
{
96+
my ($opt, $value)= _split_option($from);
97+
next unless defined($opt);
98+
$from{$opt}= $value;
99+
}
100+
101+
#print "from: ", %from, "\n";
102+
103+
my %to;
104+
foreach my $to (@$to_opts)
105+
{
106+
my ($opt, $value)= _split_option($to);
107+
next unless defined($opt);
108+
$to{$opt}= $value;
109+
}
110+
111+
#print "to: ", %to, "\n";
112+
113+
# Remove the ones that are in both lists
114+
foreach my $name (keys %from){
115+
if (exists $to{$name} and $to{$name} eq $from{$name}){
116+
#print "removing '$name' from both lists\n";
117+
delete $to{$name};
118+
delete $from{$name};
119+
}
120+
}
121+
122+
#print "from: ", %from, "\n";
123+
#print "to: ", %to, "\n";
124+
125+
# Add all keys in "to" to result
126+
my @result;
127+
foreach my $name (keys %to){
128+
push(@result, _build_option($name, $to{$name}));
129+
}
130+
131+
# Add all keys in "from" that are not in "to"
132+
# to result as "set to default"
133+
foreach my $name (keys %from){
134+
if (not exists $to{$name}) {
135+
push(@result, _build_option($name, "default"));
136+
}
137+
}
138+
139+
return @result;
140+
}
141+
142+
143+
sub is_set {
144+
my ($opts, $set_opts)= @_;
145+
146+
foreach my $opt (@$opts){
147+
148+
my ($opt_name1, $value1)= _split_option($opt);
149+
150+
foreach my $set_opt (@$set_opts){
151+
my ($opt_name2, $value2)= _split_option($set_opt);
152+
153+
if ($opt_name1 eq $opt_name2){
154+
# Option already set
155+
return 1;
156+
}
157+
}
158+
}
159+
160+
return 0;
161+
}
162+
163+
164+
sub toSQL {
165+
my (@options)= @_;
166+
my @sql;
167+
168+
foreach my $option (@options) {
169+
my ($name, $value)= _split_option($option);
170+
#print "name: $name\n";
171+
if ($name =~ /^O, (.*)/){
172+
push(@sql, "SET GLOBAL $1=$value");
173+
} else {
174+
my $sql_name= $name;
175+
$sql_name=~ s/-/_/g;
176+
push(@sql, "SET GLOBAL $sql_name=$value");
177+
}
178+
}
179+
return join("; ", @sql);
180+
}
181+
182+
183+
sub toStr {
184+
my $name= shift;
185+
return "$name: ",
186+
"['", join("', '", @_), "']\n";
187+
}
188+
189+
190+
1;
191+

mysql-test/lib/mtr_cases.pm

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ our $skip_rpl;
3131
our $do_test;
3232
our $skip_test;
3333
our $opt_skip_combination;
34-
our $binlog_format;;
34+
our $binlog_format;
3535
our $enable_disabled;
3636
our $default_storage_engine;
3737
our $opt_with_ndbcluster_only;
@@ -83,24 +83,25 @@ sub init_pattern {
8383
#
8484
##############################################################################
8585

86-
sub collect_test_cases ($) {
86+
sub collect_test_cases ($$) {
8787
my $suites= shift; # Semicolon separated list of test suites
88+
my $opt_cases= shift;
8889
my $cases= []; # Array of hash(one hash for each testcase)
8990

9091
$do_test_reg= init_pattern($do_test, "--do-test");
9192
$skip_test_reg= init_pattern($skip_test, "--skip-test");
9293

9394
foreach my $suite (split(",", $suites))
9495
{
95-
push(@$cases, collect_one_suite($suite));
96+
push(@$cases, collect_one_suite($suite, $opt_cases));
9697
}
9798

98-
if ( @::opt_cases )
99+
if ( @$opt_cases )
99100
{
100101
# A list of tests was specified on the command line
101102
# Check that the tests specified was found
102103
# in at least one suite
103-
foreach my $test_name_spec ( @::opt_cases )
104+
foreach my $test_name_spec ( @$opt_cases )
104105
{
105106
my $found= 0;
106107
my ($sname, $tname, $extension)= split_testname($test_name_spec);
@@ -236,6 +237,7 @@ sub split_testname {
236237
sub collect_one_suite($)
237238
{
238239
my $suite= shift; # Test suite name
240+
my $opt_cases= shift;
239241
my @cases; # Array of hash
240242

241243
mtr_verbose("Collecting: $suite");
@@ -304,10 +306,10 @@ sub collect_one_suite($)
304306
$suite_opts= opts_from_file($suite_opt_file);
305307
}
306308

307-
if ( @::opt_cases )
309+
if ( @$opt_cases )
308310
{
309311
# Collect in specified order
310-
foreach my $test_name_spec ( @::opt_cases )
312+
foreach my $test_name_spec ( @$opt_cases )
311313
{
312314
my ($sname, $tname, $extension)= split_testname($test_name_spec);
313315

@@ -428,9 +430,15 @@ sub collect_one_suite($)
428430
{
429431
foreach my $test (@cases)
430432
{
431-
#print $test->{name}, " ", $comb, "\n";
432-
my $new_test= {};
433+
# Skip this combination if the values it provides
434+
# already are set in master_opt or slave_opt
435+
if (My::Options::is_set($test->{master_opt}, $comb->{comb_opt}) &&
436+
My::Options::is_set($test->{slave_opt}, $comb->{comb_opt}) ){
437+
next;
438+
}
433439

440+
# Copy test options
441+
my $new_test= {};
434442
while (my ($key, $value) = each(%$test)) {
435443
if (ref $value eq "ARRAY") {
436444
push(@{$new_test->{$key}}, @$value);
@@ -450,6 +458,18 @@ sub collect_one_suite($)
450458
push(@new_cases, $new_test);
451459
}
452460
}
461+
462+
# Add the plain test if it was not already added
463+
# as part of a combination
464+
my %added;
465+
foreach my $new_test (@new_cases){
466+
$added{$new_test->{name}}= 1;
467+
}
468+
foreach my $test (@cases){
469+
push(@new_cases, $test) unless $added{$test->{name}};
470+
}
471+
472+
453473
#print_testcases(@new_cases);
454474
@cases= @new_cases;
455475
#print_testcases(@cases);
@@ -481,13 +501,16 @@ sub optimize_cases {
481501
# --mysqld=--binlog-format=x, skip all test that does not
482502
# support it
483503
# =======================================================
504+
#print "binlog_format: $binlog_format\n";
484505
if (defined $binlog_format )
485506
{
486507
# =======================================================
487508
# Fixed --binlog-format=x specified on command line
488509
# =======================================================
489510
if ( defined $tinfo->{'binlog_formats'} )
490511
{
512+
#print "binlog_formats: ". join(", ", @{$tinfo->{binlog_formats}})."\n";
513+
491514
# The test supports different binlog formats
492515
# check if the selected one is ok
493516
my $supported=
@@ -513,23 +536,18 @@ sub optimize_cases {
513536
mtr_match_prefix($opt, "--binlog-format=") || $test_binlog_format;
514537
}
515538

516-
if (defined $test_binlog_format)
539+
if (defined $test_binlog_format and
540+
defined $tinfo->{binlog_formats} )
517541
{
518-
if ( defined $tinfo->{binlog_formats} )
542+
my $supported=
543+
grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
544+
if ( !$supported )
519545
{
520-
my $supported=
521-
grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
522-
if ( !$supported )
523-
{
524-
$tinfo->{'skip'}= 1;
525-
$tinfo->{'comment'}=
526-
"Doesn't support --binlog-format='$test_binlog_format'";
527-
next;
528-
}
546+
$tinfo->{'skip'}= 1;
547+
$tinfo->{'comment'}=
548+
"Doesn't support --binlog-format='$test_binlog_format'";
549+
next;
529550
}
530-
531-
# Save binlog format for dynamic switching
532-
$tinfo->{binlog_format_switch}= $test_binlog_format;
533551
}
534552
}
535553
}
@@ -882,6 +900,12 @@ sub collect_one_test_case {
882900
$tinfo->{extra_template_path}= $defaults_extra_file;
883901
}
884902

903+
# ----------------------------------------------------------------------
904+
# Append mysqld extra options to both master and slave
905+
# ----------------------------------------------------------------------
906+
push(@{$tinfo->{'master_opt'}}, @::opt_extra_mysqld_opt);
907+
push(@{$tinfo->{'slave_opt'}}, @::opt_extra_mysqld_opt);
908+
885909
return $tinfo;
886910
}
887911

0 commit comments

Comments
 (0)