#include "instance.h"#include <my_global.h>#include <mysql.h>#include <signal.h>#include <sys/wait.h>#include "guardian.h"#include "instance_map.h"#include "log.h"#include "mysql_manager_error.h"#include "portability.h"#include "priv.h"Include dependency graph for instance.cc:

Go to the source code of this file.
Typedefs | |
| typedef pid_t | My_process_info |
Functions | |
| static void | start_and_monitor_instance (Instance_options *old_instance_options, Instance_map *instance_map) |
| pthread_handler_t | proxy (void *arg) |
| static int | wait_process (My_process_info *pi) |
| static int | start_process (Instance_options *instance_options, My_process_info *pi) |
Variables | |
| static const char *const | INSTANCE_NAME_PREFIX = Instance::DFLT_INSTANCE_NAME.str |
| static const int | INSTANCE_NAME_PREFIX_LEN = Instance::DFLT_INSTANCE_NAME.length |
| typedef pid_t My_process_info |
Definition at line 50 of file instance.cc.
| pthread_handler_t proxy | ( | void * | arg | ) |
Definition at line 62 of file instance.cc.
References Instance::get_map(), Instance::options, and start_and_monitor_instance().
Referenced by Instance::start().
00063 { 00064 Instance *instance= (Instance *) arg; 00065 start_and_monitor_instance(&instance->options, 00066 instance->get_map()); 00067 return 0; 00068 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void start_and_monitor_instance | ( | Instance_options * | old_instance_options, | |
| Instance_map * | instance_map | |||
| ) | [static] |
Definition at line 241 of file instance.cc.
References Instance_map::find(), Instance_name::get_c_str(), Instance_name::get_str(), Instance_options::instance_name, Instance_map::lock(), log_info(), Instance::set_crash_flag_n_wake_all(), start_process(), Instance_map::unlock(), and wait_process().
Referenced by proxy().
00243 { 00244 Instance_name instance_name(&old_instance_options->instance_name); 00245 Instance *current_instance; 00246 My_process_info process_info; 00247 00248 /* 00249 Lock instance map to guarantee that no instances are deleted during 00250 strmake() and execv() calls. 00251 */ 00252 instance_map->lock(); 00253 00254 /* 00255 Save the instance name in the case if Instance object we 00256 are using is destroyed. (E.g. by "FLUSH INSTANCES") 00257 */ 00258 00259 log_info("starting instance %s", (const char *) instance_name.get_c_str()); 00260 00261 if (start_process(old_instance_options, &process_info)) 00262 { 00263 instance_map->unlock(); 00264 return; /* error is logged */ 00265 } 00266 00267 /* allow users to delete instances */ 00268 instance_map->unlock(); 00269 00270 /* don't check for return value */ 00271 wait_process(&process_info); 00272 00273 instance_map->lock(); 00274 00275 current_instance= instance_map->find(instance_name.get_str()); 00276 00277 if (current_instance) 00278 current_instance->set_crash_flag_n_wake_all(); 00279 00280 instance_map->unlock(); 00281 00282 return; 00283 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int start_process | ( | Instance_options * | instance_options, | |
| My_process_info * | pi | |||
| ) | [static] |
Definition at line 147 of file instance.cc.
References Instance_options::argv, exit, Instance_options::instance_name, log_info(), Instance_options::mysqld_path, and LEX_STRING::str.
Referenced by start_and_monitor_instance().
00149 { 00150 #ifndef __QNX__ 00151 *pi= fork(); 00152 #else 00153 /* 00154 On QNX one cannot use fork() in multithreaded environment and we 00155 should use spawn() or one of it's siblings instead. 00156 Here we use spawnv(), which is a combination of fork() and execv() 00157 in one call. It returns the pid of newly created process (>0) or -1 00158 */ 00159 *pi= spawnv(P_NOWAIT, instance_options->mysqld_path, instance_options->argv); 00160 #endif 00161 00162 switch (*pi) { 00163 case 0: /* never happens on QNX */ 00164 execv(instance_options->mysqld_path.str, instance_options->argv); 00165 /* exec never returns */ 00166 exit(1); 00167 case -1: 00168 log_info("cannot create a new process to start instance %s", 00169 instance_options->instance_name); 00170 return 1; 00171 } 00172 return 0; 00173 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int wait_process | ( | My_process_info * | pi | ) | [static] |
Definition at line 84 of file instance.cc.
References linuxthreads, and NULL.
Referenced by start_and_monitor_instance().
00085 { 00086 /* 00087 Here we wait for the child created. This process differs for systems 00088 running LinuxThreads and POSIX Threads compliant systems. This is because 00089 according to POSIX we could wait() for a child in any thread of the 00090 process. While LinuxThreads require that wait() is called by the thread, 00091 which created the child. 00092 On the other hand we could not expect mysqld to return the pid, we 00093 got in from fork(), to wait4() fucntion when running on LinuxThreads. 00094 This is because MySQL shutdown thread is not the one, which was created 00095 by our fork() call. 00096 So basically we have two options: whether the wait() call returns only in 00097 the creator thread, but we cannot use waitpid() since we have no idea 00098 which pid we should wait for (in fact it should be the pid of shutdown 00099 thread, but we don't know this one). Or we could use waitpid(), but 00100 couldn't use wait(), because it could return in any wait() in the program. 00101 */ 00102 if (linuxthreads) 00103 wait(NULL); /* LinuxThreads were detected */ 00104 else 00105 waitpid(*pi, NULL, 0); 00106 00107 return 0; 00108 }
Here is the caller graph for this function:

const char* const INSTANCE_NAME_PREFIX = Instance::DFLT_INSTANCE_NAME.str [static] |
Definition at line 42 of file instance.cc.
Referenced by Instance::is_mysqld_compatible_name(), and Instance::is_name_valid().
const int INSTANCE_NAME_PREFIX_LEN = Instance::DFLT_INSTANCE_NAME.length [static] |
1.4.7

