diff options
author | monty@mysql.com <> | 2005-11-05 01:32:55 +0200 |
---|---|---|
committer | monty@mysql.com <> | 2005-11-05 01:32:55 +0200 |
commit | a6f5375cb0cb40055f52e92d20ca04233ce70386 (patch) | |
tree | 4a7b533b6da471261f5c13c46e4e9f256ec63a0c /server-tools | |
parent | 3b74bb1b03a32616818f50f59cc44644036ab711 (diff) | |
parent | 303f6b4a7a44511aeb33ccbd9ff43ea2d454aa4c (diff) | |
download | mariadb-git-a6f5375cb0cb40055f52e92d20ca04233ce70386.tar.gz |
Merge mysql.com:/home/my/mysql-5.0
into mysql.com:/home/my/mysql-5.1
Diffstat (limited to 'server-tools')
-rw-r--r-- | server-tools/instance-manager/Makefile.am | 4 | ||||
-rw-r--r-- | server-tools/instance-manager/command.h | 4 | ||||
-rw-r--r-- | server-tools/instance-manager/instance.cc | 21 | ||||
-rw-r--r-- | server-tools/instance-manager/instance_options.cc | 11 | ||||
-rw-r--r-- | server-tools/instance-manager/listener.cc | 15 | ||||
-rw-r--r-- | server-tools/instance-manager/listener.h | 6 | ||||
-rw-r--r-- | server-tools/instance-manager/manager.cc | 22 | ||||
-rw-r--r-- | server-tools/instance-manager/mysql_connection.h | 7 | ||||
-rw-r--r-- | server-tools/instance-manager/options.h | 8 | ||||
-rw-r--r-- | server-tools/instance-manager/parse_output.cc | 25 | ||||
-rw-r--r-- | server-tools/instance-manager/priv.cc | 36 | ||||
-rw-r--r-- | server-tools/instance-manager/priv.h | 6 | ||||
-rw-r--r-- | server-tools/instance-manager/thread_registry.cc | 23 | ||||
-rw-r--r-- | server-tools/instance-manager/thread_registry.h | 16 | ||||
-rw-r--r-- | server-tools/instance-manager/user_map.h | 7 |
15 files changed, 152 insertions, 59 deletions
diff --git a/server-tools/instance-manager/Makefile.am b/server-tools/instance-manager/Makefile.am index b872adca09d..4fa2a0da405 100644 --- a/server-tools/instance-manager/Makefile.am +++ b/server-tools/instance-manager/Makefile.am @@ -15,7 +15,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA INCLUDES= @ZLIB_INCLUDES@ -I$(top_srcdir)/include \ - $(openssl_includes) -I$(top_builddir)/include + @openssl_includes@ @yassl_includes@ -I$(top_builddir)/include DEFS= -DMYSQL_INSTANCE_MANAGER -DMYSQL_SERVER @@ -85,7 +85,7 @@ mysqlmanager_LDADD= liboptions.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/strings/libmystrings.a \ $(top_builddir)/dbug/libdbug.a \ - @openssl_libs@ @ZLIB_LIBS@ + @openssl_libs@ @yassl_libs@ @ZLIB_LIBS@ tags: diff --git a/server-tools/instance-manager/command.h b/server-tools/instance-manager/command.h index 82ded800e65..b84cc6a8e9e 100644 --- a/server-tools/instance-manager/command.h +++ b/server-tools/instance-manager/command.h @@ -16,12 +16,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <my_global.h> + #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif -#include <my_global.h> - /* Class responsible for allocation of im commands. */ class Instance_map; diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index ff3387334b6..3d54d000d5f 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -138,15 +138,25 @@ static int wait_process(My_process_info *pi) static int start_process(Instance_options *instance_options, My_process_info *pi) { +#ifndef __QNX__ *pi= fork(); +#else + /* + On QNX one cannot use fork() in multithreaded environment and we + should use spawn() or one of it's siblings instead. + Here we use spawnv(), which is a combination of fork() and execv() + in one call. It returns the pid of newly created process (>0) or -1 + */ + *pi= spawnv(P_NOWAIT, instance_options->mysqld_path, instance_options->argv); +#endif switch (*pi) { - case 0: + case 0: /* never happens on QNX */ execv(instance_options->mysqld_path, instance_options->argv); /* exec never returns */ exit(1); - case 1: - log_info("cannot fork() to start instance %s", + case -1: + log_info("cannot create a new process to start instance %s", instance_options->instance_name); return 1; } @@ -170,7 +180,8 @@ static int start_process(Instance_options *instance_options, char *cmdline= new char[cmdlen]; if (cmdline == NULL) return 1; - + + cmdline[0]= 0; for (int i= 0; instance_options->argv[i] != 0; i++) { strcat(cmdline, "\""); @@ -469,7 +480,7 @@ int Instance::stop() status= pthread_cond_timedwait(&COND_instance_stopped, &LOCK_instance, &timeout); - if (status == ETIMEDOUT) + if (status == ETIMEDOUT || status == ETIME) break; } diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc index 25609f489af..83f13b34aa2 100644 --- a/server-tools/instance-manager/instance_options.cc +++ b/server-tools/instance-manager/instance_options.cc @@ -47,14 +47,12 @@ static inline int create_mysqld_command(Buffer *buf, if (buf->get_size()) /* malloc succeeded */ { #ifdef __WIN__ - buf->append(position, "\"", 1); - position++; + buf->append(position++, "\"", 1); #endif buf->append(position, mysqld_path_str, mysqld_path_len); position+= mysqld_path_len; #ifdef __WIN__ - buf->append(position, "\"", 1); - position++; + buf->append(position++, "\"", 1); #endif /* here the '\0' character is copied from the option string */ buf->append(position, option, option_len); @@ -336,10 +334,15 @@ int Instance_options::complete_initialization(const char *default_path, uint instance_type) { const char *tmp; + char *end; if (!mysqld_path && !(mysqld_path= strdup_root(&alloc, default_path))) goto err; + // it's safe to cast this to char* since this is a buffer we are allocating + end= convert_dirname((char*)mysqld_path, mysqld_path, NullS); + end[-1]= 0; + mysqld_path_len= strlen(mysqld_path); if (mysqld_port) diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc index 08c28dc9f7d..67d798a1700 100644 --- a/server-tools/instance-manager/listener.cc +++ b/server-tools/instance-manager/listener.cc @@ -122,11 +122,15 @@ void Listener_thread::run() n++; timeval tv; - tv.tv_sec= 0; - tv.tv_usec= 100000; while (!thread_registry.is_shutdown()) { fd_set read_fds_arg= read_fds; + /* + We should reintialize timer as on linux it is modified + to reflect amount of time not slept. + */ + tv.tv_sec= 0; + tv.tv_usec= 100000; /* When using valgrind 2.0 this syscall doesn't get kicked off by a @@ -358,12 +362,13 @@ void Listener_thread::handle_new_mysql_connection(Vio *vio) pthread_attr_t mysql_thd_attr; pthread_attr_init(&mysql_thd_attr); pthread_attr_setdetachstate(&mysql_thd_attr, PTHREAD_CREATE_DETACHED); - if (pthread_create(&mysql_thd_id, &mysql_thd_attr, mysql_connection, - mysql_thread_args)) + if (set_stacksize_n_create_thread(&mysql_thd_id, &mysql_thd_attr, + mysql_connection, mysql_thread_args)) { delete mysql_thread_args; vio_delete(vio); - log_error("handle_one_mysql_connection(): pthread_create(mysql) failed"); + log_error("handle_one_mysql_connection():" + "set_stacksize_n_create_thread(mysql) failed"); } pthread_attr_destroy(&mysql_thd_attr); } diff --git a/server-tools/instance-manager/listener.h b/server-tools/instance-manager/listener.h index e0ab5b8ef2b..28ccbf91731 100644 --- a/server-tools/instance-manager/listener.h +++ b/server-tools/instance-manager/listener.h @@ -16,13 +16,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <my_global.h> +#include <my_pthread.h> + #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) #pragma interface #endif -#include <my_global.h> -#include <my_pthread.h> - pthread_handler_t listener(void *arg); diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index a42a25eadf3..3ecd5fbc0d0 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -162,12 +162,12 @@ void manager(const Options &options) pthread_attr_init(&listener_thd_attr); pthread_attr_setdetachstate(&listener_thd_attr, PTHREAD_CREATE_DETACHED); - rc= pthread_create(&listener_thd_id, &listener_thd_attr, listener, - &listener_args); + rc= set_stacksize_n_create_thread(&listener_thd_id, &listener_thd_attr, + listener, &listener_args); pthread_attr_destroy(&listener_thd_attr); if (rc) { - log_error("manager(): pthread_create(listener) failed"); + log_error("manager(): set_stacksize_n_create_thread(listener) failed"); goto err; } @@ -187,12 +187,12 @@ void manager(const Options &options) pthread_attr_init(&guardian_thd_attr); pthread_attr_setdetachstate(&guardian_thd_attr, PTHREAD_CREATE_DETACHED); - rc= pthread_create(&guardian_thd_id, &guardian_thd_attr, guardian, - &guardian_thread); + rc= set_stacksize_n_create_thread(&guardian_thd_id, &guardian_thd_attr, + guardian, &guardian_thread); pthread_attr_destroy(&guardian_thd_attr); if (rc) { - log_error("manager(): pthread_create(guardian) failed"); + log_error("manager(): set_stacksize_n_create_thread(guardian) failed"); goto err; } @@ -231,6 +231,16 @@ void manager(const Options &options) } #ifndef __WIN__ +/* + On some Darwin kernels SIGHUP is delivered along with most + signals. This is why we skip it's processing on these + platforms. For more details and test program see + Bug #14164 IM tests fail on MacOS X (powermacg5) +*/ +#ifdef IGNORE_SIGHUP_SIGQUIT + if ( SIGHUP == signo ) + continue; +#endif if (THR_SERVER_ALARM == signo) process_alarm(signo); else diff --git a/server-tools/instance-manager/mysql_connection.h b/server-tools/instance-manager/mysql_connection.h index 492937b2198..3496cc05815 100644 --- a/server-tools/instance-manager/mysql_connection.h +++ b/server-tools/instance-manager/mysql_connection.h @@ -16,13 +16,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) -#pragma interface -#endif - #include <my_global.h> #include <my_pthread.h> +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif pthread_handler_t mysql_connection(void *arg); diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h index 3a60de2bb39..6d719c69629 100644 --- a/server-tools/instance-manager/options.h +++ b/server-tools/instance-manager/options.h @@ -16,16 +16,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) -#pragma interface -#endif - /* Options - all possible options for the instance manager grouped in one struct. */ #include <my_global.h> +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif + struct Options { #ifdef __WIN__ diff --git a/server-tools/instance-manager/parse_output.cc b/server-tools/instance-manager/parse_output.cc index b5af3cb83a7..ebc45c1f7d4 100644 --- a/server-tools/instance-manager/parse_output.cc +++ b/server-tools/instance-manager/parse_output.cc @@ -24,6 +24,20 @@ #include "portability.h" +void trim_space(const char **text, uint *word_len) +{ + const char *start= *text; + while (*start != 0 && *start == ' ') + start++; + *text= start; + + int len= strlen(start); + const char *end= start + len - 1; + while (end > start && my_isspace(&my_charset_latin1, *end)) + end--; + *word_len= (end - start)+1; +} + /* Parse output of the given command @@ -82,20 +96,17 @@ int parse_output_and_get_value(const char *command, const char *word, linebuf[sizeof(linebuf) - 1]= '\0'; /* safety */ /* - Get the word, which might contain non-alphanumeric characters. (Usually - these are '/', '-' and '.' in the path expressions and filenames) + Compare the start of our line with the word(s) we are looking for. */ - get_word((const char **) &linep, &found_word_len, NONSPACE); if (!strncmp(word, linep, wordlen)) { /* - If we have found the word, return the next one (this is usually - an option value) or the whole line (if flag) + If we have found our word(s), then move linep past the word(s) */ - linep+= found_word_len; /* swallow the previous one */ + linep+= wordlen; if (flag & GET_VALUE) { - get_word((const char **) &linep, &found_word_len, NONSPACE); + trim_space((const char**) &linep, &found_word_len); if (input_buffer_len <= found_word_len) goto err; strmake(result, linep, found_word_len); diff --git a/server-tools/instance-manager/priv.cc b/server-tools/instance-manager/priv.cc index 02a788ec469..a5040aa2e83 100644 --- a/server-tools/instance-manager/priv.cc +++ b/server-tools/instance-manager/priv.cc @@ -18,6 +18,17 @@ #include "priv.h" #include "portability.h" +#if defined(__ia64__) || defined(__ia64) +/* + We can live with 32K, but reserve 64K. Just to be safe. + On ia64 we need to reserve double of the size. +*/ +#define IM_THREAD_STACK_SIZE (128*1024L) +#else +#define IM_THREAD_STACK_SIZE (64*1024) +#endif + + /* the pid of the manager process (of the signal thread on the LinuxThreads) */ pid_t manager_pid; @@ -52,3 +63,28 @@ unsigned int test_flags= 0; unsigned long bytes_sent = 0L, bytes_received = 0L; unsigned long mysqld_net_retry_count = 10L; unsigned long open_files_limit; + +/* + Change the stack size and start a thread. Return an error if either + pthread_attr_setstacksize or pthread_create fails. + Arguments are the same as for pthread_create(). +*/ + +int set_stacksize_n_create_thread(pthread_t *thread, pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg) +{ + int rc= 0; + +#ifndef __WIN__ + /* + Set stack size to be safe on the platforms with too small + default thread stack. + */ + rc= pthread_attr_setstacksize(attr, + (size_t) (PTHREAD_STACK_MIN + + IM_THREAD_STACK_SIZE)); +#endif + if (!rc) + rc= pthread_create(thread, attr, start_routine, arg); + return rc; +} diff --git a/server-tools/instance-manager/priv.h b/server-tools/instance-manager/priv.h index ce9d54293c7..4739bca68eb 100644 --- a/server-tools/instance-manager/priv.h +++ b/server-tools/instance-manager/priv.h @@ -22,7 +22,7 @@ #else #include <unistd.h> #endif - +#include "my_pthread.h" /* the pid of the manager process (of the signal thread on the LinuxThreads) */ extern pid_t manager_pid; @@ -80,4 +80,8 @@ extern unsigned long bytes_sent, bytes_received; extern unsigned long mysqld_net_retry_count; extern unsigned long open_files_limit; + +int set_stacksize_n_create_thread(pthread_t *thread, pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg); + #endif // INCLUDES_MYSQL_INSTANCE_MANAGER_PRIV_H diff --git a/server-tools/instance-manager/thread_registry.cc b/server-tools/instance-manager/thread_registry.cc index fe665f410e5..0091d713a91 100644 --- a/server-tools/instance-manager/thread_registry.cc +++ b/server-tools/instance-manager/thread_registry.cc @@ -1,4 +1,4 @@ -/* cOPYRIght (C) 2003 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +/* Copyright (C) 2003 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,6 +38,14 @@ static void handle_signal(int __attribute__((unused)) sig_no) #endif /* + Thread_info initializer methods +*/ + +Thread_info::Thread_info() {} +Thread_info::Thread_info(pthread_t thread_id_arg) : + thread_id(thread_id_arg) {} + +/* TODO: think about moving signal information (now it's shutdown_in_progress) to Thread_info. It will reduce contention and allow signal deliverence to a particular thread, not to the whole worker crew @@ -145,6 +153,7 @@ int Thread_registry::cond_timedwait(Thread_info *info, pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *wait_time) { + int rc; pthread_mutex_lock(&LOCK_thread_registry); if (shutdown_in_progress) { @@ -154,7 +163,8 @@ int Thread_registry::cond_timedwait(Thread_info *info, pthread_cond_t *cond, info->current_cond= cond; pthread_mutex_unlock(&LOCK_thread_registry); /* sic: race condition here, cond can be signaled in deliver_shutdown */ - int rc= pthread_cond_timedwait(cond, mutex, wait_time); + if ((rc= pthread_cond_timedwait(cond, mutex, wait_time)) == ETIME) + rc= ETIMEDOUT; // For easier usage pthread_mutex_lock(&LOCK_thread_registry); info->current_cond= 0; pthread_mutex_unlock(&LOCK_thread_registry); @@ -172,6 +182,7 @@ void Thread_registry::deliver_shutdown() { Thread_info *info; struct timespec shutdown_time; + int error; set_timespec(shutdown_time, 1); pthread_mutex_lock(&LOCK_thread_registry); @@ -204,11 +215,13 @@ void Thread_registry::deliver_shutdown() released - the only case when the predicate is false is when no other threads exist. */ - while (pthread_cond_timedwait(&COND_thread_registry_is_empty, - &LOCK_thread_registry, - &shutdown_time) != ETIMEDOUT && + while (((error= pthread_cond_timedwait(&COND_thread_registry_is_empty, + &LOCK_thread_registry, + &shutdown_time)) != ETIMEDOUT && + error != ETIME) && head.next != &head) ; + /* If previous signals did not reach some threads, they must be sleeping in pthread_cond_wait or in a blocking syscall. Wake them up: diff --git a/server-tools/instance-manager/thread_registry.h b/server-tools/instance-manager/thread_registry.h index a1075e719d6..6dc320a8533 100644 --- a/server-tools/instance-manager/thread_registry.h +++ b/server-tools/instance-manager/thread_registry.h @@ -50,13 +50,12 @@ in manner, similar to ``quit'' signals. */ -#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) -#pragma interface -#endif - #include <my_global.h> #include <my_pthread.h> +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif /* Thread_info - repository entry for each worker thread @@ -67,13 +66,14 @@ class Thread_info { +public: + Thread_info(); + Thread_info(pthread_t thread_id_arg); + friend class Thread_registry; +private: pthread_cond_t *current_cond; Thread_info *prev, *next; pthread_t thread_id; - Thread_info() {} - friend class Thread_registry; -public: - Thread_info(pthread_t thread_id_arg) : thread_id(thread_id_arg) {} }; diff --git a/server-tools/instance-manager/user_map.h b/server-tools/instance-manager/user_map.h index a57174a37c3..4134017dd9b 100644 --- a/server-tools/instance-manager/user_map.h +++ b/server-tools/instance-manager/user_map.h @@ -16,15 +16,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) -#pragma interface -#endif #include <my_global.h> #include <my_sys.h> #include <hash.h> +#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE) +#pragma interface +#endif + /* User_map -- all users and passwords */ |