From d9711e32b966610af3969c76f7e96f18478dffca Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 May 2003 22:44:37 +0300 Subject: Many files: Exit all threads created by innoDB at shutdown innobase/os/os0file.c: Exit all threads created by innoDB at shutdown innobase/os/os0sync.c: Exit all threads created by innoDB at shutdown innobase/os/os0thread.c: Exit all threads created by innoDB at shutdown innobase/include/os0file.h: Exit all threads created by innoDB at shutdown innobase/include/os0sync.h: Exit all threads created by innoDB at shutdown innobase/include/os0thread.h: Exit all threads created by innoDB at shutdown innobase/log/log0log.c: Exit all threads created by innoDB at shutdown innobase/srv/srv0srv.c: Exit all threads created by innoDB at shutdown innobase/srv/srv0start.c: Exit all threads created by innoDB at shutdown --- innobase/srv/srv0start.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'innobase/srv/srv0start.c') diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index d47af68d663..3d98e116905 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -1470,6 +1470,8 @@ innobase_shutdown_for_mysql(void) /*=============================*/ /* out: DB_SUCCESS or error code */ { + ulint i; + if (!srv_was_started) { if (srv_is_being_started) { ut_print_timestamp(stderr); @@ -1494,6 +1496,58 @@ innobase_shutdown_for_mysql(void) srv_conc_n_threads); } + /* Now we will exit all threads InnoDB created */ + + srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS; + + /* All threads end up waiting for certain events. Put those events + to the signaled state. Then the threads will exit themselves in + os_thread_event_wait(). */ + + for (i = 0; i < 1000; i++) { + /* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM + HERE OR EARLIER */ + + /* 1. Let the lock timeout thread exit */ + os_event_set(srv_lock_timeout_thread_event); + + /* 2. srv error monitor thread exits automatically, no need + to do anything here */ + + /* 3. We wake the master thread so that it exits */ + srv_wake_master_thread(); + + /* 4. Exit the i/o threads */ + + os_aio_wake_all_threads_at_shutdown(); + + os_mutex_enter(os_thread_count_mutex); + + if (os_thread_count == 0) { + /* All the threads have exited or are just exiting; + NOTE that the threads may not have completed their + exit yet. Should we use pthread_join() to make sure + they have exited? Now we just sleep 0.1 seconds and + hope that is enough! */ + + os_mutex_exit(os_thread_count_mutex); + + os_thread_sleep(100000); + + break; + } + + os_mutex_exit(os_thread_count_mutex); + + os_thread_sleep(100000); + } + + if (i == 1000) { + fprintf(stderr, +"InnoDB: Warning: %lu threads created by InnoDB had not exited at shutdown!\n", + os_thread_count); + } + #if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) /* TODO: Fix this temporary solution @@ -1518,6 +1572,10 @@ innobase_shutdown_for_mysql(void) /* NetWare requires this free */ ut_free_all_mem(); #endif + if (srv_print_verbose_log) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Shutdown completed\n"); + } return((int) DB_SUCCESS); } -- cgit v1.2.1 From 5d1171c024089093d6274dd9d18b480c93516109 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 May 2003 23:00:37 +0300 Subject: srv0start.c: Cleanup innobase/srv/srv0start.c: Cleanup --- innobase/srv/srv0start.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'innobase/srv/srv0start.c') diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index 3d98e116905..d34c18b1a25 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -1549,13 +1549,6 @@ innobase_shutdown_for_mysql(void) } #if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) - /* - TODO: Fix this temporary solution - We are having a race condition occure with io_handler_thread threads. - When they yield in os_aio_simulated_handle during shutdown, this - thread was able to free the memory early. - */ - os_thread_yield(); /* TODO: Where should this be called? */ srv_free(); @@ -1563,11 +1556,7 @@ innobase_shutdown_for_mysql(void) /* TODO: Where should this be called? */ srv_general_free(); #endif - /* - TODO: We should exit the i/o-handler and other utility threads - before freeing all memory. Now this can potentially cause a seg - fault! - */ + #if defined(NOT_WORKING_YET) || defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) /* NetWare requires this free */ ut_free_all_mem(); -- cgit v1.2.1 From 3cba21f9f5abdaea110f40155467cab2899b5461 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 31 May 2003 03:12:03 +0300 Subject: Many files: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/os/os0sync.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/os/os0thread.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/include/os0sync.h: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/include/srv0srv.h: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/include/srv0start.h: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/ibuf/ibuf0ibuf.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/srv/srv0srv.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/srv/srv0start.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/sync/sync0sync.c: Free all OS sync primitives and allocated memory in InnoDB shutdown innobase/ut/ut0mem.c: Free all OS sync primitives and allocated memory in InnoDB shutdown --- innobase/srv/srv0start.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'innobase/srv/srv0start.c') diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index d34c18b1a25..f03355b825c 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -1442,9 +1442,7 @@ innobase_start_or_create_for_mysql(void) os_fast_mutex_unlock(&srv_os_test_mutex); -#if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) - os_fast_mutex_free(&srv_os_test_mutex); /* all platforms? */ -#endif /* __NETWARE__ */ + os_fast_mutex_free(&srv_os_test_mutex); if (srv_print_verbose_log) { ut_print_timestamp(stderr); @@ -1484,7 +1482,7 @@ innobase_shutdown_for_mysql(void) return(DB_SUCCESS); } - /* Flush buffer pool to disk, write the current lsn to + /* 1. Flush buffer pool to disk, write the current lsn to the tablespace header(s), and copy all log data to archive */ logs_empty_and_mark_files_at_shutdown(); @@ -1496,7 +1494,7 @@ innobase_shutdown_for_mysql(void) srv_conc_n_threads); } - /* Now we will exit all threads InnoDB created */ + /* 2. Make all threads created by InnoDB to exit */ srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS; @@ -1521,7 +1519,7 @@ innobase_shutdown_for_mysql(void) os_aio_wake_all_threads_at_shutdown(); - os_mutex_enter(os_thread_count_mutex); + os_mutex_enter(os_sync_mutex); if (os_thread_count == 0) { /* All the threads have exited or are just exiting; @@ -1530,14 +1528,14 @@ innobase_shutdown_for_mysql(void) they have exited? Now we just sleep 0.1 seconds and hope that is enough! */ - os_mutex_exit(os_thread_count_mutex); + os_mutex_exit(os_sync_mutex); os_thread_sleep(100000); break; } - os_mutex_exit(os_thread_count_mutex); + os_mutex_exit(os_sync_mutex); os_thread_sleep(100000); } @@ -1548,19 +1546,21 @@ innobase_shutdown_for_mysql(void) os_thread_count); } -#if defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) + /* 3. Free all InnoDB's own mutexes */ + + sync_close(); + + /* 4. Free all OS synchronization primitives (in Windows currently + events are not freed) */ - /* TODO: Where should this be called? */ srv_free(); + os_sync_free(); - /* TODO: Where should this be called? */ - srv_general_free(); -#endif + /* 5. Free all allocated memory (and the os_fast_mutex created in + ut0mem.c */ -#if defined(NOT_WORKING_YET) || defined(__NETWARE__) || defined(SAFE_MUTEX_DETECT_DESTROY) - /* NetWare requires this free */ ut_free_all_mem(); -#endif + if (srv_print_verbose_log) { ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Shutdown completed\n"); -- cgit v1.2.1