diff options
author | unknown <anozdrin/alik@alik.> | 2006-10-24 18:23:16 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@alik.> | 2006-10-24 18:23:16 +0400 |
commit | aeec459369c951b66a65fa2238dd0e4185ab2aa3 (patch) | |
tree | 6d8630918dcef38a122bcfb66ecee31e94a8b0af /server-tools/instance-manager/instance.cc | |
parent | 66b872805cbd542c6012eef7141443d95a697f7d (diff) | |
download | mariadb-git-aeec459369c951b66a65fa2238dd0e4185ab2aa3.tar.gz |
Fix for BUG#17486: IM: race condition on exit.
The problem was that IM stoped guarded instances on shutdown,
but didn't wait for them to stop.
The fix is to wait for guarded instances to stop before exitting
from the main thread.
The idea is that Instance-monitoring thread should add itself
to Thread_registry so that it will be taken into account on shutdown.
However, Thread_registry should not signal it on shutdown in order to
not interrupt wait()/waitpid().
server-tools/instance-manager/guardian.cc:
Be more verbose.
server-tools/instance-manager/instance.cc:
Register mysqld-monitoring thread in Thread_registry.
server-tools/instance-manager/instance.h:
Add reference to Thread_registry.
server-tools/instance-manager/instance_map.cc:
Pass Thread_registry reference to Instance.
server-tools/instance-manager/instance_map.h:
Add reference to Thread_registry.
server-tools/instance-manager/listener.cc:
Be more verbose.
server-tools/instance-manager/manager.cc:
Be more verbose.
server-tools/instance-manager/mysql_connection.cc:
Eliminate type-conversion warnings.
server-tools/instance-manager/thread_registry.cc:
Be more verbose.
server-tools/instance-manager/thread_registry.h:
Eliminate copy&paste, make impl-specific constructor private.
Diffstat (limited to 'server-tools/instance-manager/instance.cc')
-rw-r--r-- | server-tools/instance-manager/instance.cc | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index 1dfe6167020..3927363a3e5 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -34,6 +34,7 @@ #include "mysql_manager_error.h" #include "portability.h" #include "priv.h" +#include "thread_registry.h" const LEX_STRING @@ -44,7 +45,8 @@ 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); + Instance_map *instance_map, + Thread_registry *thread_registry); #ifndef __WIN__ typedef pid_t My_process_info; @@ -63,7 +65,8 @@ pthread_handler_t proxy(void *arg) { Instance *instance= (Instance *) arg; start_and_monitor_instance(&instance->options, - instance->get_map()); + instance->get_map(), + &instance->thread_registry); return 0; } @@ -99,6 +102,7 @@ static int wait_process(My_process_info *pi) thread, but we don't know this one). Or we could use waitpid(), but couldn't use wait(), because it could return in any wait() in the program. */ + if (linuxthreads) wait(NULL); /* LinuxThreads were detected */ else @@ -239,11 +243,28 @@ static int start_process(Instance_options *instance_options, */ static void start_and_monitor_instance(Instance_options *old_instance_options, - Instance_map *instance_map) + 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); + + log_info("Monitoring thread (instance: '%s'): started.", + (const char *) instance_name.get_c_str()); + + if (!old_instance_options->nonguarded) + { + /* + 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 + finish, because nonguarded instances are not stopped on shutdown. + */ + + thread_registry->register_thread(&thread_info); + my_thread_init(); + } /* Lock instance map to guarantee that no instances are deleted during @@ -280,7 +301,14 @@ static void start_and_monitor_instance(Instance_options *old_instance_options, instance_map->unlock(); - return; + 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()); } @@ -343,10 +371,6 @@ int Instance::start() { remove_pid(); - /* - No need to monitor this thread in the Thread_registry, as all - instances are to be stopped during shutdown. - */ pthread_t proxy_thd_id; pthread_attr_t proxy_thd_attr; int rc; @@ -404,7 +428,8 @@ void Instance::set_crash_flag_n_wake_all() -Instance::Instance(): crashed(FALSE), configured(FALSE) +Instance::Instance(Thread_registry &thread_registry_arg): + crashed(FALSE), configured(FALSE), thread_registry(thread_registry_arg) { pthread_mutex_init(&LOCK_instance, 0); pthread_cond_init(&COND_instance_stopped, 0); |