2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2003-2006 MySQL AB
|
2003-08-16 21:44:24 +04:00
|
|
|
|
|
|
|
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.
|
2003-08-16 21:44:24 +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 */
|
|
|
|
|
2003-08-19 19:55:20 +04:00
|
|
|
#include "manager.h"
|
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
#include <my_global.h>
|
2005-01-25 13:54:56 +03:00
|
|
|
#include <m_string.h>
|
2006-05-18 18:57:50 +04:00
|
|
|
#include <my_sys.h>
|
2005-01-25 13:54:56 +03:00
|
|
|
#include <thr_alarm.h>
|
2006-05-18 18:57:50 +04:00
|
|
|
|
|
|
|
#include <signal.h>
|
2005-07-20 10:55:40 -05:00
|
|
|
#ifndef __WIN__
|
2005-01-25 13:54:56 +03:00
|
|
|
#include <sys/wait.h>
|
2005-07-20 10:55:40 -05:00
|
|
|
#endif
|
2005-01-25 13:54:56 +03:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
#include "exit_codes.h"
|
|
|
|
#include "guardian.h"
|
|
|
|
#include "instance_map.h"
|
|
|
|
#include "listener.h"
|
2007-02-18 15:45:28 +03:00
|
|
|
#include "mysql_manager_error.h"
|
|
|
|
#include "mysqld_error.h"
|
2006-05-18 18:57:50 +04:00
|
|
|
#include "log.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "priv.h"
|
|
|
|
#include "thread_registry.h"
|
|
|
|
#include "user_map.h"
|
|
|
|
|
2005-01-25 13:54:56 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**********************************************************************
|
|
|
|
{{{ Platform-specific implementation.
|
|
|
|
**********************************************************************/
|
2004-10-25 14:23:31 +04:00
|
|
|
|
2005-07-20 10:55:40 -05:00
|
|
|
#ifndef __WIN__
|
|
|
|
void set_signals(sigset_t *mask)
|
|
|
|
{
|
|
|
|
/* block signals */
|
|
|
|
sigemptyset(mask);
|
|
|
|
sigaddset(mask, SIGINT);
|
|
|
|
sigaddset(mask, SIGTERM);
|
|
|
|
sigaddset(mask, SIGPIPE);
|
|
|
|
sigaddset(mask, SIGHUP);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
We want this signal to be blocked in all theads but the signal
|
|
|
|
one. It is needed for the thr_alarm subsystem to work.
|
|
|
|
*/
|
|
|
|
sigaddset(mask,THR_SERVER_ALARM);
|
|
|
|
|
|
|
|
/* all new threads will inherite this signal mask */
|
|
|
|
pthread_sigmask(SIG_BLOCK, mask, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
In our case the signal thread also implements functions of alarm thread.
|
|
|
|
Here we init alarm thread functionality. We suppose that we won't have
|
|
|
|
more then 10 alarms at the same time.
|
|
|
|
*/
|
|
|
|
init_thr_alarm(10);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
bool have_signal;
|
|
|
|
|
|
|
|
void onsignal(int signo)
|
|
|
|
{
|
2006-05-18 18:57:50 +04:00
|
|
|
have_signal= TRUE;
|
2005-07-20 10:55:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_signals(sigset_t *set)
|
|
|
|
{
|
|
|
|
signal(SIGINT, onsignal);
|
|
|
|
signal(SIGTERM, onsignal);
|
2006-05-18 18:57:50 +04:00
|
|
|
have_signal= FALSE;
|
2005-07-20 10:55:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int my_sigwait(const sigset_t *set, int *sig)
|
|
|
|
{
|
|
|
|
while (!have_signal)
|
|
|
|
{
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**********************************************************************
|
|
|
|
}}}
|
|
|
|
**********************************************************************/
|
|
|
|
|
2003-08-16 21:44:24 +04:00
|
|
|
|
2006-11-21 17:31:03 +03:00
|
|
|
/**********************************************************************
|
2006-11-30 12:23:55 +03:00
|
|
|
{{{ Implementation of checking the actual thread model.
|
2006-11-21 17:31:03 +03:00
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
namespace { /* no-indent */
|
|
|
|
|
|
|
|
class ThreadModelChecker: public Thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThreadModelChecker()
|
|
|
|
:main_pid(getpid())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline bool is_linux_threads() const
|
|
|
|
{
|
|
|
|
return linux_threads;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void run()
|
|
|
|
{
|
|
|
|
linux_threads= main_pid != getpid();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
pid_t main_pid;
|
|
|
|
bool linux_threads;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool check_if_linux_threads(bool *linux_threads)
|
|
|
|
{
|
|
|
|
ThreadModelChecker checker;
|
|
|
|
|
|
|
|
if (checker.start() || checker.join())
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
*linux_threads= checker.is_linux_threads();
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**********************************************************************
|
|
|
|
}}}
|
|
|
|
***********************************************************************/
|
|
|
|
|
2006-11-21 17:31:03 +03:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Manager implementation
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
Guardian *Manager::p_guardian;
|
|
|
|
Instance_map *Manager::p_instance_map;
|
|
|
|
Thread_registry *Manager::p_thread_registry;
|
|
|
|
User_map *Manager::p_user_map;
|
|
|
|
|
|
|
|
#ifndef __WIN__
|
|
|
|
bool Manager::linux_threads;
|
|
|
|
#endif // __WIN__
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Request shutdown of guardian and threads registered in Thread_registry.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
stop_all_threads()
|
|
|
|
*/
|
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
void Manager::stop_all_threads()
|
2006-10-05 22:07:21 +04:00
|
|
|
{
|
|
|
|
/*
|
2006-11-30 12:23:55 +03:00
|
|
|
Let Guardian thread know that it should break it's processing cycle,
|
2006-10-05 22:07:21 +04:00
|
|
|
once it wakes up.
|
|
|
|
*/
|
2006-11-18 01:34:44 +03:00
|
|
|
p_guardian->request_shutdown();
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
/* Stop all threads. */
|
2006-11-18 01:34:44 +03:00
|
|
|
p_thread_registry->deliver_shutdown();
|
Fix for BUG#24415: Instance manager test im_daemon_life_cycle fails randomly.
The cause of im_daemon_life_cycle.imtest random failures was the following
behaviour of some implementations of LINUX threads: let's suppose that a
process has several threads (in LINUX threads, there is a separate process for
each thread). When the main process gets killed, the parent receives SIGCHLD
before all threads (child processes) die. In other words, the parent receives
SIGCHLD, when its child is not completely dead.
In terms of IM, that means that IM-angel receives SIGCHLD when IM-main is not dead
and still holds some resources. After receiving SIGCHLD, IM-angel restarts
IM-main, but IM-main failed to initialize, because previous instance (copy) of
IM-main still holds server socket (TCP-port).
Another problem here was that IM-angel restarted IM-main only if it was killed
by signal. If it exited with error, IM-angel thought it's intended / graceful
shutdown and exited itself.
So, when the second instance of IM-main failed to initialize, IM-angel thought
it's intended shutdown and quit.
The fix is
1. to change IM-angel so that it restarts IM-main if it exited with error code;
2. to change IM-main so that it returns proper exit code in case of failure.
2007-02-20 22:31:50 +03:00
|
|
|
|
|
|
|
/* Set error status in the thread registry. */
|
2007-02-22 21:59:43 +03:00
|
|
|
p_thread_registry->set_error_status();
|
2006-10-05 22:07:21 +04:00
|
|
|
}
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
|
2007-02-20 21:28:30 +03:00
|
|
|
/**
|
|
|
|
Initialize user map and load password file.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
init_user_map()
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE on success
|
|
|
|
TRUE on failure
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Manager::init_user_map(User_map *user_map)
|
|
|
|
{
|
|
|
|
int err_code;
|
|
|
|
const char *err_msg;
|
|
|
|
|
|
|
|
if (user_map->init())
|
|
|
|
{
|
|
|
|
log_error("Manager: can not initialize user list: out of memory.");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
err_code= user_map->load(Options::Main::password_file_name, &err_msg);
|
|
|
|
|
|
|
|
if (!err_code)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (err_code == ERR_PASSWORD_FILE_DOES_NOT_EXIST &&
|
|
|
|
Options::Main::mysqld_safe_compatible)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The password file does not exist, but we are running in
|
|
|
|
mysqld_safe-compatible mode. Continue, but complain in log.
|
|
|
|
*/
|
|
|
|
|
|
|
|
log_info("Warning: password file does not exist, "
|
|
|
|
"nobody will be able to connect to Instance Manager.");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_error("Manager: %s.", (const char *) err_msg);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/**
|
|
|
|
Main manager function.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
main()
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This is an entry point to the main instance manager process:
|
|
|
|
start listener thread, write pid file and enter into signal handling.
|
|
|
|
See also comments in mysqlmanager.cc to picture general Instance Manager
|
|
|
|
architecture.
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2007-02-22 22:56:43 +03:00
|
|
|
RETURNS
|
|
|
|
main() returns exit status (exit code).
|
2004-10-23 11:32:52 +04:00
|
|
|
*/
|
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
int Manager::main()
|
2003-08-16 21:44:24 +04:00
|
|
|
{
|
2006-05-18 22:31:28 +04:00
|
|
|
bool shutdown_complete= FALSE;
|
2006-11-20 15:37:12 +03:00
|
|
|
pid_t manager_pid= getpid();
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
log_info("Manager: initializing...");
|
|
|
|
|
2006-11-21 21:43:24 +03:00
|
|
|
#ifndef __WIN__
|
2006-11-21 17:31:03 +03:00
|
|
|
if (check_if_linux_threads(&linux_threads))
|
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: can not determine thread model.");
|
2006-11-21 17:31:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
log_info("Manager: detected threads model: %s.",
|
2006-11-21 17:31:03 +03:00
|
|
|
(const char *) (linux_threads ? "LINUX threads" : "POSIX threads"));
|
2006-11-21 21:43:24 +03:00
|
|
|
#endif // __WIN__
|
2006-11-21 17:31:03 +03:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
/*
|
2006-11-30 12:23:55 +03:00
|
|
|
All objects created in the Manager object live as long as thread_registry
|
|
|
|
lives, and thread_registry is alive until there are working threads.
|
|
|
|
|
|
|
|
There are two main purposes of the Thread Registry:
|
|
|
|
1. Interrupt blocking I/O and signal condition variables in case of
|
|
|
|
shutdown;
|
|
|
|
2. Wait for detached threads before shutting down the main thread.
|
|
|
|
|
|
|
|
NOTE:
|
|
|
|
1. Handling shutdown can be done in more elegant manner by introducing
|
|
|
|
Event (or Condition) object with support of logical operations.
|
|
|
|
2. Using Thread Registry to wait for detached threads is definitely not
|
|
|
|
the best way, because when Thread Registry unregisters an thread, the
|
|
|
|
thread is still alive. Accurate way to wait for threads to stop is
|
|
|
|
not using detached threads and join all threads before shutdown.
|
2004-10-23 11:32:52 +04:00
|
|
|
*/
|
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
Thread_registry thread_registry;
|
2004-10-23 11:32:52 +04:00
|
|
|
User_map user_map;
|
2006-11-18 01:34:44 +03:00
|
|
|
Instance_map instance_map;
|
2006-11-30 12:23:55 +03:00
|
|
|
Guardian guardian(&thread_registry, &instance_map);
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
Listener listener(&thread_registry, &user_map);
|
2004-10-25 14:23:31 +04:00
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
p_instance_map= &instance_map;
|
2006-11-30 12:23:55 +03:00
|
|
|
p_guardian= &guardian;
|
2006-11-18 01:34:44 +03:00
|
|
|
p_thread_registry= &thread_registry;
|
|
|
|
p_user_map= &user_map;
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-05-18 18:57:50 +04:00
|
|
|
/* Initialize instance map. */
|
|
|
|
|
|
|
|
if (instance_map.init())
|
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: can not initialize instance list: out of memory.");
|
2006-11-16 23:36:20 +03:00
|
|
|
return 1;
|
2006-05-18 18:57:50 +04:00
|
|
|
}
|
2005-02-15 04:38:33 +03:00
|
|
|
|
2007-02-20 21:28:30 +03:00
|
|
|
/* Initialize user db. */
|
2006-05-18 18:57:50 +04:00
|
|
|
|
2007-02-20 21:28:30 +03:00
|
|
|
if (init_user_map(&user_map))
|
|
|
|
return 1; /* logging has been already done. */
|
2003-08-16 21:44:24 +04:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
/* Write Instance Manager pid file. */
|
2006-05-06 13:57:56 +04:00
|
|
|
|
2006-05-22 14:22:58 +04:00
|
|
|
if (create_pid_file(Options::Main::pid_file_name, manager_pid))
|
2006-11-16 23:36:20 +03:00
|
|
|
return 1; /* necessary logging has been already done. */
|
2003-08-16 21:44:24 +04:00
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
log_info("Manager: pid file (%s) created.",
|
|
|
|
(const char *) Options::Main::pid_file_name);
|
|
|
|
|
2006-06-19 14:16:10 +04:00
|
|
|
/*
|
|
|
|
Initialize signals and alarm-infrastructure.
|
|
|
|
|
|
|
|
NOTE: To work nicely with LinuxThreads, the signal thread is the first
|
|
|
|
thread in the process.
|
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
NOTE: After init_thr_alarm() call it's possible to call thr_alarm()
|
|
|
|
(from different threads), that results in sending ALARM signal to the
|
|
|
|
alarm thread (which can be the main thread). That signal can interrupt
|
|
|
|
blocking calls. In other words, a blocking call can be interrupted in
|
|
|
|
the main thread after init_thr_alarm().
|
2006-06-19 14:16:10 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
sigset_t mask;
|
|
|
|
set_signals(&mask);
|
|
|
|
|
2006-11-17 16:11:04 +03:00
|
|
|
/*
|
|
|
|
Create the guardian thread. The newly started thread will block until
|
|
|
|
we actually load instances.
|
|
|
|
|
|
|
|
NOTE: Guardian should be shutdown first. Only then all other threads
|
|
|
|
can be stopped. This should be done in this order because the guardian
|
|
|
|
is responsible for shutting down all the guarded instances, and this
|
|
|
|
is a long operation.
|
|
|
|
|
|
|
|
NOTE: Guardian uses thr_alarm() when detects the current state of an
|
|
|
|
instance (is_running()), but this does not interfere with
|
|
|
|
flush_instances() call later in the code, because until
|
|
|
|
flush_instances() completes in the main thread, Guardian thread is not
|
|
|
|
permitted to process instances. And before flush_instances() has
|
|
|
|
completed, there are no instances to guard.
|
|
|
|
*/
|
2006-11-30 12:23:55 +03:00
|
|
|
|
2006-11-21 17:31:03 +03:00
|
|
|
if (guardian.start(Thread::DETACHED))
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: can not start Guardian thread.");
|
2006-11-17 16:11:04 +03:00
|
|
|
goto err;
|
2003-08-16 21:44:24 +04:00
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-06-19 14:16:10 +04:00
|
|
|
/* Load instances. */
|
2006-11-18 01:34:44 +03:00
|
|
|
|
2006-11-30 12:23:55 +03:00
|
|
|
if (Manager::flush_instances())
|
2006-02-21 15:57:56 +03:00
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: can not init instances repository.");
|
2006-11-30 12:23:55 +03:00
|
|
|
stop_all_threads();
|
|
|
|
goto err;
|
2006-02-21 15:57:56 +03:00
|
|
|
}
|
2005-02-27 18:41:34 +03:00
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
/* Initialize the Listener. */
|
|
|
|
|
2006-11-21 17:31:03 +03:00
|
|
|
if (listener.start(Thread::DETACHED))
|
2006-05-29 17:26:52 +04:00
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: can not start Listener thread.");
|
2006-11-18 01:34:44 +03:00
|
|
|
stop_all_threads();
|
2006-11-17 16:11:04 +03:00
|
|
|
goto err;
|
2006-05-29 17:26:52 +04:00
|
|
|
}
|
|
|
|
|
2005-02-03 20:48:58 +03:00
|
|
|
/*
|
|
|
|
After the list of guarded instances have been initialized,
|
|
|
|
Guardian should start them.
|
|
|
|
*/
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
guardian.ping();
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
/* Main loop. */
|
|
|
|
|
|
|
|
log_info("Manager: started.");
|
2006-10-24 18:23:16 +04:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
while (!shutdown_complete)
|
|
|
|
{
|
2006-05-18 22:31:28 +04:00
|
|
|
int signo;
|
2005-02-13 15:13:33 +03:00
|
|
|
int status= 0;
|
|
|
|
|
2005-02-15 04:38:33 +03:00
|
|
|
if ((status= my_sigwait(&mask, &signo)) != 0)
|
2005-02-13 15:13:33 +03:00
|
|
|
{
|
2007-02-18 15:45:28 +03:00
|
|
|
log_error("Manager: sigwait() failed");
|
2006-11-18 01:34:44 +03:00
|
|
|
stop_all_threads();
|
2005-02-13 15:13:33 +03:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2006-10-24 18:23:16 +04:00
|
|
|
/*
|
|
|
|
The general idea in this loop is the following:
|
|
|
|
- we are waiting for SIGINT, SIGTERM -- signals that mean we should
|
|
|
|
shutdown;
|
|
|
|
- as shutdown signal is caught, we stop Guardian thread (by calling
|
2006-11-16 23:36:20 +03:00
|
|
|
Guardian::request_shutdown());
|
|
|
|
- as Guardian is stopped, it sends SIGTERM to this thread
|
2006-10-24 18:23:16 +04:00
|
|
|
(by calling Thread_registry::request_shutdown()), so that the
|
|
|
|
my_sigwait() above returns;
|
|
|
|
- as we catch the second SIGTERM, we send signals to all threads
|
|
|
|
registered in Thread_registry (by calling
|
|
|
|
Thread_registry::deliver_shutdown()) and waiting for threads to stop;
|
|
|
|
*/
|
|
|
|
|
2005-07-20 10:55:40 -05:00
|
|
|
#ifndef __WIN__
|
2005-10-27 04:00:31 +04:00
|
|
|
/*
|
|
|
|
On some Darwin kernels SIGHUP is delivered along with most
|
|
|
|
signals. This is why we skip it's processing on these
|
|
|
|
platforms. For more details and test program see
|
|
|
|
Bug #14164 IM tests fail on MacOS X (powermacg5)
|
|
|
|
*/
|
2005-10-17 05:14:03 +04:00
|
|
|
#ifdef IGNORE_SIGHUP_SIGQUIT
|
2006-11-18 01:34:44 +03:00
|
|
|
if (SIGHUP == signo)
|
2005-10-17 05:14:03 +04:00
|
|
|
continue;
|
|
|
|
#endif
|
2005-07-20 10:55:40 -05:00
|
|
|
if (THR_SERVER_ALARM == signo)
|
|
|
|
process_alarm(signo);
|
|
|
|
else
|
|
|
|
#endif
|
2005-08-05 17:02:06 +04:00
|
|
|
{
|
2006-11-18 01:34:44 +03:00
|
|
|
log_info("Manager: got shutdown signal.");
|
2006-10-24 18:23:16 +04:00
|
|
|
|
2006-11-16 23:36:20 +03:00
|
|
|
if (!guardian.is_stopped())
|
2005-08-05 17:02:06 +04:00
|
|
|
{
|
2006-11-16 23:36:20 +03:00
|
|
|
guardian.request_shutdown();
|
2005-08-05 17:02:06 +04:00
|
|
|
}
|
|
|
|
else
|
2005-02-11 14:21:59 +03:00
|
|
|
{
|
2005-08-05 17:02:06 +04:00
|
|
|
thread_registry.deliver_shutdown();
|
|
|
|
shutdown_complete= TRUE;
|
2005-02-11 14:21:59 +03:00
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
2005-08-05 17:02:06 +04:00
|
|
|
}
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2006-11-18 01:34:44 +03:00
|
|
|
log_info("Manager: finished.");
|
2006-10-24 18:23:16 +04:00
|
|
|
|
2004-10-23 11:32:52 +04:00
|
|
|
err:
|
|
|
|
/* delete the pid file */
|
2006-05-18 18:57:50 +04:00
|
|
|
my_delete(Options::Main::pid_file_name, MYF(0));
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2005-07-20 10:55:40 -05:00
|
|
|
#ifndef __WIN__
|
2004-10-23 11:32:52 +04:00
|
|
|
/* free alarm structures */
|
|
|
|
end_thr_alarm(1);
|
2005-07-20 10:55:40 -05:00
|
|
|
#endif
|
2007-02-22 22:56:43 +03:00
|
|
|
|
Fix for BUG#24415: Instance manager test im_daemon_life_cycle fails randomly.
The cause of im_daemon_life_cycle.imtest random failures was the following
behaviour of some implementations of LINUX threads: let's suppose that a
process has several threads (in LINUX threads, there is a separate process for
each thread). When the main process gets killed, the parent receives SIGCHLD
before all threads (child processes) die. In other words, the parent receives
SIGCHLD, when its child is not completely dead.
In terms of IM, that means that IM-angel receives SIGCHLD when IM-main is not dead
and still holds some resources. After receiving SIGCHLD, IM-angel restarts
IM-main, but IM-main failed to initialize, because previous instance (copy) of
IM-main still holds server socket (TCP-port).
Another problem here was that IM-angel restarted IM-main only if it was killed
by signal. If it exited with error, IM-angel thought it's intended / graceful
shutdown and exited itself.
So, when the second instance of IM-main failed to initialize, IM-angel thought
it's intended shutdown and quit.
The fix is
1. to change IM-angel so that it restarts IM-main if it exited with error code;
2. to change IM-main so that it returns proper exit code in case of failure.
2007-02-20 22:31:50 +03:00
|
|
|
return thread_registry.get_error_status() ? 1 : 0;
|
2003-08-16 21:44:24 +04:00
|
|
|
}
|
2006-11-30 12:23:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Re-read instance configuration file.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
flush_instances()
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function will:
|
|
|
|
- clear the current list of instances. This removes both
|
|
|
|
running and stopped instances.
|
|
|
|
- load a new instance configuration from the file.
|
|
|
|
- pass on the new map to the guardian thread: it will start
|
|
|
|
all instances that are marked `guarded' and not yet started.
|
|
|
|
|
|
|
|
Note, as the check whether an instance is started is currently
|
|
|
|
very simple (returns TRUE if there is a MySQL server running
|
|
|
|
at the given port), this function has some peculiar
|
|
|
|
side-effects:
|
|
|
|
* if the port number of a running instance was changed, the
|
|
|
|
old instance is forgotten, even if it was running. The new
|
|
|
|
instance will be started at the new port.
|
|
|
|
* if the configuration was changed in a way that two
|
|
|
|
instances swapped their port numbers, the guardian thread
|
|
|
|
will not notice that and simply report that both instances
|
|
|
|
are configured successfully and running.
|
|
|
|
|
|
|
|
In order to avoid such side effects one should never call
|
|
|
|
FLUSH INSTANCES without prior stop of all running instances.
|
2007-02-18 15:45:28 +03:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 On success
|
|
|
|
ER_OUT_OF_RESOURCES Not enough resources to complete the operation
|
|
|
|
ER_THERE_IS_ACTIVE_INSTACE If there is an active instance
|
2006-11-30 12:23:55 +03:00
|
|
|
*/
|
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
int Manager::flush_instances()
|
2006-11-30 12:23:55 +03:00
|
|
|
{
|
|
|
|
p_instance_map->lock();
|
|
|
|
|
|
|
|
if (p_instance_map->is_there_active_instance())
|
|
|
|
{
|
|
|
|
p_instance_map->unlock();
|
2007-02-18 15:45:28 +03:00
|
|
|
return ER_THERE_IS_ACTIVE_INSTACE;
|
2006-11-30 12:23:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_instance_map->reset())
|
|
|
|
{
|
|
|
|
p_instance_map->unlock();
|
2007-02-18 15:45:28 +03:00
|
|
|
return ER_OUT_OF_RESOURCES;
|
2006-11-30 12:23:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_instance_map->load())
|
|
|
|
{
|
|
|
|
p_instance_map->unlock();
|
2007-02-18 15:45:28 +03:00
|
|
|
|
|
|
|
/* Don't init guardian if we failed to load instances. */
|
|
|
|
return ER_OUT_OF_RESOURCES;
|
2006-11-30 12:23:55 +03:00
|
|
|
}
|
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
get_guardian()->init();
|
2006-11-30 12:23:55 +03:00
|
|
|
get_guardian()->ping();
|
|
|
|
|
|
|
|
p_instance_map->unlock();
|
|
|
|
|
2007-02-18 15:45:28 +03:00
|
|
|
return 0;
|
2006-11-30 12:23:55 +03:00
|
|
|
}
|