⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql-test-run.pl

📁 开启mysql的远程连接的方法 mysql-noinstall-5.1.6-alpha-win32.zip
💻 PL
📖 第 1 页 / 共 5 页
字号:
  my $instance_manager = shift;  im_create_passwd_file($instance_manager);  im_prepare_data_dir($instance_manager);}sub im_create_passwd_file($) {  my $instance_manager = shift;  my $pwd_file_path = $instance_manager->{'password_file'};    mtr_report("Creating IM password file ($pwd_file_path)");    open(OUT, ">", $pwd_file_path)    or mtr_error("Can't write to $pwd_file_path: $!");    print OUT $instance_manager->{'admin_login'}, ":",        $instance_manager->{'admin_sha1'}, "\n";    close(OUT);}sub im_create_defaults_file($) {  my $instance_manager = shift;  my $defaults_file = $instance_manager->{'defaults_file'};  open(OUT, ">", $defaults_file)    or mtr_error("Can't write to $defaults_file: $!");    print OUT <<EOF[mysql][manager]pid-file            = $instance_manager->{path_pid}socket              = $instance_manager->{path_sock}port                = $instance_manager->{port}password-file       = $instance_manager->{password_file}default-mysqld-path = $exe_mysqldEOF;  foreach my $instance (@{$instance_manager->{'instances'}})  {    my $server_id = $instance->{'server_id'};    print OUT <<EOF[mysqld$server_id]socket              = $instance->{path_sock}pid-file            = $instance->{path_pid}port                = $instance->{port}datadir             = $instance->{path_datadir}log                 = $instance->{path_datadir}/mysqld$server_id.loglog-error           = $instance->{path_datadir}/mysqld$server_id.err.loglog-slow-queries    = $instance->{path_datadir}/mysqld$server_id.slow.loglanguage            = $path_languagecharacter-sets-dir  = $path_charsetsdirbasedir             = $path_my_basedirserver_id           =$server_idskip-stack-traceskip-innodbskip-bdbskip-ndbclusterEOF;    print OUT "nonguarded\n" if $instance->{'nonguarded'};    print OUT "log-output=FILE\n" if $instance->{'old_log_format'};    print OUT "\n";  }  close(OUT);}sub im_prepare_data_dir($) {  my $instance_manager = shift;  foreach my $instance (@{$instance_manager->{'instances'}})  {    install_db(      'im_mysqld_' . $instance->{'server_id'},      $instance->{'path_datadir'});  }}################################################################################  Run a single test case################################################################################ When we get here, we have already filtered out test cases that doesn't# apply to the current setup, for example if we use a running server, test# cases that restart the server are dropped. So this function should mostly# be about doing things, not a lot of logic.# We don't start and kill the servers for each testcase. But some# testcases needs a restart, because they specify options to start# mysqld with. After that testcase, we need to restart again, to set# back the normal options.sub run_testcase ($) {  my $tinfo=  shift;  my $tname= $tinfo->{'name'};  my $ndbcluster_opt;  mtr_tonewfile($opt_current_test,"$tname\n"); # Always tell where we are  # output current test to ndbcluster log file to enable diagnostics  mtr_tofile($file_ndb_testrun_log,"CURRENT TEST $tname\n");  # ----------------------------------------------------------------------  # If marked to skip, just print out and return.  # Note that a test case not marked as 'skip' can still be  # skipped later, because of the test case itself in cooperation  # with the mysqltest program tells us so.  # ----------------------------------------------------------------------  if ( $tinfo->{'skip'} )  {    mtr_report_test_name($tinfo);    mtr_report_test_skipped($tinfo);    return;  }  # ----------------------------------------------------------------------  # If not using a running servers we may need to stop and restart.  # We restart in the case we have initiation scripts, server options  # etc to run. But we also restart again after the test first restart  # and test is run, to get back to normal server settings.  #  # To make the code a bit more clean, we actually only stop servers  # here, and mark this to be done. Then a generic "start" part will  # start up the needed servers again.  # ----------------------------------------------------------------------  if ( ! $glob_use_running_server and ! $glob_use_embedded_server )  {    if ( $tinfo->{'master_restart'} or         $master->[0]->{'running_master_is_special'} or         ( $tinfo->{'ndb_test'} != $using_ndbcluster_master ) )    {      stop_masters();      $master->[0]->{'running_master_is_special'}= 0; # Forget why we stopped    }    # ----------------------------------------------------------------------    # Always terminate all slaves, if any. Else we may have useless    # reconnection attempts and error messages in case the slave and    # master servers restart.    # ----------------------------------------------------------------------    stop_slaves();  }      # ----------------------------------------------------------------------  # Prepare to start masters. Even if we use embedded, we want to run  # the preparation.  # ----------------------------------------------------------------------  $ENV{'TZ'}= $tinfo->{'timezone'};  mtr_report_test_name($tinfo);  mtr_tofile($master->[0]->{'path_myerr'},"CURRENT_TEST: $tname\n");# FIXME test cases that depend on each other, prevent this from# being at this location.#  do_before_start_master($tname,$tinfo->{'master_sh'});  # ----------------------------------------------------------------------  # If any mysqld servers running died, we have to know  # ----------------------------------------------------------------------  mtr_record_dead_children();  # ----------------------------------------------------------------------  # Start masters  # ----------------------------------------------------------------------  if ( ! $glob_use_running_server and ! $glob_use_embedded_server )  {    # FIXME give the args to the embedded server?!    # FIXME what does $opt_local_master mean?!    # FIXME split up start and check that started so that can do    #       starts in parallel, masters and slaves at the same time.    if ( $tinfo->{'component_id'} eq 'mysqld' and ! $opt_local_master )    {      if ( $master->[0]->{'ndbcluster'} )      {	$master->[0]->{'ndbcluster'}= ndbcluster_start($tinfo->{'ndb_test'});        if ( $master->[0]->{'ndbcluster'} )        {          report_failure_and_restart($tinfo);          return;        }      }      if ( ! $master->[0]->{'pid'} )      {        # FIXME not correct location for do_before_start_master()        do_before_start_master($tname,$tinfo->{'master_sh'});        $master->[0]->{'pid'}=          mysqld_start('master',0,$tinfo->{'master_opt'},[],		       $using_ndbcluster_master);        if ( ! $master->[0]->{'pid'} )        {          report_failure_and_restart($tinfo);          return;        }      }      if ( $using_ndbcluster_master and ! $master->[1]->{'pid'} )      {        $master->[1]->{'pid'}=          mysqld_start('master',1,$tinfo->{'master_opt'},[],		       $using_ndbcluster_master);        if ( ! $master->[1]->{'pid'} )        {          report_failure_and_restart($tinfo);          return;        }      }      if ( $tinfo->{'master_restart'} )      {        $master->[0]->{'running_master_is_special'}= 1;      }    }    elsif ( ! $opt_skip_im and $tinfo->{'component_id'} eq 'im' )    {      # We have to create defaults file every time, in order to ensure that it      # will be the same for each test. The problem is that test can change the      # file (by SET/UNSET commands), so w/o recreating the file, execution of      # one test can affect the other.      im_create_defaults_file($instance_manager);      im_start($instance_manager, $tinfo->{im_opts});    }    # ----------------------------------------------------------------------    # Start slaves - if needed    # ----------------------------------------------------------------------    if ( $tinfo->{'slave_num'} )    {      mtr_tofile($slave->[0]->{'path_myerr'},"CURRENT_TEST: $tname\n");      do_before_start_slave($tname,$tinfo->{'slave_sh'});      for ( my $idx= 0; $idx <  $tinfo->{'slave_num'}; $idx++ )      {        if ( ! $slave->[$idx]->{'pid'} )        {	  $ndbcluster_opt= 0;          if ( $idx == 0)	  {	    if ( $slave->[0]->{'ndbcluster'} )	    {	      $slave->[0]->{'ndbcluster'}=		ndbcluster_start_slave($tinfo->{'ndb_test'});	      if ( $slave->[0]->{'ndbcluster'} )	      {		report_failure_and_restart($tinfo);		return;	      }	    }	    $ndbcluster_opt= $using_ndbcluster_slave;	  }          $slave->[$idx]->{'pid'}=            mysqld_start('slave',$idx,                         $tinfo->{'slave_opt'}, $tinfo->{'slave_mi'},			 $ndbcluster_opt);          if ( ! $slave->[$idx]->{'pid'} )          {            report_failure_and_restart($tinfo);            return;          }        }      }    }  }  # ----------------------------------------------------------------------  # If --start-and-exit given, stop here to let user manually run tests  # ----------------------------------------------------------------------  if ( $opt_start_and_exit )  {    mtr_report("\nServers started, exiting");    exit(0);  }  # ----------------------------------------------------------------------  # Run the test case  # ----------------------------------------------------------------------  {    # remove the old reject file    if ( $opt_suite eq "main" )    {      unlink("r/$tname.reject");    }    else    {      unlink("suite/$opt_suite/r/$tname.reject");    }    unlink($path_timefile);    my $res= run_mysqltest($tinfo);    if ( $res == 0 )    {      mtr_report_test_passed($tinfo);    }    elsif ( $res == 62 )    {      # Testcase itself tell us to skip this one      mtr_report_test_skipped($tinfo);    }    elsif ( $res == 63 )    {      $tinfo->{'timeout'}= 1;           # Mark as timeout      report_failure_and_restart($tinfo);    }    else    {      # Test case failed, if in control mysqltest returns 1      if ( $res != 1 )      {        mtr_tofile($path_timefile,                   "mysqltest returned unexpected code $res, " .                   "it has probably crashed");      }      report_failure_and_restart($tinfo);    }    # Save info from this testcase run to mysqltest.log    mtr_tofile($path_mysqltest_log,"CURRENT TEST $tname\n");    my $testcase_log= mtr_fromfile($path_timefile);    mtr_tofile($path_mysqltest_log,	       $testcase_log);  }  # ----------------------------------------------------------------------  # Stop Instance Manager if we are processing an IM-test case.  # ----------------------------------------------------------------------  if ( ! $glob_use_running_server and $tinfo->{'component_id'} eq 'im' and       $instance_manager->{'pid'} )  {    im_stop($instance_manager);  }}sub report_failure_and_restart ($) {  my $tinfo= shift;  mtr_report_test_failed($tinfo);  mtr_show_failed_diff($tinfo->{'name'});  print "\n";  if ( ! $opt_force )  {    my $test_mode= join(" ", @::glob_test_mode) || "default";    print "Aborting: $tinfo->{'name'} failed in $test_mode mode. ";    print "To continue, re-run with '--force'.\n";    if ( ! $opt_gdb and ! $glob_use_running_server and         ! $opt_ddd and ! $glob_use_embedded_server )    {      stop_masters_slaves();    }    mtr_exit(1);  }  # FIXME always terminate on failure?!  if ( ! $opt_gdb and ! $glob_use_running_server and       ! $opt_ddd and ! $glob_use_embedded_server )  {    stop_masters_slaves();  }  print "Resuming Tests\n\n";}################################################################################  Start and stop servers################################################################################ The embedded server needs the cleanup so we do some of the start work# but stop before actually running mysqld or anything.sub do_before_start_master ($$) {  my $tname=       shift;  my $init_script= shift;  # FIXME what about second master.....  # Remove stale binary logs except for 2 tests which need them FIXME here????  if ( $tname ne "rpl_crash_binlog_ib_1b" and       $tname ne "rpl_crash_binlog_ib_2b" and       $tname ne "rpl_crash_binlog_ib_3b")  {    # FIXME we really want separate dir for binlogs    foreach my $bin ( glob("$opt_vardir/log/master*-bin*") )    {      unlink($bin);    }  }  # FIXME only remove the ones that are tied to this master  # Remove old master.info and relay-log.info files  unlink("$master->[0]->{'path_myddir'}/master.info");  unlink("$master->[0]->{'path_myddir'}/relay-log.info");  unlink("$master->[1]->{'path_myddir'}/master.info");  unlink("$master->[1]->{'path_myddir'}/relay-log.info");  # Run master initialization shell script if one exists  if ( $init_script )  {    my $ret= mtr_run("/bin/sh", [$init_script], "", "", "", "");    if ( $ret != 0 )    {      # FIXME rewrite those scripts to return 0 if successful#      mtr_warning("$init_script exited with code $ret");    }  }  # for gcov  FIXME needed? If so we need more absolute paths# chdir($glob_basedir);}sub do_before_start_slave ($$) {  my $tname=       shift;  my $

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -