Skip to content

Commit 5dc6a77

Browse files
author
Arun Kuruvila
committed
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()".
1 parent 115f082 commit 5dc6a77

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

client/mysqlimport.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ pthread_handler_t worker_thread(void *arg)
592592
pthread_cond_signal(&count_threshhold);
593593
pthread_mutex_unlock(&counter_mutex);
594594
mysql_thread_end();
595-
595+
pthread_exit(0);
596596
return 0;
597597
}
598598

@@ -615,15 +615,30 @@ int main(int argc, char **argv)
615615

616616
if (opt_use_threads && !lock_tables)
617617
{
618-
pthread_t mainthread; /* Thread descriptor */
619-
pthread_attr_t attr; /* Thread attributes */
618+
char **save_argv;
619+
uint worker_thread_count= 0, table_count= 0, i= 0;
620+
pthread_t *worker_threads; /* Thread descriptor */
621+
pthread_attr_t attr; /* Thread attributes */
620622
pthread_attr_init(&attr);
621623
pthread_attr_setdetachstate(&attr,
622-
PTHREAD_CREATE_DETACHED);
624+
PTHREAD_CREATE_JOINABLE);
623625

624626
pthread_mutex_init(&counter_mutex, NULL);
625627
pthread_cond_init(&count_threshhold, NULL);
626628

629+
/* Count the number of tables. This number denotes the total number
630+
of threads spawn.
631+
*/
632+
save_argv= argv;
633+
for (table_count= 0; *argv != NULL; argv++)
634+
table_count++;
635+
argv= save_argv;
636+
637+
if (!(worker_threads= (pthread_t*) my_malloc(table_count *
638+
sizeof(*worker_threads),
639+
MYF(0))))
640+
return -2;
641+
627642
for (counter= 0; *argv != NULL; argv++) /* Loop through tables */
628643
{
629644
pthread_mutex_lock(&counter_mutex);
@@ -638,15 +653,16 @@ int main(int argc, char **argv)
638653
counter++;
639654
pthread_mutex_unlock(&counter_mutex);
640655
/* now create the thread */
641-
if (pthread_create(&mainthread, &attr, worker_thread,
642-
(void *)*argv) != 0)
656+
if (pthread_create(&worker_threads[worker_thread_count], &attr,
657+
worker_thread, (void *)*argv) != 0)
643658
{
644659
pthread_mutex_lock(&counter_mutex);
645660
counter--;
646661
pthread_mutex_unlock(&counter_mutex);
647-
fprintf(stderr,"%s: Could not create thread\n",
648-
my_progname);
662+
fprintf(stderr,"%s: Could not create thread\n", my_progname);
663+
continue;
649664
}
665+
worker_thread_count++;
650666
}
651667

652668
/*
@@ -664,6 +680,14 @@ int main(int argc, char **argv)
664680
pthread_mutex_destroy(&counter_mutex);
665681
pthread_cond_destroy(&count_threshhold);
666682
pthread_attr_destroy(&attr);
683+
684+
for(i= 0; i < worker_thread_count; i++)
685+
{
686+
if (pthread_join(worker_threads[i], NULL))
687+
fprintf(stderr,"%s: Could not join worker thread.\n", my_progname);
688+
}
689+
690+
my_free(worker_threads);
667691
}
668692
else
669693
{

0 commit comments

Comments
 (0)