summaryrefslogtreecommitdiff
path: root/storage/spider
diff options
context:
space:
mode:
authorKentoku SHIBA <kentokushiba@gmail.com>2019-08-01 08:59:53 +0900
committerGitHub <noreply@github.com>2019-08-01 08:59:53 +0900
commitb428b09997d172f29fc201b9ab05c160ef4cbc39 (patch)
tree2151d5a0cb3f576c4d43660ae8b36851b195129a /storage/spider
parent798080f4b3a49ba51c41a4be3922b4efa34e6896 (diff)
downloadmariadb-git-b428b09997d172f29fc201b9ab05c160ef4cbc39.tar.gz
MDEV-20179 Server hangs on shutdown during installation of Spider (#1369)
Use LOCK_server_started, COND_server_started and mysqld_server_started for waiting starting the server
Diffstat (limited to 'storage/spider')
-rw-r--r--storage/spider/spd_include.h3
-rw-r--r--storage/spider/spd_table.cc119
2 files changed, 53 insertions, 69 deletions
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index 6cd7ddfa181..30a5d598709 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008-2018 Kentoku Shiba
+/* Copyright (C) 2008-2019 Kentoku Shiba
+ Copyright (C) 2019 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index bc788d3e168..ec7549a38c7 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -129,6 +129,9 @@ const char **spd_mysqld_unix_port;
uint *spd_mysqld_port;
bool volatile *spd_abort_loop;
Time_zone *spd_tz_system;
+static int *spd_mysqld_server_started;
+static pthread_mutex_t *spd_LOCK_server_started;
+static pthread_cond_t *spd_COND_server_started;
extern long spider_conn_mutex_id;
handlerton *spider_hton_ptr;
SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
@@ -6568,11 +6571,27 @@ handler* spider_create_handler(
) {
DBUG_ENTER("spider_create_handler");
#ifndef WITHOUT_SPIDER_BG_SEARCH
- if (unlikely(spider_table_sts_threads[0].init_command))
+ SPIDER_THREAD *thread = &spider_table_sts_threads[0];
+ if (unlikely(thread->init_command))
{
+ THD *thd = current_thd;
+ pthread_cond_t *cond = thd->mysys_var->current_cond;
+ pthread_mutex_t *mutex = thd->mysys_var->current_mutex;
/* wait for finishing init_command */
- pthread_mutex_lock(&spider_table_sts_threads[0].mutex);
- pthread_mutex_unlock(&spider_table_sts_threads[0].mutex);
+ pthread_mutex_lock(&thread->mutex);
+ if (unlikely(thread->init_command))
+ {
+ thd->mysys_var->current_cond = &thread->sync_cond;
+ thd->mysys_var->current_mutex = &thread->mutex;
+ pthread_cond_wait(&thread->sync_cond, &thread->mutex);
+ }
+ pthread_mutex_unlock(&thread->mutex);
+ thd->mysys_var->current_cond = cond;
+ thd->mysys_var->current_mutex = mutex;
+ if (thd->killed)
+ {
+ DBUG_RETURN(NULL);
+ }
}
#endif
DBUG_RETURN(new (mem_root) ha_spider(hton, table));
@@ -6998,6 +7017,13 @@ int spider_db_init(
#else
GetProcAddress(current_module, "?my_tz_SYSTEM@@3PAVTime_zone@@A");
#endif
+ spd_mysqld_server_started = (int *)
+ GetProcAddress(current_module, "?mysqld_server_started@@3HA");
+ spd_LOCK_server_started = (pthread_mutex_t *)
+ GetProcAddress(current_module,
+ "?LOCK_server_started@@3Ust_mysql_mutex@@A");
+ spd_COND_server_started = (pthread_cond_t *)
+ GetProcAddress(current_module, "?COND_server_started@@3Ust_mysql_cond@@A");
#else
#ifndef SPIDER_HAS_NEXT_THREAD_ID
spd_db_att_thread_id = &thread_id;
@@ -7020,6 +7046,9 @@ int spider_db_init(
spd_mysqld_port = &mysqld_port;
spd_abort_loop = &abort_loop;
spd_tz_system = my_tz_SYSTEM;
+ spd_mysqld_server_started = &mysqld_server_started;
+ spd_LOCK_server_started = &LOCK_server_started;
+ spd_COND_server_started = &COND_server_started;
#endif
#ifdef HAVE_PSI_INTERFACE
@@ -7357,39 +7386,9 @@ int spider_db_init(
}
}
}
-
-#ifndef WITHOUT_SPIDER_BG_SEARCH
- DBUG_PRINT("info",("spider before getting mutex"));
- pthread_mutex_lock(&spider_table_sts_threads[0].mutex);
- DBUG_PRINT("info",("spider after getting mutex"));
- if (spider_table_sts_threads[0].init_command)
- {
- if (spider_table_sts_threads[0].thd_wait)
- {
- pthread_cond_signal(&spider_table_sts_threads[0].cond);
- }
- spider_table_sts_threads[0].first_free_wait = TRUE;
- pthread_cond_wait(&spider_table_sts_threads[0].sync_cond,
- &spider_table_sts_threads[0].mutex);
- spider_table_sts_threads[0].first_free_wait = FALSE;
- if (spider_table_sts_threads[0].thd_wait)
- {
- pthread_cond_signal(&spider_table_sts_threads[0].cond);
- }
- }
- DBUG_PRINT("info",("spider before releasing mutex"));
- pthread_mutex_unlock(&spider_table_sts_threads[0].mutex);
- DBUG_PRINT("info",("spider after releasing mutex"));
- if (spider_table_sts_threads[0].error)
- {
- error_num = spider_table_sts_threads[0].error;
- goto error_init_sql;
- }
-#endif
DBUG_RETURN(0);
#ifndef WITHOUT_SPIDER_BG_SEARCH
-error_init_sql:
error_init_dbton:
for (roop_count--; roop_count >= 0; roop_count--)
{
@@ -10033,13 +10032,25 @@ void *spider_table_bg_sts_action(
tmp_disable_binlog(thd);
thd->security_ctx->skip_grants();
thd->client_capabilities |= CLIENT_MULTI_RESULTS;
- while (spider_init_queries[i + 2].length && !thd->killed)
+ if (!(*spd_mysqld_server_started) && !thd->killed)
+ {
+ pthread_mutex_lock(spd_LOCK_server_started);
+ thd->mysys_var->current_cond = spd_COND_server_started;
+ thd->mysys_var->current_mutex = spd_LOCK_server_started;
+ if (!(*spd_mysqld_server_started) && !thd->killed)
+ {
+ pthread_cond_wait(spd_COND_server_started, spd_LOCK_server_started);
+ }
+ pthread_mutex_unlock(spd_LOCK_server_started);
+ thd->mysys_var->current_cond = &thread->cond;
+ thd->mysys_var->current_mutex = &thread->mutex;
+ }
+ while (spider_init_queries[i].length && !thd->killed)
{
dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
(uint) spider_init_queries[i].length, FALSE, FALSE);
if (unlikely(thd->is_error()))
{
- thread->error = spider_stmt_da_sql_errno(thd);
fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
thd->clear_error();
break;
@@ -10048,42 +10059,14 @@ void *spider_table_bg_sts_action(
}
thd->mysys_var->current_cond = &thread->cond;
thd->mysys_var->current_mutex = &thread->mutex;
- DBUG_PRINT("info",("spider first_free_wait=%s",
- thread->first_free_wait ? "TRUE" : "FALSE"));
- if (!thread->first_free_wait && !thd->killed)
- {
- thread->thd_wait = TRUE;
- pthread_cond_wait(&thread->cond, &thread->mutex);
- thread->thd_wait = FALSE;
- }
- DBUG_ASSERT(thread->first_free_wait);
- pthread_cond_signal(&thread->sync_cond);
- if (!thd->killed)
- {
- thread->thd_wait = TRUE;
- pthread_cond_wait(&thread->cond, &thread->mutex);
- thread->thd_wait = FALSE;
- }
- if (likely(!thread->error))
- {
- while (spider_init_queries[i].length && !thd->killed)
- {
- dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
- (uint) spider_init_queries[i].length, FALSE, FALSE);
- if (unlikely(thd->is_error()))
- {
- fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
- thd->clear_error();
- break;
- }
- ++i;
- }
- }
- thd->mysys_var->current_cond = &thread->cond;
- thd->mysys_var->current_mutex = &thread->mutex;
thd->client_capabilities -= CLIENT_MULTI_RESULTS;
reenable_binlog(thd);
thread->init_command = FALSE;
+ pthread_cond_broadcast(&thread->sync_cond);
+ }
+ if (thd->killed)
+ {
+ thread->killed = TRUE;
}
if (thd->killed)
{