Commit 26b6b1b2 authored by unknown's avatar unknown
Browse files

Cleanup the instance manager code.


BitKeeper/deleted/.del-factory.h~c1679505d3a6dd53:
  Delete: server-tools/instance-manager/factory.h
BitKeeper/deleted/.del-factory.cc~6836cccd4cd35b4d:
  Delete: server-tools/instance-manager/factory.cc
server-tools/instance-manager/Makefile.am:
  - remove Commands_factory: it'll be needed when we add support
  for NNTP/HTTP connections, currently it only adds unnecessary
  complexity.
server-tools/instance-manager/commands.cc:
  - fix coding style: no else after return; fix comments, make
  one place a bit faster.
server-tools/instance-manager/guardian.cc:
  - fix coding style and comments.
  - we must register the current thread in the thread registry
    before entering pthread_cond_timedwait, because at shutdown
    the thread registry will try to kick out of wait all blocked 
    threads. Unregistered threads are not awakened by the registry. 
    This fixes the failinig assert in Thread_registry::~Thread_registry
    at shutdown, when shutdown is requested and there is an
    instance monitored by Guardian.
server-tools/instance-manager/guardian.h:
  - fix coding style: enums must start with enum_
server-tools/instance-manager/instance.h:
  - move comment to the variable it comments
server-tools/instance-manager/instance_map.cc:
  - cleanup
server-tools/instance-manager/instance_options.cc:
  - cleanup; no else after return (fix coding style).
server-tools/instance-manager/manager.cc:
  - fix alignment; make some code easier to read.
server-tools/instance-manager/mysql_connection.cc:
  - remove Commands_factory
server-tools/instance-manager/options.cc:
  - fix a possible crash when the instance manager is started with
  --no-defaults --defaults-file=~/.my.cnf: if we return
  without cloning saved_argv by calling load_defaults, Options::cleanup
  will crash on attempt to free_defaults(saved_argv);
server-tools/instance-manager/parse.cc:
  - get rid of Commands_factory
server-tools/instance-manager/parse.h:
  - get rid of Commands_factory
server-tools/instance-manager/parse_output.cc:
  - in parse_output_and_get_value return error also if the specified
    pattern was not found, or the command failed to execute.
server-tools/instance-manager/portability.h:
  - fix coding style (// comments are allowed only at ends of lines)
server-tools/instance-manager/thread_registry.cc:
  - implement Thread_registry::cond_timedwait
server-tools/instance-manager/thread_registry.h:
  - implement Thread_registry::cond_timedwait; remove
    unused out parameter from Thread_registry::cond_wait.
server-tools/instance-manager/user_map.cc:
  - safety: newline can take 2 bytes.
parent 7efa8d9b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ mysqlmanager_SOURCES= command.cc command.h mysqlmanager.cc \
			user_map.h user_map.cc \
			messages.h messages.cc \
			commands.h commands.cc \
			factory.h factory.cc \
			instance.h instance.cc \
			instance_map.h instance_map.cc\
			instance_options.h instance_options.cc \
+21 −31
Original line number Diff line number Diff line
@@ -461,7 +461,8 @@ int Show_instance_log::execute(struct st_net *net, ulong connection_id)
    /* Instance has no such log */
    if (logpath == NULL)
      return ER_NO_SUCH_LOG;
    else if (*logpath == '\0')

    if (*logpath == '\0')
      return ER_GUESS_LOGFILE;


@@ -571,6 +572,7 @@ int Show_instance_log_files::execute(struct st_net *net, ulong connection_id)
  if ((instance= instance_map->
                 find(instance_name, strlen(instance_name))) == NULL)
    goto err;

  {
    /*
      We have alike structure in instance_options.cc. We use such to be able
@@ -686,7 +688,7 @@ Set_option::Set_option(Instance_map *instance_map_arg,
  option.

  RETURN
    ER_BAD_INSTANCE_NAME    The instance name specified is not valid
    ER_OUT_OF_RESOURCES     out of resources
    ER_ACCESS_OPTION_FILE   Cannot access the option file
    0 - ok
*/
@@ -694,22 +696,14 @@ Set_option::Set_option(Instance_map *instance_map_arg,
int Set_option::correct_file(int skip)
{
  int error;
  const static int mysys_to_im_error[]= { 0, ER_OUT_OF_RESOURCES,
                                             ER_ACCESS_OPTION_FILE };

  error= modify_defaults_file(Options::config_file, option,
                              option_value, instance_name, skip);
  switch (error)
  {
  case 0:
    return 0;                                   /* everything was fine */
  case 1:
    return ER_OUT_OF_RESOURCES;
  case 2:
    return ER_ACCESS_OPTION_FILE;
  default:
    DBUG_ASSERT(0);                           /* should never get here */
  }
  DBUG_ASSERT(error >= 0 && error <= 2);

  return 0;                                   /* keep compiler happy */
  return mysys_to_im_error[error];
}


@@ -725,10 +719,9 @@ int Set_option::correct_file(int skip)
    1 - error occured
*/


int Set_option::do_command(struct st_net *net)
{
  int error= 0;
  int error;

  /* we must hold the instance_map mutex while changing config file */
  instance_map->lock();
@@ -746,15 +739,13 @@ int Set_option::execute(struct st_net *net, ulong connection_id)
    int val;

    val= do_command(net);

    if (val == 0)
    {
      net_send_ok(net, connection_id, NULL);
      return 0;
    }

    return val;
  }
  else

  return ER_BAD_INSTANCE_NAME;
}

@@ -785,17 +776,16 @@ int Stop_instance::execute(struct st_net *net, ulong connection_id)

  if (instance == 0)
    return ER_BAD_INSTANCE_NAME; /* haven't found an instance */
  else
  {

  if (!(instance->options.nonguarded))
        instance_map->guardian->
               stop_guard(instance);
    instance_map->guardian->stop_guard(instance);

  if ((err_code= instance->stop()))
    return err_code;

  net_send_ok(net, connection_id, NULL);
  return 0;
}
}


int Syntax_error::execute(struct st_net *net, ulong connection_id)
+0 −100
Original line number Diff line number Diff line
/* Copyright (C) 2004 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "factory.h"


Show_instances *Command_factory::new_Show_instances()
{
  return new Show_instances(&instance_map);
}


Flush_instances *Command_factory::new_Flush_instances()
{
  return new Flush_instances(&instance_map);
}


Show_instance_status *Command_factory::
                      new_Show_instance_status(const char *name, uint len)
{
  return new Show_instance_status(&instance_map, name, len);
}


Show_instance_options *Command_factory::
                       new_Show_instance_options(const char *name, uint len)
{
  return new Show_instance_options(&instance_map, name, len);
}


Start_instance *Command_factory::
                new_Start_instance(const char *name, uint len)
{
  return new Start_instance(&instance_map, name, len);
}


Stop_instance *Command_factory::new_Stop_instance(const char *name, uint len)
{
  return new Stop_instance(&instance_map, name, len);
}


Syntax_error *Command_factory::new_Syntax_error()
{
  return new Syntax_error();
}


Set_option *Command_factory::
            new_Set_option(const char* name, uint len,
                           const char *option_arg, uint option_len,
                           const char *option_value_arg, uint option_value_len)
{
  return new Set_option(&instance_map, name, len, option_arg,
                        option_len, option_value_arg, option_value_len);
}


Unset_option *Command_factory::
            new_Unset_option(const char* name, uint len,
                             const char *option_arg, uint option_len,
                             const char *option_value_arg, uint option_value_len)
{
  return new Unset_option(&instance_map, name, len, option_arg,
                          option_len, option_value_arg, option_value_len);
}


Show_instance_log *Command_factory::
                   new_Show_instance_log(const char *name, uint len,
                                         Log_type log_type_arg,
                                         const char *size, const char *offset)
{
  return new Show_instance_log(&instance_map, name, len,
                               log_type_arg, size, offset);
}


Show_instance_log_files *Command_factory::
                       new_Show_instance_log_files(const char *name, uint len)
{
  return new Show_instance_log_files(&instance_map, name, len);
}
+0 −61
Original line number Diff line number Diff line
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_FACTORY_H
#define INCLUDES_MYSQL_INSTANCE_MANAGER_FACTORY_H
/* Copyright (C) 2004 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "command.h"
#include "commands.h"
#include "instance_map.h"

/*
  This class could be used to handle various protocols. We could pass to
  the parser various derived classes. I.e Mylsq_command_factory,
  Http_command_factory e.t.c. Also see comment in the instance_map.cc
*/

class Show_instances;

class Command_factory
{
public:
  Command_factory(Instance_map &instance_map): instance_map(instance_map)
  {}

  Show_instances        *new_Show_instances        ();
  Flush_instances       *new_Flush_instances       ();
  Syntax_error          *new_Syntax_error          ();
  Show_instance_status  *new_Show_instance_status  (const char *name, uint len);
  Show_instance_options *new_Show_instance_options (const char *name, uint len);
  Start_instance        *new_Start_instance        (const char *name, uint len);
  Stop_instance         *new_Stop_instance         (const char *name, uint len);
  Show_instance_log *new_Show_instance_log (const char *name, uint len,
                                            Log_type log_type_arg,
                                            const char *size,
                                            const char *offset);
  Set_option *new_Set_option (const char *name, uint len,
                              const char *option_arg, uint option_len,
                              const char *option_value_arg,
                              uint option_value_len);
  Unset_option *new_Unset_option (const char *name, uint len,
                                  const char *option_arg, uint option_len,
                                  const char *option_value_arg,
                                  uint option_value_len);
  Show_instance_log_files *new_Show_instance_log_files (const char *name,
                                                        uint len);

  Instance_map &instance_map;
};
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_FACTORY_H */
+11 −8
Original line number Diff line number Diff line
@@ -122,8 +122,7 @@ void Guardian_thread::process_instance(Instance *instance,
  }
  else
  {
    switch (current_node->state)
    {
    switch (current_node->state) {
    case NOT_STARTED:
      instance->start();
      current_node->last_checked= current_time;
@@ -149,7 +148,8 @@ void Guardian_thread::process_instance(Instance *instance,
        log_info("guardian: starting instance %s",
                 instance->options.instance_name);
      }
      else current_node->state= CRASHED;
      else
        current_node->state= CRASHED;
      break;
    case CRASHED:    /* just regular restarts */
      if (current_time - current_node->last_checked >
@@ -219,7 +219,8 @@ void Guardian_thread::run()

    /* check the loop predicate before sleeping */
    if (!(shutdown_requested && (!(guarded_instances))))
      pthread_cond_timedwait(&COND_guardian, &LOCK_guardian, &timeout);
      thread_registry.cond_timedwait(&thread_info, &COND_guardian,
                                     &LOCK_guardian, &timeout);
  }

  stopped= TRUE;
@@ -365,18 +366,20 @@ int Guardian_thread::stop_guard(Instance *instance)
}

/*
  Start Guardian shutdown. Attempt to start instances if requested.
  An internal method which is called at shutdown to unregister instances and
  attempt to stop them if requested.

  SYNOPSYS
    stop_instances()
    stop_instances_arg          whether we should stop instances at shutdown

  DESCRIPTION

    Loops through the guarded_instances list and prepares them for shutdown.
    If stop_instances was requested, we need to issue a stop command and change
    the state accordingly. Otherwise we could simply delete an entry.
    NOTE: Guardian should be locked by the calling function
    the state accordingly. Otherwise we simply delete an entry.

  NOTE
    Guardian object should be locked by the calling function.

  RETURN
    0 - ok
Loading