Commit c95482d4 authored by unknown's avatar unknown
Browse files

Port cleanups, trivial refactoring and code rearrangements from

Alik's patch for BUG#22306: STOP INSTANCE can not be applied for 
instances in Crashed, Failed and Abandoned" to ease review process.
Evaluate global variable linuxthreads before starting threads to avoid
a race.


server-tools/instance-manager/buffer.cc:
  Fix spelling.
server-tools/instance-manager/command.h:
  Fix spelling.
server-tools/instance-manager/commands.cc:
  Fix spelling.
server-tools/instance-manager/commands.h:
  Fix spelling, tidy up.
server-tools/instance-manager/guardian.cc:
  Cleanup logging, options.get_shutdown_delay() is a method, tidy up.
server-tools/instance-manager/instance.cc:
  Rearrange methods to be the same as in Alik's patch, fix spelling errors,
  clean up logging texts, port comments from Alik's patch, 
  implement some basic renames from his patch.
  No real changes.
server-tools/instance-manager/instance.h:
  Tidy up, renames.
server-tools/instance-manager/instance_map.cc:
  Fix spellings, port some refactoring from Alik's patch.
server-tools/instance-manager/instance_map.h:
  Cleanup.
server-tools/instance-manager/instance_options.cc:
  Cleanup. Implement Instance_options::get_shutdown_delay() and
  Instance_options::get_mysqld_port().
server-tools/instance-manager/instance_options.h:
  Cleanup.
server-tools/instance-manager/listener.cc:
  Cleanup.
server-tools/instance-manager/log.cc:
  Fix spelling.
server-tools/instance-manager/manager.cc:
  Cleanup.
server-tools/instance-manager/manager.h:
  Add getters for Manager members.
server-tools/instance-manager/mysqlmanager.cc:
  Evaluate linuxthreads before starting threads to avoid a race.
server-tools/instance-manager/parse_output.cc:
  Fix spelling.
server-tools/instance-manager/priv.cc:
  Cleanup.
server-tools/instance-manager/priv.h:
  Cleanup.
server-tools/instance-manager/user_management_commands.cc:
  Fix spelling.
server-tools/instance-manager/user_management_commands.h:
  Fix spelling.
server-tools/instance-manager/user_map.cc:
  Fix spelling.
parent 08df0556
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ const uint Buffer::MAX_BUFFER_SIZE= 16777216;
/*
  Puts the given string to the buffer.

  SYNOPSYS
  SYNOPSIS
    append()
    position          start position in the buffer
    string            string to be put in the buffer
@@ -59,7 +59,7 @@ int Buffer::append(uint position, const char *string, uint len_arg)
  Checks whether the current buffer size is ok to put a string of the length
  "len_arg" starting from "position" and reallocs it if no.

  SYNOPSYS
  SYNOPSIS
    reserve()
    position          the number starting byte on the buffer to store a buffer
    len_arg           the length of the string.
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ class Command
  /*
    This operation incapsulates behaviour of the command.

    SYNOPSYS
    SYNOPSIS
      net             The network connection to the client.
      connection_id   Client connection ID

+6 −6
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ static const int modify_defaults_to_im_error[]= { 0, ER_OUT_OF_RESOURCES,
/*
  Add a string to a buffer.

  SYNOPSYS
  SYNOPSIS
    put_to_buff()
    buff              buffer to add the string
    str               string to add
@@ -590,7 +590,7 @@ Create_instance::Create_instance(const LEX_STRING *instance_name_arg)
/*
  This operation initializes Create_instance object.

  SYNOPSYS
  SYNOPSIS
    text            [IN/OUT] a pointer to the text containing instance options.

  RETURN
@@ -607,7 +607,7 @@ bool Create_instance::init(const char **text)
/*
  This operation parses CREATE INSTANCE options.

  SYNOPSYS
  SYNOPSIS
    text            [IN/OUT] a pointer to the text containing instance options.

  RETURN
@@ -1255,7 +1255,7 @@ bool Abstract_option_cmd::init(const char **text)
  Correct the option file. The "skip" option is used to remove the found
  option.

  SYNOPSYS
  SYNOPSIS
  Abstract_option_cmd::correct_file()
    skip     Skip the option, being searched while writing the result file.
             That is, to delete it.
@@ -1395,7 +1395,7 @@ int Abstract_option_cmd::execute_impl(st_net *net, ulong connection_id)
/*
  This operation parses SET options.

  SYNOPSYS
  SYNOPSIS
    text            [IN/OUT] a pointer to the text containing options.

  RETURN
@@ -1569,7 +1569,7 @@ int Set_option::process_option(Instance *instance, Named_value *option)
/*
  This operation parses UNSET options.

  SYNOPSYS
  SYNOPSIS
    text            [IN/OUT] a pointer to the text containing options.

  RETURN
+3 −23
Original line number Diff line number Diff line
@@ -32,15 +32,11 @@

/*
  Print all instances of this instance manager.
  Grammar: SHOW ISTANCES
  Grammar: SHOW INSTANCES
*/

class Show_instances: public Command
{
public:
  Show_instances()
  { }

public:
  int execute(st_net *net, ulong connection_id);

@@ -57,10 +53,6 @@ class Show_instances : public Command

class Flush_instances : public Command
{
public:
  Flush_instances()
  { }

public:
  int execute(st_net *net, ulong connection_id);
};
@@ -103,7 +95,7 @@ class Abstract_instance_cmd : public Command

/*
  Print status of an instance.
  Grammar: SHOW ISTANCE STATUS <instance_name>
  Grammar: SHOW INSTANCE STATUS <instance_name>
*/

class Show_instance_status : public Abstract_instance_cmd
@@ -319,10 +311,6 @@ class Abstract_option_cmd : public Command

class Set_option : public Abstract_option_cmd
{
public:
  Set_option()
  { }

protected:
  virtual bool parse_args(const char **text);
  virtual int process_option(Instance *instance, Named_value *option);
@@ -336,10 +324,6 @@ class Set_option : public Abstract_option_cmd

class Unset_option: public Abstract_option_cmd
{
public:
  Unset_option()
  { }

protected:
  virtual bool parse_args(const char **text);
  virtual int process_option(Instance *instance, Named_value *option);
@@ -357,10 +341,6 @@ class Unset_option: public Abstract_option_cmd

class Syntax_error : public Command
{
public:
  Syntax_error()
  { }

public:
  int execute(st_net *net, ulong connection_id);
};
+16 −25
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ Guardian::~Guardian()
void Guardian::request_shutdown()
{
  pthread_mutex_lock(&LOCK_guardian);
  /* stop instances or just clean up Guardian repository */
  /* STOP Instances or just clean up Guardian repository */
  stop_instances();
  shutdown_requested= TRUE;
  pthread_mutex_unlock(&LOCK_guardian);
@@ -110,23 +110,14 @@ void Guardian::process_instance(Instance *instance,

  if (current_node->state == STOPPING)
  {
    /* this branch is executed during shutdown */
    if (instance->options.shutdown_delay)
    {
      /*
        NOTE: it is important to check shutdown_delay here, but use
        shutdown_delay_val. The idea is that if the option is unset,
        shutdown_delay will be NULL, but shutdown_delay_val will not be reset.
      */
      waitchild= instance->options.shutdown_delay_val;
    }
    waitchild= instance->options.get_shutdown_delay();

    /* this returns TRUE if and only if an instance was stopped for sure */
    if (instance->is_crashed())
      *guarded_instances= list_delete(*guarded_instances, node);
    else if ( (uint) (current_time - current_node->last_checked) > waitchild)
    {
      instance->kill_instance(SIGKILL);
      instance->kill_mysqld(SIGKILL);
      /*
        Later we do node= node->next. This is ok, as we are only removing
        the node from the list. The pointer to the next one is still valid.
@@ -137,20 +128,20 @@ void Guardian::process_instance(Instance *instance,
    return;
  }

  if (instance->is_running())
  if (instance->is_mysqld_running())
  {
    /* The instance can be contacted  on it's port */

    /* If STARTING also check that pidfile has been created */
    if (current_node->state == STARTING &&
        current_node->instance->options.get_pid() == 0)
        current_node->instance->options.load_pid() == 0)
    {
      /* Pid file not created yet, don't go to STARTED state yet  */
    }
    else if (current_node->state != STARTED)
    {
      /* clear status fields */
      log_info("guardian: instance '%s' is running, set state to STARTED.",
      log_info("Guardian: '%s' is running, set state to STARTED.",
               (const char *) instance->options.instance_name.str);
      current_node->restart_counter= 0;
      current_node->crash_moment= 0;
@@ -161,7 +152,7 @@ void Guardian::process_instance(Instance *instance,
  {
    switch (current_node->state) {
    case NOT_STARTED:
      log_info("guardian: starting instance '%s'...",
      log_info("Guardian: starting '%s'...",
               (const char *) instance->options.instance_name.str);

      /* NOTE, set state to STARTING _before_ start() is called */
@@ -186,7 +177,7 @@ void Guardian::process_instance(Instance *instance,
        if (instance->is_crashed())
        {
          instance->start();
          log_info("guardian: starting instance '%s'...",
          log_info("Guardian: starting '%s'...",
                   (const char *) instance->options.instance_name.str);
        }
      }
@@ -204,14 +195,15 @@ void Guardian::process_instance(Instance *instance,
            instance->start();
            current_node->last_checked= current_time;
            current_node->restart_counter++;
            log_info("guardian: restarting instance '%s'...",
            log_info("Guardian: restarting '%s'...",
                     (const char *) instance->options.instance_name.str);
          }
        }
        else
        {
          log_info("guardian: cannot start instance %s. Abandoning attempts "
                   "to (re)start it", instance->options.instance_name.str);
          log_info("Guardian: can not start '%s'. "
                   "Abandoning attempts to (re)start it",
                   (const char *) instance->options.instance_name.str);
          current_node->state= CRASHED_AND_ABANDONED;
        }
      }
@@ -226,13 +218,12 @@ void Guardian::process_instance(Instance *instance,


/*
  Run guardian thread
  Main function of Guardian thread.

  SYNOPSIS
    run()

  DESCRIPTION

    Check for all guarded instances and restart them if needed. If everything
    is fine go and sleep for some time.
*/
@@ -436,7 +427,7 @@ int Guardian::stop_instances()
      If instance is running or was running (and now probably hanging),
      request stop.
    */
    if (current_node->instance->is_running() ||
    if (current_node->instance->is_mysqld_running() ||
        (current_node->state == STARTED))
    {
      current_node->state= STOPPING;
@@ -446,7 +437,7 @@ int Guardian::stop_instances()
      /* otherwise remove it from the list */
      guarded_instances= list_delete(guarded_instances, node);
    /* But try to kill it anyway. Just in case */
    current_node->instance->kill_instance(SIGTERM);
    current_node->instance->kill_mysqld(SIGTERM);
    node= node->next;
  }
  return 0;
@@ -499,5 +490,5 @@ bool Guardian::is_active(Instance *instance)
  if (guarded)
    return true;

  return instance->is_running();
  return instance->is_mysqld_running();
}
Loading