summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorArun Kuruvila <arun.kuruvila@oracle.com>2016-05-30 15:20:08 +0530
committerArun Kuruvila <arun.kuruvila@oracle.com>2016-05-30 15:20:08 +0530
commit5dc6a77b409291140e072470673589982a6623a2 (patch)
tree67b4e6c4db8ec0cb4caacccb3be736961fbc949c /client
parent115f08284df1dac6a29cbca49dc7534b4a4f23f7 (diff)
downloadmariadb-git-5dc6a77b409291140e072470673589982a6623a2.tar.gz
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()".
Diffstat (limited to 'client')
-rw-r--r--client/mysqlimport.c40
1 files changed, 32 insertions, 8 deletions
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
{