Commit 406d0ea5 authored by unknown's avatar unknown

Start cluster only for testcases that really needs it and stop it when

not needed by the tescases. This will save test time for those testcases
that does not need cluster, but need a restart, as they dont have to wait
the extra time it would take for cluster to restart. It will also save
time for other testcases, as cluster does not 
need to be contacted for each table to be dropped or created.
Backport from 5.1


mysql-test/lib/mtr_cases.pl:
  Mark all test cases where name contains "ndb" as ndbcluster needed
mysql-test/lib/mtr_match.pl:
  Add mtr_match_substring function
mysql-test/lib/mtr_stress.pl:
  Extre param to mysqld_start
mysql-test/mysql-test-run.pl:
  Only start ndbcluster for testcases that needs it.
parent fb6928cb
...@@ -252,6 +252,26 @@ sub collect_one_test_case($$$$$$$) { ...@@ -252,6 +252,26 @@ sub collect_one_test_case($$$$$$$) {
$tinfo->{'slave_restart'}= 1; $tinfo->{'slave_restart'}= 1;
} }
# Cluster is needed by test case if testname contains ndb
if ( ( $::opt_with_ndbcluster or $::glob_use_running_ndbcluster ) and
defined mtr_match_substring($tname,"ndb") )
{
if ( $::opt_skip_ndbcluster )
{
$tinfo->{'ndb_test'}= 0;
$tinfo->{'skip'}= 1;
return;
}
else
{
$tinfo->{'ndb_test'}= 1;
}
}
else
{
$tinfo->{'ndb_test'}= 0;
}
# FIXME what about embedded_server + ndbcluster, skip ?! # FIXME what about embedded_server + ndbcluster, skip ?!
my $master_opt_file= "$testdir/$tname-master.opt"; my $master_opt_file= "$testdir/$tname-master.opt";
......
...@@ -50,6 +50,23 @@ sub mtr_match_extension ($$) { ...@@ -50,6 +50,23 @@ sub mtr_match_extension ($$) {
} }
# Match a substring anywere in a string
sub mtr_match_substring ($$) {
my $string= shift;
my $substring= shift;
if ( $string =~ /(.*)\Q$substring\E(.*)$/ ) # strncmp
{
return $1;
}
else
{
return undef; # NULL
}
}
sub mtr_match_any_exact ($$) { sub mtr_match_any_exact ($$) {
my $string= shift; my $string= shift;
my $mlist= shift; my $mlist= shift;
......
...@@ -28,7 +28,7 @@ sub run_stress_test () ...@@ -28,7 +28,7 @@ sub run_stress_test ()
if ( ! $::glob_use_embedded_server and ! $::opt_local_master ) if ( ! $::glob_use_embedded_server and ! $::opt_local_master )
{ {
$::master->[0]->{'pid'}= mysqld_start('master',0,[],[]); $::master->[0]->{'pid'}= mysqld_start('master',0,[],[],0);
if ( ! $::master->[0]->{'pid'} ) if ( ! $::master->[0]->{'pid'} )
{ {
mtr_error("Can't start the mysqld server"); mtr_error("Can't start the mysqld server");
......
...@@ -143,6 +143,8 @@ our $glob_use_running_ndbcluster= 0; ...@@ -143,6 +143,8 @@ our $glob_use_running_ndbcluster= 0;
our $glob_use_embedded_server= 0; our $glob_use_embedded_server= 0;
our @glob_test_mode; our @glob_test_mode;
our $using_ndbcluster_master= 0;
our $glob_basedir; our $glob_basedir;
# The total result # The total result
...@@ -322,7 +324,7 @@ sub kill_and_cleanup (); ...@@ -322,7 +324,7 @@ sub kill_and_cleanup ();
sub check_ssl_support (); sub check_ssl_support ();
sub check_ndbcluster_support (); sub check_ndbcluster_support ();
sub ndbcluster_install (); sub ndbcluster_install ();
sub ndbcluster_start (); sub ndbcluster_start ($);
sub ndbcluster_stop (); sub ndbcluster_stop ();
sub run_benchmarks ($); sub run_benchmarks ($);
sub run_tests (); sub run_tests ();
...@@ -332,8 +334,8 @@ sub run_testcase ($); ...@@ -332,8 +334,8 @@ sub run_testcase ($);
sub report_failure_and_restart ($); sub report_failure_and_restart ($);
sub do_before_start_master ($$); sub do_before_start_master ($$);
sub do_before_start_slave ($$); sub do_before_start_slave ($$);
sub mysqld_start ($$$$); sub mysqld_start ($$$$$);
sub mysqld_arguments ($$$$$); sub mysqld_arguments ($$$$$$);
sub stop_masters_slaves (); sub stop_masters_slaves ();
sub stop_masters (); sub stop_masters ();
sub stop_slaves (); sub stop_slaves ();
...@@ -390,11 +392,11 @@ sub main () { ...@@ -390,11 +392,11 @@ sub main () {
if ( $opt_start_dirty ) if ( $opt_start_dirty )
{ {
if ( ndbcluster_start() ) if ( ndbcluster_start($opt_with_ndbcluster) )
{ {
mtr_error("Can't start ndbcluster"); mtr_error("Can't start ndbcluster");
} }
if ( mysqld_start('master',0,[],[]) ) if ( mysqld_start('master',0,[],[],$using_ndbcluster_master) )
{ {
mtr_report("Servers started, exiting"); mtr_report("Servers started, exiting");
} }
...@@ -1180,6 +1182,7 @@ sub kill_running_server () { ...@@ -1180,6 +1182,7 @@ sub kill_running_server () {
mkpath("$opt_vardir/log"); # Needed for mysqladmin log mkpath("$opt_vardir/log"); # Needed for mysqladmin log
mtr_kill_leftovers(); mtr_kill_leftovers();
$using_ndbcluster_master= 1;
ndbcluster_stop(); ndbcluster_stop();
$master->[0]->{'ndbcluster'}= 1; $master->[0]->{'ndbcluster'}= 1;
} }
...@@ -1327,16 +1330,29 @@ sub ndbcluster_install () { ...@@ -1327,16 +1330,29 @@ sub ndbcluster_install () {
return 1; return 1;
} }
$using_ndbcluster_master= 1;
ndbcluster_stop(); ndbcluster_stop();
$master->[0]->{'ndbcluster'}= 1; $master->[0]->{'ndbcluster'}= 1;
return 0; return 0;
} }
sub ndbcluster_start () { sub ndbcluster_start ($) {
my $use_ndbcluster= shift;
if ( ! $opt_with_ndbcluster or $glob_use_running_ndbcluster ) if ( ! $use_ndbcluster )
{
$using_ndbcluster_master= 0;
return 0;
}
if ( $glob_use_running_ndbcluster )
{ {
$using_ndbcluster_master= 1;
return 0;
}
if ( $using_ndbcluster_master )
{
# Master already started
return 0; return 0;
} }
# FIXME, we want to _append_ output to file $file_ndb_testrun_log instead of /dev/null # FIXME, we want to _append_ output to file $file_ndb_testrun_log instead of /dev/null
...@@ -1349,13 +1365,14 @@ sub ndbcluster_start () { ...@@ -1349,13 +1365,14 @@ sub ndbcluster_start () {
return 1; return 1;
} }
$using_ndbcluster_master= 1;
return 0; return 0;
} }
sub ndbcluster_stop () { sub ndbcluster_stop () {
if ( ! $using_ndbcluster_master or $glob_use_running_ndbcluster )
if ( ! $opt_with_ndbcluster or $glob_use_running_ndbcluster )
{ {
$using_ndbcluster_master= 0;
return; return;
} }
# FIXME, we want to _append_ output to file $file_ndb_testrun_log instead of /dev/null # FIXME, we want to _append_ output to file $file_ndb_testrun_log instead of /dev/null
...@@ -1365,6 +1382,7 @@ sub ndbcluster_stop () { ...@@ -1365,6 +1382,7 @@ sub ndbcluster_stop () {
"--stop"], "--stop"],
"", "/dev/null", "", ""); "", "/dev/null", "", "");
$using_ndbcluster_master= 0;
return; return;
} }
...@@ -1382,7 +1400,8 @@ sub run_benchmarks ($) { ...@@ -1382,7 +1400,8 @@ sub run_benchmarks ($) {
if ( ! $glob_use_embedded_server and ! $opt_local_master ) if ( ! $glob_use_embedded_server and ! $opt_local_master )
{ {
$master->[0]->{'pid'}= mysqld_start('master',0,[],[]); $master->[0]->{'pid'}= mysqld_start('master',0,[],[],
$using_ndbcluster_master);
if ( ! $master->[0]->{'pid'} ) if ( ! $master->[0]->{'pid'} )
{ {
mtr_error("Can't start the mysqld server"); mtr_error("Can't start the mysqld server");
...@@ -1730,7 +1749,9 @@ sub run_testcase ($) { ...@@ -1730,7 +1749,9 @@ sub run_testcase ($) {
if ( ! $glob_use_running_server and ! $glob_use_embedded_server ) if ( ! $glob_use_running_server and ! $glob_use_embedded_server )
{ {
if ( $tinfo->{'master_restart'} or if ( $tinfo->{'master_restart'} or
$master->[0]->{'running_master_is_special'} ) $master->[0]->{'running_master_is_special'} or
# Stop if cluster is started but test cases does not need cluster
( $tinfo->{'ndb_test'} != $using_ndbcluster_master ) )
{ {
stop_masters(); stop_masters();
$master->[0]->{'running_master_is_special'}= 0; # Forget why we stopped $master->[0]->{'running_master_is_special'}= 0; # Forget why we stopped
...@@ -1781,29 +1802,36 @@ sub run_testcase ($) { ...@@ -1781,29 +1802,36 @@ sub run_testcase ($) {
{ {
if ( $master->[0]->{'ndbcluster'} ) if ( $master->[0]->{'ndbcluster'} )
{ {
$master->[0]->{'ndbcluster'}= ndbcluster_start(); # Cluster is not started
if ( $master->[0]->{'ndbcluster'} )
{ # Call ndbcluster_start to check if test case needs cluster
report_failure_and_restart($tinfo); # Start it if not already started
return; $master->[0]->{'ndbcluster'}= ndbcluster_start($tinfo->{'ndb_test'});
} if ( $master->[0]->{'ndbcluster'} )
{
report_failure_and_restart($tinfo);
return;
}
} }
if ( ! $master->[0]->{'pid'} ) if ( ! $master->[0]->{'pid'} )
{ {
# FIXME not correct location for do_before_start_master() # FIXME not correct location for do_before_start_master()
do_before_start_master($tname,$tinfo->{'master_sh'}); do_before_start_master($tname,$tinfo->{'master_sh'});
$master->[0]->{'pid'}= $master->[0]->{'pid'}=
mysqld_start('master',0,$tinfo->{'master_opt'},[]); mysqld_start('master',0,$tinfo->{'master_opt'},[],
$using_ndbcluster_master);
if ( ! $master->[0]->{'pid'} ) if ( ! $master->[0]->{'pid'} )
{ {
report_failure_and_restart($tinfo); report_failure_and_restart($tinfo);
return; return;
} }
} }
if ( $opt_with_ndbcluster and ! $master->[1]->{'pid'} ) if ( $using_ndbcluster_master and ! $master->[1]->{'pid'} )
{ {
# Test needs cluster, start an extra mysqld connected to cluster
$master->[1]->{'pid'}= $master->[1]->{'pid'}=
mysqld_start('master',1,$tinfo->{'master_opt'},[]); mysqld_start('master',1,$tinfo->{'master_opt'},[],
$using_ndbcluster_master);
if ( ! $master->[1]->{'pid'} ) if ( ! $master->[1]->{'pid'} )
{ {
report_failure_and_restart($tinfo); report_failure_and_restart($tinfo);
...@@ -1844,7 +1872,8 @@ sub run_testcase ($) { ...@@ -1844,7 +1872,8 @@ sub run_testcase ($) {
{ {
$slave->[$idx]->{'pid'}= $slave->[$idx]->{'pid'}=
mysqld_start('slave',$idx, mysqld_start('slave',$idx,
$tinfo->{'slave_opt'}, $tinfo->{'slave_mi'}); $tinfo->{'slave_opt'}, $tinfo->{'slave_mi'},
0);
if ( ! $slave->[$idx]->{'pid'} ) if ( ! $slave->[$idx]->{'pid'} )
{ {
report_failure_and_restart($tinfo); report_failure_and_restart($tinfo);
...@@ -2041,12 +2070,13 @@ sub do_before_start_slave ($$) { ...@@ -2041,12 +2070,13 @@ sub do_before_start_slave ($$) {
} }
} }
sub mysqld_arguments ($$$$$) { sub mysqld_arguments ($$$$$$) {
my $args= shift; my $args= shift;
my $type= shift; # master/slave/bootstrap my $type= shift; # master/slave/bootstrap
my $idx= shift; my $idx= shift;
my $extra_opt= shift; my $extra_opt= shift;
my $slave_master_info= shift; my $slave_master_info= shift;
my $using_ndbcluster= shift;
my $sidx= ""; # Index as string, 0 is empty string my $sidx= ""; # Index as string, 0 is empty string
if ( $idx > 0 ) if ( $idx > 0 )
...@@ -2104,10 +2134,16 @@ sub mysqld_arguments ($$$$$) { ...@@ -2104,10 +2134,16 @@ sub mysqld_arguments ($$$$$) {
mtr_add_arg($args, "%s--skip-innodb", $prefix); mtr_add_arg($args, "%s--skip-innodb", $prefix);
} }
if ( $opt_skip_ndbcluster ) if ( $opt_skip_ndbcluster || !$using_ndbcluster)
{ {
mtr_add_arg($args, "%s--skip-ndbcluster", $prefix); mtr_add_arg($args, "%s--skip-ndbcluster", $prefix);
} }
else
{
mtr_add_arg($args, "%s--ndbcluster", $prefix);
mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
$opt_ndbconnectstring);
}
} }
if ( $type eq 'slave' ) if ( $type eq 'slave' )
...@@ -2180,13 +2216,6 @@ sub mysqld_arguments ($$$$$) { ...@@ -2180,13 +2216,6 @@ sub mysqld_arguments ($$$$$) {
} }
} }
if ( $opt_with_ndbcluster )
{
mtr_add_arg($args, "%s--ndbcluster", $prefix);
mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix,
$opt_ndbconnectstring);
}
# FIXME always set nowdays??? SMALL_SERVER # FIXME always set nowdays??? SMALL_SERVER
mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix); mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix);
mtr_add_arg($args, "%s--sort_buffer=256K", $prefix); mtr_add_arg($args, "%s--sort_buffer=256K", $prefix);
...@@ -2274,11 +2303,13 @@ sub mysqld_arguments ($$$$$) { ...@@ -2274,11 +2303,13 @@ sub mysqld_arguments ($$$$$) {
# #
############################################################################## ##############################################################################
sub mysqld_start ($$$$) { sub mysqld_start ($$$$$) {
my $type= shift; # master/slave/bootstrap my $type= shift; # master/slave/bootstrap
my $idx= shift; my $idx= shift;
my $extra_opt= shift; my $extra_opt= shift;
my $slave_master_info= shift; my $slave_master_info= shift;
my $using_ndbcluster= shift;
my $args; # Arg vector my $args; # Arg vector
my $exe; my $exe;
...@@ -2304,7 +2335,8 @@ sub mysqld_start ($$$$) { ...@@ -2304,7 +2335,8 @@ sub mysqld_start ($$$$) {
valgrind_arguments($args, \$exe); valgrind_arguments($args, \$exe);
} }
mysqld_arguments($args,$type,$idx,$extra_opt,$slave_master_info); mysqld_arguments($args,$type,$idx,$extra_opt,$slave_master_info,
$using_ndbcluster);
if ( $type eq 'master' ) if ( $type eq 'master' )
{ {
...@@ -2706,7 +2738,7 @@ sub run_mysqltest ($) { ...@@ -2706,7 +2738,7 @@ sub run_mysqltest ($) {
if ( $glob_use_embedded_server ) if ( $glob_use_embedded_server )
{ {
mysqld_arguments($args,'master',0,$tinfo->{'master_opt'},[]); mysqld_arguments($args,'master',0,$tinfo->{'master_opt'},[],0);
} }
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment