Skip to content

Commit c160a11

Browse files
MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table
Spider waits until the server initialization has been completed (i.e., mysqld_server_started has been set to 1) before creating the Spider system tables. Spider also wait until the system tables have been created before instantiating ha_spider. These waits leads to dead lock when a non-system Spider table is created by --in-file. This is because queries passed by --in-file are executed during the server initialization and creating the non-system Spider table causes an instantiation of ha_spider. In the first place, there seems to be no need for Spider to do such a synchronization. Thus, we simply remove the synchronization.
1 parent e967e81 commit c160a11

File tree

9 files changed

+64
-214
lines changed

9 files changed

+64
-214
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table
3+
#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--init-file=$MYSQL_TEST_DIR/../storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INSTALL SONAME 'ha_spider.so';
2+
USE test;
3+
CREATE TABLE t (c INT) ENGINE=SPIDER;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--echo #
2+
--echo # MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table
3+
--echo #

storage/spider/mysql-test/spider/include/deinit_spider.inc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`)
2020
if ($HAS_REWRITE)
2121
{
2222
DROP FUNCTION spider_flush_rewrite_cache;
23-
UNINSTALL PLUGIN spider_rewrite;
2423
DROP TABLE IF EXISTS mysql.spider_rewrite_tables;
2524
DROP TABLE IF EXISTS mysql.spider_rewrite_table_tables;
2625
DROP TABLE IF EXISTS mysql.spider_rewrite_table_partitions;
@@ -33,9 +32,7 @@ DROP FUNCTION spider_copy_tables;
3332
DROP FUNCTION spider_ping_table;
3433
DROP FUNCTION spider_bg_direct_sql;
3534
DROP FUNCTION spider_direct_sql;
36-
UNINSTALL PLUGIN spider_wrapper_protocols;
37-
UNINSTALL PLUGIN spider_alloc_mem;
38-
UNINSTALL PLUGIN spider;
35+
UNINSTALL SONAME "ha_spider.so";
3936
DROP TABLE IF EXISTS mysql.spider_xa;
4037
DROP TABLE IF EXISTS mysql.spider_xa_member;
4138
DROP TABLE IF EXISTS mysql.spider_xa_failed_log;

storage/spider/mysql-test/spider/include/init_spider.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let $VERSION_COMPILE_OS_WIN=
22
`SELECT IF(@@version_compile_os like 'Win%', 1, 0)`;
33
if ($VERSION_COMPILE_OS_WIN)
44
{
5-
INSTALL PLUGIN spider SONAME 'ha_spider.dll';
5+
INSTALL SONAME 'ha_spider.dll';
66
if ($MASTER_1_MYPORT)
77
{
88
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
@@ -76,7 +76,7 @@ if ($VERSION_COMPILE_OS_WIN)
7676
}
7777
if (!$VERSION_COMPILE_OS_WIN)
7878
{
79-
INSTALL PLUGIN spider SONAME 'ha_spider.so';
79+
INSTALL SONAME 'ha_spider.so';
8080
if ($MASTER_1_MYSOCK)
8181
{
8282
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (

storage/spider/spd_include.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ typedef struct st_spider_thread
324324
volatile bool killed;
325325
volatile bool thd_wait;
326326
volatile bool first_free_wait;
327-
volatile bool init_command;
328327
volatile int error;
329328
pthread_t thread;
330329
pthread_cond_t cond;

storage/spider/spd_init_query.h

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -662,82 +662,6 @@ static LEX_STRING spider_init_queries[] = {
662662
"create procedure mysql.spider_plugin_installer()"
663663
"begin"
664664
" set @win_plugin := IF(@@version_compile_os like 'Win%', 1, 0);"
665-
/*
666-
Install spider plugin
667-
*/
668-
/*
669-
" set @have_spider_i_s_plugin := 0;"
670-
" select @have_spider_i_s_plugin := 1 from INFORMATION_SCHEMA.plugins"
671-
" where PLUGIN_NAME = 'SPIDER';"
672-
" set @have_spider_plugin := 0;"
673-
" select @have_spider_plugin := 1 from mysql.plugin"
674-
" where name = 'spider';"
675-
" if @have_spider_i_s_plugin = 0 then"
676-
" if @have_spider_plugin = 1 then"
677-
" / *"
678-
" spider plugin is present in mysql.plugin but not in"
679-
" information_schema.plugins. Remove spider plugin entry"
680-
" in mysql.plugin first."
681-
" * /"
682-
" delete from mysql.plugin where name = 'spider';"
683-
" end if;"
684-
" if @win_plugin = 0 then "
685-
" install plugin spider soname 'ha_spider.so';"
686-
" else"
687-
" install plugin spider soname 'ha_spider.dll';"
688-
" end if;"
689-
" end if;"
690-
*/
691-
/*
692-
Install spider_alloc_mem plugin
693-
*/
694-
" set @have_spider_i_s_alloc_mem_plugin := 0;"
695-
" select @have_spider_i_s_alloc_mem_plugin := 1"
696-
" from INFORMATION_SCHEMA.plugins"
697-
" where PLUGIN_NAME = 'SPIDER_ALLOC_MEM';"
698-
" set @have_spider_alloc_mem_plugin := 0;"
699-
" select @have_spider_alloc_mem_plugin := 1 from mysql.plugin"
700-
" where name = 'spider_alloc_mem';"
701-
" if @have_spider_i_s_alloc_mem_plugin = 0 then"
702-
" if @have_spider_alloc_mem_plugin = 1 then"
703-
" /*"
704-
" spider_alloc_mem plugin is present in mysql.plugin but not in"
705-
" information_schema.plugins. Remove spider_alloc_mem plugin entry"
706-
" in mysql.plugin first."
707-
" */"
708-
" delete from mysql.plugin where name = 'spider_alloc_mem';"
709-
" end if;"
710-
" if @win_plugin = 0 then "
711-
" install plugin spider_alloc_mem soname 'ha_spider.so';"
712-
" else"
713-
" install plugin spider_alloc_mem soname 'ha_spider.dll';"
714-
" end if;"
715-
" end if;"
716-
/*
717-
Install spider_wrapper_protocols plugin
718-
*/
719-
" set @have_spider_i_s_wrapper_protocols_plugin := 0;"
720-
" select @have_spider_i_s_wrapper_protocols_plugin := 1"
721-
" from INFORMATION_SCHEMA.plugins"
722-
" where PLUGIN_NAME = 'SPIDER_WRAPPER_PROTOCOLS';"
723-
" set @have_spider_wrapper_protocols_plugin := 0;"
724-
" select @have_spider_wrapper_protocols_plugin := 1 from mysql.plugin"
725-
" where name = 'spider_wrapper_protocols';"
726-
" if @have_spider_i_s_wrapper_protocols_plugin = 0 then"
727-
" if @have_spider_wrapper_protocols_plugin = 1 then"
728-
" /*"
729-
" spider_wrapper_protocols plugin is present in mysql.plugin but not in"
730-
" information_schema.plugins. Remove spider_wrapper_protocols plugin entry"
731-
" in mysql.plugin first."
732-
" */"
733-
" delete from mysql.plugin where name = 'spider_wrapper_protocols';"
734-
" end if;"
735-
" if @win_plugin = 0 then "
736-
" install plugin spider_wrapper_protocols soname 'ha_spider.so';"
737-
" else"
738-
" install plugin spider_wrapper_protocols soname 'ha_spider.dll';"
739-
" end if;"
740-
" end if;"
741665
" set @have_spider_direct_sql_udf := 0;"
742666
" select @have_spider_direct_sql_udf := 1 from mysql.func"
743667
" where name = 'spider_direct_sql';"
@@ -798,60 +722,12 @@ static LEX_STRING spider_init_queries[] = {
798722
" soname 'ha_spider.dll';"
799723
" end if;"
800724
" end if;"
801-
" if @server_name = 'MariaDB' and"
802-
" ("
803-
" @server_major_version > 10 or"
804-
" ("
805-
" @server_major_version = 10 and"
806-
" @server_minor_version >= 8"
807-
" )"
808-
" )"
809-
" then"
810-
/*
811-
Install spider_rewrite plugin
812-
*/
813-
" set @have_spider_i_s_rewrite_plugin := 0;"
814-
" select @have_spider_i_s_rewrite_plugin := 1"
815-
" from INFORMATION_SCHEMA.plugins"
816-
" where PLUGIN_NAME = 'SPIDER_REWRITE';"
817-
" set @have_spider_rewrite_plugin := 0;"
818-
" select @have_spider_rewrite_plugin := 1 from mysql.plugin"
819-
" where name = 'spider_rewrite';"
820-
" if @have_spider_i_s_rewrite_plugin = 0 then"
821-
" if @have_spider_rewrite_plugin = 1 then"
822-
" /*"
823-
" spider_rewrite plugin is present in mysql.plugin but not in"
824-
" information_schema.plugins. Remove spider_rewrite plugin entry"
825-
" in mysql.plugin first."
826-
" */"
827-
" delete from mysql.plugin where name = 'spider_rewrite';"
828-
" end if;"
829-
" if @win_plugin = 0 then "
830-
" install plugin spider_rewrite soname 'ha_spider.so';"
831-
" else"
832-
" install plugin spider_rewrite soname 'ha_spider.dll';"
833-
" end if;"
834-
" end if;"
835-
" set @have_spider_flush_rewrite_cache_udf := 0;"
836-
" select @have_spider_flush_rewrite_cache_udf := 1 from mysql.func"
837-
" where name = 'spider_flush_rewrite_cache';"
838-
" if @have_spider_flush_rewrite_cache_udf = 0 then"
839-
" if @win_plugin = 0 then "
840-
" create function spider_flush_rewrite_cache returns int"
841-
" soname 'ha_spider.so';"
842-
" else"
843-
" create function spider_flush_rewrite_cache returns int"
844-
" soname 'ha_spider.dll';"
845-
" end if;"
846-
" end if;"
847-
" end if;"
848725
"end;"
849726
)},
850727
{C_STRING_WITH_LEN(
851728
"call mysql.spider_plugin_installer"
852729
)},
853730
{C_STRING_WITH_LEN(
854731
"drop procedure mysql.spider_plugin_installer"
855-
)},
856-
{C_STRING_WITH_LEN("")}
732+
)}
857733
};

storage/spider/spd_table.cc

Lines changed: 50 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ const char **spd_mysqld_unix_port;
129129
uint *spd_mysqld_port;
130130
bool volatile *spd_abort_loop;
131131
Time_zone *spd_tz_system;
132-
static int *spd_mysqld_server_started;
133-
static pthread_mutex_t *spd_LOCK_server_started;
134-
static pthread_cond_t *spd_COND_server_started;
135132
extern long spider_conn_mutex_id;
136133
handlerton *spider_hton_ptr;
137134
SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
@@ -7053,30 +7050,6 @@ handler* spider_create_handler(
70537050
MEM_ROOT *mem_root
70547051
) {
70557052
DBUG_ENTER("spider_create_handler");
7056-
#ifndef WITHOUT_SPIDER_BG_SEARCH
7057-
SPIDER_THREAD *thread = &spider_table_sts_threads[0];
7058-
if (unlikely(thread->init_command))
7059-
{
7060-
THD *thd = current_thd;
7061-
pthread_cond_t *cond = thd->mysys_var->current_cond;
7062-
pthread_mutex_t *mutex = thd->mysys_var->current_mutex;
7063-
/* wait for finishing init_command */
7064-
pthread_mutex_lock(&thread->mutex);
7065-
if (unlikely(thread->init_command))
7066-
{
7067-
thd->mysys_var->current_cond = &thread->sync_cond;
7068-
thd->mysys_var->current_mutex = &thread->mutex;
7069-
pthread_cond_wait(&thread->sync_cond, &thread->mutex);
7070-
}
7071-
pthread_mutex_unlock(&thread->mutex);
7072-
thd->mysys_var->current_cond = cond;
7073-
thd->mysys_var->current_mutex = mutex;
7074-
if (thd->killed)
7075-
{
7076-
DBUG_RETURN(NULL);
7077-
}
7078-
}
7079-
#endif
70807053
DBUG_RETURN(new (mem_root) ha_spider(hton, table));
70817054
}
70827055

@@ -7397,6 +7370,50 @@ int spider_panic(
73977370
DBUG_RETURN(0);
73987371
}
73997372

7373+
/*
7374+
Create or fix the system tables. See spd_init_query.h for the details.
7375+
*/
7376+
bool spider_init_system_tables()
7377+
{
7378+
DBUG_ENTER("spider_init_system_tables");
7379+
7380+
MYSQL *mysql= mysql_init(NULL);
7381+
if (!mysql)
7382+
{
7383+
DBUG_RETURN(TRUE);
7384+
}
7385+
7386+
if (!mysql_real_connect_local(mysql))
7387+
{
7388+
mysql_close(mysql);
7389+
DBUG_RETURN(TRUE);
7390+
}
7391+
7392+
int size= sizeof(spider_init_queries) / sizeof(spider_init_queries[0]);
7393+
for (int i= 0; i < size; i++)
7394+
{
7395+
if (mysql_real_query(mysql, spider_init_queries[i].str,
7396+
spider_init_queries[i].length))
7397+
{
7398+
fprintf(stderr,
7399+
"[ERROR] SPIDER plugin initialization failed at '%s' by '%s'\n",
7400+
spider_init_queries[i].str, mysql_error(mysql));
7401+
7402+
mysql_close(mysql);
7403+
DBUG_RETURN(TRUE);
7404+
}
7405+
7406+
if (MYSQL_RES *res= mysql_store_result(mysql))
7407+
{
7408+
mysql_free_result(res);
7409+
}
7410+
}
7411+
7412+
mysql_close(mysql);
7413+
7414+
DBUG_RETURN(FALSE);
7415+
}
7416+
74007417
int spider_db_init(
74017418
void *p
74027419
) {
@@ -7484,9 +7501,6 @@ int spider_db_init(
74847501
spd_mysqld_port = &mysqld_port;
74857502
spd_abort_loop = &abort_loop;
74867503
spd_tz_system = my_tz_SYSTEM;
7487-
spd_mysqld_server_started = &mysqld_server_started;
7488-
spd_LOCK_server_started = &LOCK_server_started;
7489-
spd_COND_server_started = &COND_server_started;
74907504

74917505
#ifdef HAVE_PSI_INTERFACE
74927506
init_spider_psi_keys();
@@ -7762,6 +7776,11 @@ int spider_db_init(
77627776
spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
77637777
}
77647778

7779+
if (spider_init_system_tables())
7780+
{
7781+
goto error_system_table_creation;
7782+
}
7783+
77657784
#ifndef WITHOUT_SPIDER_BG_SEARCH
77667785
if (!(spider_table_sts_threads = (SPIDER_THREAD *)
77677786
spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL),
@@ -7772,7 +7791,6 @@ int spider_db_init(
77727791
NullS))
77737792
)
77747793
goto error_alloc_mon_mutxes;
7775-
spider_table_sts_threads[0].init_command = TRUE;
77767794

77777795
for (roop_count = 0;
77787796
roop_count < (int) spider_param_table_sts_thread_count();
@@ -7863,6 +7881,7 @@ int spider_db_init(
78637881
error_init_udf_table_mon_cond:
78647882
for (; roop_count >= 0; roop_count--)
78657883
pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
7884+
error_system_table_creation:
78667885
roop_count = spider_param_udf_table_mon_mutex_count() - 1;
78677886
error_init_udf_table_mon_mutex:
78687887
for (; roop_count >= 0; roop_count--)
@@ -10478,57 +10497,6 @@ void *spider_table_bg_sts_action(
1047810497
trx->thd = thd;
1047910498
/* init end */
1048010499

10481-
if (thread->init_command)
10482-
{
10483-
uint i = 0;
10484-
tmp_disable_binlog(thd);
10485-
thd->security_ctx->skip_grants();
10486-
thd->client_capabilities |= CLIENT_MULTI_RESULTS;
10487-
if (!(*spd_mysqld_server_started) && !thd->killed)
10488-
{
10489-
pthread_mutex_lock(spd_LOCK_server_started);
10490-
thd->mysys_var->current_cond = spd_COND_server_started;
10491-
thd->mysys_var->current_mutex = spd_LOCK_server_started;
10492-
if (!(*spd_mysqld_server_started) && !thd->killed)
10493-
{
10494-
do
10495-
{
10496-
struct timespec abstime;
10497-
set_timespec_nsec(abstime, 1000);
10498-
error_num = pthread_cond_timedwait(spd_COND_server_started,
10499-
spd_LOCK_server_started, &abstime);
10500-
} while (
10501-
(error_num == ETIMEDOUT || error_num == ETIME) &&
10502-
!(*spd_mysqld_server_started) && !thd->killed && !thread->killed
10503-
);
10504-
}
10505-
pthread_mutex_unlock(spd_LOCK_server_started);
10506-
thd->mysys_var->current_cond = &thread->cond;
10507-
thd->mysys_var->current_mutex = &thread->mutex;
10508-
}
10509-
while (spider_init_queries[i].length && !thd->killed && !thread->killed)
10510-
{
10511-
dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
10512-
(uint) spider_init_queries[i].length);
10513-
if (unlikely(thd->is_error()))
10514-
{
10515-
fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
10516-
thd->clear_error();
10517-
break;
10518-
}
10519-
++i;
10520-
}
10521-
thd->mysys_var->current_cond = &thread->cond;
10522-
thd->mysys_var->current_mutex = &thread->mutex;
10523-
thd->client_capabilities -= CLIENT_MULTI_RESULTS;
10524-
reenable_binlog(thd);
10525-
thread->init_command = FALSE;
10526-
pthread_cond_broadcast(&thread->sync_cond);
10527-
}
10528-
if (thd->killed)
10529-
{
10530-
thread->killed = TRUE;
10531-
}
1053210500
if (thd->killed)
1053310501
{
1053410502
thread->killed = TRUE;

0 commit comments

Comments
 (0)