summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager/instance.cc
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.local>2006-11-17 16:11:04 +0300
committerunknown <kostja@bodhi.local>2006-11-17 16:11:04 +0300
commita163ae30f23239e1f7a9efafc620e1bc74e009ba (patch)
tree5ecdad467c796454f72a94e294ff4958563441fb /server-tools/instance-manager/instance.cc
parent211b2bc92a25609e0c7323b5fee6f646abb3c748 (diff)
downloadmariadb-git-a163ae30f23239e1f7a9efafc620e1bc74e009ba.tar.gz
Replace the approach using Foo_thread_args + Foo_thread and manually
spawned threads with a reusable class Thread. This is the second idea implemented in the Alik's patch for BUG#22306: STOP INSTANCE can not be applied for instances in Crashed, Failed and Abandoned. Commiting separately to ease review process. server-tools/instance-manager/commands.cc: Remove an unused header. server-tools/instance-manager/guardian.cc: Use Thread framework instead of manually spawning the Guardian thread. Tidy up. server-tools/instance-manager/guardian.h: Use Thread framework instead of manually spawning the Guardian thread. server-tools/instance-manager/instance.cc: Use Thread framework instead of manually spawning the instance monitoring thread. server-tools/instance-manager/listener.cc: Use Thread framework instead of manually spawning the mysql connection thread. server-tools/instance-manager/listener.h: Use Thread framework instead of manually spawning the mysql connection thread. Rename Listener_thread to Listener for brevity. server-tools/instance-manager/manager.cc: Change references to pointers, as per the coding style. Use Thread framework instead of manually spawning threads. server-tools/instance-manager/mysql_connection.cc: Get rid of Mysql_connection_thread_args. Use class Thread framework instead. Rename Mysql_connection_thread to Mysql_connection for brevity. server-tools/instance-manager/mysql_connection.h: Get rid of Mysql_connection_thread_args. Use class Thread framework instead. Rename Mysql_connection_thread to Mysql_connection for brevity. server-tools/instance-manager/priv.cc: Move set_stacksize_and_create_thread to thread_registry.cc and make it static: it is not used anywhere else now. server-tools/instance-manager/priv.h: No public set_stacksize_n_create_thread server-tools/instance-manager/thread_registry.cc: Implement a base Thread class to be used for all Instance Manager threads. server-tools/instance-manager/thread_registry.h: Implement a base Thread class to be used for all Instance Manager threads.
Diffstat (limited to 'server-tools/instance-manager/instance.cc')
-rw-r--r--server-tools/instance-manager/instance.cc60
1 files changed, 31 insertions, 29 deletions
diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc
index 3927363a3e5..f170332e132 100644
--- a/server-tools/instance-manager/instance.cc
+++ b/server-tools/instance-manager/instance.cc
@@ -44,9 +44,6 @@ static const char * const INSTANCE_NAME_PREFIX= Instance::DFLT_INSTANCE_NAME.str
static const int INSTANCE_NAME_PREFIX_LEN= Instance::DFLT_INSTANCE_NAME.length;
-static void start_and_monitor_instance(Instance_options *old_instance_options,
- Instance_map *instance_map,
- Thread_registry *thread_registry);
#ifndef __WIN__
typedef pid_t My_process_info;
@@ -61,13 +58,24 @@ typedef PROCESS_INFORMATION My_process_info;
to do it in a portable way.
*/
-pthread_handler_t proxy(void *arg)
+class Instance_monitor: public Thread
{
- Instance *instance= (Instance *) arg;
- start_and_monitor_instance(&instance->options,
- instance->get_map(),
+public:
+ Instance_monitor(Instance *instance_arg) :instance(instance_arg) {}
+protected:
+ virtual void run();
+ void start_and_monitor_instance(Instance_options *old_instance_options,
+ Instance_map *instance_map,
+ Thread_registry *thread_registry);
+private:
+ Instance *instance;
+};
+
+void Instance_monitor::run()
+{
+ start_and_monitor_instance(&instance->options, instance->get_map(),
&instance->thread_registry);
- return 0;
+ delete this;
}
/*
@@ -242,14 +250,16 @@ static int start_process(Instance_options *instance_options,
Function returns no value
*/
-static void start_and_monitor_instance(Instance_options *old_instance_options,
- Instance_map *instance_map,
- Thread_registry *thread_registry)
+void
+Instance_monitor::
+start_and_monitor_instance(Instance_options *old_instance_options,
+ Instance_map *instance_map,
+ Thread_registry *thread_registry)
{
Instance_name instance_name(&old_instance_options->instance_name);
Instance *current_instance;
My_process_info process_info;
- Thread_info thread_info(pthread_self(), FALSE);
+ Thread_info thread_info;
log_info("Monitoring thread (instance: '%s'): started.",
(const char *) instance_name.get_c_str());
@@ -258,12 +268,10 @@ static void start_and_monitor_instance(Instance_options *old_instance_options,
{
/*
Register thread in Thread_registry to wait for it to stop on shutdown
- only if instance is nuarded. If instance is guarded, the thread will not
+ only if instance is guarded. If instance is guarded, the thread will not
finish, because nonguarded instances are not stopped on shutdown.
*/
-
- thread_registry->register_thread(&thread_info);
- my_thread_init();
+ thread_registry->register_thread(&thread_info, FALSE);
}
/*
@@ -302,10 +310,7 @@ static void start_and_monitor_instance(Instance_options *old_instance_options,
instance_map->unlock();
if (!old_instance_options->nonguarded)
- {
thread_registry->unregister_thread(&thread_info);
- my_thread_end();
- }
log_info("Monitoring thread (instance: '%s'): finished.",
(const char *) instance_name.get_c_str());
@@ -369,22 +374,19 @@ int Instance::start()
if (configured && !is_running())
{
+ Instance_monitor *instance_monitor;
remove_pid();
- pthread_t proxy_thd_id;
- pthread_attr_t proxy_thd_attr;
- int rc;
+ instance_monitor= new Instance_monitor(this);
- pthread_attr_init(&proxy_thd_attr);
- pthread_attr_setdetachstate(&proxy_thd_attr, PTHREAD_CREATE_DETACHED);
- rc= pthread_create(&proxy_thd_id, &proxy_thd_attr, proxy,
- this);
- pthread_attr_destroy(&proxy_thd_attr);
- if (rc)
+ if (instance_monitor == NULL || instance_monitor->start_detached())
{
- log_error("Instance::start(): pthread_create(proxy) failed");
+ delete instance_monitor;
+ log_error("Instance::start(): failed to create the monitoring thread"
+ " to start an instance");
return ER_CANNOT_START_INSTANCE;
}
+ /* The monitoring thread will delete itself when it's finished. */
return 0;
}