diff options
Diffstat (limited to 'server-tools/instance-manager/manager.cc')
-rw-r--r-- | server-tools/instance-manager/manager.cc | 135 |
1 files changed, 84 insertions, 51 deletions
diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index e126b407522..792461e41a9 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -29,6 +29,8 @@ #include "guardian.h" #include "instance_map.h" #include "listener.h" +#include "mysql_manager_error.h" +#include "mysqld_error.h" #include "log.h" #include "options.h" #include "priv.h" @@ -179,6 +181,56 @@ void Manager::stop_all_threads() /* Stop all threads. */ p_thread_registry->deliver_shutdown(); + + /* Set error status in the thread registry. */ + p_thread_registry->set_error_status(); +} + + +/** + 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; } @@ -194,25 +246,25 @@ void Manager::stop_all_threads() See also comments in mysqlmanager.cc to picture general Instance Manager architecture. - TODO: how about returning error status. + RETURNS + main() returns exit status (exit code). */ int Manager::main() { - int err_code; - int rc= 1; - const char *err_msg; bool shutdown_complete= FALSE; pid_t manager_pid= getpid(); + log_info("Manager: initializing..."); + #ifndef __WIN__ if (check_if_linux_threads(&linux_threads)) { - log_error("Can not determine thread model."); + log_error("Manager: can not determine thread model."); return 1; } - log_info("Detected threads model: %s.", + log_info("Manager: detected threads model: %s.", (const char *) (linux_threads ? "LINUX threads" : "POSIX threads")); #endif // __WIN__ @@ -250,47 +302,23 @@ int Manager::main() if (instance_map.init()) { - log_error("Can not initialize instance list: out of memory."); + log_error("Manager: can not initialize instance list: out of memory."); return 1; } - /* Initialize user map and load password file. */ + /* Initialize user db. */ - if (user_map.init()) - { - log_error("Can not initialize user list: out of memory."); - return 1; - } - - if ((err_code= user_map.load(Options::Main::password_file_name, &err_msg))) - { - 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."); - } - else - { - log_error("%s.", (const char *) err_msg); - return 1; - } - } + if (init_user_map(&user_map)) + return 1; /* logging has been already done. */ /* Write Instance Manager pid file. */ - log_info("IM pid file: '%s'; PID: %d.", - (const char *) Options::Main::pid_file_name, - (int) manager_pid); - if (create_pid_file(Options::Main::pid_file_name, manager_pid)) return 1; /* necessary logging has been already done. */ + log_info("Manager: pid file (%s) created.", + (const char *) Options::Main::pid_file_name); + /* Initialize signals and alarm-infrastructure. @@ -326,7 +354,7 @@ int Manager::main() if (guardian.start(Thread::DETACHED)) { - log_error("Can not start Guardian thread."); + log_error("Manager: can not start Guardian thread."); goto err; } @@ -334,7 +362,7 @@ int Manager::main() if (Manager::flush_instances()) { - log_error("Can not init instances repository."); + log_error("Manager: can not init instances repository."); stop_all_threads(); goto err; } @@ -343,7 +371,7 @@ int Manager::main() if (listener.start(Thread::DETACHED)) { - log_error("Can not start Listener thread."); + log_error("Manager: can not start Listener thread."); stop_all_threads(); goto err; } @@ -366,7 +394,7 @@ int Manager::main() if ((status= my_sigwait(&mask, &signo)) != 0) { - log_error("sigwait() failed"); + log_error("Manager: sigwait() failed"); stop_all_threads(); goto err; } @@ -417,8 +445,6 @@ int Manager::main() log_info("Manager: finished."); - rc= 0; - err: /* delete the pid file */ my_delete(Options::Main::pid_file_name, MYF(0)); @@ -426,9 +452,9 @@ err: #ifndef __WIN__ /* free alarm structures */ end_thr_alarm(1); - /* don't pthread_exit to kill all threads who did not shut down in time */ #endif - return rc; + + return thread_registry.get_error_status() ? 1 : 0; } @@ -460,34 +486,41 @@ err: In order to avoid such side effects one should never call FLUSH INSTANCES without prior stop of all running instances. + + 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 */ -bool Manager::flush_instances() +int Manager::flush_instances() { p_instance_map->lock(); if (p_instance_map->is_there_active_instance()) { p_instance_map->unlock(); - return TRUE; + return ER_THERE_IS_ACTIVE_INSTACE; } if (p_instance_map->reset()) { p_instance_map->unlock(); - return TRUE; + return ER_OUT_OF_RESOURCES; } if (p_instance_map->load()) { p_instance_map->unlock(); - return TRUE; /* Don't init guardian if we failed to load instances. */ + + /* Don't init guardian if we failed to load instances. */ + return ER_OUT_OF_RESOURCES; } - get_guardian()->init(); /* TODO: check error status. */ + get_guardian()->init(); get_guardian()->ping(); p_instance_map->unlock(); - return FALSE; + return 0; } |