summaryrefslogtreecommitdiff
path: root/server-tools
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.local>2006-10-23 12:35:56 +0400
committerunknown <kostja@bodhi.local>2006-10-23 12:35:56 +0400
commitd946b64dcecc083e4df52776dff0e6bd139ba785 (patch)
tree55d8dd8c7c418b931fb38f3ee01b272e6327b15d /server-tools
parentefcd6b42b44ce178a779924c1e960cde3d9a4246 (diff)
parent8db4dc3f91dfbe03181e63ed45bdf35a5d65aeb0 (diff)
downloadmariadb-git-d946b64dcecc083e4df52776dff0e6bd139ba785.tar.gz
Merge bodhi.local:/opt/local/work/mysql-5.0-runtime
into bodhi.local:/opt/local/work/mysql-5.1-runtime-merge mysql-test/r/im_daemon_life_cycle.result: Auto merged mysql-test/r/ps.result: Auto merged mysql-test/r/rpl_insert_id.result: Auto merged mysql-test/r/sp-vars.result: Auto merged mysql-test/r/trigger.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/func_gconcat.test: Auto merged mysql-test/t/im_daemon_life_cycle.imtest: Auto merged mysql-test/t/ps.test: Auto merged mysql-test/t/rpl_insert_id.test: Auto merged mysql-test/t/sp.test: Auto merged mysql-test/t/trigger.test: Auto merged server-tools/instance-manager/guardian.cc: Auto merged server-tools/instance-manager/guardian.h: Auto merged server-tools/instance-manager/instance_map.cc: Auto merged server-tools/instance-manager/listener.cc: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/sp_head.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_trigger.cc: Auto merged sql/sql_view.cc: Auto merged sql/sql_yacc.yy: Auto merged tests/mysql_client_test.c: Auto merged mysql-test/r/sp-error.result: Use local mysql-test/r/sp.result: Use local (will overwrite) mysql-test/t/view.test: Use local. mysql-test/mysql-test-run.pl: Manual merge. mysql-test/t/sp-error.test: Manual merge. server-tools/instance-manager/instance.cc: Manual merge. server-tools/instance-manager/manager.cc: Manual merge. server-tools/instance-manager/options.cc: Manual merge. server-tools/instance-manager/options.h: Manual merge. sql/log_event.cc: Manual merge. sql/set_var.cc: Manual merge. sql/sql_class.h: Manual merge. sql/sql_insert.cc: Manual merge. sql/sql_load.cc: Manual merge. sql/sql_select.cc: Manual merge. sql/sql_update.cc: Manual merge.
Diffstat (limited to 'server-tools')
-rw-r--r--server-tools/instance-manager/guardian.cc70
-rw-r--r--server-tools/instance-manager/guardian.h4
-rw-r--r--server-tools/instance-manager/instance.cc23
-rw-r--r--server-tools/instance-manager/instance_map.cc4
-rw-r--r--server-tools/instance-manager/listener.cc4
-rw-r--r--server-tools/instance-manager/manager.cc22
-rw-r--r--server-tools/instance-manager/options.cc6
-rw-r--r--server-tools/instance-manager/options.h2
8 files changed, 69 insertions, 66 deletions
diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc
index 68d89a4b375..9fc3a6583ef 100644
--- a/server-tools/instance-manager/guardian.cc
+++ b/server-tools/instance-manager/guardian.cc
@@ -95,11 +95,11 @@ Guardian_thread::~Guardian_thread()
}
-void Guardian_thread::request_shutdown(bool stop_instances_arg)
+void Guardian_thread::request_shutdown()
{
pthread_mutex_lock(&LOCK_guardian);
/* stop instances or just clean up Guardian repository */
- stop_instances(stop_instances_arg);
+ stop_instances();
shutdown_requested= TRUE;
pthread_mutex_unlock(&LOCK_guardian);
}
@@ -154,11 +154,11 @@ void Guardian_thread::process_instance(Instance *instance,
{
/* Pid file not created yet, don't go to STARTED state yet */
}
- else
+ else if (current_node->state != STARTED)
{
/* clear status fields */
- log_info("guardian: instance %s is running, set state to STARTED",
- instance->options.instance_name);
+ log_info("guardian: instance '%s' is running, set state to STARTED.",
+ (const char *) instance->options.instance_name);
current_node->restart_counter= 0;
current_node->crash_moment= 0;
current_node->state= STARTED;
@@ -168,8 +168,8 @@ void Guardian_thread::process_instance(Instance *instance,
{
switch (current_node->state) {
case NOT_STARTED:
- log_info("guardian: starting instance %s",
- instance->options.instance_name);
+ log_info("guardian: starting instance '%s'...",
+ (const char *) instance->options.instance_name);
/* NOTE, set state to STARTING _before_ start() is called */
current_node->state= STARTING;
@@ -193,8 +193,8 @@ void Guardian_thread::process_instance(Instance *instance,
if (instance->is_crashed())
{
instance->start();
- log_info("guardian: starting instance %s",
- instance->options.instance_name);
+ log_info("guardian: starting instance '%s'...",
+ (const char *) instance->options.instance_name);
}
}
else
@@ -211,8 +211,8 @@ void Guardian_thread::process_instance(Instance *instance,
instance->start();
current_node->last_checked= current_time;
current_node->restart_counter++;
- log_info("guardian: restarting instance %s",
- instance->options.instance_name);
+ log_info("guardian: restarting instance '%s'...",
+ (const char *) instance->options.instance_name);
}
}
else
@@ -414,12 +414,11 @@ int Guardian_thread::stop_guard(Instance *instance)
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 simply delete an entry.
+ For each instance we issue a stop command and change the state
+ accordingly.
NOTE
Guardian object should be locked by the calling function.
@@ -429,42 +428,29 @@ int Guardian_thread::stop_guard(Instance *instance)
1 - error occured
*/
-int Guardian_thread::stop_instances(bool stop_instances_arg)
+int Guardian_thread::stop_instances()
{
LIST *node;
node= guarded_instances;
while (node != NULL)
{
- if (!stop_instances_arg)
+ GUARD_NODE *current_node= (GUARD_NODE *) node->data;
+ /*
+ If instance is running or was running (and now probably hanging),
+ request stop.
+ */
+ if (current_node->instance->is_running() ||
+ (current_node->state == STARTED))
{
- /* just forget about an instance */
- guarded_instances= list_delete(guarded_instances, node);
- /*
- This should still work fine, as we have only removed the
- node from the list. The pointer to the next one is still valid
- */
- node= node->next;
+ current_node->state= STOPPING;
+ current_node->last_checked= time(NULL);
}
else
- {
- GUARD_NODE *current_node= (GUARD_NODE *) node->data;
- /*
- If instance is running or was running (and now probably hanging),
- request stop.
- */
- if (current_node->instance->is_running() ||
- (current_node->state == STARTED))
- {
- current_node->state= STOPPING;
- current_node->last_checked= time(NULL);
- }
- else
- /* 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);
- node= node->next;
- }
+ /* 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);
+ node= node->next;
}
return 0;
}
diff --git a/server-tools/instance-manager/guardian.h b/server-tools/instance-manager/guardian.h
index 6d3a2b222d7..27ca155fd67 100644
--- a/server-tools/instance-manager/guardian.h
+++ b/server-tools/instance-manager/guardian.h
@@ -91,7 +91,7 @@ public:
/* Initialize or refresh the list of guarded instances */
int init();
/* Request guardian shutdown. Stop instances if needed */
- void request_shutdown(bool stop_instances);
+ void request_shutdown();
/* Start instance protection */
int guard(Instance *instance, bool nolock= FALSE);
/* Stop instance protection */
@@ -123,7 +123,7 @@ public:
private:
/* Prepares Guardian shutdown. Stops instances is needed */
- int stop_instances(bool stop_instances_arg);
+ int stop_instances();
/* check instance state and act accordingly */
void process_instance(Instance *instance, GUARD_NODE *current_node,
LIST **guarded_instances, LIST *elem);
diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc
index dfe26397414..c4bd1e211e1 100644
--- a/server-tools/instance-manager/instance.cc
+++ b/server-tools/instance-manager/instance.cc
@@ -165,8 +165,8 @@ static int start_process(Instance_options *instance_options,
/* exec never returns */
exit(1);
case -1:
- log_info("cannot create a new process to start instance %s",
- instance_options->instance_name);
+ log_info("cannot create a new process to start instance '%s'.",
+ (const char *) instance_options->instance_name);
return 1;
}
return 0;
@@ -256,7 +256,8 @@ static void start_and_monitor_instance(Instance_options *old_instance_options,
are using is destroyed. (E.g. by "FLUSH INSTANCES")
*/
- log_info("starting instance %s", (const char *) instance_name.get_c_str());
+ log_info("starting instance %s...",
+ (const char *) instance_name.get_c_str());
if (start_process(old_instance_options, &process_info))
{
@@ -311,9 +312,9 @@ void Instance::remove_pid()
int pid;
if ((pid= options.get_pid()) != 0) /* check the pidfile */
if (options.unlink_pidfile()) /* remove stalled pidfile */
- log_error("cannot remove pidfile for instance %i, this might be \
+ log_error("cannot remove pidfile for instance '%s', this might be \
since IM lacks permmissions or hasn't found the pidifle",
- options.instance_name);
+ (const char *) options.instance_name);
}
@@ -467,9 +468,9 @@ bool Instance::is_running()
We have successfully connected to the server using fake
username/password. Write a warning to the logfile.
*/
- log_info("The Instance Manager was able to log into you server \
- with faked compiled-in password while checking server status. \
- Looks like something is wrong.");
+ log_info("The Instance Manager was able to log into you server "
+ "with faked compiled-in password while checking server status. "
+ "Looks like something is wrong.");
pthread_mutex_unlock(&LOCK_instance);
return_val= TRUE; /* server is alive */
}
@@ -616,10 +617,10 @@ void Instance::kill_instance(int signum)
/* Kill suceeded */
if (signum == SIGKILL) /* really killed instance with SIGKILL */
{
- log_error("The instance %s is being stopped forcibly. Normally" \
- "it should not happen. Probably the instance has been" \
+ log_error("The instance '%s' is being stopped forcibly. Normally"
+ "it should not happen. Probably the instance has been"
"hanging. You should also check your IM setup",
- options.instance_name);
+ (const char *) options.instance_name);
/* After sucessful hard kill the pidfile need to be removed */
options.unlink_pidfile();
}
diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc
index ec73fb7d73a..b7704c027f1 100644
--- a/server-tools/instance-manager/instance_map.cc
+++ b/server-tools/instance-manager/instance_map.cc
@@ -293,7 +293,9 @@ int Instance_map::flush_instances()
get_instance_key, delete_instance, 0);
rc= load();
- guardian->init(); // TODO: check error status.
+ /* don't init guardian if we failed to load instances */
+ if (!rc)
+ guardian->init(); // TODO: check error status.
return rc;
}
diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc
index 197c315dee8..0ab85c0e7aa 100644
--- a/server-tools/instance-manager/listener.cc
+++ b/server-tools/instance-manager/listener.cc
@@ -283,7 +283,7 @@ int Listener_thread::create_tcp_socket()
FD_SET(ip_socket, &read_fds);
sockets[num_sockets++]= ip_socket;
- log_info("accepting connections on ip socket");
+ log_info("accepting connections on ip socket (port: %d)", (int) im_port);
return 0;
}
@@ -337,7 +337,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address)
/* make sure that instances won't be listening our sockets */
set_no_inherit(unix_socket);
- log_info("accepting connections on unix socket %s",
+ log_info("accepting connections on unix socket '%s'",
unix_socket_address.sun_path);
sockets[num_sockets++]= unix_socket;
FD_SET(unix_socket, &read_fds);
diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc
index d2d498eebf1..3fb967fc352 100644
--- a/server-tools/instance-manager/manager.cc
+++ b/server-tools/instance-manager/manager.cc
@@ -120,6 +120,19 @@ int my_sigwait(const sigset_t *set, int *sig)
#endif
+void stop_all(Guardian_thread *guardian, Thread_registry *registry)
+{
+ /*
+ Let guardian thread know that it should break it's processing cycle,
+ once it wakes up.
+ */
+ guardian->request_shutdown();
+ /* wake guardian */
+ pthread_cond_signal(&guardian->COND_guardian);
+ /* stop all threads */
+ registry->deliver_shutdown();
+}
+
/*
manager - entry point to the main instance manager process: start
listener thread, write pid file and enter into signal handling.
@@ -251,7 +264,6 @@ void manager()
/* Load instances. */
-
{
instance_map.guardian->lock();
instance_map.lock();
@@ -266,7 +278,8 @@ void manager()
log_error("Cannot init instances repository. This might be caused by "
"the wrong config file options. For instance, missing mysqld "
"binary. Aborting.");
- return;
+ stop_all(&guardian_thread, &thread_registry);
+ goto err;
}
}
@@ -284,6 +297,7 @@ void manager()
if (rc)
{
log_error("manager(): set_stacksize_n_create_thread(listener) failed");
+ stop_all(&guardian_thread, &thread_registry);
goto err;
}
}
@@ -302,6 +316,7 @@ void manager()
if ((status= my_sigwait(&mask, &signo)) != 0)
{
log_error("sigwait() failed");
+ stop_all(&guardian_thread, &thread_registry);
goto err;
}
@@ -323,8 +338,7 @@ void manager()
{
if (!guardian_thread.is_stopped())
{
- bool stop_instances= TRUE;
- guardian_thread.request_shutdown(stop_instances);
+ guardian_thread.request_shutdown();
pthread_cond_signal(&guardian_thread.COND_guardian);
}
else
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index 07a1fd3e932..0fff68fbd4f 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -41,7 +41,6 @@
static char win_dflt_config_file_name[FN_REFLEN];
static char win_dflt_password_file_name[FN_REFLEN];
static char win_dflt_pid_file_name[FN_REFLEN];
-static char win_dflt_socket_file_name[FN_REFLEN];
static char win_dflt_mysqld_path[FN_REFLEN];
@@ -54,7 +53,6 @@ my_bool Options::Service::stand_alone;
const char *Options::Main::config_file= win_dflt_config_file_name;
const char *Options::Main::password_file_name= win_dflt_password_file_name;
const char *Options::Main::pid_file_name= win_dflt_pid_file_name;
-const char *Options::Main::socket_file_name= win_dflt_socket_file_name;
const char *Options::Main::default_mysqld_path= win_dflt_mysqld_path;
@@ -262,10 +260,12 @@ static struct my_option my_long_options[] =
0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
#endif
+#ifndef __WIN__
{ "socket", OPT_SOCKET, "Socket file to use for connection.",
(gptr *) &Options::Main::socket_file_name,
(gptr *) &Options::Main::socket_file_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+#endif
#ifdef __WIN__
{ "standalone", OPT_STAND_ALONE, "Run the application in stand alone mode.",
@@ -550,8 +550,6 @@ static int setup_windows_defaults()
strxmov(win_dflt_password_file_name, dir_name, im_name, DFLT_PASSWD_FILE_EXT,
NullS);
strxmov(win_dflt_pid_file_name, dir_name, im_name, DFLT_PID_FILE_EXT, NullS);
- strxmov(win_dflt_socket_file_name, dir_name, im_name, DFLT_SOCKET_FILE_EXT,
- NullS);
return 0;
}
diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h
index 5c54ff201b2..ac4f6507892 100644
--- a/server-tools/instance-manager/options.h
+++ b/server-tools/instance-manager/options.h
@@ -50,7 +50,9 @@ struct Options
static bool is_forced_default_file;
static const char *pid_file_name;
+#ifndef __WIN__
static const char *socket_file_name;
+#endif
static const char *password_file_name;
static const char *default_mysqld_path;
static uint monitoring_interval;