2004-10-23 11:32:52 +04:00
|
|
|
/* 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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
2005-09-23 21:28:56 +03:00
|
|
|
#if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION)
|
2004-10-23 11:32:52 +04:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "guardian.h"
|
|
|
|
#include <string.h>
|
2005-02-11 14:21:59 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
#include "instance.h"
|
|
|
|
#include "instance_map.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "mysql_manager_error.h"
|
2006-11-30 12:23:55 +03:00
|
|
|
#include "options.h"
|
2005-02-11 14:21:59 +03:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/*************************************************************************
|
|
|
|
{{{ Constructor & destructor.
|
|
|
|
*************************************************************************/
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Guardian constructor.
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
SYNOPSIS
|
|
|
|
Guardian()
|
|
|
|
thread_registry_arg
|
|
|
|
instance_map_arg
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
DESCRIPTION
|
|
|
|
Nominal contructor intended for assigning references and initialize
|
|
|
|
trivial objects. Real initialization is made by init() method.
|
|
|
|
*/
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
Guardian::Guardian(Thread_registry *thread_registry_arg,
|
2006-11-30 12:23:55 +03:00
|
|
|
Instance_map *instance_map_arg)
|
|
|
|
:shutdown_requested(FALSE),
|
|
|
|
stopped(FALSE),
|
2006-11-17 16:11:04 +03:00
|
|
|
thread_registry(thread_registry_arg),
|
2006-12-12 23:22:46 +03:00
|
|
|
instance_map(instance_map_arg)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
|
|
|
pthread_mutex_init(&LOCK_guardian, 0);
|
2005-01-25 13:54:56 +03:00
|
|
|
pthread_cond_init(&COND_guardian, 0);
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
Guardian::~Guardian()
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
/*
|
|
|
|
NOTE: it's necessary to synchronize here, because Guiardian thread can be
|
|
|
|
still alive an hold the mutex (because it is detached and we have no
|
|
|
|
control over it).
|
|
|
|
*/
|
|
|
|
|
|
|
|
lock();
|
|
|
|
unlock();
|
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
pthread_mutex_destroy(&LOCK_guardian);
|
2005-01-25 13:54:56 +03:00
|
|
|
pthread_cond_destroy(&COND_guardian);
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/*************************************************************************
|
|
|
|
}}}
|
|
|
|
*************************************************************************/
|
2006-11-17 16:11:04 +03:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Send request to stop Guardian.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
request_shutdown()
|
|
|
|
*/
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
void Guardian::request_shutdown()
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
{
|
2006-10-20 22:26:40 +04:00
|
|
|
stop_instances();
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
lock();
|
2005-02-11 14:21:59 +03:00
|
|
|
shutdown_requested= TRUE;
|
2006-11-30 12:23:55 +03:00
|
|
|
unlock();
|
|
|
|
|
|
|
|
ping();
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Process an instance.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
process_instance()
|
|
|
|
instance a pointer to the instance for processing
|
|
|
|
|
|
|
|
MT-NOTE:
|
|
|
|
- the given instance must be locked before calling this operation;
|
|
|
|
- Guardian must be locked before calling this operation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Guardian::process_instance(Instance *instance)
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
{
|
2005-02-11 14:21:59 +03:00
|
|
|
int restart_retry= 100;
|
|
|
|
time_t current_time= time(NULL);
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
if (instance->get_state() == Instance::STOPPING)
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
/* This brach is executed during shutdown. */
|
2005-02-11 14:21:59 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/* This returns TRUE if and only if an instance was stopped for sure. */
|
2005-02-11 14:21:59 +03:00
|
|
|
if (instance->is_crashed())
|
2005-02-27 18:41:34 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
log_info("Guardian: '%s' stopped.",
|
|
|
|
(const char *) instance->get_name()->str);
|
|
|
|
|
|
|
|
instance->set_state(Instance::STOPPED);
|
|
|
|
}
|
|
|
|
else if ((uint) (current_time - instance->last_checked) >=
|
|
|
|
instance->options.get_shutdown_delay())
|
|
|
|
{
|
|
|
|
log_info("Guardian: '%s' hasn't stopped within %d secs.",
|
|
|
|
(const char *) instance->get_name()->str,
|
|
|
|
(int) instance->options.get_shutdown_delay());
|
|
|
|
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
instance->kill_mysqld(SIGKILL);
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
log_info("Guardian: pretend that '%s' is killed.",
|
|
|
|
(const char *) instance->get_name()->str);
|
|
|
|
|
|
|
|
instance->set_state(Instance::STOPPED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_info("Guardian: waiting for '%s' to stop (%d secs left).",
|
|
|
|
(const char *) instance->get_name()->str,
|
|
|
|
(int) (instance->options.get_shutdown_delay() -
|
|
|
|
current_time + instance->last_checked));
|
2005-02-27 18:41:34 +03:00
|
|
|
}
|
2005-02-11 14:21:59 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
if (instance->is_mysqld_running())
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2006-09-25 09:28:52 +02:00
|
|
|
/* The instance can be contacted on it's port */
|
|
|
|
|
|
|
|
/* If STARTING also check that pidfile has been created */
|
2006-11-30 12:23:55 +03:00
|
|
|
if (instance->get_state() == Instance::STARTING &&
|
|
|
|
instance->options.load_pid() == 0)
|
2006-09-25 09:28:52 +02:00
|
|
|
{
|
|
|
|
/* Pid file not created yet, don't go to STARTED state yet */
|
|
|
|
}
|
2006-11-30 12:23:55 +03:00
|
|
|
else if (instance->get_state() != Instance::STARTED)
|
2006-09-25 09:28:52 +02:00
|
|
|
{
|
|
|
|
/* clear status fields */
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
log_info("Guardian: '%s' is running, set state to STARTED.",
|
2006-10-23 20:08:00 +04:00
|
|
|
(const char *) instance->options.instance_name.str);
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->reset_stat();
|
|
|
|
instance->set_state(Instance::STARTED);
|
2006-09-25 09:28:52 +02:00
|
|
|
}
|
2005-02-11 14:21:59 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
switch (instance->get_state()) {
|
|
|
|
case Instance::NOT_STARTED:
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
log_info("Guardian: starting '%s'...",
|
2006-10-23 20:08:00 +04:00
|
|
|
(const char *) instance->options.instance_name.str);
|
2006-09-25 09:28:52 +02:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/* NOTE: set state to STARTING _before_ start() is called. */
|
|
|
|
instance->set_state(Instance::STARTING);
|
|
|
|
instance->last_checked= current_time;
|
|
|
|
|
|
|
|
instance->start_mysqld();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Instance::STARTED: /* fallthrough */
|
|
|
|
case Instance::STARTING: /* let the instance start or crash */
|
|
|
|
if (!instance->is_crashed())
|
|
|
|
return;
|
|
|
|
|
|
|
|
instance->crash_moment= current_time;
|
|
|
|
instance->last_checked= current_time;
|
|
|
|
instance->set_state(Instance::JUST_CRASHED);
|
|
|
|
/* fallthrough -- restart an instance immediately */
|
|
|
|
|
|
|
|
case Instance::JUST_CRASHED:
|
|
|
|
if (current_time - instance->crash_moment <= 2)
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2006-05-29 17:30:30 +04:00
|
|
|
if (instance->is_crashed())
|
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->start_mysqld();
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
log_info("Guardian: starting '%s'...",
|
2006-10-23 20:08:00 +04:00
|
|
|
(const char *) instance->options.instance_name.str);
|
2006-05-29 17:30:30 +04:00
|
|
|
}
|
2005-02-11 14:21:59 +03:00
|
|
|
}
|
2005-08-29 23:29:35 +04:00
|
|
|
else
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->set_state(Instance::CRASHED);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Instance::CRASHED: /* just regular restarts */
|
|
|
|
if (current_time - instance->last_checked <=
|
|
|
|
Options::Main::monitoring_interval)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (instance->restart_counter < restart_retry)
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
if (instance->is_crashed())
|
2006-05-18 18:57:50 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->start_mysqld();
|
|
|
|
instance->last_checked= current_time;
|
|
|
|
|
|
|
|
log_info("Guardian: restarting '%s'...",
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
(const char *) instance->options.instance_name.str);
|
2006-05-18 18:57:50 +04:00
|
|
|
}
|
2005-02-11 14:21:59 +03:00
|
|
|
}
|
2006-11-30 12:23:55 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
log_info("Guardian: can not start '%s'. "
|
|
|
|
"Abandoning attempts to (re)start it",
|
|
|
|
(const char *) instance->options.instance_name.str);
|
|
|
|
|
|
|
|
instance->set_state(Instance::CRASHED_AND_ABANDONED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Instance::CRASHED_AND_ABANDONED:
|
|
|
|
return; /* do nothing */
|
|
|
|
|
2005-02-11 14:21:59 +03:00
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
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.
2006-11-18 01:34:44 +03:00
|
|
|
Main function of Guardian thread.
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
SYNOPSIS
|
2004-10-23 11:32:52 +04:00
|
|
|
run()
|
|
|
|
|
|
|
|
DESCRIPTION
|
2006-11-30 12:23:55 +03:00
|
|
|
Check for all guarded instances and restart them if needed.
|
2004-10-23 11:32:52 +04:00
|
|
|
*/
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
void Guardian::run()
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2005-01-25 13:54:56 +03:00
|
|
|
struct timespec timeout;
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-10-24 18:23:16 +04:00
|
|
|
log_info("Guardian: started.");
|
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
thread_registry->register_thread(&thread_info);
|
2005-02-03 20:48:58 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/* Loop, until all instances were shut down at the end. */
|
2005-01-25 13:54:56 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
while (true)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
Instance_map::Iterator instances_it(instance_map);
|
|
|
|
Instance *instance;
|
|
|
|
bool all_instances_stopped= TRUE;
|
|
|
|
|
|
|
|
instance_map->lock();
|
2005-02-03 20:48:58 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
while ((instance= instances_it.next()))
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->lock();
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
if (!instance->is_guarded() ||
|
|
|
|
instance->get_state() == Instance::STOPPED)
|
|
|
|
{
|
|
|
|
instance->unlock();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
process_instance(instance);
|
|
|
|
|
|
|
|
if (instance->get_state() != Instance::STOPPED)
|
|
|
|
all_instances_stopped= FALSE;
|
|
|
|
|
|
|
|
instance->unlock();
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
instance_map->unlock();
|
|
|
|
|
|
|
|
lock();
|
|
|
|
|
|
|
|
if (shutdown_requested && all_instances_stopped)
|
|
|
|
{
|
|
|
|
log_info("Guardian: all guarded mysqlds stopped.");
|
|
|
|
|
|
|
|
stopped= TRUE;
|
|
|
|
unlock();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-18 08:30:35 -07:00
|
|
|
set_timespec(timeout, Options::Main::monitoring_interval);
|
2005-01-25 13:54:56 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
thread_registry->cond_timedwait(&thread_info, &COND_guardian,
|
|
|
|
&LOCK_guardian, &timeout);
|
|
|
|
unlock();
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
2006-10-24 18:23:16 +04:00
|
|
|
log_info("Guardian: stopped.");
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/* Now, when the Guardian is stopped we can stop the IM. */
|
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
thread_registry->unregister_thread(&thread_info);
|
|
|
|
thread_registry->request_shutdown();
|
2006-10-24 18:23:16 +04:00
|
|
|
|
|
|
|
log_info("Guardian: finished.");
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Return the value of stopped flag.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Guardian::is_stopped()
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
|
|
|
int var;
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
lock();
|
2005-02-11 14:21:59 +03:00
|
|
|
var= stopped;
|
2006-11-30 12:23:55 +03:00
|
|
|
unlock();
|
|
|
|
|
2005-02-11 14:21:59 +03:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Wake up Guardian thread.
|
2005-02-11 14:21:59 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
MT-NOTE: though usually the mutex associated with condition variable should
|
|
|
|
be acquired before signalling the variable, here this is not needed.
|
|
|
|
Signalling under locked mutex is used to avoid lost signals. In the current
|
|
|
|
logic however locking mutex does not guarantee that the signal will not be
|
|
|
|
lost.
|
2005-02-11 14:21:59 +03:00
|
|
|
*/
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
void Guardian::ping()
|
2004-10-26 23:22:12 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
pthread_cond_signal(&COND_guardian);
|
2004-10-26 23:22:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Prepare list of instances.
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
SYNOPSIS
|
2006-11-30 12:23:55 +03:00
|
|
|
init()
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
MT-NOTE: Instance Map must be locked before calling the operation.
|
2004-10-23 11:32:52 +04:00
|
|
|
*/
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
void Guardian::init()
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
Instance *instance;
|
|
|
|
Instance_map::Iterator iterator(instance_map);
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
while ((instance= iterator.next()))
|
|
|
|
{
|
|
|
|
instance->lock();
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->reset_stat();
|
|
|
|
instance->set_state(Instance::NOT_STARTED);
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->unlock();
|
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
/**
|
2005-08-29 23:29:35 +04:00
|
|
|
An internal method which is called at shutdown to unregister instances and
|
|
|
|
attempt to stop them if requested.
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
SYNOPSIS
|
2005-02-11 14:21:59 +03:00
|
|
|
stop_instances()
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Loops through the guarded_instances list and prepares them for shutdown.
|
2006-10-20 22:26:40 +04:00
|
|
|
For each instance we issue a stop command and change the state
|
|
|
|
accordingly.
|
2005-08-29 23:29:35 +04:00
|
|
|
|
|
|
|
NOTE
|
2006-11-30 12:23:55 +03:00
|
|
|
Guardian object should be locked by the caller.
|
2005-02-11 14:21:59 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
void Guardian::stop_instances()
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
Instance_map::Iterator instances_it(instance_map);
|
|
|
|
Instance *instance;
|
|
|
|
|
|
|
|
instance_map->lock();
|
|
|
|
|
|
|
|
while ((instance= instances_it.next()))
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->lock();
|
|
|
|
|
|
|
|
if (!instance->is_guarded() ||
|
|
|
|
instance->get_state() == Instance::STOPPED)
|
|
|
|
{
|
|
|
|
instance->unlock();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-10-20 22:26:40 +04:00
|
|
|
/*
|
|
|
|
If instance is running or was running (and now probably hanging),
|
|
|
|
request stop.
|
|
|
|
*/
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
if (instance->is_mysqld_running() ||
|
|
|
|
instance->get_state() == Instance::STARTED)
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
{
|
2006-11-30 12:23:55 +03:00
|
|
|
instance->set_state(Instance::STOPPING);
|
|
|
|
instance->last_checked= time(NULL);
|
2005-02-11 14:21:59 +03:00
|
|
|
}
|
|
|
|
else
|
2006-11-30 12:23:55 +03:00
|
|
|
{
|
|
|
|
/* Otherwise mark it as STOPPED. */
|
|
|
|
instance->set_state(Instance::STOPPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request mysqld to stop. */
|
|
|
|
|
|
|
|
instance->kill_mysqld(SIGTERM);
|
|
|
|
|
|
|
|
instance->unlock();
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
}
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
instance_map->unlock();
|
more fixes for IM to substitude mysqld_safe in startup scripts
BitKeeper/deleted/.del-thread_repository.cc~bba09f64f8cb4037:
Delete: server-tools/instance-manager/thread_repository.cc
BitKeeper/deleted/.del-thread_repository.h~e6a3b9cab7a6612a:
Delete: server-tools/instance-manager/thread_repository.h
server-tools/instance-manager/commands.cc:
All instances are guarded by default now, so we need to perform check on whether the instance is nonguarded,
rather then guarded when adding it to the list of guarded instnces.
server-tools/instance-manager/guardian.cc:
Guardian rewritten to start instances by default, and shut them down, when exiting. Behaviour of the guardian
in case of the instance crash has changed. Now it tries to restart an instance constantly in the first 2
seconds after the crash was noticed, and then it tries restart an instance once in the MONITORING_INTERVAL.
If it failed to restart instance for "restart_retry" (compiled-in value) times, guardian stops trying to
restart it.
server-tools/instance-manager/guardian.h:
Several new functions and variables declared.
server-tools/instance-manager/instance.cc:
now start doesn't call stop(), but rather tries to remove the pidfile itself
server-tools/instance-manager/instance.h:
cleanup
server-tools/instance-manager/instance_map.cc:
no more "admin" options
server-tools/instance-manager/instance_map.h:
User and password purged from instance_map options, as IM shouldn't know them
server-tools/instance-manager/instance_options.cc:
new option added -- shutdown_delay, guarded option now called nonguaded and has the opposite meaning
server-tools/instance-manager/instance_options.h:
appropriate changes, reflecting options addition/removal
server-tools/instance-manager/manager.cc:
shutdown process is complicated a bit -- at first signal thread should stop guardian, and only then the IM
itself
server-tools/instance-manager/messages.cc:
update error message
server-tools/instance-manager/options.cc:
admin user/password purged from mysqlmanager options
2005-01-31 23:54:08 +03:00
|
|
|
}
|
2005-02-27 18:41:34 +03:00
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Lock Guardian.
|
|
|
|
*/
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
void Guardian::lock()
|
2005-02-27 18:41:34 +03:00
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
pthread_mutex_lock(&LOCK_guardian);
|
2005-02-27 18:41:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Unlock Guardian.
|
|
|
|
*/
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
void Guardian::unlock()
|
2005-02-27 18:41:34 +03:00
|
|
|
{
|
2005-07-20 10:55:40 -05:00
|
|
|
pthread_mutex_unlock(&LOCK_guardian);
|
2005-02-27 18:41:34 +03:00
|
|
|
}
|