From 5dc6a77b409291140e072470673589982a6623a2 Mon Sep 17 00:00:00 2001 From: Arun Kuruvila Date: Mon, 30 May 2016 15:20:08 +0530 Subject: Bug#23035296: MAIN.MYSQLDUMP FAILS BECUASE OF UNEXPECTED ERROR MESSAGE Description:- Mtr test, "main.mysqldump" is failing with an assert when "mysqlimport" client utility is executed with the option "--use_threads". Analysis:- "mysqlimport" uses the option, "--use_threads", to spawn worker threads to complete its job in parallel. But currently the main thread is not waiting for the worker threads to complete its cleanup, rather just wait for the worker threads to say its done doing its job. So the cleanup is done in a race between the worker threads and the main thread. This lead to an assertion failure. Fix:- "my_thread_join()" is introduced in the main thread to join all the worker threads it have spawned. This will let the main thread to wait for all the worker threads to complete its cleanup before calling "my_end()". --- client/mysqlimport.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'client/mysqlimport.c') diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 416159abd81..3e8f694d96d 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -592,7 +592,7 @@ error: pthread_cond_signal(&count_threshhold); pthread_mutex_unlock(&counter_mutex); mysql_thread_end(); - + pthread_exit(0); return 0; } @@ -615,15 +615,30 @@ int main(int argc, char **argv) if (opt_use_threads && !lock_tables) { - pthread_t mainthread; /* Thread descriptor */ - pthread_attr_t attr; /* Thread attributes */ + char **save_argv; + uint worker_thread_count= 0, table_count= 0, i= 0; + pthread_t *worker_threads; /* Thread descriptor */ + pthread_attr_t attr; /* Thread attributes */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, - PTHREAD_CREATE_DETACHED); + PTHREAD_CREATE_JOINABLE); pthread_mutex_init(&counter_mutex, NULL); pthread_cond_init(&count_threshhold, NULL); + /* Count the number of tables. This number denotes the total number + of threads spawn. + */ + save_argv= argv; + for (table_count= 0; *argv != NULL; argv++) + table_count++; + argv= save_argv; + + if (!(worker_threads= (pthread_t*) my_malloc(table_count * + sizeof(*worker_threads), + MYF(0)))) + return -2; + for (counter= 0; *argv != NULL; argv++) /* Loop through tables */ { pthread_mutex_lock(&counter_mutex); @@ -638,15 +653,16 @@ int main(int argc, char **argv) counter++; pthread_mutex_unlock(&counter_mutex); /* now create the thread */ - if (pthread_create(&mainthread, &attr, worker_thread, - (void *)*argv) != 0) + if (pthread_create(&worker_threads[worker_thread_count], &attr, + worker_thread, (void *)*argv) != 0) { pthread_mutex_lock(&counter_mutex); counter--; pthread_mutex_unlock(&counter_mutex); - fprintf(stderr,"%s: Could not create thread\n", - my_progname); + fprintf(stderr,"%s: Could not create thread\n", my_progname); + continue; } + worker_thread_count++; } /* @@ -664,6 +680,14 @@ int main(int argc, char **argv) pthread_mutex_destroy(&counter_mutex); pthread_cond_destroy(&count_threshhold); pthread_attr_destroy(&attr); + + for(i= 0; i < worker_thread_count; i++) + { + if (pthread_join(worker_threads[i], NULL)) + fprintf(stderr,"%s: Could not join worker thread.\n", my_progname); + } + + my_free(worker_threads); } else { -- cgit v1.2.1 From 96d90250c66d9159522582a541c87e3c9d8b8d08 Mon Sep 17 00:00:00 2001 From: Arun Kuruvila Date: Thu, 2 Jun 2016 15:02:46 +0530 Subject: Bug#23035296: MAIN.MYSQLDUMP FAILS BECUASE OF UNEXPECTED ERROR MESSAGE Post push patch to fix test case failure. --- client/mysqlimport.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'client/mysqlimport.c') diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 3e8f694d96d..81eb5a37fde 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -30,6 +30,7 @@ /* Global Thread counter */ uint counter; +pthread_mutex_t init_mutex; pthread_mutex_t counter_mutex; pthread_cond_t count_threshhold; @@ -417,8 +418,13 @@ static MYSQL *db_connect(char *host, char *database, MYSQL *mysql; if (verbose) fprintf(stdout, "Connecting to %s\n", host ? host : "localhost"); + pthread_mutex_lock(&init_mutex); if (!(mysql= mysql_init(NULL))) + { + pthread_mutex_unlock(&init_mutex); return 0; + } + pthread_mutex_unlock(&init_mutex); if (opt_compress) mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS); if (opt_local_file) @@ -623,6 +629,7 @@ int main(int argc, char **argv) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + pthread_mutex_init(&init_mutex, NULL); pthread_mutex_init(&counter_mutex, NULL); pthread_cond_init(&count_threshhold, NULL); @@ -677,6 +684,7 @@ int main(int argc, char **argv) pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime); } pthread_mutex_unlock(&counter_mutex); + pthread_mutex_destroy(&init_mutex); pthread_mutex_destroy(&counter_mutex); pthread_cond_destroy(&count_threshhold); pthread_attr_destroy(&attr); -- cgit v1.2.1 From df0d8efaf25a69990cf422d55011c1c0eebdec51 Mon Sep 17 00:00:00 2001 From: Arun Kuruvila Date: Fri, 3 Jun 2016 12:50:23 +0530 Subject: Bug#23035296: MAIN.MYSQLDUMP FAILS BECUASE OF UNEXPECTED ERROR MESSAGE Post push patch to fix test case failure. --- client/mysqlimport.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'client/mysqlimport.c') diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 81eb5a37fde..5841c0b855a 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -418,13 +418,19 @@ static MYSQL *db_connect(char *host, char *database, MYSQL *mysql; if (verbose) fprintf(stdout, "Connecting to %s\n", host ? host : "localhost"); - pthread_mutex_lock(&init_mutex); - if (!(mysql= mysql_init(NULL))) + if (opt_use_threads && !lock_tables) { + pthread_mutex_lock(&init_mutex); + if (!(mysql= mysql_init(NULL))) + { + pthread_mutex_unlock(&init_mutex); + return 0; + } pthread_mutex_unlock(&init_mutex); - return 0; } - pthread_mutex_unlock(&init_mutex); + else + if (!(mysql= mysql_init(NULL))) + return 0; if (opt_compress) mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS); if (opt_local_file) -- cgit v1.2.1