summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKentoku <kentokushiba@gmail.com>2019-08-01 04:25:22 +0900
committerKentoku <kentokushiba@gmail.com>2019-08-01 07:29:19 +0900
commit8c18af1754b4626902ec62ac69491ad3c58935c3 (patch)
treeb7eb4245209fcd9455ca8309c63b479ae2d20050
parent9ff663b6a8c3f2ed016c807e4d407918fd3ff47d (diff)
downloadmariadb-git-bb-10.4-MDEV-20179.tar.gz
MDEV-20179 Server hangs on shutdown during installation of Spiderbb-10.4-MDEV-20179
Use LOCK_server_started, COND_server_started and mysqld_server_started for waiting starting the server
-rw-r--r--sql/mysqld.cc2
-rw-r--r--storage/spider/spd_include.h4
-rw-r--r--storage/spider/spd_table.cc115
3 files changed, 50 insertions, 71 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index ae6334014a7..63d1d07cfaa 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5882,7 +5882,7 @@ int mysqld_main(int argc, char **argv)
/* Signal threads waiting for server to be started */
mysql_mutex_lock(&LOCK_server_started);
mysqld_server_started= 1;
- mysql_cond_signal(&COND_server_started);
+ mysql_cond_broadcast(&COND_server_started);
mysql_mutex_unlock(&LOCK_server_started);
MYSQL_SET_STAGE(0 ,__FILE__, __LINE__);
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index 6cd7ddfa181..cd468e486f4 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
@@ -293,7 +294,6 @@ typedef struct st_spider_thread
volatile bool thd_wait;
volatile bool first_free_wait;
volatile bool init_command;
- volatile int error;
pthread_t thread;
pthread_cond_t cond;
pthread_mutex_t mutex;
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index bc788d3e168..58d606bfe83 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,10 @@ 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)
{