Commit 5dc6a77b authored by Arun Kuruvila's avatar Arun Kuruvila

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()".
parent 115f0828
...@@ -592,7 +592,7 @@ pthread_handler_t worker_thread(void *arg) ...@@ -592,7 +592,7 @@ pthread_handler_t worker_thread(void *arg)
pthread_cond_signal(&count_threshhold); pthread_cond_signal(&count_threshhold);
pthread_mutex_unlock(&counter_mutex); pthread_mutex_unlock(&counter_mutex);
mysql_thread_end(); mysql_thread_end();
pthread_exit(0);
return 0; return 0;
} }
...@@ -615,15 +615,30 @@ int main(int argc, char **argv) ...@@ -615,15 +615,30 @@ int main(int argc, char **argv)
if (opt_use_threads && !lock_tables) if (opt_use_threads && !lock_tables)
{ {
pthread_t mainthread; /* Thread descriptor */ char **save_argv;
pthread_attr_t attr; /* Thread attributes */ 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_init(&attr);
pthread_attr_setdetachstate(&attr, pthread_attr_setdetachstate(&attr,
PTHREAD_CREATE_DETACHED); PTHREAD_CREATE_JOINABLE);
pthread_mutex_init(&counter_mutex, NULL); pthread_mutex_init(&counter_mutex, NULL);
pthread_cond_init(&count_threshhold, 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 */ for (counter= 0; *argv != NULL; argv++) /* Loop through tables */
{ {
pthread_mutex_lock(&counter_mutex); pthread_mutex_lock(&counter_mutex);
...@@ -638,15 +653,16 @@ int main(int argc, char **argv) ...@@ -638,15 +653,16 @@ int main(int argc, char **argv)
counter++; counter++;
pthread_mutex_unlock(&counter_mutex); pthread_mutex_unlock(&counter_mutex);
/* now create the thread */ /* now create the thread */
if (pthread_create(&mainthread, &attr, worker_thread, if (pthread_create(&worker_threads[worker_thread_count], &attr,
(void *)*argv) != 0) worker_thread, (void *)*argv) != 0)
{ {
pthread_mutex_lock(&counter_mutex); pthread_mutex_lock(&counter_mutex);
counter--; counter--;
pthread_mutex_unlock(&counter_mutex); pthread_mutex_unlock(&counter_mutex);
fprintf(stderr,"%s: Could not create thread\n", fprintf(stderr,"%s: Could not create thread\n", my_progname);
my_progname); continue;
} }
worker_thread_count++;
} }
/* /*
...@@ -664,6 +680,14 @@ int main(int argc, char **argv) ...@@ -664,6 +680,14 @@ int main(int argc, char **argv)
pthread_mutex_destroy(&counter_mutex); pthread_mutex_destroy(&counter_mutex);
pthread_cond_destroy(&count_threshhold); pthread_cond_destroy(&count_threshhold);
pthread_attr_destroy(&attr); 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 else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment