Commit fa1e23d9 authored by unknown's avatar unknown
Browse files

Merge bk-internal.mysql.com:/home/bk/mysql-5.0-runtime

into  mysql.com:/home/dlenev/mysql-5.0-bg12472

parents 82727c62 2038148c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ sub mtr_record_dead_children ();
sub mtr_exit ($);
sub sleep_until_file_created ($$$);
sub mtr_kill_processes ($);
sub mtr_kill_process ($$$$);

# static in C
sub spawn_impl ($$$$$$$$);
@@ -885,6 +886,25 @@ sub mtr_kill_processes ($) {
  }
}


sub mtr_kill_process ($$$$) {
  my $pid= shift;
  my $signal= shift;
  my $retries= shift;
  my $timeout= shift;

  while (1)
  {
    kill($signal, $pid);

    last unless kill (0, $pid) and $retries--;

    mtr_debug("Sleep $timeout second waiting for processes to die");

    sleep($timeout);
  }
}

##############################################################################
#
#  When we exit, we kill off all children
+73 −13
Original line number Diff line number Diff line
@@ -924,6 +924,7 @@ sub command_line_setup () {
   path_err =>        "$opt_vardir/log/im.err",
   path_log =>        "$opt_vardir/log/im.log",
   path_pid =>        "$opt_vardir/run/im.pid",
   path_angel_pid =>  "$opt_vardir/run/im.angel.pid",
   path_sock =>       "$sockdir/im.sock",
   port =>            $im_port,
   start_timeout =>   $master->[0]->{'start_timeout'},
@@ -1179,6 +1180,7 @@ sub environment_setup () {
  $ENV{'NDB_STATUS_OK'}=      "YES";

  $ENV{'IM_PATH_PID'}=        $instance_manager->{path_pid};
  $ENV{'IM_PATH_ANGEL_PID'}=  $instance_manager->{path_angel_pid};
  $ENV{'IM_PORT'}=            $instance_manager->{port};

  $ENV{'IM_MYSQLD1_SOCK'}=    $instance_manager->{instances}->[0]->{path_sock};
@@ -1803,6 +1805,7 @@ sub im_create_defaults_file($) {

[manager]
pid-file            = $instance_manager->{path_pid}
angel-pid-file      = $instance_manager->{path_angel_pid}
socket              = $instance_manager->{path_sock}
port                = $instance_manager->{port}
password-file       = $instance_manager->{password_file}
@@ -2786,6 +2789,18 @@ sub im_start($$) {
sub im_stop($) {
  my $instance_manager = shift;

  # Obtain mysqld-process pids before we start stopping IM (it can delete pid
  # files).

  my @mysqld_pids = ();
  my $instances = $instance_manager->{'instances'};

  push(@mysqld_pids, mtr_get_pid_from_file($instances->[0]->{'path_pid'}))
    if -r $instances->[0]->{'path_pid'};

  push(@mysqld_pids, mtr_get_pid_from_file($instances->[1]->{'path_pid'}))
    if -r $instances->[1]->{'path_pid'};

  # Re-read pid from the file, since during tests Instance Manager could have
  # been restarted, so its pid could have been changed.

@@ -2793,34 +2808,79 @@ sub im_stop($) {
    mtr_get_pid_from_file($instance_manager->{'path_pid'})
      if -f $instance_manager->{'path_pid'};

  if (-f $instance_manager->{'path_angel_pid'})
  {
    $instance_manager->{'angel_pid'} =
      mtr_get_pid_from_file($instance_manager->{'path_angel_pid'})
  }
  else
  {
    $instance_manager->{'angel_pid'} = undef;
  }

  # Inspired from mtr_stop_mysqld_servers().

  start_reap_all();

  # Create list of pids. We should stop Instance Manager and all started
  # mysqld-instances. Some of them may be nonguarded, so IM will not stop them
  # on shutdown.
  # Try graceful shutdown.

  my @pids = ( $instance_manager->{'pid'} );
  my $instances = $instance_manager->{'instances'};
  mtr_kill_process($instance_manager->{'pid'}, 'TERM', 10, 1);

  if ( -r $instances->[0]->{'path_pid'} )
  # Check that all processes died.

  my $clean_shutdown= 0;

  while (1)
  {
    push(@pids, mtr_get_pid_from_file($instances->[0]->{'path_pid'}));
  }
    last if kill (0, $instance_manager->{'pid'});

  if ( -r $instances->[1]->{'path_pid'} )
    last if (defined $instance_manager->{'angel_pid'}) &&
            kill (0, $instance_manager->{'angel_pid'});

    foreach my $pid (@mysqld_pids)
    {
    push(@pids, mtr_get_pid_from_file($instances->[1]->{'path_pid'}));
      last if kill (0, $pid);
    }

    $clean_shutdown= 1;
    last;
  }

  # Kill processes.
  # Kill leftovers (the order is important).

  unless ($clean_shutdown)
  {
    mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1)
      if defined $instance_manager->{'angel_pid'};
    
    mtr_kill_process($instance_manager->{'pid'}, 'KILL', 10, 1);

    # Shutdown managed mysqld-processes. Some of them may be nonguarded, so IM
    # will not stop them on shutdown. So, we should firstly try to end them
    # legally.

    mtr_kill_processes(\@mysqld_pids);

    # Complain in error log so that a warning will be shown.

    my $errlog= "$opt_vardir/log/mysql-test-run.pl.err";

    open (ERRLOG, ">>$errlog") ||
      mtr_error("Can not open error log ($errlog)");

    my $ts= localtime();
    print ERRLOG
      "Warning: [$ts] Instance Manager did not shutdown gracefully.\n";

    close ERRLOG;
  }

  mtr_kill_processes(\@pids);
  # That's all.

  stop_reap_all();

  $instance_manager->{'pid'} = undef;
  $instance_manager->{'angel_pid'} = undef;
}


+9 −4
Original line number Diff line number Diff line
@@ -35,12 +35,12 @@
#endif


static int create_pid_file(const char *pid_file_name)
int create_pid_file(const char *pid_file_name, int pid)
{
  if (FILE *pid_file= my_fopen(pid_file_name,
                               O_WRONLY | O_CREAT | O_BINARY, MYF(0)))
  {
    fprintf(pid_file, "%d\n", (int) getpid());
    fprintf(pid_file, "%d\n", (int) pid);
    my_fclose(pid_file, MYF(0));
    return 0;
  }
@@ -138,8 +138,13 @@ void manager(const Options &options)
  if (user_map.load(options.password_file_name))
    return;

  /* write pid file */
  if (create_pid_file(options.pid_file_name))
  /* write Instance Manager pid file */

  log_info("IM pid file: '%s'; PID: %d.",
           (const char *) options.pid_file_name,
           (int) manager_pid);

  if (create_pid_file(options.pid_file_name, manager_pid))
    return;

  sigset_t mask;
+2 −0
Original line number Diff line number Diff line
@@ -20,4 +20,6 @@ struct Options;

void manager(const Options &options);

int create_pid_file(const char *pid_file_name, int pid);

#endif // INCLUDES_MYSQL_INSTANCE_MANAGER_MANAGER_H
+8 −0
Original line number Diff line number Diff line
@@ -338,6 +338,14 @@ static void angel(const Options &options)
    /* Here we return to main, and fall into manager */
    break;
  default:                                    // parent, success
    pid= getpid(); /* Get our pid. */

    log_info("Angel pid file: '%s'; PID: %d.",
             (const char *) options.angel_pid_file_name,
             (int) pid);

    create_pid_file(Options::angel_pid_file_name, pid);

    while (child_status == CHILD_OK && is_terminated == 0)
      sigsuspend(&zeromask);

Loading